Search in sources :

Example 6 with DeploymentUnitDAO

use of org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO 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);
    }
}
Also used : HumanTaskDeploymentException(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException) File(java.io.File) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 7 with DeploymentUnitDAO

use of org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO 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;
        }
    }
}
Also used : DeploymentUnitDAO(org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO) QName(javax.xml.namespace.QName) ArchiveBasedHumanTaskDeploymentUnitBuilder(org.wso2.carbon.humantask.core.deployment.ArchiveBasedHumanTaskDeploymentUnitBuilder) HumanTaskDeploymentException(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException) File(java.io.File) HumanTaskDeploymentUnit(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit)

Example 8 with DeploymentUnitDAO

use of org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO 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;
}
Also used : DeploymentUnitDAO(org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO) HumanTaskDeploymentUnit(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit)

Example 9 with DeploymentUnitDAO

use of org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO in project carbon-business-process by wso2.

the class ProcessStoreImpl method onBPELPackageDeployment.

public void onBPELPackageDeployment(Integer tenantId, final String duName, final String duLocation, final List<ProcessConfigurationImpl> processConfs) {
    boolean status = exec(new Callable<Boolean>() {

        @Override
        public Boolean call(ConfStoreConnection conn) {
            DeploymentUnitDAO duDao = conn.getDeploymentUnit(duName);
            if (duDao != null) {
                /*
                    This is for clustering scenario. update/deployment
                     */
                return true;
            }
            duDao = conn.createDeploymentUnit(duName);
            duDao.setDeploymentUnitDir(duLocation);
            for (ProcessConf pConf : processConfs) {
                try {
                    ProcessConfDAO processConfDao = duDao.createProcess(pConf.getProcessId(), pConf.getType(), pConf.getVersion());
                    processConfDao.setState(pConf.getState());
                    for (Map.Entry<QName, Node> prop : pConf.getProcessProperties().entrySet()) {
                        processConfDao.setProperty(prop.getKey(), DOMUtils.domToString(prop.getValue()));
                    }
                    conn.setVersion(pConf.getVersion());
                } catch (Exception e) {
                    String errmsg = "Error persisting deployment record for " + pConf.getProcessId() + "; process will not be available after restart!";
                    log.error(errmsg, e);
                    return false;
                }
            }
            return true;
        }
    });
    if (status) {
        CopyOnWriteArrayList<QName> pids = new CopyOnWriteArrayList<QName>();
        for (ProcessConf pConf : processConfs) {
            pids.add(pConf.getProcessId());
        }
        updateProcessAndDUMaps(tenantId, duName, pids, true);
        for (ProcessConfigurationImpl processConf : processConfs) {
            fireEvent(new ProcessStoreEvent(ProcessStoreEvent.Type.DEPLOYED, processConf.getProcessId(), duName));
            fireStateChange(processConf.getProcessId(), processConf.getState(), duName);
        }
    }
}
Also used : DeploymentUnitDAO(org.apache.ode.store.DeploymentUnitDAO) QName(javax.xml.namespace.QName) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) ConfStoreConnection(org.apache.ode.store.ConfStoreConnection) ProcessStoreEvent(org.apache.ode.bpel.iapi.ProcessStoreEvent) SQLException(java.sql.SQLException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) ContextException(org.apache.ode.bpel.iapi.ContextException) ProcessConfDAO(org.apache.ode.store.ProcessConfDAO) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 10 with DeploymentUnitDAO

use of org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO in project carbon-business-process by wso2.

the class HumanTaskDAOConnectionImpl method getDeploymentUnit.

public DeploymentUnitDAO getDeploymentUnit(int tenantId, String md5sum) {
    Query q = entityManager.createQuery("select hu from org.wso2.carbon.humantask.core.dao.jpa.openjpa.model" + ".DeploymentUnit hu WHERE hu.status=?1 and hu.tenantId=?2 and hu.checksum=?3");
    q.setParameter(1, TaskPackageStatus.ACTIVE);
    q.setParameter(2, tenantId);
    q.setParameter(3, md5sum);
    List<DeploymentUnit> resultList = q.getResultList();
    DeploymentUnit deploymentUnit = null;
    if (resultList.size() != 0) {
        deploymentUnit = resultList.get(0);
    }
    return deploymentUnit;
}
Also used : Query(javax.persistence.Query) HumanTaskDeploymentUnit(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit)

Aggregations

HumanTaskDeploymentUnit (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit)5 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 File (java.io.File)3 Query (javax.persistence.Query)2 QName (javax.xml.namespace.QName)2 DeploymentUnitDAO (org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO)2 HumanTaskDeploymentException (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ContextException (org.apache.ode.bpel.iapi.ContextException)1 ProcessConf (org.apache.ode.bpel.iapi.ProcessConf)1 ProcessStoreEvent (org.apache.ode.bpel.iapi.ProcessStoreEvent)1 ConfStoreConnection (org.apache.ode.store.ConfStoreConnection)1 DeploymentUnitDAO (org.apache.ode.store.DeploymentUnitDAO)1 DeploymentUnitDir (org.apache.ode.store.DeploymentUnitDir)1 ProcessConfDAO (org.apache.ode.store.ProcessConfDAO)1