Search in sources :

Example 36 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete 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 37 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class SampleWorkFlowExecutor method execute.

@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    WorkflowResponse workflowResponse = complete(workflowDTO);
    if (workflowDTO instanceof ApplicationRegistrationWorkflowDTO) {
        OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
        AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setApplicationInfo(oAuthApplicationInfo);
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setAccessTokenInfo(accessTokenInfo);
    }
    return workflowResponse;
}
Also used : AccessTokenInfo(org.wso2.carbon.apimgt.api.model.AccessTokenInfo) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse)

Example 38 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class SubscriptionCreationSimpleWorkflowExecutorTest method testFailureWhileExecutingSubscriptionCreationWorkFlow.

@Test
public void testFailureWhileExecutingSubscriptionCreationWorkFlow() throws APIManagementException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    try {
        PowerMockito.doThrow(new APIManagementException("Could not complete subscription creation workflow")).when(apiMgtDAO).updateSubscriptionStatus(1, "UNBLOCKED");
        subscriptionCreationSimpleWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException is not thrown when subscription creation simple workflow" + " execution failed");
    } catch (WorkflowException e) {
        Assert.assertTrue(e.getMessage().contains("Could not complete subscription creation workflow"));
    }
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class ApiMgtDAO method getAPIPolicy.

/**
 * Retrieves {@link APIPolicy} with name <code>policyName</code> and tenant Id <code>tenantNId</code>
 * <p>This will retrieve complete details about the APIPolicy with all pipelins and conditions.</p>
 *
 * @param policyName name of the policy to retrieve from the database
 * @param tenantId   tenantId of the policy
 * @return {@link APIPolicy}
 * @throws APIManagementException
 */
public APIPolicy getAPIPolicy(String policyName, int tenantId) throws APIManagementException {
    APIPolicy policy = null;
    Connection connection = null;
    PreparedStatement selectStatement = null;
    ResultSet resultSet = null;
    String sqlQuery = SQLConstants.ThrottleSQLConstants.GET_API_POLICY_SQL;
    if (forceCaseInsensitiveComparisons) {
        sqlQuery = SQLConstants.ThrottleSQLConstants.GET_API_POLICY_SQL;
    }
    try {
        connection = APIMgtDBUtil.getConnection();
        selectStatement = connection.prepareStatement(sqlQuery);
        selectStatement.setString(1, policyName);
        selectStatement.setInt(2, tenantId);
        // Should return only single result
        resultSet = selectStatement.executeQuery();
        if (resultSet.next()) {
            policy = new APIPolicy(resultSet.getString(ThrottlePolicyConstants.COLUMN_NAME));
            setCommonPolicyDetails(policy, resultSet);
            policy.setUserLevel(resultSet.getString(ThrottlePolicyConstants.COLUMN_APPLICABLE_LEVEL));
            policy.setPipelines(getPipelines(policy.getPolicyId()));
        }
    } catch (SQLException e) {
        handleException("Failed to get api policy: " + policyName + '-' + tenantId, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(selectStatement, connection, resultSet);
    }
    return policy;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy)

Example 40 with Complete

use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.

the class UserSignUpSimpleWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("User Sign Up [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
    }
    String tenantDomain = workflowDTO.getTenantDomain();
    try {
        UserRegistrationConfigDTO signupConfig = SelfSignUpUtil.getSignupConfiguration(tenantDomain);
        String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(workflowDTO.getWorkflowReference());
        updateRolesOfUser(tenantAwareUserName, SelfSignUpUtil.getRoleNames(signupConfig), tenantDomain);
    } catch (APIManagementException e) {
        throw new WorkflowException("Error while accessing signup configuration", e);
    } catch (Exception e) {
        throw new WorkflowException("Error while assigning role to user", e);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)23 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)14 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)9 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)5 List (java.util.List)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 WorkflowResponse (org.wso2.carbon.apimgt.api.WorkflowResponse)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 RepositoryService (org.activiti.engine.RepositoryService)2 Element (org.w3c.dom.Element)2