Search in sources :

Example 11 with Artifact

use of org.wso2.carbon.application.deployer.config.Artifact 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)

Aggregations

Artifact (org.wso2.carbon.application.deployer.config.Artifact)8 DeploymentException (org.apache.axis2.deployment.DeploymentException)7 Deployer (org.apache.axis2.deployment.Deployer)6 CappFile (org.wso2.carbon.application.deployer.config.CappFile)6 File (java.io.File)5 DeploymentFileData (org.apache.axis2.deployment.repository.util.DeploymentFileData)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)2 CarbonApplication (org.wso2.carbon.application.deployer.CarbonApplication)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ZipInputStream (java.util.zip.ZipInputStream)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1 DeploymentBuilder (org.activiti.engine.repository.DeploymentBuilder)1 BPELPackageManagementServiceSkeleton (org.wso2.carbon.bpel.core.ode.integration.mgt.services.BPELPackageManagementServiceSkeleton)1 LimitedProcessInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedProcessInfoType)1 PackageType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PackageType)1