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);
}
}
}
}
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() + ".");
}
}
}
Aggregations