Search in sources :

Example 1 with BpelDAOConnection

use of org.apache.ode.bpel.dao.BpelDAOConnection in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method getFailedActivitiesForInstance.

/**
 * Get Failed Activities for give instance id.
 *
 * @param instanceID
 * @return
 * @throws InstanceManagementException
 */
@Override
public ActivityRecoveryInfoType[] getFailedActivitiesForInstance(final long instanceID) throws InstanceManagementException {
    try {
        isOperationIsValidForTheCurrentTenant(instanceID);
    } catch (IllegalAccessException ex) {
        handleError(ex);
    }
    ActivityRecoveryInfoType[] activityRecoveryInfoTypes = null;
    try {
        BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
        Object result = bpelDb.exec(new BpelDatabase.Callable<Object>() {

            public Object run(BpelDAOConnection conn) throws InstanceManagementException {
                ProcessInstanceDAO instance = conn.getInstance(instanceID);
                Collection<ActivityRecoveryDAO> activityRecoveries = instance.getActivityRecoveries();
                return activityRecoveries;
            }
        });
        ArrayList<ActivityRecoveryDAO> activityRecoveryDAOs = (ArrayList<ActivityRecoveryDAO>) result;
        if (activityRecoveryDAOs != null) {
            activityRecoveryInfoTypes = new ActivityRecoveryInfoType[activityRecoveryDAOs.size()];
            for (int i = 0; i < activityRecoveryDAOs.size(); i++) {
                ActivityRecoveryDAO activityRecovery = activityRecoveryDAOs.get(i);
                ActivityRecoveryInfoType info = new ActivityRecoveryInfoType();
                info.setActions(activityRecovery.getActions());
                info.setActivityID(activityRecovery.getActivityId());
                info.setDateTime(String.valueOf(activityRecovery.getDateTime()));
                info.setInstanceID(instanceID);
                info.setReason(activityRecovery.getReason());
                info.setRetires(activityRecovery.getRetries());
                activityRecoveryInfoTypes[i] = info;
            }
        }
    } catch (Exception e) {
        String errMsg = "Error occurred while retrieving failed activity information for instance id " + instanceID;
        log.error(errMsg, e);
        throw new InstanceManagementException(errMsg, e);
    }
    return activityRecoveryInfoTypes;
}
Also used : BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) ArrayList(java.util.ArrayList) ActivityRecoveryInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityRecoveryInfoType) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) ProcessNotFoundException(org.apache.ode.bpel.pmapi.ProcessNotFoundException) InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) ProcessingException(org.apache.ode.bpel.pmapi.ProcessingException) InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) ActivityRecoveryDAO(org.apache.ode.bpel.dao.ActivityRecoveryDAO) Collection(java.util.Collection)

Example 2 with BpelDAOConnection

use of org.apache.ode.bpel.dao.BpelDAOConnection in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method getInstanceInformationWithEvents.

private InstanceInfoWithEventsType getInstanceInformationWithEvents(final long iid) throws InstanceManagementException {
    final InstanceInfoWithEventsType instanceInfoWithEvents = new InstanceInfoWithEventsType();
    instanceInfoWithEvents.setIid(Long.toString(iid));
    dbexec(new BpelDatabase.Callable<Object>() {

        public Object run(BpelDAOConnection conn) throws InstanceManagementException {
            ProcessInstanceDAO instance = conn.getInstanceEagerly(iid, true);
            if (instance == null) {
                String errMsg = "Instance " + iid + " not found.";
                log.error(errMsg);
                throw new InstanceManagementException(errMsg);
            }
            fillInstanceInfoWithEvents(instanceInfoWithEvents, instance);
            return null;
        }
    });
    return instanceInfoWithEvents;
}
Also used : InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) InstanceInfoWithEventsType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.InstanceInfoWithEventsType)

Example 3 with BpelDAOConnection

use of org.apache.ode.bpel.dao.BpelDAOConnection in project carbon-business-process by wso2.

the class Utils method getInstanceCountForProcess.

/**
 * Return the instances in the given processes list
 *
 * @param processesInPackage
 * @return Instance count
 * @throws ManagementException
 */
