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;
}
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;
}
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;
}
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);
}
}
Aggregations