Search in sources :

Example 1 with DeploymentUnitDAO

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

the class TenantProcessStoreImpl method findBPELPackageInFileSystem.

private File findBPELPackageInFileSystem(DeploymentUnitDAO dudao) {
    String duName = dudao.getName();
    // Done: Fix the logic to handle registry
    log.info("Looking for BPEL package in file system for deployment unit " + duName);
    File bpelDUDirectory = new File(bpelDURepo, duName);
    if (bpelDUDirectory.exists()) {
        return bpelDUDirectory;
    } else {
        String registryCollectionPath = dudao.getDeploymentUnitDir();
        try {
            if (tenantConfigRegistry.resourceExists(registryCollectionPath)) {
                if (!bpelDUDirectory.exists() && !bpelDUDirectory.mkdirs()) {
                    String errMsg = "Error creating BPEL deployment unit repository for " + "tenant " + tenantId;
                    log.error(errMsg);
                    log.error("Failed to load BPEL deployment unit " + duName + " due to above error.");
                    throw new BPELDeploymentException(errMsg);
                }
                boolean deployedOnCarbon310 = false;
                // Check whether the registry repo is of type carbon 3.1.0
                if (tenantConfigRegistry.resourceExists(registryCollectionPath + RegistryConstants.PATH_SEPARATOR + duName)) {
                    registryCollectionPath += RegistryConstants.PATH_SEPARATOR + duName;
                    deployedOnCarbon310 = true;
                    if (log.isDebugEnabled()) {
                        log.debug("Found a carbon 3.1.0 compatible deployment unit at " + registryCollectionPath);
                    }
                }
                RegistryClientUtils.exportFromRegistry(bpelDUDirectory, registryCollectionPath, tenantConfigRegistry);
                if (deployedOnCarbon310) {
                    if (log.isDebugEnabled()) {
                        log.debug("Recompiling the carbon 3.1.0 compatible deployment unit at " + bpelDUDirectory);
                    }
                    // Re-compiling to get rid of binary compatibility issues.
                    DeploymentUnitDir du = new DeploymentUnitDir(bpelDUDirectory);
                    for (File file : du.allFiles()) {
                        if (file.getAbsolutePath().endsWith(".cbp") && !file.delete()) {
                            log.warn("Unable to delete " + file);
                        }
                    }
                    du.compile();
                }
                return bpelDUDirectory;
            } else {
                String errMsg = "Expected resource: " + registryCollectionPath + " not found in the registry";
                log.error(errMsg);
                throw new BPELDeploymentException(errMsg);
            }
        } catch (RegistryException re) {
            String errMsg = "Error while exporting deployment unit: " + duName + " to file system from the registry.";
            log.error(errMsg, re);
            throw new BPELDeploymentException(errMsg, re);
        }
    }
}
Also used : DeploymentUnitDir(org.apache.ode.store.DeploymentUnitDir) File(java.io.File) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 2 with DeploymentUnitDAO

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

the class HumanTaskPackageRepository method createHumanTaskPackageParentCollectionWithProperties.

/**
 * Create parent collection for human task package using DeploymentUnitDAO
 *
 * @param deploymentUnitDAO
 * @throws RegistryException
 */
private void createHumanTaskPackageParentCollectionWithProperties(DeploymentUnitDAO deploymentUnitDAO) throws RegistryException {
    Collection humanPackage = configRegistry.newCollection();
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_CHECKSUM, deploymentUnitDAO.getChecksum());
    if (log.isDebugEnabled()) {
        log.debug(deploymentUnitDAO.getPackageName() + " updating checksum: " + deploymentUnitDAO.getChecksum() + " in registry");
    }
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_STATUS, String.valueOf(deploymentUnitDAO.getStatus()));
    humanPackage.setProperty(HumanTaskConstants.HUMANTASK_PACKAGE_PROP_LATEST_VERSION, Long.toString(deploymentUnitDAO.getVersion()));
    configRegistry.put(HumanTaskPackageRepositoryUtils.getResourcePathForHumanTaskPackage(deploymentUnitDAO), humanPackage);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Example 3 with DeploymentUnitDAO

use of org.wso2.carbon.humantask.core.dao.DeploymentUnitDAO 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);
            }
        }
    }
}
Also used : HumanTaskStoreException(org.wso2.carbon.humantask.core.store.HumanTaskStoreException) Resource(org.wso2.carbon.registry.core.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) FileInputStream(java.io.FileInputStream)

Example 4 with DeploymentUnitDAO

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

the class HumanTaskDAOConnectionImpl method createDeploymentUnitDAO.

public DeploymentUnitDAO createDeploymentUnitDAO(HumanTaskDeploymentUnit deploymentUnit, int tenantId) {
    String taskRelativePath = "repository" + File.separator + HumanTaskConstants.HUMANTASK_REPO_DIRECTORY + File.separator + tenantId + File.separator + deploymentUnit.getName();
    DeploymentUnitDAO deploymentUnitDAO = new DeploymentUnit();
    deploymentUnitDAO.setVersion(deploymentUnit.getVersion());
    deploymentUnitDAO.setName(deploymentUnit.getName());
    deploymentUnitDAO.setPackageName(deploymentUnit.getPackageName());
    deploymentUnitDAO.setStatus(TaskPackageStatus.ACTIVE);
    deploymentUnitDAO.setChecksum(deploymentUnit.getMd5sum());
    deploymentUnitDAO.setDeploymentUnitDir(taskRelativePath);
    deploymentUnitDAO.setDeployDate(new Date());
    deploymentUnitDAO.setTenantId(tenantId);
    entityManager.persist(deploymentUnitDAO);
    return deploymentUnitDAO;
}
Also used : HumanTaskDeploymentUnit(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentUnit) Date(java.util.Date)

Example 5 with DeploymentUnitDAO

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

the class HumanTaskDAOConnectionImpl method getDeploymentUnitByName.

public DeploymentUnitDAO getDeploymentUnitByName(int tenantId, String packageName) {
    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.packageName=?3");
    q.setParameter(1, TaskPackageStatus.ACTIVE);
    q.setParameter(2, tenantId);
    q.setParameter(3, packageName);
    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