public static long getInstanceCountForProcess(List<QName> processesInPackage) throws ManagementException {
    if (processesInPackage != null) {
        String filter = null;
        for (QName q : processesInPackage) {
            if (filter == null) {
                filter = "pid=" + q.toString();
            } else {
                filter += "|" + q.toString();
            }
        }
        try {
            final InstanceFilter instanceFilter = new InstanceFilter(filter);
            long count = (long) dbexec(new BpelDatabase.Callable<Object>() {

                public Object run(BpelDAOConnection conn) {
                    return conn.instanceCount(instanceFilter);
                }
            });
            return count;
        } catch (Exception e) {
            String errMsg = "Exception during instance count for deletion. Filter: " + filter;
            throw new ManagementException(errMsg, e);
        }
    } else {
        return 0;
    }
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) QName(javax.xml.namespace.QName) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with BpelDAOConnection

use of org.apache.ode.bpel.dao.BpelDAOConnection in project carbon-business-process by wso2.

the class ProcessManagementServiceSkeleton method addInstanceSummaryEntry.

private void addInstanceSummaryEntry(InstanceSummary instSum, ProcessConf pconf, InstanceStatus state) throws ProcessManagementException {
    Instances_type0 instances = new Instances_type0();
    instances.setState(state);
    String queryStatus = InstanceFilter.StatusKeys.valueOf(state.toString()).toString().toLowerCase();
    final InstanceFilter instanceFilter = new InstanceFilter("status=" + queryStatus + " pid=" + pconf.getProcessId());
    int count = dbexec(new BpelDatabase.Callable<Integer>() {

        public Integer run(BpelDAOConnection conn) throws Exception {
            return conn.instanceCount(instanceFilter).intValue();
        }
    });
    instances.setCount(count);
    instSum.addInstances(instances);
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) Instances_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.Instances_type0) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) XMLStreamException(javax.xml.stream.XMLStreamException) ParseException(java.text.ParseException) ProcessManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.ProcessManagementException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 5 with BpelDAOConnection

use of org.apache.ode.bpel.dao.BpelDAOConnection in project carbon-business-process by wso2.

the class ProcessManagementServiceSkeleton method addFailuresToInstanceSummary.

private void addFailuresToInstanceSummary(final InstanceSummary instSum, ProcessConf pconf) throws ProcessManagementException {
    final FailuresInfo failureInfo = new FailuresInfo();
    String queryStatus = InstanceFilter.StatusKeys.valueOf(TInstanceStatus.ACTIVE.toString()).toString().toLowerCase();
    final InstanceFilter instanceFilter = new InstanceFilter("status=" + queryStatus + " pid=" + pconf.getProcessId());
    dbexec(new BpelDatabase.Callable<Void>() {

        public Void run(BpelDAOConnection conn) throws Exception {
            Date lastFailureDt = null;
            int failureInstances = 0;
            for (ProcessInstanceDAO instance : conn.instanceQuery(instanceFilter)) {
                int count = instance.getActivityFailureCount();
                if (count > 0) {
                    ++failureInstances;
                    Date failureDt = instance.getActivityFailureDateTime();
                    if (lastFailureDt == null || lastFailureDt.before(failureDt)) {
                        lastFailureDt = failureDt;
                    }
                }
            }
            if (failureInstances > 0) {
                failureInfo.setCount(failureInstances);
                failureInfo.setFailureDate(AdminServiceUtils.toCalendar(lastFailureDt));
                instSum.setFailures(failureInfo);
            }
            return null;
        }
    });
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) FailuresInfo(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.FailuresInfo) XMLStreamException(javax.xml.stream.XMLStreamException) ParseException(java.text.ParseException) ProcessManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.ProcessManagementException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)14 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)13 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)11 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)10 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)9 Collection (java.util.Collection)6 ProcessNotFoundException (org.apache.ode.bpel.pmapi.ProcessNotFoundException)6 ProcessingException (org.apache.ode.bpel.pmapi.ProcessingException)6 IOException (java.io.IOException)4 TenantProcessStoreImpl (org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)4 ArrayList (java.util.ArrayList)3 FileNotFoundException (java.io.FileNotFoundException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ParseException (java.text.ParseException)2 LinkedList (java.util.LinkedList)2 QName (javax.xml.namespace.QName)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 ActivityRecoveryDAO (org.apache.ode.bpel.dao.ActivityRecoveryDAO)2 ProcessConf (org.apache.ode.bpel.iapi.ProcessConf)2 ManagementException (org.apache.ode.bpel.pmapi.ManagementException)2