Search in sources :

Example 1 with ActivityRecoveryDAO

use of org.apache.ode.bpel.dao.ActivityRecoveryDAO 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 ActivityRecoveryDAO

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

the class InstanceManagementServiceSkeleton method getActivitiesWithEvents.

private ActivitiesWithEvents_type0 getActivitiesWithEvents(ScopeDAO scope) {
    ActivitiesWithEvents_type0 activitiesWithEvents = new ActivitiesWithEvents_type0();
    Collection<ActivityRecoveryDAO> recoveries = scope.getProcessInstance().getActivityRecoveries();
    // List<BpelEvent> events = scope.listEvents();
    Set<EventDAOImpl> eventsEntities = ((ScopeDAOImpl) scope).getEvents();
    List<BpelEvent> events = new ArrayList<BpelEvent>();
    for (EventDAOImpl event : eventsEntities) {
        events.add(event.getEvent());
    }
    ActivityStateAndEventDocumentBuilder docBuilder = new ActivityStateAndEventDocumentBuilder();
    for (BpelEvent e : events) {
        docBuilder.onEvent(e);
    }
    for (ActivityInfoWithEventsDocument aweDoc : docBuilder.getActivitiesWithEvents()) {
        for (ActivityRecoveryDAO recovery : recoveries) {
            if (String.valueOf(recovery.getActivityId()).equals(aweDoc.getActivityInfoDoc().getActivityInfo().getAiid())) {
                TFailureInfo failure = aweDoc.getActivityInfoDoc().getActivityInfo().addNewFailure();
                failure.setReason(recovery.getReason());
                failure.setDtFailure(toCalendar(recovery.getDateTime()));
                failure.setActions(recovery.getActions());
                failure.setRetries(recovery.getRetries());
                aweDoc.getActivityInfoDoc().getActivityInfo().setStatus(TActivityStatus.FAILURE);
            }
        }
        ActivityInfoWithEventsType activityWE = new ActivityInfoWithEventsType();
        TActivityInfo actInfoDoc = aweDoc.getActivityInfoDoc().getActivityInfo();
        TEventInfoList evtInfoList = aweDoc.getEventInfoList().getEventInfoList();
        // add activityInfo
        // add event info
        ActivityInfoType activity = fillActivityInfo(new ActivityInfoType(), actInfoDoc);
        /*XmlOptions opt = new XmlOptions();
            opt = opt.setSaveOuter();*/
        EventInfoList eventList = fillEventInfo(new EventInfoList(), evtInfoList);
        activityWE.setActivityInfo(activity);
        activityWE.setActivityEventsList(eventList);
        activitiesWithEvents.addActivityInfoWithEvents(activityWE);
    }
    return activitiesWithEvents;
}
Also used : ActivitiesWithEvents_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivitiesWithEvents_type0) TEventInfoList(org.apache.ode.bpel.pmapi.TEventInfoList) ArrayList(java.util.ArrayList) ScopeDAOImpl(org.apache.ode.dao.jpa.ScopeDAOImpl) BpelEvent(org.apache.ode.bpel.evt.BpelEvent) TActivityInfo(org.apache.ode.bpel.pmapi.TActivityInfo) TFailureInfo(org.apache.ode.bpel.pmapi.TFailureInfo) ActivityInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityInfoType) EventInfoList(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.EventInfoList) TEventInfoList(org.apache.ode.bpel.pmapi.TEventInfoList) ActivityRecoveryDAO(org.apache.ode.bpel.dao.ActivityRecoveryDAO) ActivityStateAndEventDocumentBuilder(org.wso2.carbon.bpel.core.ode.integration.utils.ActivityStateAndEventDocumentBuilder) ActivityInfoWithEventsDocument(org.wso2.carbon.bpel.core.ode.integration.utils.ActivityInfoWithEventsDocument) ActivityInfoWithEventsType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityInfoWithEventsType) EventDAOImpl(org.apache.ode.dao.jpa.EventDAOImpl)

