Search in sources :

Example 46 with Registry

use of org.wso2.carbon.registry.core.Registry in project carbon-business-process by wso2.

the class HumanTaskPackageRepository method handleExceptionWithRollback.

/**
 * Handles exception and rollbacks an already started transaction. Don't use this method if
 * you haven't already started a registry transaction
 *
 * @param msg - Message to log
 * @param e   - original exception
 * @throws RegistryException on registry rollback error case, we'll init the cause to the
 *                           original exception we got when accessing registry
 */
protected void handleExceptionWithRollback(String msg, Exception e) throws Exception {
    Exception cachedException = null;
    log.error(msg, e);
    try {
        configRegistry.rollbackTransaction();
    } catch (RegistryException re) {
        cachedException = re;
        log.error("Transaction rollback failed", re);
    }
    if (cachedException != null) {
        cachedException.initCause(e);
        throw cachedException;
    } else {
        throw e;
    }
}
Also used : RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HumanTaskStoreException(org.wso2.carbon.humantask.core.store.HumanTaskStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 47 with Registry

use of org.wso2.carbon.registry.core.Registry in project carbon-business-process by wso2.

the class UnifiedEndpointHandler method loadPolicy.

private Policy loadPolicy(String path, MessageContext msgContext) throws AxisFault {
    Policy policyDoc = null;
    if (path.startsWith(UnifiedEndpointConstants.VIRTUAL_FILE)) {
        path = path.replaceFirst(UnifiedEndpointConstants.VIRTUAL_FILE, "");
        try {
            InputStream policyStream = UnifiedEndpointUtils.getFileInputStream(path);
            try {
                policyDoc = PolicyEngine.getPolicy(policyStream);
            } finally {
                policyStream.close();
            }
        } catch (IOException e) {
            String errMsg = "Exception while parsing policy: " + path;
            log.error(errMsg, e);
            throw new AxisFault(errMsg, e);
        }
    } else if (path.startsWith(UnifiedEndpointConstants.VIRTUAL_GOV_REG)) {
        Registry reg = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
        path = path.substring(UnifiedEndpointConstants.VIRTUAL_GOV_REG.length());
        try {
            if (reg.resourceExists(path)) {
                Resource policyResource = reg.get(path);
                policyDoc = PolicyEngine.getPolicy(policyResource.getContentStream());
            }
        } catch (RegistryException e) {
            String errMsg = "Exception while loading policy from Governance registry: " + path;
            log.error(errMsg, e);
            throw new AxisFault(errMsg, e);
        }
    } else if (path.startsWith(UnifiedEndpointConstants.VIRTUAL_CONF_REG)) {
        Registry reg = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
        path = path.substring(UnifiedEndpointConstants.VIRTUAL_CONF_REG.length());
        try {
            if (reg.resourceExists(path)) {
                Resource policyResource = reg.get(path);
                policyDoc = PolicyEngine.getPolicy(policyResource.getContentStream());
            }
        } catch (RegistryException e) {
            String errMsg = "Exception while loading policy from Configuration registry: " + path;
            log.error(errMsg, e);
            throw new AxisFault(errMsg, e);
        }
    } else {
        String errMsg = "Invalid policy path: " + path;
        log.error(errMsg);
        throw new AxisFault(errMsg);
    }
    return policyDoc;
}
Also used : Policy(org.apache.neethi.Policy) AxisFault(org.apache.axis2.AxisFault) InputStream(java.io.InputStream) Resource(org.wso2.carbon.registry.api.Resource) IOException(java.io.IOException) Registry(org.wso2.carbon.registry.api.Registry) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 48 with Registry

use of org.wso2.carbon.registry.core.Registry in project carbon-business-process by wso2.

the class BPELPackageRepository method readPropertiesOfUpdatedDeploymentInfo.

/**
 * Reads the updated properties from registry and sets the process configuration fields
 *
 * @param processConfiguration - Process's configuration details after updated
 * @param bpelPackageName      - the relevant bpel package
 * @throws RegistryException          on registry rollback error case, we'll init the cause to the
 *                                    original exception we got when accessing registry
 * @throws ProcessManagementException
 */
public void readPropertiesOfUpdatedDeploymentInfo(ProcessConfigurationImpl processConfiguration, String bpelPackageName) throws RegistryException, ProcessManagementException {
    String versionlessPackageName = BPELPackageRepositoryUtils.getVersionlessPackageName(bpelPackageName);
    String packageLocation = BPELPackageRepositoryUtils.getResourcePathForDeployInfoUpdatedBPELPackage(processConfiguration.getPackage(), versionlessPackageName);
    Resource bpelPackage = configRegistry.get(packageLocation);
    String stateInString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_STATE + processConfiguration.getProcessId());
    String inMemoryInString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_INMEMORY + processConfiguration.getProcessId());
    String processEventsInString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_EVENTS + processConfiguration.getProcessId());
    String generateTypeString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_EVENT_GENERATE + processConfiguration.getProcessId());
    String successCleanupsInString = bpelPackage.getProperty(BPELConstants.BPEL_INSTANCE_CLEANUP_SUCCESS + processConfiguration.getProcessId());
    String failureCleanupsInString = bpelPackage.getProperty(BPELConstants.BPEL_INSTANCE_CLEANUP_FAILURE + processConfiguration.getProcessId());
    // editor has been updated, read the updated fields
    if (stateInString != null) {
        ProcessState state = BPELPackageRepositoryUtils.getProcessState(stateInString);
        processConfiguration.setState(state);
        processConfiguration.setIsTransient(Boolean.parseBoolean(inMemoryInString));
        ProcessEventsListType processEventsList = new ProcessEventsListType();
        EnableEventListType enabledEventList = BPELPackageRepositoryUtils.getEnabledEventsListFromString(processEventsInString);
        processEventsList.setEnableEventsList(enabledEventList);
        Generate_type1 generateType = BPELPackageRepositoryUtils.getProcessGenerateTypeFromString(generateTypeString);
        processEventsList.setGenerate(generateType);
        ScopeEventListType scopeEventList = new ScopeEventListType();
        int j = 0;
        while (bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_SCOPE_EVENT + (j + 1) + processConfiguration.getProcessId()) != null) {
            ScopeEventType scopeEvent = BPELPackageRepositoryUtils.getScopeEventFromString(bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_SCOPE_EVENT + (j + 1) + processConfiguration.getProcessId()));
            scopeEventList.addScopeEvent(scopeEvent);
            j++;
        }
        processEventsList.setScopeEventsList(scopeEventList);
        processConfiguration.setProcessEventsList(processEventsList);
        CleanUpListType cleanUpList = new CleanUpListType();
        CleanUpType successCleanUp = BPELPackageRepositoryUtils.getSuccessCleanUpType(successCleanupsInString);
        cleanUpList.addCleanUp(successCleanUp);
        CleanUpType failureCleanUp = BPELPackageRepositoryUtils.getFailureCleanUpType(failureCleanupsInString);
        cleanUpList.addCleanUp(failureCleanUp);
        processConfiguration.setProcessCleanupConfImpl(cleanUpList);
    }
}
Also used : ProcessState(org.apache.ode.bpel.iapi.ProcessState) ProcessEventsListType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ProcessEventsListType) EnableEventListType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.EnableEventListType) ScopeEventType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ScopeEventType) Generate_type1(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.Generate_type1) ScopeEventListType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ScopeEventListType) Resource(org.wso2.carbon.registry.core.Resource) CleanUpListType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.CleanUpListType) CleanUpType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.CleanUpType)

