[jbpm-commits] JBoss JBPM SVN: r5533 - in projects/jopr-integration/trunk/src/main: java/org/rhq/plugins/jbpm4/connector and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Aug 25 09:08:28 EDT 2009


Author: jim.ma
Date: 2009-08-25 09:08:27 -0400 (Tue, 25 Aug 2009)
New Revision: 5533

Added:
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityDiscoveryComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ExceptionalJobComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryDiscoveryComponent.java
Modified:
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/JobComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDefComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDeploymentComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceDiscoveryComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/JBPMEngineConnection.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java
   projects/jopr-integration/trunk/src/main/resources/META-INF/rhq-plugin.xml
Log:
Added the component to monitor the process instance duration

Added: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityComponent.java	                        (rev 0)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.rhq.plugins.jbpm4;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.api.ProcessDefinition;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementDataTrait;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.plugins.jbpm4.connector.JBPMEngineConnection;
+
+public class ActivityComponent implements ResourceComponent<ProcessDefComponent> , MeasurementFacet {
+	private ResourceContext<ProcessDefComponent> resourceContext;
+	private Log log = LogFactory.getLog(this.getClass());
+	private String definitionId = null;
+	public void start(ResourceContext<ProcessDefComponent> resourceContext) {
+		definitionId = 	resourceContext.getParentResourceComponent().getResourceKey();
+		this.resourceContext = resourceContext;
+	    
+	}
+
+	public void stop() {
+	}
+
+	public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) {
+		for (MeasurementScheduleRequest request : metrics) {
+		if (request.getName().equals("avgDuration")) {
+			Map<String, Long> map = ActivityDiscoveryComponent.defActivityDurationMap.get(definitionId);
+			String activityName = resourceContext.getResourceKey();
+			Long duration = map.get(activityName);
+			MeasurementDataTrait value = new MeasurementDataTrait(request,
+					String.valueOf(duration));
+			report.addData(value);
+		}
+		if (request.getName().equals("name")) {
+			String activityName = resourceContext.getResourceKey();			
+			MeasurementDataTrait value = new MeasurementDataTrait(request,
+					String.valueOf(activityName));
+			report.addData(value);
+		}
+		}
+
+	}
+	
+	
+	public AvailabilityType getAvailability() {
+		ProcessDefinition processDef = getJBPMConnection().getProcessDefById(definitionId);
+		if (processDef != null) {
+			return AvailabilityType.UP;
+		}
+		return AvailabilityType.DOWN;	   
+	}
+
+	public JBPMEngineConnection getJBPMConnection() {
+		return resourceContext.getParentResourceComponent().getJBPMConnection();
+	}	
+}

Added: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityDiscoveryComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityDiscoveryComponent.java	                        (rev 0)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ActivityDiscoveryComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.rhq.plugins.jbpm4;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.plugins.jbpm4.connector.JBPMEngineConnection;
+
+public class ActivityDiscoveryComponent implements
+		ResourceDiscoveryComponent<ProcessDefComponent> {
+	public static Map<String, Map<String, Long>> defActivityDurationMap = new HashMap<String, Map<String, Long>>();
+	public Set<DiscoveredResourceDetails> discoverResources(
+			ResourceDiscoveryContext<ProcessDefComponent> context) {
+		Set<DiscoveredResourceDetails> activities = new java.util.HashSet<DiscoveredResourceDetails>();
+		String definitionId = context.getParentResourceContext()
+				.getResourceKey();
+		JBPMEngineConnection jbpmConnection = context
+				.getParentResourceComponent().getJBPMConnection();
+		if (defActivityDurationMap.containsKey(definitionId)) {
+			defActivityDurationMap.remove(definitionId);
+		}
+		Map<String, Long> activityDurationMap = jbpmConnection
+				.avgDurationPerActivity(definitionId);
+		defActivityDurationMap.put(definitionId, activityDurationMap);
+		if (activityDurationMap != null) {
+			Iterator<Entry<String, Long>> iterator = activityDurationMap
+					.entrySet().iterator();
+			while (iterator.hasNext()) {
+
+				Entry<String, Long> entry = iterator.next();
+				// activity name can be null?
+				String activityName = entry.getKey();
+
+				DiscoveredResourceDetails details = new DiscoveredResourceDetails(
+						context.getResourceType(), activityName, activityName,
+						null, activityName, null, null);
+				activities.add(details);
+			}
+		}
+		return activities;
+	}
+}
\ No newline at end of file

