Search in sources :

Example 76 with Server

use of org.wso2.broker.amqp.Server 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 77 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class AnalyticsServerProfileBuilder method parseAnalyticsProfile.

/**
 * Parse Analytics Profile file content and adding content to AnalyticsProfile instance.
 *
 * @param content                Content of Analytics Profile
 * @param analyticsServerProfile AnalyticsServerProfile instance
 */
private void parseAnalyticsProfile(String content, AnalyticsServerProfile analyticsServerProfile) {
    try {
        OMElement resourceElement = new StAXOMBuilder(new ByteArrayInputStream(content.getBytes())).getDocumentElement();
        processAnalyticsServerProfileName(resourceElement, analyticsServerProfile);
        processCredentialElement(resourceElement, analyticsServerProfile);
        processConnectionElement(resourceElement, analyticsServerProfile);
        processStreamsElement(resourceElement, analyticsServerProfile);
    } catch (XMLStreamException e) {
        String errMsg = "Error occurred while creating the OMElement out of Analytics server " + "profile: " + profileLocation;
        handleError(errMsg, e);
    } catch (CryptoException e) {
        String errMsg = "Error occurred while decrypting password in Analytics server profile: " + profileLocation;
        handleError(errMsg, e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) CryptoException(org.wso2.carbon.core.util.CryptoException)

Example 78 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class BPELServerImpl method init.

/**
 * Initialize the ODE BPEL engine.
 *
 * @throws Exception if failed to start the BPEL engine.
 */
public void init() throws Exception {
    bpelServerConfiguration = new BPELServerConfiguration();
    odeConfigurationProperties = new ODEConfigurationProperties(bpelServerConfiguration);
    if (log.isDebugEnabled()) {
        log.debug("Initializing transaction manager");
    }
    initTransactionManager();
    if (log.isDebugEnabled()) {
        log.debug("Creating data source");
    }
    initDataSource();
    if (log.isDebugEnabled()) {
        log.debug("Starting DAO");
    }
    initDAO();
    BPELEndpointReferenceContextImpl eprContext = new BPELEndpointReferenceContextImpl();
    if (log.isDebugEnabled()) {
        log.debug("Initializing BPEL process store");
    }
    initProcessStore(eprContext);
    if (log.isDebugEnabled()) {
        log.debug("Initializing BPEL server");
    }
    initBPELServer(eprContext);
    if (log.isDebugEnabled()) {
        log.debug("Initializing multithreaded connection manager");
    }
    initHttpConnectionManager();
    /* Register event listeners configured in ode-axis2.properties file*/
    registerEventListeners();
    /* Register message exchange interceptors configured in ode-axis.properties file*/
    registerMexInterceptors();
    registerExtensionActivityBundles();
    registerExtensionCorrelationFilters();
    try {
        odeBpelServer.start();
    } catch (Exception e) {
        shutdown();
        String errMsg = "BPEL Server failed to start.";
        log.error(errMsg, e);
        throw new Exception(errMsg, e);
    }
    if (bpelServerConfiguration.getUseDistributedLock() && isAxis2ClusteringEnabled()) {
        BPELServerHolder.getInstance().addObserver(this);
        if (log.isDebugEnabled()) {
            log.debug("Clustering Enabled, Registering Observer for HazelCast service");
        }
    }
    registerMBeans();
}
Also used : BPELServerConfiguration(org.wso2.carbon.bpel.core.ode.integration.config.BPELServerConfiguration) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) BpelEngineException(org.apache.ode.bpel.iapi.BpelEngineException)

Example 79 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class TenantProcessStoreImpl method reloadExistingVersionsOfBPELPackage.

/**
 * Reload old versions of BPEL package. This is used to handle restart of BPS server.
 * At restart based on the last modified time of the BPEL archives we'll reload all the versions
 * of that BPEL archive.
 *
 * @param deploymentContext information about current deployment
 * @throws RegistryException                                                                     on error loading
 * resources from registry.
 * @throws org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.ProcessManagementException
 */
private void reloadExistingVersionsOfBPELPackage(BPELDeploymentContext deploymentContext) throws RegistryException, ProcessManagementException {
    BPELPackageInfo bpelPackage = repository.getBPELPackageInfo(deploymentContext);
    String lastActivePackageName = null;
    for (String packageName : bpelPackage.getAvailableVersions()) {
        if (deploymentUnits.containsKey(packageName)) {
            lastActivePackageName = packageName;
        } else {
            // version of the package
            if (null != lastActivePackageName && isConfigRegistryReadOnly()) {
                loadExistingBPELPackage(lastActivePackageName);
            }
            loadExistingBPELPackage(packageName);
        }
    }
}
Also used : BPELPackageInfo(org.wso2.carbon.bpel.core.ode.integration.store.repository.BPELPackageInfo)

Example 80 with Server

use of org.wso2.broker.amqp.Server in project carbon-business-process by wso2.

the class ProcessKPIParseHandler method executeParse.

@Override
protected void executeParse(BpmnParse bpmnParse, BaseElement baseElement) {
    ProcessDefinitionEntity processDefinitionEntity = bpmnParse.getCurrentProcessDefinition();
    // We have to check if the data publishing KPI listener has already been associated at server startup.
    ExecutionListener processTerminationKPIListener = null;
    List<ExecutionListener> endListeners = processDefinitionEntity.getExecutionListeners(PvmEvent.EVENTNAME_END);
    if (endListeners != null) {
        for (ExecutionListener listener : endListeners) {
            if (listener instanceof ProcessTerminationKPIListener) {
                processTerminationKPIListener = listener;
            }
        }
    }
    if (processTerminationKPIListener == null) {
        if (log.isDebugEnabled()) {
            log.debug("Enabling data publishing for process: " + processDefinitionEntity.getName());
        }
        processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationKPIListener());
    }
}
Also used : ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessTerminationKPIListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.ProcessTerminationKPIListener) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)28 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 File (java.io.File)8 JSONObject (org.json.simple.JSONObject)7 MalformedURLException (java.net.MalformedURLException)6 URL (java.net.URL)6 OMElement (org.apache.axiom.om.OMElement)6 JSONObject (org.json.JSONObject)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 Test (org.testng.annotations.Test)5 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)5 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)5 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4