Example 3 with ActivityRecoveryDAO

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

the class InstanceManagementServiceSkeleton method getActivities.

private Activities_type0 getActivities(ScopeDAO scope) {
    Activities_type0 activities = new Activities_type0();
    Collection<ActivityRecoveryDAO> recoveries = scope.getProcessInstance().getActivityRecoveries();
    /*List<BpelEvent> events = scope.listEvents();*/
    Set<EventDAOImpl> eventsEntities = ((ScopeDAOImpl) scope).getEvents();
    List<BpelEvent> events = new ArrayList<BpelEvent>();
    for (EventDAOImpl event : eventsEntities) {
        events.add(event.getEvent());
    }
    ActivityStateDocumentBuilder b = new ActivityStateDocumentBuilder();
    for (BpelEvent e : events) {
        b.onEvent(e);
    }
    for (ActivityInfoDocument ai : b.getActivities()) {
        for (ActivityRecoveryDAO recovery : recoveries) {
            if (String.valueOf(recovery.getActivityId()).equals(ai.getActivityInfo().getAiid())) {
                TFailureInfo failure = ai.getActivityInfo().addNewFailure();
                failure.setReason(recovery.getReason());
                failure.setDtFailure(toCalendar(recovery.getDateTime()));
                failure.setActions(recovery.getActions());
                failure.setRetries(recovery.getRetries());
                ai.getActivityInfo().setStatus(TActivityStatus.FAILURE);
            }
        }
        ActivityInfoType activity = new ActivityInfoType();
        fillActivityInfo(activity, ai.getActivityInfo());
        activities.addActivityInfo(activity);
    }
    return activities;
}
Also used : ActivityInfoDocument(org.apache.ode.bpel.pmapi.ActivityInfoDocument) Activities_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.Activities_type0) ArrayList(java.util.ArrayList) ScopeDAOImpl(org.apache.ode.dao.jpa.ScopeDAOImpl) BpelEvent(org.apache.ode.bpel.evt.BpelEvent) ActivityStateDocumentBuilder(org.apache.ode.bpel.evtproc.ActivityStateDocumentBuilder) TFailureInfo(org.apache.ode.bpel.pmapi.TFailureInfo) ActivityInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityInfoType) ActivityRecoveryDAO(org.apache.ode.bpel.dao.ActivityRecoveryDAO) EventDAOImpl(org.apache.ode.dao.jpa.EventDAOImpl)

Example 4 with ActivityRecoveryDAO

use of org.apache.ode.bpel.dao.ActivityRecoveryDAO 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)

Aggregations

ActivityRecoveryDAO (org.apache.ode.bpel.dao.ActivityRecoveryDAO)4 ArrayList (java.util.ArrayList)3 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)2 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)2 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)2 BpelEvent (org.apache.ode.bpel.evt.BpelEvent)2 ProcessNotFoundException (org.apache.ode.bpel.pmapi.ProcessNotFoundException)2 ProcessingException (org.apache.ode.bpel.pmapi.ProcessingException)2 TFailureInfo (org.apache.ode.bpel.pmapi.TFailureInfo)2 EventDAOImpl (org.apache.ode.dao.jpa.EventDAOImpl)2 ScopeDAOImpl (org.apache.ode.dao.jpa.ScopeDAOImpl)2 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)2 ActivityInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityInfoType)2 Collection (java.util.Collection)1 QName (javax.xml.namespace.QName)1 BpelEngineImpl (org.apache.ode.bpel.engine.BpelEngineImpl)1 BpelProcess (org.apache.ode.bpel.engine.BpelProcess)1 ActivityStateDocumentBuilder (org.apache.ode.bpel.evtproc.ActivityStateDocumentBuilder)1 ActivityInfoDocument (org.apache.ode.bpel.pmapi.ActivityInfoDocument)1 TActivityInfo (org.apache.ode.bpel.pmapi.TActivityInfo)1