Author: jeff.yuchang
Date: 2011-04-11 09:21:03 -0400 (Mon, 11 Apr 2011)
New Revision: 1351
Modified:
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java
trunk/docs/docbook/userguide/src/main/en-US/module/riftsaw_restful_service.xml
trunk/samples/quickstart/management/src/org/jboss/riftsaw/management/ManagementClient.java
Log:
*RIFTSAW-370, replace the errai based services into RESTful services.
Modified:
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java
===================================================================
---
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java 2011-04-04
14:31:39 UTC (rev 1350)
+++
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java 2011-04-11
13:21:03 UTC (rev 1351)
@@ -5,24 +5,24 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManagerFactory;
import org.jboss.bpm.console.client.model.HistoryProcessInstanceRef;
+import org.jboss.bpm.console.client.model.ProcessDefinitionRef;
import org.jboss.bpm.console.server.plugin.ProcessHistoryPlugin;
import org.jboss.bpm.monitor.model.BPAFDataSource;
import org.jboss.bpm.monitor.model.DefaultBPAFDataSource;
import org.jboss.bpm.monitor.model.bpaf.Event;
import org.jboss.bpm.monitor.model.bpaf.State;
import org.jboss.bpm.monitor.model.bpaf.Tuple;
+import org.jboss.bpm.monitor.model.json.XYDataSetJSO;
+import org.jboss.bpm.monitor.model.metric.Grouping;
import org.jboss.bpm.monitor.model.metric.Timespan;
+import org.jboss.bpm.monitor.model.metric.TimespanFactory;
/**
* @author Jeff Yu
@@ -55,12 +55,7 @@
String definitionkey, String status, long starttime, long endtime,
String correlationkey) {
- String dkey = null;
- try {
- dkey = URLDecoder.decode(definitionkey, "UTF-8");
- } catch (UnsupportedEncodingException e1) {
- throw new IllegalStateException("Decode definition key of " + definitionkey
+ " failed.");
- }
+ String dkey = ModelAdaptor.decodeId(definitionkey);
List<Event> events = ds.getInstanceEvents(dkey, new Timespan(starttime, endtime,
"Custom"), getStatus(status));
List<String> instanceIds = null;
if (correlationkey != null && !("".equals(correlationkey.trim()))) {
@@ -110,8 +105,135 @@
return refs;
}
-
- private State getStatus(String status) {
+
+
+
+ public List<ProcessDefinitionRef> getProcessDefinitions() {
+ List<ProcessDefinitionRef> refs = new
ArrayList<ProcessDefinitionRef>();
+
+ List<String> keys = ds.getProcessDefinitions();
+
+ for (String id : keys) {
+ ProcessDefinitionRef ref = new ProcessDefinitionRef();
+ ref.setName(id);
+ ref.setId(ModelAdaptor.encodeId(id));
+
+ refs.add(ref);
+ }
+
+ return refs;
+ }
+
+ public List<String> getProcessInstanceKeys(String definitionId) {
+ String decodedId = ModelAdaptor.decodeId(definitionId);
+ return ds.getProcessInstances(decodedId);
+ }
+
+ public List<String> getActivityKeys(String instanceId) {
+ return ds.getActivityDefinitions(instanceId);
+ }
+
+ public List<String> getAllEvents(String instanceId) {
+ List<Event> events = ds.getPastActivities(instanceId);
+
+ List<String> result = new LinkedList<String>();
+ for (Event event: events) {
+ for (Tuple tuple : event.getDataElement()) {
+ if ("data".equals(tuple.getName())) {
+ result.add(tuple.getValue());
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public Set<String> getCompletedInstances(String definitionKey, long timestamp,
String timespan) {
+ return getInstances(definitionKey, timestamp, timespan, State.Closed_Completed);
+ }
+
+ public Set<String> getFailedInstances(String definitionKey, long timestamp,
String timespan) {
+
+ return getInstances(definitionKey, timestamp, timespan,
State.Closed_Completed_Failed);
+ }
+
+ public Set<String> getTerminatedInstances(String definitionKey, long timestamp,
String timespan) {
+ return getInstances(definitionKey, timestamp, timespan,
State.Closed_Cancelled_Terminated);
+ }
+
+ public String getCompletedInstances4Chart(String processDefinition, String
timespanValue) {
+ final Timespan timespan = TimespanFactory.fromValue(timespanValue);
+
+ List<Event> events = ds.getInstanceEvents(processDefinition, timespan,
State.Closed_Completed);
+
+ return createDatasetJSO(
+ new String[]{"Completed"}, timespan, true, events);
+ }
+
+ public String getFailedInstances4Chart(String processDefinition, String
timespanValue) {
+ final Timespan timespan = TimespanFactory.fromValue(timespanValue);
+
+ List<Event> completed = ds.getInstanceEvents(processDefinition, timespan,
State.Closed_Completed);
+ List<Event> failed = ds.getInstanceEvents(processDefinition, timespan,
State.Closed_Completed_Failed);
+ List<Event> terminated = ds.getInstanceEvents(processDefinition, timespan,
State.Closed_Cancelled_Terminated);
+
+ return createDatasetJSO(
+ new String[]{"Completed", "Failed",
"Terminated"}, timespan, true, completed, failed, terminated);
+ }
+
+
+ private Set<String> getInstances(String definitionKey, long timestamp, String
timespan, State completionState) {
+
+ String decodedId = ModelAdaptor.decodeId(definitionKey);
+
+ Set<String> instanceIds = new HashSet<String>();
+
+ Timespan chartTimespan = TimespanFactory.fromValue(timespan);
+ long[] bounds = TimespanFactory.getLeftBounds(chartTimespan, new
Date(timestamp));
+
+ List<Event> events = ds.getInstanceEvents(
+ decodedId,
+ new Timespan(bounds[0], bounds[1], chartTimespan.getUnit(),
"custom"),
+ completionState
+ );
+
+ // parity matched, only consider actual 'Closed_...' events
+ for(Event e : events)
+ {
+ if(e.getEventDetails().getCurrentState().equals(completionState))
+ instanceIds.add(e.getProcessInstanceID());
+ }
+
+ //Retrieve the Correlation information from the process instances.
+
+ Set<String> result = new HashSet<String>();
+
+ for (String instanceId : instanceIds) {
+ List<Event> theEvents = ds.getPastActivities(instanceId);
+ StringBuffer sbuffer = new StringBuffer();
+ sbuffer.append("Instance Id: " + instanceId + " ");
+ addCorrelationInformation(theEvents, sbuffer);
+ result.add(sbuffer.toString());
+ }
+
+ return result;
+ }
+
+
+ private void addCorrelationInformation(List<Event> theEvents, StringBuffer
sbuffer) {
+ for (Event theEvent : theEvents) {
+ if ("CORRELATION_SET_WRITE".equals(theEvent.getActivityName())) {
+ for (Tuple tuple : theEvent.getDataElement()) {
+ if ("correlation-key".equals(tuple.getName())) {
+ sbuffer.append(" Correlation key: ");
+ sbuffer.append(tuple.getValue());
+ }
+ }
+ }
+ }
+ }
+
+ private State getStatus(String status) {
if ("COMPLETED".equalsIgnoreCase(status)) {
return State.Closed_Completed;
}
@@ -124,4 +246,61 @@
return null;
}
+
+ private static String createDatasetJSO(String[] title, Timespan timespan, boolean
matchParity, List<Event>... events) {
+
+ XYDataSetJSO dataSet = new XYDataSetJSO(
+ title,
+ UUID.randomUUID().toString()
+ );
+
+ for(List<Event> subset : events)
+ {
+
+ SortedMap<Date, List<Event>> grouped = group(timespan, subset);
+
+ List<Long> domainData = new ArrayList<Long>(grouped.size());
+ List<Long> rangeData = new ArrayList<Long>(grouped.size());
+ for(Date d : grouped.keySet())
+ {
+ domainData.add(d.getTime());
+
+ // if parity matched datasets, then we get Open and Closed events.
+ int actualSize = matchParity ? grouped.get(d).size()/2 :
grouped.get(d).size();
+ rangeData.add(new Integer(actualSize).longValue());
+ }
+
+ dataSet.getDomain().add(domainData);
+ dataSet.getRange().add(rangeData);
+ }
+
+ dataSet.setAxis("date");
+
+ return dataSet.toJSO();
+ }
+
+ private static SortedMap<Date, List<Event>> group(Timespan timespan,
List<Event> events) {
+ SortedMap<Date, List<Event>> grouped;
+
+ switch (timespan.getUnit())
+ {
+ case HOUR:
+ grouped = Grouping.byHour(events, timespan);
+ break;
+ case DAY:
+ grouped = Grouping.byDay(events, timespan);
+ break;
+ case WEEK:
+ grouped = Grouping.byWeek(events, timespan);
+ break;
+ case MONTH:
+ grouped = Grouping.byMonth(events, timespan);
+ break;
+ default:
+ throw new IllegalArgumentException("UNIT not supported:
"+timespan.getUnit());
+
+ }
+ return grouped;
+ }
+
}
Modified: trunk/docs/docbook/userguide/src/main/en-US/module/riftsaw_restful_service.xml
===================================================================
---
trunk/docs/docbook/userguide/src/main/en-US/module/riftsaw_restful_service.xml 2011-04-04
14:31:39 UTC (rev 1350)
+++
trunk/docs/docbook/userguide/src/main/en-US/module/riftsaw_restful_service.xml 2011-04-11
13:21:03 UTC (rev 1351)
@@ -24,7 +24,16 @@
<tr><td colspan="5"><emphasis>Process Engine(Process runtime
state)</emphasis></td></tr>
<tr><td>GET</td><td>/gwt-console-server/rs/engine/deployments</td><td></td><td>*/*</td><td>application/json</td></tr>
<tr><td colspan="5"><emphasis>Process History(Process History
Service)</emphasis></td></tr>
-<tr><td>GET</td><td>/gwt-console-server/rs//history/search</td><td></td><td>*/*</td><td>applications/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definition/{id}/instances</td><td></td><td>*/*</td><td>applications/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definitions</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definition/{id}/instances</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/instance/{id}/activities</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/instance/{id}/events</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definition/{id}/instances/completed</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definition/{id}/instances/failed</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definition/{id}/instances/terminated</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definition/{id}/instances/chart/completed</td><td></td><td>*/*</td><td>application/json</td></tr>
+<tr><td>GET</td><td>/gwt-console-server/rs//history/definition/{id}/instances/chart/failed</td><td></td><td>*/*</td><td>application/json</td></tr>
</tbody>
</table>
</para>
Modified:
trunk/samples/quickstart/management/src/org/jboss/riftsaw/management/ManagementClient.java
===================================================================
---
trunk/samples/quickstart/management/src/org/jboss/riftsaw/management/ManagementClient.java 2011-04-04
14:31:39 UTC (rev 1350)
+++
trunk/samples/quickstart/management/src/org/jboss/riftsaw/management/ManagementClient.java 2011-04-11
13:21:03 UTC (rev 1351)
@@ -26,7 +26,7 @@
private static final String authentication_url =
"http://localhost:8080/gwt-console-server/rs/identity/secure/j_security_check";
- private static final String history_search_url =
"http://localhost:8080/gwt-console-server/rs/history/search";
+ private static final String history_search_url =
"http://localhost:8080/gwt-console-server/rs/history/definition/";
public void showAllDeployments() throws Exception {
System.out.println("-----------------------------");
@@ -84,13 +84,13 @@
public void getHistoricProcessInstance() throws Exception {
String processId =
"{http://www.jboss.org/bpel/examples}HelloGoodbye-1";
- String encodedId = URLEncoder.encode(processId, "UTF-8");
+ String encodedId = ModelAdaptor.encodeId(processId);
String status = "COMPLETED";
Long starttime = new java.util.Date(103, 1, 1).getTime();
Long endtime = new java.util.Date().getTime();
- String search_url = history_search_url + "?definitionkey=" + encodedId
+ "&status=" + status
+ String search_url = history_search_url + encodedId +
"/instances?status=" + status
+ "&starttime="+starttime +
"&endtime=" + endtime;
System.out.println("-----------------------------");