Search in sources :

Example 76 with Collection

use of org.wso2.carbon.registry.core.Collection 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)

Example 77 with Collection

use of org.wso2.carbon.registry.core.Collection 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 78 with Collection

use of org.wso2.carbon.registry.core.Collection 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 79 with Collection

use of org.wso2.carbon.registry.core.Collection in project carbon-business-process by wso2.

the class BPELPackageRepository method createBPELPackageParentCollectionWithProperties.

/**
 * Create parent collection to persisting BPEL package information. For example, if you deploy
 * a BPEL archive called 'HelloWorld.zip', we store information of that package in collection
 * named 'HelloWorld'. This will be the root for 'HelloWorld' BPEL package information and
 * there will several versions of this BPEL package in this registry collection which relates
 * to the versions deployed in BPEL engine.
 *
 * @param deploymentContext containing information on current deployment
 * @throws RegistryException        when there is a error accessing registry
 * @throws IOException              if file access error occurred during MD5 checksum generation
 * @throws NoSuchAlgorithmException when there is a error during MD5 generation
 */
private void createBPELPackageParentCollectionWithProperties(BPELDeploymentContext deploymentContext) throws RegistryException, IOException, NoSuchAlgorithmException {
    Collection bpelPackage = configRegistry.newCollection();
    bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_CHECKSUM, Utils.getMD5Checksum(deploymentContext.getBpelArchive()));
    if (log.isDebugEnabled()) {
        log.debug(deploymentContext.getBpelPackageName() + " updating checksum: " + Utils.getMD5Checksum(deploymentContext.getBpelArchive()) + " in registry");
    }
    if (deploymentContext.isFailed()) {
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_FAILED);
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_ERROR_LOG, deploymentContext.getDeploymentFailureCause());
    // bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_STACK_TRACE,
    // ExceptionUtils.getStackTrace(deploymentContext.getStackTrace()));
    } else {
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_DEPLOYED);
    }
    bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_VERSION, Long.toString(deploymentContext.getVersion()));
    configRegistry.put(BPELPackageRepositoryUtils.getResourcePathForBPELPackage(deploymentContext), bpelPackage);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Example 80 with Collection

use of org.wso2.carbon.registry.core.Collection in project carbon-business-process by wso2.

the class BPELPackageRepository method createCollectionWithBPELPackageWithoutContentForCurrentVersion.

/**
 * This repository persist the BPEL package versions inside the BPEL Package collection
 * under the child collection 'versions'. The collection name is same as directory with version
 * attached to it's name(Example: HelloWorld-3).
 * <p/>
 * For the 'HelloWorld' BPEL package, extracted BPEL package will be stored in a registry
 * location like '<config_registry_root>/bpel/packages/HelloWorld/versions/HelloWorld-3'.
 *
 * @param deploymentContext containing information on current BPEL deployment.
 * @throws RegistryException if an error occurred during import of file system content to
 *                           registry.
 */
private void createCollectionWithBPELPackageWithoutContentForCurrentVersion(BPELDeploymentContext deploymentContext) throws RegistryException {
    String collectionLocation = BPELPackageRepositoryUtils.getResourcePathForBPELPackageContent(deploymentContext);
    Collection collection = configRegistry.newCollection();
    configRegistry.put(collectionLocation, collection);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Aggregations

Collection (org.wso2.carbon.registry.core.Collection)45 Resource (org.wso2.carbon.registry.core.Resource)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Test (org.junit.Test)24 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)23 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)20 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 ArrayList (java.util.ArrayList)17 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)17 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)16 FileInputStream (java.io.FileInputStream)14 OMElement (org.apache.axiom.om.OMElement)13 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)13 Collection (java.util.Collection)11 CollectionImpl (org.wso2.carbon.registry.core.CollectionImpl)11 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)11 File (java.io.File)10