Search in sources :

Example 6 with ProcessInstanceDAO

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

the class InstanceManagementServiceSkeleton method getInstanceInformation.

private InstanceInfoType getInstanceInformation(final long iid) throws InstanceManagementException {
    final InstanceInfoType instanceInfo = new InstanceInfoType();
    instanceInfo.setIid(Long.toString(iid));
    dbexec(new BpelDatabase.Callable<Object>() {

        public Object run(BpelDAOConnection conn) throws InstanceManagementException {
            ProcessInstanceDAO instance = conn.getInstanceEagerly(iid, false);
            if (instance == null) {
                String errMsg = "Instance " + iid + " not found.";
                log.error(errMsg);
                throw new InstanceManagementException(errMsg);
            }
            fillInstanceInfo(instanceInfo, instance);
            return null;
        }
    });
    return instanceInfo;
}
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) InstanceInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.InstanceInfoType) LimitedInstanceInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedInstanceInfoType)

Example 7 with ProcessInstanceDAO

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

the class InstanceManagementServiceSkeleton method getActivityLifeCycleEvents.

private ActivityLifeCycleEventsType getActivityLifeCycleEvents(final long iid) throws InstanceManagementException {
    final ActivityLifeCycleEventsType activityLifeCycleEvents = new ActivityLifeCycleEventsType();
    activityLifeCycleEvents.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);
            }
            fillActivityLifeCycleEvents(activityLifeCycleEvents, instance);
            return null;
        }
    });
    return activityLifeCycleEvents;
}
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) ActivityLifeCycleEventsType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityLifeCycleEventsType)

Example 8 with ProcessInstanceDAO

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

the class InstanceManagementServiceSkeleton method recoverActivity.

/**
 * Retry failed activity of an instance of a process
 *
 * @param iid    Instance ID
 * @param aid    Activity ID
 * @param action Action to perform
 */
public void recoverActivity(final long iid, final long aid, final Action_type1 action) throws InstanceManagementException {
    try {
        dbexec(new BpelDatabase.Callable<QName>() {

            public QName run(BpelDAOConnection conn) throws Exception {
                ProcessInstanceDAO instance = conn.getInstance(iid);
                if (instance == null) {
                    return null;
                }
                for (ActivityRecoveryDAO recovery : instance.getActivityRecoveries()) {
                    if (recovery.getActivityId() == aid) {
                        BpelProcess process = ((BpelEngineImpl) bpelServer.getODEBPELServer().getEngine())._activeProcesses.get(instance.getProcess().getProcessId());
                        if (process != null) {
                            if (action == Action_type1.cancel) {
                                process.recoverActivity(instance, recovery.getChannel(), aid, Action_type1.cancel.getValue(), null);
                                log.info("Activity retrying is canceled for activity: " + aid + " of instance: " + iid);
                            } else if (action == Action_type1.retry) {
                                process.recoverActivity(instance, recovery.getChannel(), aid, Action_type1.retry.getValue(), null);
                                log.info("Activity is retried for activity: " + aid + " of instance: " + iid);
                            } else {
                                log.warn("Invalid retry action: " + action + " for activity: " + aid + " of instance: " + iid);
                            // TODO process fault action
                            }
                            break;
                        }
                    }
                }
                return instance.getProcess().getProcessId();
            }
        });
    } catch (Exception e) {
        String errMsg = "Exception occurred while recovering the activity: " + aid + " of ths instance: " + iid + " action: " + action.getValue();
        log.error(errMsg, e);
        throw new InstanceManagementException(errMsg, e);
    }
}
Also used : InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) BpelEngineImpl(org.apache.ode.bpel.engine.BpelEngineImpl) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) QName(javax.xml.namespace.QName) BpelProcess(org.apache.ode.bpel.engine.BpelProcess) ActivityRecoveryDAO(org.apache.ode.bpel.dao.ActivityRecoveryDAO) 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)

Example 9 with ProcessInstanceDAO

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

the class InstanceManagementServiceSkeleton method getLongRunningInstances.

/**
 * Get long running instances with duration
 *
 * @param limit The maximum number of instances to be fetched
 * @return Long running instances
 * @throws InstanceManagementException When an error occurs
 */
public LimitedInstanceInfoType[] getLongRunningInstances(int limit) throws InstanceManagementException {
    final List<LimitedInstanceInfoType> longRunningInstances = new ArrayList<LimitedInstanceInfoType>();
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
    if (tenantProcessStore.getProcessConfigMap().size() <= 0) {
        return longRunningInstances.toArray(new LimitedInstanceInfoType[longRunningInstances.size()]);
    }
    String filter = "status=ACTIVE";
    if (!filter.contains(" pid=")) {
        filter = filter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
    }
    if (log.isDebugEnabled()) {
        log.debug("Instance Filter:" + filter);
    }
    String orderBy = "started";
    final InstanceFilter instanceFilter = new InstanceFilter(filter, orderBy, limit);
    try {
        BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
        bpelDb.exec(new BpelDatabase.Callable<Object>() {

            public Object run(BpelDAOConnection conn) throws InstanceManagementException {
                Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
                for (ProcessInstanceDAO piDAO : instances) {
                    longRunningInstances.add(createLimitedInstanceInfoObject(piDAO));
                }
                return null;
            }
        });
    } catch (Exception e) {
        String errMsg = "Error querying instances from database. Instance Filter:" + instanceFilter.toString();
        log.error(errMsg, e);
        throw new InstanceManagementException(errMsg, e);
    }
    return longRunningInstances.toArray(new LimitedInstanceInfoType[longRunningInstances.size()]);
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) ArrayList(java.util.ArrayList) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) TenantProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl) 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) LimitedInstanceInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedInstanceInfoType) Collection(java.util.Collection)

Example 10 with ProcessInstanceDAO

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

the class Utils method delete.

public static List<Long> delete(String filter) {
    log.info("Instance filter for instance deletion:" + filter);
    final InstanceFilter instanceFilter = new InstanceFilter(filter);
    final List<Long> ret = new LinkedList<Long>();
    try {
        dbexec(new BpelDatabase.Callable<Object>() {

            public Object run(BpelDAOConnection conn) {
                Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
                for (ProcessInstanceDAO instance : instances) {
                    instance.delete(EnumSet.allOf(ProcessConf.CLEANUP_CATEGORY.class), true);
                    ret.add(instance.getInstanceId());
                }
                return null;
            }
        });
    } catch (Exception e) {
        String errMsg = "Exception during instance deletion. Filter: " + filter;
        log.error(errMsg, e);
        throw new ManagementException(errMsg, e);
    }
    return ret;
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) LinkedList(java.util.LinkedList) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) Collection(java.util.Collection)

Aggregations

BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)11 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)11 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)11 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)9 Collection (java.util.Collection)6 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)6 ProcessNotFoundException (org.apache.ode.bpel.pmapi.ProcessNotFoundException)5 ProcessingException (org.apache.ode.bpel.pmapi.ProcessingException)5 TenantProcessStoreImpl (org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ActivityRecoveryDAO (org.apache.ode.bpel.dao.ActivityRecoveryDAO)2 ProcessConf (org.apache.ode.bpel.iapi.ProcessConf)2 LimitedInstanceInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedInstanceInfoType)2 PaginatedInstanceList (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList)2 FileNotFoundException (java.io.FileNotFoundException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1