Search in sources :

Example 1 with InstanceFilter

use of org.apache.ode.bpel.common.InstanceFilter 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 2 with InstanceFilter

use of org.apache.ode.bpel.common.InstanceFilter 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 3 with InstanceFilter

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

Example 4 with InstanceFilter

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

use of org.apache.ode.bpel.common.InstanceFilter in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method deleteInstances.

/**
 * Delete Instances that matches the filter
 *
 * @param filter Instance filter
 * @return Number of instances deleted
 * @throws InstanceManagementException If the filter is invalid or an exception occurred during
 *                                     instance deletion
 */
public int deleteInstances(String filter, final boolean deleteMessageExchanges) throws InstanceManagementException {
    String tFilter = filter;
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
    if (isInvalidFilter(tFilter)) {
        String errMsg = "Invalid instance filter: " + tFilter;
        log.error(errMsg);
        throw new InstanceManagementException(errMsg);
    }
    if (!isSecureFilter(new InstanceFilter(tFilter), tenantProcessStore.getProcessConfigMap().keySet())) {
        String errMsg = "Instance deletion operation not permitted due to insecure filter: " + tFilter;
        log.error(errMsg);
        throw new InstanceManagementException(errMsg);
    }
    if (!tFilter.contains(" pid=")) {
        tFilter = tFilter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
    }
    final InstanceFilter instanceFilter = new InstanceFilter(tFilter);
    final List<Long> ret = new LinkedList<Long>();
    try {
        final int deletionBatchSize = BPELServerImpl.getInstance().getBpelServerConfiguration().getBpelInstanceDeletionLimit();
        dbexec(new BpelDatabase.Callable<Object>() {

            public Object run(BpelDAOConnection conn) throws IllegalAccessException {
                Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
                // not delete other instances also.
                for (ProcessInstanceDAO instance : instances) {
                    isOperationIsValidForTheCurrentTenant(instance.getProcess().getProcessId());
                }
                int count = 1;
                for (ProcessInstanceDAO instance : instances) {
                    instance.delete(EnumSet.allOf(ProcessConf.CLEANUP_CATEGORY.class), deleteMessageExchanges);
                    ret.add(instance.getInstanceId());
                    count++;
                    // limiting number of instances that can be deleted to avoid timeout exceptions
                    if (count > deletionBatchSize) {
                        break;
                    }
                }
                return null;
            }
        });
    } catch (Exception e) {
        String errMsg = "Exception during instance deletion. Filter: " + instanceFilter.toString();
        log.error(errMsg, e);
        throw new InstanceManagementException(errMsg, e);
    }
    return ret.size();
}
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) TenantProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl) LinkedList(java.util.LinkedList) 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) Collection(java.util.Collection)

Aggregations

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