Example 49 with Registry

use of org.wso2.carbon.registry.core.Registry in project carbon-business-process by wso2.

the class BPELPackageRepository method createBPELPackageParentCollectionWithProperties.

/**
 * Create parent collection to persisting BPEL package information. For example, if you deploy
 * a BPEL archive called 'HelloWorld.zip', we store information of that package in collection
 * named 'HelloWorld'. This will be the root for 'HelloWorld' BPEL package information and
 * there will several versions of this BPEL package in this registry collection which relates
 * to the versions deployed in BPEL engine.
 *
 * @param deploymentContext containing information on current deployment
 * @throws RegistryException        when there is a error accessing registry
 * @throws IOException              if file access error occurred during MD5 checksum generation
 * @throws NoSuchAlgorithmException when there is a error during MD5 generation
 */
private void createBPELPackageParentCollectionWithProperties(BPELDeploymentContext deploymentContext) throws RegistryException, IOException, NoSuchAlgorithmException {
    Collection bpelPackage = configRegistry.newCollection();
    bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_CHECKSUM, Utils.getMD5Checksum(deploymentContext.getBpelArchive()));
    if (log.isDebugEnabled()) {
        log.debug(deploymentContext.getBpelPackageName() + " updating checksum: " + Utils.getMD5Checksum(deploymentContext.getBpelArchive()) + " in registry");
    }
    if (deploymentContext.isFailed()) {
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_FAILED);
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_ERROR_LOG, deploymentContext.getDeploymentFailureCause());
    // bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_STACK_TRACE,
    // ExceptionUtils.getStackTrace(deploymentContext.getStackTrace()));
    } else {
        bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_DEPLOYED);
    }
    bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_VERSION, Long.toString(deploymentContext.getVersion()));
    configRegistry.put(BPELPackageRepositoryUtils.getResourcePathForBPELPackage(deploymentContext), bpelPackage);
}
Also used : Collection(org.wso2.carbon.registry.core.Collection)

Example 50 with Registry

use of org.wso2.carbon.registry.core.Registry in project carbon-business-process by wso2.

the class BPELPackageRepository method getBPELPackages.

public List<BPELPackageInfo> getBPELPackages() throws Exception {
    List<BPELPackageInfo> bpelPackages = new ArrayList<BPELPackageInfo>();
    try {
        if (configRegistry.resourceExists(BPELConstants.REG_PATH_OF_BPEL_PACKAGES)) {
            Resource parentCollection = configRegistry.get(BPELConstants.REG_PATH_OF_BPEL_PACKAGES);
            // The above registry resource we retrieve only contains set of child collections.
            // So we can directly cast the returned object to a string array.
            String[] children = (String[]) parentCollection.getContent();
            for (int i = children.length - 1; i >= 0; i--) {
                bpelPackages.add(getBPELPackageInfo(children[i]));
            }
            return sortByPackageName(bpelPackages);
        }
    } catch (RegistryException re) {
        handleExceptionWithRollback("Unable to get BPEL Packages from Repository.", re);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.wso2.carbon.registry.core.Resource) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

RegistryException (org.wso2.carbon.registry.api.RegistryException)18 Registry (org.wso2.carbon.registry.api.Registry)12 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)12 Resource (org.wso2.carbon.registry.api.Resource)10 File (java.io.File)8 IOException (java.io.IOException)8 Resource (org.wso2.carbon.registry.core.Resource)8 OMElement (org.apache.axiom.om.OMElement)7 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)7 Collection (org.wso2.carbon.registry.core.Collection)7 ArrayList (java.util.ArrayList)5 FileNotFoundException (java.io.FileNotFoundException)4 QName (javax.xml.namespace.QName)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 RegistryService (org.wso2.carbon.registry.api.RegistryService)4 ResourceData (org.wso2.carbon.registry.common.ResourceData)4 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FileInputStream (java.io.FileInputStream)3 ProcessEngine (org.activiti.engine.ProcessEngine)3