use of org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit 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;
}
}
}
use of org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit in project carbon-business-process by wso2.
the class HumanTaskStore method validateTaskConfig.
/**
* Performance a test deployment of the task in order to avoid deployment issues due to invalid task packages
* @param humanTaskDU
* @return
* @throws HumanTaskDeploymentException
*/
public void validateTaskConfig(HumanTaskDeploymentUnit humanTaskDU) throws HumanTaskDeploymentException, AxisFault {
boolean validateTask = HumanTaskServiceComponent.getHumanTaskServer().getServerConfig().getEnableTaskValidationBeforeDeployment();
if (validateTask) {
TTask[] tasks = humanTaskDU.getTasks();
if (tasks != null) {
for (TTask task : tasks) {
QName taskQName = new QName(humanTaskDU.getNamespace(), task.getName());
TaskConfiguration taskConf = new TaskConfiguration(task, humanTaskDU.getTaskServiceInfo(taskQName), humanTaskDU.getHumanInteractionsDefinition(), humanTaskDU.getWSDLs(), humanTaskDU.getNamespace(), humanTaskDU.getName(), getTenantAxisConfig(), humanTaskDU.getPackageName(), humanTaskDU.getVersion(), humanTaskDU.getHumanTaskDefinitionFile());
if (taskConf.isErroneous()) {
throw new HumanTaskDeploymentException(taskConf.getDeploymentError());
}
validateServiceCreationForTaskConfig(taskConf);
}
}
TNotification[] notifications = humanTaskDU.getNotifications();
if (notifications != null) {
for (TNotification notification : notifications) {
QName notificationQName = new QName(humanTaskDU.getNamespace(), notification.getName());
NotificationConfiguration notificationConf = new NotificationConfiguration(notification, humanTaskDU.getNotificationServiceInfo(notificationQName), humanTaskDU.getHumanInteractionsDefinition(), humanTaskDU.getWSDLs(), humanTaskDU.getNamespace(), humanTaskDU.getName(), getTenantAxisConfig(), humanTaskDU.getPackageName(), humanTaskDU.getVersion(), humanTaskDU.getHumanTaskDefinitionFile());
if (notificationConf.isErroneous()) {
throw new HumanTaskDeploymentException(notificationConf.getDeploymentError());
}
validateServiceCreationForTaskConfig(notificationConf);
}
}
for (TNotification inlineNotification : humanTaskDU.getInlineNotifications()) {
QName notificationQName = new QName(humanTaskDU.getNamespace(), inlineNotification.getName());
NotificationConfiguration notificationConf = new NotificationConfiguration(inlineNotification, humanTaskDU.getNotificationServiceInfo(notificationQName), humanTaskDU.getHumanInteractionsDefinition(), humanTaskDU.getWSDLs(), humanTaskDU.getNamespace(), humanTaskDU.getName(), getTenantAxisConfig(), humanTaskDU.getPackageName(), humanTaskDU.getVersion(), humanTaskDU.getHumanTaskDefinitionFile());
notificationConf.setPackageStatus(humanTaskDU.getTaskPackageStatus());
if (notificationConf.isErroneous()) {
throw new HumanTaskDeploymentException(notificationConf.getDeploymentError());
}
validateServiceCreationForTaskConfig(notificationConf);
}
}
return;
}
use of org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit in project carbon-business-process by wso2.
the class HumanTaskStore method deploy.
/**
* Handles the deployment steps for the master node and salve node in the cluster
* @param humanTaskFile
* @throws Exception
*/
public void deploy(File humanTaskFile) throws Exception {
// Currently using the registry read/write mount property to determine whether this node is a master node
// or a salve node.
// Handle this properly with hazelcast leader for cluster scenario TODO
boolean isMasterServer = !isServerReadOnly();
// Versions of this ht package is already deployed
boolean isExistingPackage = false;
// Exactly matching ht package already exists
boolean isPackageReload = false;
DeploymentUnitDAO currentlyActiveTaskPackage = null;
String md5sum = HumanTaskStoreUtils.getMD5Checksum(humanTaskFile);
String packageName = FilenameUtils.removeExtension(humanTaskFile.getName());
List<DeploymentUnitDAO> existingDeploymentUnitsForPackage = getExistingDeploymentUnitsForPackage(packageName.trim());
if (existingDeploymentUnitsForPackage != null && existingDeploymentUnitsForPackage.size() > 0) {
isExistingPackage = true;
for (DeploymentUnitDAO dao : existingDeploymentUnitsForPackage) {
if ((dao.getStatus() == (TaskPackageStatus.ACTIVE))) {
// extract the currently active task package
currentlyActiveTaskPackage = dao;
if (dao.getChecksum().equals(md5sum)) {
// Check whether the md5sum matches the active task package.
isPackageReload = true;
}
}
}
}
// We will only allow writes to db only for the master node to avoid duplicate version creation
if (isExistingPackage && isPackageReload) {
// Reload the existing versions of the human task package . No need of creating a new version of the package
// This could be due to server restart, deployment of the same package or master node has already deployed the
// new version of the package
// First check if the currently active task package is already loaded
String activePackageName = loadedPackages.get(currentlyActiveTaskPackage.getPackageName());
if (activePackageName != null && activePackageName.equals(currentlyActiveTaskPackage.getName())) {
if (log.isDebugEnabled()) {
log.debug("This task package and its previous versions are already loaded " + activePackageName);
}
// This task package and its previous versions are already loaded , hence return
return;
}
// Load the existing versions of the package
reloadExistingTaskVersions(existingDeploymentUnitsForPackage, humanTaskFile, md5sum, isMasterServer);
return;
}
// New version of the package is being deployed on top of the existing version
if (isExistingPackage && !isPackageReload) {
if (isMasterServer) {
// Retire the existing version of the package and deploy the new version
// This could be two scenarios. Server restart with new version and deploying on existing version.
String activePackageName = loadedPackages.get(currentlyActiveTaskPackage.getPackageName());
if (activePackageName == null) {
// This is a server restart, we need to load existing versions
reloadExistingTaskVersions(existingDeploymentUnitsForPackage, humanTaskFile, md5sum, isMasterServer);
}
long newVersion = getNextVersion();
HumanTaskDeploymentUnit newDeploymentUnit = createNewDeploymentUnit(humanTaskFile, tenantId, newVersion, md5sum);
validateTaskConfig(newDeploymentUnit);
retireTaskPackageConfigurations(currentlyActiveTaskPackage.getName());
currentlyActiveTaskPackage.setStatus(TaskPackageStatus.RETIRED);
updateDeploymentUnitDao(currentlyActiveTaskPackage);
// Retiring of currently active package is complete.
// Create and deploy new version
deployNewTaskVersion(newDeploymentUnit, newVersion);
// Add new version of human task package to registry
// Update the zip and package properties in the registry
repository.handleNewHumanTaskPackageAddition(newDeploymentUnit, humanTaskFile);
// Successfully deployed the packages.
return;
} else {
// Cannot allow creation of a new version from slave nodes, deploy the new version on the master node
// first to avoid duplicate version creation
// Write log, issue warning and return
log.warn("Cannot deploy new version of the task in slave node. Hence deploy the task archive in master" + "node fist");
return;
}
}
if (!isMasterServer) {
// Issue warning, write warn message and return as we cannot allow deployment of new versions on slave nodes
// before deployment of the ht package in the master node
log.warn("Cannot deploy a new version on the package on the salve node first, " + "Deploy the package on the master node first");
return;
}
// Create new version of deployment unit
// Process the human task configurations
// Store deployment unit information to the db
// Deploy axis2 services
// Adding HumanTask package the registry.
long newVersion = getNextVersion();
HumanTaskDeploymentUnit newDeploymentUnit = createNewDeploymentUnit(humanTaskFile, tenantId, newVersion, md5sum);
validateTaskConfig(newDeploymentUnit);
deployNewTaskVersion(newDeploymentUnit, newVersion);
repository.handleNewHumanTaskPackageAddition(newDeploymentUnit, humanTaskFile);
return;
}
use of org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit in project carbon-business-process by wso2.
the class HumanTaskPackageRepository method updateHumanTaskPackageProperties.
/**
* Update the properties of existing human task package in the registry
*
* @param humanTaskDeploymentUnit
* @throws RegistryException
*/
private void updateHumanTaskPackageProperties(HumanTaskDeploymentUnit humanTaskDeploymentUnit) throws RegistryException {
String packageLocation = HumanTaskPackageRepositoryUtils.getResourcePathForHumanTaskPackage(humanTaskDeploymentUnit);
Resource humanTaskPackage = configRegistry.get(packageLocation);
humanTaskPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_CHECKSUM, humanTaskDeploymentUnit.getMd5sum());
if (log.isDebugEnabled()) {
log.debug(humanTaskDeploymentUnit.getPackageName() + " updated checksum to: " + humanTaskDeploymentUnit.getMd5sum());
}
humanTaskPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_STATUS, String.valueOf(humanTaskDeploymentUnit.getTaskPackageStatus()));
humanTaskPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_VERSION, Long.toString(humanTaskDeploymentUnit.getVersion()));
configRegistry.put(packageLocation, humanTaskPackage);
}
Aggregations