Search in sources :

Example 16 with BPSFault

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

the class BPMNDeployer method createTenantRepo.

/**
 * @param configurationContext axis2 configurationContext
 * @return                     bpmn repo file
 * @throws BPSFault        repo creation failure will result in this xception
 */
private File createTenantRepo(ConfigurationContext configurationContext) throws BPSFault {
    String axisRepoPath = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(axisRepoPath)) {
        String msg = "URL Repositories are not supported: " + axisRepoPath;
        throw new BPSFault(msg);
    }
    File tenantsRepository = new File(axisRepoPath);
    File bpmnRepo = new File(tenantsRepository, BPMNConstants.BPMN_REPO_NAME);
    if (!bpmnRepo.exists()) {
        boolean status = bpmnRepo.mkdir();
        if (!status) {
            String msg = "Failed to create BPMN repository folder " + bpmnRepo.getAbsolutePath() + ".";
            throw new BPSFault(msg);
        }
    }
    return bpmnRepo;
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) File(java.io.File)

Example 17 with BPSFault

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

the class TenantRepository method fixDeployments.

/**
 * Information about BPMN deployments are recorded in 3 places:
 * Activiti database, Registry and the file system (deployment folder).
 * If information about a particular deployment is not recorded in all these 3 places, BPS may not work correctly.
 * Therefore, this method checks whether deployments are recorded in all these places and undeploys packages, if
 * they are missing in few places in an inconsistent way.
 * <p/>
 * As there are 3 places, there are 8 ways a package can be placed. These cases are handled as follows:
 * (1) Whenever a package is not in the deployment folder, it is undeploye (this covers 4 combinations).
 * (2) If a package is in all 3 places, it is a proper deployment and it is left untouched.
 * (3) If a package is only in the deployment folder, it is a new deployment. This will be handled by the deployer.
 * (4) If a package is in the deployment folder AND it is in either registry or Activiti DB (but not both), then it is an inconsistent deployment. This will be undeployed.
 */
