Search in sources :

Example 41 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.

the class HumanTaskAppDeployer method undeployArtifacts.

/**
 * Check the artifact type and if it is a HumanTask, delete the file from the HumanTask
 * deployment hot folder
 *
 * @param carbonApp  - CarbonApplication instance to check for HumanTask artifacts
 * @param axisConfig - - axisConfig of the current tenant
 */
public void undeployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) {
    List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
    // loop through all dependencies
    for (Artifact.Dependency dep : artifacts) {
        Deployer deployer;
        Artifact artifact = dep.getArtifact();
        if (artifact == null) {
            continue;
        }
        if (HUMANTASK_TYPE.equals(artifact.getType())) {
            deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, HUMANTASK_DIR, "zip");
        } else {
            continue;
        }
        List<CappFile> files = artifact.getFiles();
        if (files.size() != 1) {
            log.error("A HumanTask artifact must have a single file. But " + files.size() + " files found.");
            continue;
        }
        if (deployer != null && AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED.equals(artifact.getDeploymentStatus())) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            try {
                deployer.undeploy(artifactPath);
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_PENDING);
            } catch (DeploymentException e) {
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                log.error("Error occured while trying to un deploy : " + artifact.getName());
            }
        }
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) Artifact(org.wso2.carbon.application.deployer.config.Artifact) Deployer(org.apache.axis2.deployment.Deployer) CappFile(org.wso2.carbon.application.deployer.config.CappFile)

Example 42 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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 43 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method isOperationIsValidForTheCurrentTenant.

/**
 * Check whether the instance belongs to the current tenant. If not, don't allow any operations.
 *
 * @param iid instance id
 * @throws IllegalAccessException if instance doesn't belong to the current tenant
 * @throws ProcessingException    if there a error getting instance data
 * @throws InstanceManagementException if the processId does not exist
 */
private void isOperationIsValidForTheCurrentTenant(final long iid) throws IllegalAccessException, ProcessingException, InstanceManagementException {
    QName processId = getProcess(iid);
    TenantProcessStoreImpl processStore = getTenantProcessForCurrentSession();
    if (processId != null) {
        if (!processStore.containsProcess(processId)) {
            log.error("Trying to invoke a illegal operation. Instance ID:" + iid);
            throw new IllegalAccessException("Operation is not permitted.");
        }
    } else {
        throw new InstanceManagementException("Process instance for instance ID " + iid + " does not exist");
    }
}
Also used : InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) QName(javax.xml.namespace.QName) TenantProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)

Example 44 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method resumeInstance.

/**
 * Resume a suspended instance
 *
 * @param iid Instance Id
 * @throws InstanceManagementException If the instance cannot be resumed due to the
 *                                     unavailability of Debugger support
 */
public void resumeInstance(long iid) throws InstanceManagementException {
    try {
        isOperationIsValidForTheCurrentTenant(iid);
    } catch (IllegalAccessException ex) {
        handleError(ex);
    }
    /*
        We need debugger support in order to resume (since we have to force
        a reduction. If one is not available the getDebugger() method should
        throw a ProcessingException
        */
    DebuggerSupport debugSupport = getDebugger(iid);
    if (debugSupport == null) {
        String errMsg = "Cannot resume the instance " + iid + ", Debugger support not available";
        log.error(errMsg);
        throw new InstanceManagementException(errMsg);
    }
    debugSupport.resume(iid);
}
Also used : InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) DebuggerSupport(org.apache.ode.bpel.engine.DebuggerSupport)

Example 45 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method fillFaultAndFailure.

/**
 * Use fillFaultAndFailure(ProcessInstanceDAO, InstanceInfoType) to fill the
 * instanceInfoWithEvents
 *
 * @param instance               Process Instance DAO
 * @param instanceInfoWithEvents Instance info with events
 */
private void fillFaultAndFailure(ProcessInstanceDAO instance, InstanceInfoWithEventsType instanceInfoWithEvents) {
    InstanceInfoType instanceInfo = new InstanceInfoType();
    fillFaultAndFailure(instance, instanceInfo);
    if (instance.getFault() != null) {
        instanceInfoWithEvents.setFaultInfo(instanceInfo.getFaultInfo());
    }
    if (instance.getActivityFailureCount() > 0) {
        instanceInfoWithEvents.setFailuresInfo(instanceInfo.getFailuresInfo());
    }
}
Also used : InstanceInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.InstanceInfoType) LimitedInstanceInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedInstanceInfoType)

Aggregations

ArrayList (java.util.ArrayList)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)20 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)15 RuntimeService (org.activiti.engine.RuntimeService)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)14 Produces (javax.ws.rs.Produces)13 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)13 IOException (java.io.IOException)12 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)12 GET (javax.ws.rs.GET)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8