Added: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ExceptionalJobComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ExceptionalJobComponent.java	                        (rev 0)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ExceptionalJobComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.rhq.plugins.jbpm4;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.core.pluginapi.operation.OperationResult;
+/**
+ * @author ema at redhat.com
+ *
+ */
+public class ExceptionalJobComponent extends JobComponent implements OperationFacet {
+	 public OperationResult invokeOperation(String name, Configuration parameters) throws InterruptedException, Exception {
+		 OperationResult result = new OperationResult();
+		 if ("RETRY".equals(name.toUpperCase())) {
+			 jbpmConnection.executeJob(job.getId());
+		 }
+		 //TODO handle job exception message...
+		 if (result.getErrorMessage() == null) {
+			 result.setSimpleResult("Success");
+		 } else {
+		     result.setErrorMessage(job.getException());
+		     result.setSimpleResult("Failed");
+		 }
+		 return result;
+	 }
+}

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/JobComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/JobComponent.java	2009-08-25 09:12:29 UTC (rev 5532)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/JobComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -39,10 +39,10 @@
  *
  */
 public class JobComponent implements ResourceComponent , MeasurementFacet {
-	private ResourceContext resourceContext;
-	private Log log = LogFactory.getLog(this.getClass());
-	private Job job = null;
-    private JBPMEngineConnection jbpmConnection = null;
+	protected ResourceContext resourceContext;
+	protected Log log = LogFactory.getLog(this.getClass());
+	protected Job job = null;
+	protected JBPMEngineConnection jbpmConnection = null;
 	public void start(ResourceContext resourceContext) {
 		this.resourceContext = resourceContext;
 		if (resourceContext.getParentResourceComponent() instanceof ProcessEngineComponent) {

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDefComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDefComponent.java	2009-08-25 09:12:29 UTC (rev 5532)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDefComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -21,12 +21,14 @@
  */
 package org.rhq.plugins.jbpm4;
 
+import java.util.List;
 import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jbpm.api.ProcessDefinition;
 import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
 import org.rhq.core.domain.measurement.AvailabilityType;
 import org.rhq.core.domain.measurement.MeasurementDataTrait;
 import org.rhq.core.domain.measurement.MeasurementReport;
@@ -75,8 +77,12 @@
 				report.addData(value);
 			}
 			
+			if (request.getName().equals("avgPerProcessInstanceDuration")) {
+			    String duration = getAverageProcessInstanceDuration() == null ? "--" : String.valueOf(getAverageProcessInstanceDuration());
+				MeasurementDataTrait value = new MeasurementDataTrait(request, duration);
+				report.addData(value);
+			}				
 		}
-
 	}
 	
 	
@@ -97,7 +103,7 @@
 		String resourceTypeName = report.getResourceType().getName();
 		report.setResourceKey(resourceTypeName);
 		report.setResourceName(resourceTypeName);
