use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE 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.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE 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);
}
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.
the class HumanTaskStore method removeMatchingPackageAfterTaskObsoletion.
private boolean removeMatchingPackageAfterTaskObsoletion(String packageName) {
final HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
boolean matchingPackagesFound = false;
final int tId = this.tenantId;
List<HumanTaskBaseConfiguration> matchingTaskConfigurations = new ArrayList<HumanTaskBaseConfiguration>();
for (final HumanTaskBaseConfiguration configuration : this.getTaskConfigurations()) {
if (configuration.getPackageName().equals(packageName)) {
matchingTaskConfigurations.add(configuration);
try {
taskEngine.getScheduler().execTransaction(new Callable<Object>() {
public Object call() throws Exception {
taskEngine.getDaoConnectionFactory().getConnection().obsoleteTasks(configuration.getName().toString(), tId);
return null;
}
});
} catch (Exception e) {
String errMsg = "Error occurred while making tasks obsolete";
log.error(errMsg);
throw new HumanTaskRuntimeException(errMsg, e);
}
// we don't want the associated service once the task configuration is removed!
removeAxisServiceForTaskConfiguration(configuration);
matchingPackagesFound = true;
}
}
// remove the task configurations with the matching package name.
for (HumanTaskBaseConfiguration removableConfiguration : matchingTaskConfigurations) {
this.getTaskConfigurations().remove(removableConfiguration);
}
return matchingPackagesFound;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.
the class HumanTaskStore method findHumanTaskPackageInFileSystem.
/**
* This method provides the extracted human task package location in file system.
* If human task package does not exist in file system then package will be exported from registry.
* If human task package does not exist in registry then package will be imported to registry from file system.
* If registry and file location don't have extracted human task package content then exception will be thrown
*
* @param dudao
* @return File
* @throws HumanTaskDeploymentException
*/
private File findHumanTaskPackageInFileSystem(DeploymentUnitDAO dudao, File archiveFile) throws Exception {
String duName = dudao.getName();
log.info("Looking for HumanTask package in file system for deployment unit " + duName);
File humanTaskDUDirectory = new File(humanTaskDeploymentRepo, duName);
String registryCollectionPath = HumanTaskPackageRepositoryUtils.getResourcePathForHumanTaskPackageContent(dudao.getPackageName(), dudao.getName());
try {
if (humanTaskDUDirectory.exists()) {
if (!tenantConfigRegistry.resourceExists(registryCollectionPath)) {
// Import human task package content to registry from file system
repository.restoreHumanTaskPackageContentInRegistry(dudao, archiveFile);
}
return humanTaskDUDirectory;
} else {
if (tenantConfigRegistry.resourceExists(registryCollectionPath)) {
if (!humanTaskDUDirectory.exists() && !humanTaskDUDirectory.mkdirs()) {
String errMsg = "Error creating HumanTask deployment unit repository for " + "tenant " + tenantId;
log.error(errMsg);
log.error("Failed to load HumanTask deployment unit " + duName + " due to above error.");
throw new HumanTaskDeploymentException(errMsg);
}
// Export human task package content from registry to file system
RegistryClientUtils.exportFromRegistry(humanTaskDUDirectory, registryCollectionPath, tenantConfigRegistry);
return humanTaskDUDirectory;
} else {
String errMsg = "Expected resource: " + registryCollectionPath + " not found in the registry";
log.error(errMsg);
throw new HumanTaskDeploymentException(errMsg);
}
}
} catch (RegistryException re) {
String errMsg = "Error while exporting deployment unit: " + duName + " to file system from the " + "registry.";
log.error(errMsg, re);
throw new HumanTaskDeploymentException(errMsg, re);
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE in project carbon-business-process by wso2.
the class HumanTaskStore method reloadExistingTaskVersions.
/**
* Reload existing task versions for a given deployment unit
* @param existingDeploymentUnitsForPackage
* @param archiveFile
* @param md5sum
* @throws HumanTaskDeploymentException
*/
public void reloadExistingTaskVersions(List<DeploymentUnitDAO> existingDeploymentUnitsForPackage, File archiveFile, String md5sum, boolean isMasterServer) throws Exception {
// deployment units list should not be null, having a safety check anyway
if (existingDeploymentUnitsForPackage == null) {
return;
}
if (log.isDebugEnabled()) {
log.debug("Reloading existing task versions for human task archive [ " + archiveFile.getName() + "]");
}
for (DeploymentUnitDAO dao : existingDeploymentUnitsForPackage) {
if (!isMasterServer) {
// We need to avoid deployment of already loaded packages
String versionedName = dao.getName();
List<QName> qNames = taskConfigurationsInTaskPackage.get(versionedName);
if (qNames != null && qNames.size() > 0) {
// This dao is already loaded
if (log.isDebugEnabled()) {
log.debug("This is already loaded package, skipping " + versionedName);
}
continue;
}
}
try {
File taskDirectory = findHumanTaskPackageInFileSystem(dao, archiveFile);
ArchiveBasedHumanTaskDeploymentUnitBuilder deploymentUnitBuilder = null;
if (log.isDebugEnabled()) {
log.debug("Loading task : " + dao.getName());
}
if (taskDirectory.exists()) {
// This is an existing task configuration
deploymentUnitBuilder = new ArchiveBasedHumanTaskDeploymentUnitBuilder(taskDirectory, tenantId, dao.getVersion(), dao.getPackageName(), dao.getChecksum());
} else if (dao.getStatus() == TaskPackageStatus.ACTIVE) {
// This node is a salve node and task is being reloaded or new version has been deployed on master
deploymentUnitBuilder = new ArchiveBasedHumanTaskDeploymentUnitBuilder(archiveFile, tenantId, dao.getVersion(), md5sum);
} else {
String errMsg = "Error loading task. Cannot find the task directory for retired task " + dao.getName();
log.error(errMsg);
throw new HumanTaskDeploymentException(errMsg);
}
// Check whether this is a new version deployment on a slave node
if (!isMasterServer && dao.getStatus() == TaskPackageStatus.ACTIVE) {
String currentDeployedVersion = loadedPackages.get(dao.getPackageName());
if (currentDeployedVersion != null && currentDeployedVersion.equals(dao.getName()) == false) {
// This is a new version on the salve node , retire the existing version
retireTaskPackageConfigurations(currentDeployedVersion);
}
}
HumanTaskDeploymentUnit taskDeploymentUnit = deploymentUnitBuilder.createNewHumanTaskDeploymentUnit();
taskDeploymentUnit.setTaskPackageStatus(dao.getStatus());
deploy(taskDeploymentUnit);
if (dao.getStatus() == TaskPackageStatus.ACTIVE) {
// Add the active package to the loaded packages
loadedPackages.put(dao.getPackageName(), dao.getName());
}
} catch (HumanTaskDeploymentException e) {
String errMsg = "Error loading the task configuration ";
log.error(errMsg, e);
throw e;
}
}
}
Aggregations