Search in sources :

Example 1 with TenantRepository

use of org.wso2.carbon.bpmn.core.deployment.TenantRepository in project carbon-business-process by wso2.

the class BPMNDeploymentService method undeploy.

public void undeploy(String deploymentName) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine processEngine = BPMNServerHolder.getInstance().getEngine();
    DeploymentQuery query = processEngine.getRepositoryService().createDeploymentQuery();
    query = query.deploymentTenantId(tenantId.toString());
    query = query.deploymentNameLike("%" + deploymentName + "%");
    int deploymentCount = (int) query.count();
    log.info("Package " + deploymentName + " id going to be undeployed for the deployment count : " + deploymentCount);
    BPMNDeletableInstances bpmnDeletableInstances = new BPMNDeletableInstances();
    bpmnDeletableInstances.setTenantId(tenantId);
    List<Deployment> deployments = query.listPage(0, deploymentCount + 1);
    for (Deployment deployment : deployments) {
        aggregateRemovableProcessInstances(bpmnDeletableInstances, deployment.getId(), tenantId, processEngine);
    }
    if ((bpmnDeletableInstances.getActiveInstanceCount() + bpmnDeletableInstances.getCompletedInstanceCount()) > maximumDeleteCount) {
        String errorMessage = " Failed to un deploy the package. Please delete the instances before un deploying " + "the package";
        throw new BPSFault(errorMessage, new Exception(errorMessage));
    }
    deleteInstances(bpmnDeletableInstances, processEngine);
    TenantRepository tenantRepository = BPMNServerHolder.getInstance().getTenantManager().getTenantRepository(tenantId);
    tenantRepository.undeploy(deploymentName, false);
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment) Deployment(org.activiti.engine.repository.Deployment) TenantRepository(org.wso2.carbon.bpmn.core.deployment.TenantRepository) RegistryException(org.wso2.carbon.registry.api.RegistryException) IOException(java.io.IOException) ProcessEngine(org.activiti.engine.ProcessEngine) BPMNDeletableInstances(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances)

Example 2 with TenantRepository

use of org.wso2.carbon.bpmn.core.deployment.TenantRepository in project carbon-business-process by wso2.

the class BPMNDeployer method init.

/**
 * Initializes the deployment per tenant
 *
 * @param configurationContext axis2 configurationContext
 */
@Override
public void init(ConfigurationContext configurationContext) {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    log.info("Initializing BPMN Deployer for tenant " + tenantId + ".");
    try {
        File tenantRepoFolder = createTenantRepo(configurationContext);
        tenantRepository = BPMNServerHolder.getInstance().getTenantManager().createTenantRepository(tenantId);
        tenantRepository.setRepoFolder(tenantRepoFolder);
        // This is to check whether the user have added resolveDeploymentAtStartup system property to true if need
        // for resolving deployment to avoid inconsistencies
        boolean fixDeployments = true;
        if (System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP) != null && !Boolean.parseBoolean(System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP))) {
            fixDeployments = false;
            log.info("BPMN deployment inconsistencies will not resolved");
        }
        if (!isWorkerNode() && fixDeployments) {
            log.info("Resolving BPMN deployments to avoid inconsistencies");
            tenantRepository.fixDeployments();
        }
    } catch (BPSFault e) {
        String msg = "Tenant Error: " + tenantId;
        log.error(msg, e);
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) File(java.io.File)

Example 3 with TenantRepository

use of org.wso2.carbon.bpmn.core.deployment.TenantRepository in project carbon-business-process by wso2.

the class BPMNDeploymentService method getDeployedProcesses.

public BPMNProcess[] getDeployedProcesses() throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TenantRepository tenantRepository = BPMNServerHolder.getInstance().getTenantManager().getTenantRepository(tenantId);
    List<ProcessDefinition> processDefinitions = tenantRepository.getDeployedProcessDefinitions();
    BPMNProcess[] bpmnProcesses = new BPMNProcess[processDefinitions.size()];
    for (int i = 0; i < processDefinitions.size(); i++) {
        ProcessDefinition def = processDefinitions.get(i);
        BPMNProcess bpmnProcess = new BPMNProcess();
        bpmnProcess.setProcessId(def.getId());
        bpmnProcess.setDeploymentId(def.getDeploymentId());
        bpmnProcess.setKey(def.getKey());
        bpmnProcess.setVersion(def.getVersion());
        bpmnProcesses[i] = bpmnProcess;
    }
    return bpmnProcesses;
}
Also used : BPMNProcess(org.wso2.carbon.bpmn.core.mgt.model.BPMNProcess) TenantRepository(org.wso2.carbon.bpmn.core.deployment.TenantRepository) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Aggregations

BPSFault (org.wso2.carbon.bpmn.core.BPSFault)2 TenantRepository (org.wso2.carbon.bpmn.core.deployment.TenantRepository)2 File (java.io.File)1 IOException (java.io.IOException)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 Deployment (org.activiti.engine.repository.Deployment)1 DeploymentQuery (org.activiti.engine.repository.DeploymentQuery)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 BPMNDeletableInstances (org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances)1 BPMNDeployment (org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment)1 BPMNProcess (org.wso2.carbon.bpmn.core.mgt.model.BPMNProcess)1 RegistryException (org.wso2.carbon.registry.api.RegistryException)1