// public void fixDeployments() {
// 
// // get all deployments in the deployment folder
// List<String> fileArchiveNames = new ArrayList<String>();
// File[] fileDeployments = repoFolder.listFiles();
// if (fileDeployments != null) {
// for (File fileDeployment : fileDeployments) {
// String deploymentName = FilenameUtils.getBaseName(fileDeployment.getName());
// fileArchiveNames.add(deploymentName);
// }
// } else {
// log.error("File deployments returned null for tenant" + tenantId);
// }
// 
// 
// // get all deployments in the Activiti DB
// List<String> activitiDeploymentNames = new ArrayList<String>();
// ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
// RepositoryService repositoryService = engine.getRepositoryService();
// List<Deployment> tenantDeployments =
// repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString())
// .list();
// for (Deployment deployment : tenantDeployments) {
// String deploymentName = deployment.getName();
// activitiDeploymentNames.add(deploymentName);
// }
// 
// // get all deployments in the registry
// List<String> metaDataDeploymentNames = new ArrayList<String>();
// List<DeploymentMetaDataModel> deploymentMetaDataModelList =
// activitiDAO.selectAllDeploymentModel();
// 
// int deploymentMetaDataModelListSize = deploymentMetaDataModelList.size();
// 
// for (int i = 0; i < deploymentMetaDataModelListSize; i++) {
// DeploymentMetaDataModel deploymentMetaDataModel =
// deploymentMetaDataModelList.get(i);
// 
// if (deploymentMetaDataModel != null) {
// String deploymentMetadataName = deploymentMetaDataModel.getPackageName();
// metaDataDeploymentNames.add(deploymentMetadataName);
// }
// }
// 
// // construct the union of all deployments
// Set<String> allDeploymentNames = new HashSet<String>();
// allDeploymentNames.addAll(fileArchiveNames);
// allDeploymentNames.addAll(activitiDeploymentNames);
// allDeploymentNames.addAll(metaDataDeploymentNames);
// 
// for (String deploymentName : allDeploymentNames) {
// 
// if (!(fileArchiveNames.contains(deploymentName))) {
// if (log.isDebugEnabled()) {
// log.debug(deploymentName +
// " has been removed from the deployment folder. Undeploying the package...");
// }
// undeploy(deploymentName, true);
// } else {
// if (activitiDeploymentNames.contains(deploymentName) &&
// !metaDataDeploymentNames.contains(deploymentName)) {
// if (log.isDebugEnabled()) {
// log.debug(deploymentName +
// " is missing in the registry. Undeploying the package to avoid inconsistencies...");
// }
// undeploy(deploymentName, true);
// }
// 
// if (!activitiDeploymentNames.contains(deploymentName) &&
// metaDataDeploymentNames.contains(deploymentName)) {
// if (log.isDebugEnabled()) {
// log.debug(deploymentName +
// " is missing in the BPS database. Undeploying the package to avoid inconsistencies...");
// }
// undeploy(deploymentName, true);
// }
// }
// }
// }
public void fixDeployments() throws BPSFault {
    // get all deployments in the deployment folder
    List<String> fileArchiveNames = new ArrayList<String>();
    File[] fileDeployments = repoFolder.listFiles();
    for (File fileDeployment : fileDeployments) {
        String deploymentName = FilenameUtils.getBaseName(fileDeployment.getName());
        fileArchiveNames.add(deploymentName);
    }
    // get all deployments in the Activiti DB
    List<String> activitiDeploymentNames = new ArrayList<String>();
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    RepositoryService repositoryService = engine.getRepositoryService();
    List<Deployment> tenantDeployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).list();
    for (Deployment deployment : tenantDeployments) {
        String deploymentName = deployment.getName();
        activitiDeploymentNames.add(deploymentName);
    }
    // get all deployments in the registry
    List<String> registryDeploymentNames = new ArrayList<String>();
    try {
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
        String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH;
        if (tenantRegistry.resourceExists(deploymentRegistryPath)) {
            Collection registryDeployments = (Collection) tenantRegistry.get(deploymentRegistryPath);
            String[] deploymentPaths = registryDeployments.getChildren();
            for (String deploymentPath : deploymentPaths) {
                String deploymentName = deploymentPath.substring(deploymentPath.lastIndexOf("/") + 1, deploymentPath.length());
                registryDeploymentNames.add(deploymentName);
            }
        }
    } catch (RegistryException e) {
        String msg = "Failed to obtain BPMN deployments from the Registry.";
        log.error(msg, e);
        throw new BPSFault(msg, e);
    }
    // construct the union of all deployments
    Set<String> allDeploymentNames = new HashSet<String>();
    allDeploymentNames.addAll(fileArchiveNames);
    allDeploymentNames.addAll(activitiDeploymentNames);
    allDeploymentNames.addAll(registryDeploymentNames);
    for (String deploymentName : allDeploymentNames) {
        try {
            if (!(fileArchiveNames.contains(deploymentName))) {
                if (log.isDebugEnabled()) {
                    log.debug(deploymentName + " has been removed from the deployment folder. Undeploying the package...");
                }
                undeploy(deploymentName, true);
            } else {
                if (activitiDeploymentNames.contains(deploymentName) && !registryDeploymentNames.contains(deploymentName)) {
                    if (log.isDebugEnabled()) {
                        log.debug(deploymentName + " is missing in the registry. Undeploying the package to avoid inconsistencies...");
                    }
                    undeploy(deploymentName, true);
                }
                if (!activitiDeploymentNames.contains(deploymentName) && registryDeploymentNames.contains(deploymentName)) {
                    if (log.isDebugEnabled()) {
                        log.debug(deploymentName + " is missing in the BPS database. Undeploying the package to avoid inconsistencies...");
                    }
                    undeploy(deploymentName, true);
                }
            }
        } catch (BPSFault e) {
            String msg = "Failed undeploy inconsistent deployment: " + deploymentName;
            log.error(msg, e);
            throw new BPSFault(msg, e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.repository.Deployment) Registry(org.wso2.carbon.registry.api.Registry) RegistryException(org.wso2.carbon.registry.api.RegistryException) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) Collection(org.wso2.carbon.registry.api.Collection) RegistryService(org.wso2.carbon.registry.api.RegistryService) File(java.io.File) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService) HashSet(java.util.HashSet)

Example 18 with BPSFault

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

the class BPMNHumanTasksService method getTasksOfUser.

public BPMNTask[] getTasksOfUser(String username) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    TaskService taskService = engine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskTenantId(tenantId.toString()).taskAssignee(username).list();
    BPMNTask[] bpmnTasks = new BPMNTask[tasks.size() + 1];
    int i = 0;
    for (Task t : tasks) {
        BPMNTask bpmnTask = new BPMNTask();
        bpmnTask.setId(t.getId());
        bpmnTask.setName(t.getName());
        bpmnTask.setProcessInstanceId(t.getProcessInstanceId());
        bpmnTasks[i] = bpmnTask;
        i++;
    }
    return bpmnTasks;
}
Also used : Task(org.activiti.engine.task.Task) BPMNTask(org.wso2.carbon.bpmn.core.mgt.model.BPMNTask) TaskService(org.activiti.engine.TaskService) BPMNTask(org.wso2.carbon.bpmn.core.mgt.model.BPMNTask) ProcessEngine(org.activiti.engine.ProcessEngine)

Aggregations

BPSFault (org.wso2.carbon.bpmn.core.BPSFault)13 File (java.io.File)6 ProcessEngine (org.activiti.engine.ProcessEngine)6 RuntimeService (org.activiti.engine.RuntimeService)5 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 RepositoryService (org.activiti.engine.RepositoryService)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 RegistryException (org.wso2.carbon.registry.api.RegistryException)4 IOException (java.io.IOException)3 Deployment (org.activiti.engine.repository.Deployment)3 Registry (org.wso2.carbon.registry.api.Registry)3 RegistryService (org.wso2.carbon.registry.api.RegistryService)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 TenantRepository (org.wso2.carbon.bpmn.core.deployment.TenantRepository)2 BPMNInstance (org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance)2 BufferedImage (java.awt.image.BufferedImage)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1