Search in sources :

Example 1 with BpelDatabase

use of org.apache.ode.bpel.engine.BpelDatabase 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 BpelDatabase

use of org.apache.ode.bpel.engine.BpelDatabase in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method getPaginatedInstanceList.

/**
 * Get paginated instance list
 *
 * @param filter Instance tFilter
 * @param order  The field on which to be ordered
 * @param limit  The maximum number of instances to be fetched
 * @param page   The page number
 * @return Instances that are filtered through "tFilter", ordered by "order" that fits into
 * 'page'th page
 * @throws InstanceManagementException When an error occurs
 */
public PaginatedInstanceList getPaginatedInstanceList(String filter, final String order, final int limit, final int page) throws InstanceManagementException {
    String tFilter = filter;
    final PaginatedInstanceList instanceList = new PaginatedInstanceList();
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
    if (tenantProcessStore.getProcessConfigMap().size() <= 0) {
        instanceList.setPages(0);
        return instanceList;
    }
    if (!tFilter.contains(" pid=")) {
        tFilter = tFilter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
    }
    if (log.isDebugEnabled()) {
        log.debug("Instance Filter:" + tFilter);
    }
    final InstanceFilter instanceFilter = new InstanceFilter(tFilter, order, 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);
                int pageNum = page;
                if (pageNum < 0 || pageNum == Integer.MAX_VALUE) {
                    pageNum = 0;
                }
                int startIndexOfCurrentPage = pageNum * BPELConstants.ITEMS_PER_PAGE;
                int endIndexOfCurrentPage = (pageNum + 1) * BPELConstants.ITEMS_PER_PAGE;
                int instanceListSize = instances.size();
                int pages = (int) Math.ceil((double) instanceListSize / BPELConstants.ITEMS_PER_PAGE);
                instanceList.setPages(pages);
                ProcessInstanceDAO[] instanceArray = instances.toArray(new ProcessInstanceDAO[instanceListSize]);
                for (int i = startIndexOfCurrentPage; (i < endIndexOfCurrentPage && i < instanceListSize); i++) {
                    instanceList.addInstance(createLimitedInstanceInfoObject(instanceArray[i]));
                }
                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 instanceList;
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) 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) PaginatedInstanceList(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList) InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) Collection(java.util.Collection)

Example 3 with BpelDatabase

use of org.apache.ode.bpel.engine.BpelDatabase in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method getInstanceCountByState.

private Long getInstanceCountByState(String processList, String instanceState) throws InstanceManagementException {
    if (isProcessListEmpty(processList)) {
        return (long) 0;
    }
    final List<Long> instanceCountList = new ArrayList<Long>();
    StringBuilder filter = new StringBuilder();
    if (!isProcessListEmpty(processList)) {
        filter.append(processList);
    }
    filter.append("status=");
    filter.append(instanceState);
    final InstanceFilter instanceFilter = new InstanceFilter(filter.toString(), null, Integer.MAX_VALUE);
    try {
        BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
        bpelDb.exec(new BpelDatabase.Callable<Object>() {

            public Object run(BpelDAOConnection conn) throws AxisFault {
                instanceCountList.add(conn.instanceCount(instanceFilter));
                return null;
            }
        });
    } catch (Exception e) {
        String errMsg = "Error querying instances from database. Filter: " + instanceFilter.toString();
        log.error(errMsg, e);
        throw new InstanceManagementException(errMsg, e);
    }
    return instanceCountList.get(0);
}
Also used : AxisFault(org.apache.axis2.AxisFault) 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) 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)

Example 4 with BpelDatabase

use of org.apache.ode.bpel.engine.BpelDatabase 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 5 with BpelDatabase

use of org.apache.ode.bpel.engine.BpelDatabase in project carbon-business-process by wso2.

the class Utils method dbexec.

/**
 * Execute a database transaction, unwrapping nested
 * {@link org.apache.ode.bpel.pmapi.ManagementException}s.
 *
 * @param callable action to run
 * @return object of type T
 * @throws org.apache.ode.bpel.pmapi.ManagementException if exception occurred during transaction
 */
private static <T> T dbexec(BpelDatabase.Callable<T> callable) throws ManagementException {
    try {
        BPELServerImpl bpelServer = (BPELServerImpl) BPELServiceComponent.getBPELServer();
        BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
        return bpelDb.exec(callable);
    } catch (ManagementException me) {
        // Passthrough.
        throw me;
    } catch (Exception ex) {
        log.error("Exception during database operation", ex);
        throw new ManagementException("Exception during database operation", ex);
    }
}
Also used : ManagementException(org.apache.ode.bpel.pmapi.ManagementException) BPELServerImpl(org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)6 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)5 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)5 Collection (java.util.Collection)4 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)4 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)4 ProcessNotFoundException (org.apache.ode.bpel.pmapi.ProcessNotFoundException)4 ProcessingException (org.apache.ode.bpel.pmapi.ProcessingException)4 ArrayList (java.util.ArrayList)3 TenantProcessStoreImpl (org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)3 PaginatedInstanceList (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PaginatedInstanceList)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 AxisFault (org.apache.axis2.AxisFault)1 ActivityRecoveryDAO (org.apache.ode.bpel.dao.ActivityRecoveryDAO)1 ManagementException (org.apache.ode.bpel.pmapi.ManagementException)1 BPELServerImpl (org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl)1 ActivityRecoveryInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ActivityRecoveryInfoType)1 LimitedInstanceInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedInstanceInfoType)1