Search in sources :

Example 1 with DeploymentMapper

use of org.wso2.carbon.bpmn.core.internal.mapper.DeploymentMapper in project carbon-business-process by wso2.

the class TenantRepository method undeploy.

/**
 * Undeploys a BPMN package.
 * This may be called by the BPMN deployer, when a BPMN package is deleted from the deployment folder or by admin services
 *
 * @param deploymentName package name to be undeployed
 * @param force          forceful deletion of package
 */
// public void undeploy(String deploymentName, boolean force) {
// 
// DeploymentMetaDataModel deploymentMetaDataModel;
// SqlSession sqlSession = null;
// try {
// // Remove the deployment from the tenant's registry
// deploymentMetaDataModel = activitiDAO
// .selectTenantAwareDeploymentModel(tenantId.toString(), deploymentName);
// 
// if ((deploymentMetaDataModel == null) && !force) {
// String msg = "Deployment: " + deploymentName + " does not exist.";
// log.warn(msg);
// return;
// }
// 
// ProcessEngineImpl engine = (ProcessEngineImpl) BPMNServerHolder.getInstance().getEngine();
// 
// DbSqlSessionFactory dbSqlSessionFactory =
// (DbSqlSessionFactory) engine.getProcessEngineConfiguration().
// getSessionFactories().get(DbSqlSession.class);
// 
// SqlSessionFactory sqlSessionFactory = dbSqlSessionFactory.getSqlSessionFactory();
// sqlSession = sqlSessionFactory.openSession();
// DeploymentMapper deploymentMapper = sqlSession.getMapper(DeploymentMapper.class);
// int rowCount = deploymentMapper.deleteDeploymentMetaData(deploymentMetaDataModel);
// 
// if (log.isDebugEnabled()) {
// log.debug("Total row count deleted=" + rowCount);
// }
// 
// // Remove the deployment archive from the tenant's deployment folder
// File deploymentArchive = new File(repoFolder, deploymentName + ".bar");
// FileUtils.deleteQuietly(deploymentArchive);
// 
// // Delete all versions of this package from the Activiti engine.
// RepositoryService repositoryService = engine.getRepositoryService();
// List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).
// deploymentName(deploymentName).list();
// for (Deployment deployment : deployments) {
// repositoryService.deleteDeployment(deployment.getId());
// }
// 
// //commit metadata
// sqlSession.commit();
// } finally {
// if (sqlSession != null) {
// sqlSession.close();
// }
// }
// 
// }
public void undeploy(String deploymentName, boolean force) throws BPSFault {
    try {
        // Remove the deployment from the tenant's registry
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
        String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH + BPMNConstants.REGISTRY_PATH_SEPARATOR + deploymentName;
        if (!tenantRegistry.resourceExists(deploymentRegistryPath) && !force) {
            String msg = "Deployment: " + deploymentName + " does not exist.";
            log.warn(msg);
            return;
        }
        tenantRegistry.delete(deploymentRegistryPath);
        // Remove the deployment archive from the tenant's deployment folder
        File deploymentArchive = new File(repoFolder, deploymentName + ".bar");
        FileUtils.deleteQuietly(deploymentArchive);
        // Delete all versions of this package from the Activiti engine.
        ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
        RepositoryService repositoryService = engine.getRepositoryService();
        List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).deploymentName(deploymentName).list();
        for (Deployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    } catch (RegistryException e) {
        String msg = "Failed to undeploy BPMN deployment: " + deploymentName + " for tenant: " + tenantId;
        log.error(msg, e);
        throw new BPSFault(msg, e);
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) Deployment(org.activiti.engine.repository.Deployment) Registry(org.wso2.carbon.registry.api.Registry) RegistryService(org.wso2.carbon.registry.api.RegistryService) File(java.io.File) RegistryException(org.wso2.carbon.registry.api.RegistryException) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 2 with DeploymentMapper

use of org.wso2.carbon.bpmn.core.internal.mapper.DeploymentMapper in project carbon-business-process by wso2.

the class ActivitiDAO method selectTenantAwareDeploymentModel.

/**
 * invokes the DeploymentMapper.selectMetaData for a given tenant id and package name
 *
 * @param tenantID        tenant id
 * @param bpmnPackageName package name
 * @return                DeploymentMetaDataModel object
 */
public DeploymentMetaDataModel selectTenantAwareDeploymentModel(final String tenantID, final String bpmnPackageName) {
    CustomSqlExecution<DeploymentMapper, DeploymentMetaDataModel> customSqlExecution = new AbstractCustomSqlExecution<DeploymentMapper, DeploymentMetaDataModel>(DeploymentMapper.class) {

        public DeploymentMetaDataModel execute(DeploymentMapper deploymentMapper) {
            return deploymentMapper.selectMetaData(tenantID, bpmnPackageName);
        }
    };
    DeploymentMetaDataModel deploymentMetaDataModel = managementService.executeCustomSql(customSqlExecution);
    if (log.isDebugEnabled()) {
        if (deploymentMetaDataModel != null) {
            log.debug("DeploymentDataModel exists when selecting models=" + deploymentMetaDataModel.getId());
        } else {
            log.debug("DeploymentDataModel null when selecting models");
        }
    }
    return deploymentMetaDataModel;
}
Also used : DeploymentMapper(org.wso2.carbon.bpmn.core.internal.mapper.DeploymentMapper) AbstractCustomSqlExecution(org.activiti.engine.impl.cmd.AbstractCustomSqlExecution) DeploymentMetaDataModel(org.wso2.carbon.bpmn.core.mgt.model.DeploymentMetaDataModel)

Aggregations

File (java.io.File)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1 AbstractCustomSqlExecution (org.activiti.engine.impl.cmd.AbstractCustomSqlExecution)1 Deployment (org.activiti.engine.repository.Deployment)1 BPSFault (org.wso2.carbon.bpmn.core.BPSFault)1 DeploymentMapper (org.wso2.carbon.bpmn.core.internal.mapper.DeploymentMapper)1 DeploymentMetaDataModel (org.wso2.carbon.bpmn.core.mgt.model.DeploymentMetaDataModel)1 Registry (org.wso2.carbon.registry.api.Registry)1 RegistryException (org.wso2.carbon.registry.api.RegistryException)1 RegistryService (org.wso2.carbon.registry.api.RegistryService)1