-		ProcessInstance instance = jbpmConnection.startProcessInstance(this.resourceContext.getResourceKey());
+		ProcessInstance instance = jbpmConnection.startProcessInstance(resourceContext.getResourceKey());
 		if (instance == null) {
 			report.setStatus(CreateResourceStatus.FAILURE);
 			report.setErrorMessage("Failed to start process instance");
@@ -109,8 +115,18 @@
 	
 	public String getResourceKey() {
 		return this.resourceContext.getResourceKey();
+	}	
+	
+	public Long getAverageProcessInstanceDuration() {
+		List<HistoryProcessInstance> instances = this.jbpmConnection.getHistoryProcessInstances(this.getResourceKey(), null, null, false);
+	    Long sumDuration = 0L;
+	    for (HistoryProcessInstance instance : instances) {
+	    	sumDuration = sumDuration + instance.getDuration();
+	    }
+	    if (sumDuration > 0) {
+	    	return sumDuration/instances.size();
+	    }
+	    return null;
 	}
 	
-	
-	
 }

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDeploymentComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDeploymentComponent.java	2009-08-25 09:12:29 UTC (rev 5532)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessDeploymentComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -88,8 +88,7 @@
 			if (request.getName().equals("state")) {
 				MeasurementDataTrait value = new MeasurementDataTrait(request,String.valueOf(deployment.getState()));
 				report.addData(value);
-			}
-			
+			}		
 		}
 
 	}

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceDiscoveryComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceDiscoveryComponent.java	2009-08-25 09:12:29 UTC (rev 5532)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceDiscoveryComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -42,7 +42,7 @@
         ProcessDefComponent defComponent = context.getParentResourceComponent();
         List<ProcessInstance> instances = defComponent.getJBPMConnection().getProcessInstances(context.getParentResourceContext().getResourceKey());
 		for (ProcessInstance instance: instances) {
-			DiscoveredResourceDetails details = new DiscoveredResourceDetails(context.getResourceType(), String.valueOf(instance.getId()), instance.getId(), null, instance.getId(), null, null);
+			DiscoveredResourceDetails details = new DiscoveredResourceDetails(context.getResourceType(), String.valueOf(instance.getProcessInstance().getId()), instance.getId(), null, instance.getId(), null, null);
 			jbpmDefs.add(details);
 		}
 		return jbpmDefs;

Added: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryComponent.java	                        (rev 0)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.rhq.plugins.jbpm4;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.api.Execution;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementDataTrait;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.plugins.jbpm4.connector.JBPMEngineConnection;
+/**
+ * @author ema at redhat.com
+ *
+ */
+public class ProcessInstanceHistoryComponent implements ResourceComponent<ProcessDefComponent>, MeasurementFacet {
+	private Log log = LogFactory.getLog(this.getClass());
+	private JBPMEngineConnection jbpmConnection = null;
+    private HistoryProcessInstance instance = null;
+    private String instanceId;
+	public void start(ResourceContext<ProcessDefComponent> resourceContext) {
+		instanceId = resourceContext.getResourceKey();
+		jbpmConnection = resourceContext.getParentResourceComponent().getJBPMConnection();
+		List<HistoryProcessInstance> instanceList = jbpmConnection.getHistoryProcessInstances(null,instanceId,null, false);
+		instance = instanceList.get(0);		
+	}
+
+	public void stop() {
+	}
+
+	public AvailabilityType getAvailability() {
+		return AvailabilityType.UP;
+	}
+
+	public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) {
+		for (MeasurementScheduleRequest request : metrics) {
+			if (request.getName().equals("key")) {
+
+				MeasurementDataTrait value = new MeasurementDataTrait(request,
+						String.valueOf(instance.getKey()));
+				report.addData(value);
+			}
+			
+			if (request.getName().equals("processDefinitionId")) {
+
+				MeasurementDataTrait value = new MeasurementDataTrait(request,
+						String.valueOf(instance.getProcessDefinitionId()));
+				report.addData(value);
+			}
+			
+			if (request.getName().equals("processInstanceId")) {
+
+				MeasurementDataTrait value = new MeasurementDataTrait(request,
+						String.valueOf(instance.getProcessInstanceId()));
+				report.addData(value);
+			}
+			
+			if (request.getName().equals("duration")) {
+
+				MeasurementDataTrait value = new MeasurementDataTrait(request,
+						String.valueOf(instance.getDuration()));
+				report.addData(value);
+			}
+			
+			if (request.getName().equals("startTime")) {
+
+				MeasurementDataTrait value = new MeasurementDataTrait(request,
+						String.valueOf(instance.getStartTime()));
+				report.addData(value);
+			}
+			
+			
+			if (request.getName().equals("endTime")) {
+				MeasurementDataTrait value = new MeasurementDataTrait(request,
+						String.valueOf(instance.getEndTime()));
+				report.addData(value);
+			}
+
+			if (request.getName().equals("state")) {
+				MeasurementDataTrait value = new MeasurementDataTrait(request,
+						String.valueOf(instance.getState()));
+				report.addData(value);
+			}			
+			
+		}
+	}
+	
+	public JBPMEngineConnection getJBPMConnection() {
+		return this.jbpmConnection;
+	}
+}
+

