Search in sources :

Example 31 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project carbon-business-process by wso2.

the class TenantRepository method deploy.

/**
 * Deploys a BPMN package in the Activiti engine. Each BPMN package has an entry in the registry.
 * Checksum of the latest version of the BPMN package is stored in this entry.
 * This checksum is used to determine whether a package is a new deployment
 * (or a new version of an existing package) or a redeployment of an existing package.
 * We have to ignor the later case. If a package is a new deployment, it is deployed in the Activiti engine.
 *
 * @param deploymentContext DeploymentContext
 * @return true, if artifact was deployed, false, if the artifact has not changed & hence not deployed
 * @throws DeploymentException if deployment fails
 */
// public boolean deploy(BPMNDeploymentContext deploymentContext) throws DeploymentException {
// ZipInputStream archiveStream = null;
// 
// try {
// 
// String deploymentName =
// FilenameUtils.getBaseName(deploymentContext.getBpmnArchive().getName());
// 
// // Compare the checksum of the BPMN archive with the currently available checksum in the registry
// // to determine whether this is a new deployment.
// String checksum = "";
// try {
// checksum = Utils.getMD5Checksum(deploymentContext.getBpmnArchive());
// } catch (IOException e) {
// log.error("Checksum genration failed for IO operation",e);
// } catch (NoSuchAlgorithmException e) {
// log.error("Checksum genration Algorithm not found",e);
// }
// 
// DeploymentMetaDataModel deploymentMetaDataModel =
// activitiDAO.selectTenantAwareDeploymentModel(tenantId.toString(), deploymentName);
// 
// if (log.isDebugEnabled()) {
// log.debug("deploymentName=" + deploymentName + " checksum=" + checksum);
// log.debug("deploymentMetaDataModel=" + deploymentMetaDataModel.toString());
// }
// 
// if (deploymentMetaDataModel != null) {
// if (checksum.equalsIgnoreCase(deploymentMetaDataModel.getCheckSum())) {
// return false;
// }
// }
// 
// ProcessEngineImpl engine =
// (ProcessEngineImpl) BPMNServerHolder.getInstance().getEngine();
// 
// RepositoryService repositoryService = engine.getRepositoryService();
// DeploymentBuilder deploymentBuilder =
// repositoryService.createDeployment().tenantId(tenantId.toString()).
// name(deploymentName);
// try {
// archiveStream =
// new ZipInputStream(new FileInputStream(deploymentContext.getBpmnArchive()));
// } catch (FileNotFoundException e) {
// String errMsg = "Archive stream not found for BPMN repsoitory";
// throw new DeploymentException(errMsg, e);
// }
// 
// deploymentBuilder.addZipInputStream(archiveStream);
// Deployment deployment = deploymentBuilder.deploy();
// 
// if (deploymentMetaDataModel == null) {
// 
// deploymentMetaDataModel = new DeploymentMetaDataModel();
// deploymentMetaDataModel.setPackageName(deploymentName);
// deploymentMetaDataModel.setCheckSum(checksum);
// deploymentMetaDataModel.setTenantID(tenantId.toString());
// deploymentMetaDataModel.setId(deployment.getId());
// 
// //call for insertion
// this.activitiDAO.insertDeploymentMetaDataModel(deploymentMetaDataModel);
// } else {
// //call for update
// deploymentMetaDataModel.setCheckSum(checksum);
// this.activitiDAO.updateDeploymentMetaDataModel(deploymentMetaDataModel);
// }
// 
// } finally {
// if (archiveStream != null) {
// try {
// archiveStream.close();
// } catch (IOException e) {
// log.error("Could not close archive stream", e);
// }
// }
// }
// 
// return true;
// }
public void deploy(BPMNDeploymentContext deploymentContext) throws DeploymentException {
    ZipInputStream archiveStream = null;
    try {
        String deploymentName = FilenameUtils.getBaseName(deploymentContext.getBpmnArchive().getName());
        // Compare the checksum of the BPMN archive with the currently available checksum in the registry to determine whether this is a new deployment.
        String checksum = Utils.getMD5Checksum(deploymentContext.getBpmnArchive());
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
        String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH + BPMNConstants.REGISTRY_PATH_SEPARATOR + deploymentName;
        Resource deploymentEntry = null;
        if (tenantRegistry.resourceExists(deploymentRegistryPath)) {
            deploymentEntry = tenantRegistry.get(deploymentRegistryPath);
        } else {
            // This is a new deployment
            deploymentEntry = tenantRegistry.newCollection();
        }
        String latestChecksum = deploymentEntry.getProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY);
        if (latestChecksum != null && checksum.equals(latestChecksum)) {
            // This is a server restart
            return;
        }
        deploymentEntry.setProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY, checksum);
        // Deploy the package in the Activiti engine
        ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
        RepositoryService repositoryService = engine.getRepositoryService();
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().tenantId(tenantId.toString()).name(deploymentName);
        archiveStream = new ZipInputStream(new FileInputStream(deploymentContext.getBpmnArchive()));
        deploymentBuilder.addZipInputStream(archiveStream);
        deploymentBuilder.deploy();
        tenantRegistry.put(deploymentRegistryPath, deploymentEntry);
    } catch (Exception e) {
        String errorMessage = "Failed to deploy the archive: " + deploymentContext.getBpmnArchive().getName();
        log.error(errorMessage, e);
        // Remove the deployment archive from the tenant's deployment folder
        File deploymentArchive = new File(repoFolder, deploymentContext.getBpmnArchive().getName());
        FileUtils.deleteQuietly(deploymentArchive);
        log.info("Removing the faulty archive : " + deploymentContext.getBpmnArchive().getName());
        throw new DeploymentException(errorMessage, e);
    } finally {
        if (archiveStream != null) {
            try {
                archiveStream.close();
            } catch (IOException e) {
                log.error("Could not close archive stream", e);
            }
        }
    }
}
Also used : Resource(org.wso2.carbon.registry.api.Resource) Registry(org.wso2.carbon.registry.api.Registry) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) RegistryException(org.wso2.carbon.registry.api.RegistryException) DeploymentException(org.apache.axis2.deployment.DeploymentException) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) DeploymentException(org.apache.axis2.deployment.DeploymentException) RegistryService(org.wso2.carbon.registry.api.RegistryService) File(java.io.File) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 32 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project carbon-business-process by wso2.

