use of org.wso2.carbon.registry.api.Registry in project carbon-business-process by wso2.
the class HumanTaskPackageRepository method createHumanTaskPackageParentCollectionWithProperties.
/**
* Create parent collection to persisting human task package information. For example, if you deploy
* a human task archive called 'ClaimsApprovalTask.zip', we store information of that package in collection
* named 'ClaimsApprovalTask'. This will be the root for 'ClaimsApprovalTask' human task package information and
* there will several versions of this human task package in this registry collection which relates
* to the versions deployed in human task engine.
*
* @param humanTaskDeploymentUnit containing information on current deployment
* @throws RegistryException when there is a error accessing registry
*/
private void createHumanTaskPackageParentCollectionWithProperties(HumanTaskDeploymentUnit humanTaskDeploymentUnit) throws RegistryException {
Collection humanPackage = configRegistry.newCollection();
humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_CHECKSUM, humanTaskDeploymentUnit.getMd5sum());
if (log.isDebugEnabled()) {
log.debug(humanTaskDeploymentUnit.getPackageName() + " updating checksum: " + humanTaskDeploymentUnit.getMd5sum() + " in registry");
}
humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_STATUS, String.valueOf(humanTaskDeploymentUnit.getTaskPackageStatus()));
humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_VERSION, Long.toString(humanTaskDeploymentUnit.getVersion()));
configRegistry.put(HumanTaskPackageRepositoryUtils.getResourcePathForHumanTaskPackage(humanTaskDeploymentUnit), humanPackage);
}
use of org.wso2.carbon.registry.api.Registry in project carbon-business-process by wso2.
the class HumanTaskPackageRepository method addLatestArchiveToRegistryCollection.
/**
* Add latest human task package zip to the registry
*
* @param deploymentUnitDAO
* @param humanTaskFile
* @throws RegistryException
* @throws HumanTaskStoreException
*/
private void addLatestArchiveToRegistryCollection(DeploymentUnitDAO deploymentUnitDAO, File humanTaskFile) throws HumanTaskStoreException, RegistryException {
FileInputStream fileInputStream = null;
try {
Resource latestHumanTaskArchive = configRegistry.newResource();
fileInputStream = new FileInputStream(humanTaskFile);
latestHumanTaskArchive.setContent(fileInputStream);
configRegistry.put(HumanTaskPackageRepositoryUtils.getHumanTaskPackageArchiveResourcePath(deploymentUnitDAO.getPackageName()), latestHumanTaskArchive);
} catch (FileNotFoundException ex) {
String errMsg = "HumanTask package zip file couldn't found on given location " + humanTaskFile.getAbsolutePath();
throw new HumanTaskStoreException(errMsg, ex);
} catch (RegistryException ex) {
String errMsg = "Exception occurred while adding latest archive to registry collection";
throw new RegistryException(errMsg, ex);
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
log.warn("Cannot close file input stream.", e);
}
}
}
}
use of org.wso2.carbon.registry.api.Registry in project carbon-business-process by wso2.
the class ServiceConfigurationUtil method readOMElementFromRegistry.
// If the service file is located in the registry, read if from the registry.
private static OMElement readOMElementFromRegistry(String registryLocation) {
OMElement serviceElement = null;
Registry registry;
String location;
if (registryLocation.startsWith(UnifiedEndpointConstants.VIRTUAL_CONF_REG)) {
registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
location = registryLocation.substring(registryLocation.indexOf(UnifiedEndpointConstants.VIRTUAL_CONF_REG) + UnifiedEndpointConstants.VIRTUAL_CONF_REG.length());
serviceElement = loadOMElement(registry, location);
} else if (registryLocation.startsWith(UnifiedEndpointConstants.VIRTUAL_GOV_REG)) {
registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
location = registryLocation.substring(registryLocation.indexOf(UnifiedEndpointConstants.VIRTUAL_GOV_REG) + UnifiedEndpointConstants.VIRTUAL_GOV_REG.length());
serviceElement = loadOMElement(registry, location);
} else if (registryLocation.startsWith(UnifiedEndpointConstants.VIRTUAL_REG)) {
registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.LOCAL_REPOSITORY);
location = registryLocation.substring(registryLocation.indexOf(UnifiedEndpointConstants.VIRTUAL_REG) + UnifiedEndpointConstants.VIRTUAL_REG.length());
serviceElement = loadOMElement(registry, location);
} else {
String errMsg = "Invalid service.xml file location: " + registryLocation;
log.warn(errMsg);
}
return serviceElement;
}
use of org.wso2.carbon.registry.api.Registry in project carbon-business-process by wso2.
the class BPMNDeploymentService method getLatestChecksum.
/**
* Get the checksum of latest deployment for given deployment name
*
* @param deploymentName
* @return
* @throws BPSFault
*/
public String getLatestChecksum(String deploymentName) throws BPSFault {
try {
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
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)) {
Resource deploymentEntry = tenantRegistry.get(deploymentRegistryPath);
return deploymentEntry.getProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY);
} else {
return null;
}
} catch (RegistryException e) {
String msg = "Error while accessing registry to get latest checksum for package : " + deploymentName;
throw new BPSFault(msg, e);
}
}
use of org.wso2.carbon.registry.api.Registry 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);
}
}
Aggregations