Added: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryDiscoveryComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryDiscoveryComponent.java	                        (rev 0)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessInstanceHistoryDiscoveryComponent.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.rhq.plugins.jbpm4;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstanceQuery;
+
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+/**
+ * @author ema at redhat.com
+ *
+ */
+public class ProcessInstanceHistoryDiscoveryComponent implements ResourceDiscoveryComponent<ProcessDefComponent> {
+	public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<ProcessDefComponent> context) {
+
+		Set<DiscoveredResourceDetails> historyInstances = new java.util.HashSet<DiscoveredResourceDetails>();
+        ProcessDefComponent defComponent = context.getParentResourceComponent();
+        List<HistoryProcessInstance> historyProcessInstances = defComponent.getJBPMConnection().getHistoryProcessInstances(defComponent.getResourceKey(), null, HistoryProcessInstanceQuery.PROPERTY_STARTTIME, false);
+        for (HistoryProcessInstance instance: historyProcessInstances) {
+			DiscoveredResourceDetails details = new DiscoveredResourceDetails(context.getResourceType(), String.valueOf(instance.getProcessInstanceId()), "ProcessInstance-" + instance.getProcessInstanceId(), null, null, null, null);
+			historyInstances.add(details);
+		}
+		return historyInstances;
+	}
+
+}

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/JBPMEngineConnection.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/JBPMEngineConnection.java	2009-08-25 09:12:29 UTC (rev 5532)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/JBPMEngineConnection.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -28,6 +28,7 @@
 import org.jbpm.api.Deployment;
 import org.jbpm.api.ProcessDefinition;
 import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
 import org.jbpm.api.job.Job;
 /**
  * @author ema at redhat.com
@@ -48,4 +49,6 @@
 	public List<Job> queryJob(boolean timerOnly , boolean messageOnly, boolean exception, String processInstanceId);
 	Job getJob(String jobId);
 	Map<String, Long> avgDurationPerActivity(String processDefinitionId);
+	Job executeJob(String jobDbid);
+	List<HistoryProcessInstance> getHistoryProcessInstances(String definitionId, String processInstanceId, String orderBy, boolean orderAsc); 
 }

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java	2009-08-25 09:12:29 UTC (rev 5532)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java	2009-08-25 13:08:27 UTC (rev 5533)
@@ -40,7 +40,11 @@
 import org.jbpm.api.ProcessDefinition;
 import org.jbpm.api.ProcessEngine;
 import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstanceQuery;
 import org.jbpm.api.job.Job;
+import org.jbpm.pvm.internal.cmd.CommandService;
+import org.jbpm.pvm.internal.cmd.ExecuteJobCmd;
 /**
  * @author ema at redhat.com
  *
@@ -172,5 +176,29 @@
 	public Map<String, Long> avgDurationPerActivity(String processDefinitionId) {
 		return processEngine.getHistoryService().avgDurationPerActivity(processDefinitionId);
 	}
+	
+	public Job executeJob(String jobDbid) {
+		 CommandService commandService = processEngine.get(CommandService.class);
+		 return commandService.execute(new ExecuteJobCmd(jobDbid));
+	}
+	
+  	public List<HistoryProcessInstance> getHistoryProcessInstances(String definitionId, String processInstanceId, String orderBy, boolean orderAsc) {
+	   HistoryProcessInstanceQuery historyQuery = processEngine.getHistoryService().createHistoryProcessInstanceQuery();
+	   if (definitionId != null) {
+		   historyQuery.processDefinitionId(definitionId);
+	   }
+	   if (processInstanceId != null) {
+		   historyQuery.processInstanceId(processInstanceId);
+	   }
+	   
+	   if (orderBy != null && orderAsc) {
+		   historyQuery.orderAsc(orderBy);
+	   }
+	   if (orderBy != null && !orderAsc) {
+		   historyQuery.orderDesc(orderBy);
+	   }
+       return historyQuery.list();	   
+	}
 
+
 }

Modified: projects/jopr-integration/trunk/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- projects/jopr-integration/trunk/src/main/resources/META-INF/rhq-plugin.xml	2009-08-25 09:12:29 UTC (rev 5532)
+++ projects/jopr-integration/trunk/src/main/resources/META-INF/rhq-plugin.xml	2009-08-25 13:08:27 UTC (rev 5533)
@@ -73,7 +73,8 @@
 		</service>
 
 		<service name="Exceptional Jobs" discovery="ExceptionJobDiscoveryComponent"
-			class="JobComponent" subCategory="Jobs" description="JBPM exceptional jobs">
+			class="ExceptionalJobComponent" subCategory="Jobs" description="JBPM exceptional jobs">
+			<operation name="Retry" displayName="Retry" description="Retry this exceptional job" />
 			<metric property="id" displayName="id" dataType="trait"
 				displayType="summary" defaultOn="true" description="job id" />
 			<metric property="duedate" displayName="duedate" dataType="trait"
@@ -87,6 +88,7 @@
 				dataType="trait" displayType="summary" defaultOn="true" description="job isExclusive" />
 			<metric property="exception" displayName="exception" dataType="trait"
 				displayType="summary" defaultOn="true" description="job exception" />
+		    
 		</service>
 
 		<service name="Process Deployments" discovery="ProcessDeploymentDiscoveryComponent"
@@ -114,6 +116,11 @@
 			<metric property="description" displayName="description"
 				dataType="trait" displayType="summary" defaultOn="true"
 				description="Process definition id" />
+		    <metric property="avgPerProcessInstanceDuration" displayName="avgPerProcessInstanceDuration"
+				dataType="measurement" displayType="summary" defaultOn="true"
+				description="Average process instance duration" />	
+							
+				
 			<service name="Activies" discovery="ActivityDiscoveryComponent"
 				class="ActivityComponent" description="Process Activity">
 
@@ -124,6 +131,32 @@
 					displayType="summary" defaultOn="true" description="Activity average duration" />
 			</service>
 
+           <service name="Process Instance History" discovery="ProcessInstanceHistoryDiscoveryComponent"
+				class="ProcessInstanceHistoryComponent"  description="Process Instance History">
+
+				<metric property="key" displayName="key" dataType="trait"
+					displayType="summary" defaultOn="true" description="Process instance key" />
+
+				<metric property="processDefinitionId" displayName="processDefinitionId" dataType="trait"
+					displayType="summary" defaultOn="true" description="Process instance defnitionId" />
+
+				<metric property="processInstanceId" displayName="processInstanceId" dataType="trait"
+					displayType="summary" defaultOn="true" description="Process instance id" />
+
+				<metric property="duration" displayName="duration" dataType="trait"
+					displayType="summary" defaultOn="true" description="Process instance duration" />
+
+				<metric property="startTime" displayName="startTime"
+					dataType="trait" displayType="summary" defaultOn="true"
+					description="Process instance start time" />
+
+				<metric property="endTime" displayName="endTime" dataType="trait"
+					displayType="summary" defaultOn="true" description="Process instance end time" />
+					
+				<metric property="state" displayName="state" dataType="trait"
+					displayType="summary" defaultOn="true" description="Process instance state" />	
+			</service>
+
 			<service name="Process Instances" discovery="ProcessInstanceDiscoveryComponent"
 				class="ProcessInstanceComponent" createDeletePolicy="both"
 				creationDataType="configuration" description="Process Instance">



More information about the jbpm-commits mailing list