the class HumanTaskDeployer method createHumanTaskRepository.

private void createHumanTaskRepository(ConfigurationContext configCtx) throws DeploymentException {
    String axisRepoPath = configCtx.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(axisRepoPath)) {
        throw new DeploymentException("URL Repositories are not supported: " + axisRepoPath);
    }
    File tenantsRepository = new File(axisRepoPath);
    File humanTaskRepo = new File(tenantsRepository, HumanTaskConstants.HUMANTASK_REPO_DIRECTORY);
    if (!humanTaskRepo.exists()) {
        boolean status = humanTaskRepo.mkdir();
        if (!status) {
            throw new DeploymentException("Failed to create HumanTask repository directory " + humanTaskRepo.getAbsolutePath() + ".");
        }
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Aggregations

DeploymentException (org.apache.axis2.deployment.DeploymentException)32 File (java.io.File)23 Deployer (org.apache.axis2.deployment.Deployer)6 Artifact (org.wso2.carbon.application.deployer.config.Artifact)6 CappFile (org.wso2.carbon.application.deployer.config.CappFile)6 IOException (java.io.IOException)4 AxisFault (org.apache.axis2.AxisFault)3 DeploymentFileData (org.apache.axis2.deployment.repository.util.DeploymentFileData)3 Library (org.apache.synapse.libraries.model.Library)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 QName (javax.xml.namespace.QName)2 OMElement (org.apache.axiom.om.OMElement)2 Mediator (org.apache.synapse.Mediator)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ZipInputStream (java.util.zip.ZipInputStream)1 XMLStreamException (javax.xml.stream.XMLStreamException)1