Search in sources :

Example 11 with Complete

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

the class TaskOperationsImpl method complete.

/**
 * Execution of the task finished successfully.
 * @param taskIdURI : task identifier
 * @param outputStr : task outcome (String)
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void complete(final URI taskIdURI, final String outputStr) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                Element output = DOMUtils.stringToDOM(outputStr);
                Complete completeCommand = new Complete(getCaller(), taskId, output);
                completeCommand.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Complete(org.wso2.carbon.humantask.core.engine.commands.Complete) Element(org.w3c.dom.Element) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 12 with Complete

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

the class SimpleScheduler method doLoadImmediate.

boolean doLoadImmediate() {
    if (log.isDebugEnabled()) {
        log.debug("LOAD IMMEDIATE started");
    }
    // don't load anything if we're already half-full;  we've got plenty to do already
    if (outstandingJobs.size() > todoLimit / 2) {
        return true;
    }
    List<Job> jobs = new ArrayList<Job>();
    try {
        // don't load more than we can chew
        int tps = 100;
        final int batch = Math.min((int) (immediateInterval * tps / 1000), todoLimit - outstandingJobs.size());
        // jobs might have been enqueued by #addTodoList meanwhile
        if (batch <= 0) {
            if (log.isDebugEnabled()) {
                log.debug("Max capacity reached: " + outstandingJobs.size() + " jobs dispacthed i.e. queued or being executed");
            }
            return true;
        }
        if (log.isDebugEnabled()) {
            log.debug("Started loading " + batch + " jobs from db");
        }
        // jobs = _db.dequeueImmediate(_nodeId, System.currentTimeMillis() + _immediateInterval, batch);
        List<HumanTaskJobDAO> htJobs = execTransaction(new Callable<List<HumanTaskJobDAO>>() {

            public List<HumanTaskJobDAO> call() throws Exception {
                return getConnection().dequeueImmediate(nodeId, System.currentTimeMillis() + immediateInterval, batch);
            }
        });
        for (HumanTaskJobDAO htJob : htJobs) {
            jobs.add(new Job(htJob));
        }
        if (log.isDebugEnabled()) {
            log.debug("loaded " + jobs.size() + " jobs from db");
        }
        long warningDelay = 0;
        long delayedTime = System.currentTimeMillis() - warningDelay;
        int delayedCount = 0;
        boolean runningLate;
        AbsoluteTimeDateFormat f = new AbsoluteTimeDateFormat();
        for (Job j : jobs) {
            // jobs might have been enqueued by #addTodoList meanwhile
            if (outstandingJobs.size() >= todoLimit) {
                if (log.isDebugEnabled()) {
                    log.debug("Max capacity reached: " + outstandingJobs.size() + " jobs dispacthed i.e. queued or being executed");
                }
                break;
            }
            runningLate = j.schedDate <= delayedTime;
            if (runningLate) {
                // TODO run the job here
                delayedCount++;
            }
            if (log.isDebugEnabled()) {
                log.debug("todo.enqueue job from db: " + j.getJobID() + " for " + j.schedDate + "(" + f.format(j.schedDate) + ") " + (runningLate ? " delayed=true" : ""));
            }
            enqueue(j);
        }
        if (delayedCount > 0) {
            log.warn("Dispatching jobs with more than " + (warningDelay / 60000) + " minutes delay. Either the server was down for some time or the job " + "load is greater than available capacity");
        }
        // clear only if the batch succeeded
        processedSinceLastLoadTask.clear();
        return true;
    } catch (Exception ex) {
        log.error("Error loading immediate jobs from database.", ex);
        return false;
    } finally {
        if (log.isDebugEnabled()) {
            log.debug("LOAD IMMEDIATE complete");
        }
    }
}
Also used : AbsoluteTimeDateFormat(org.apache.log4j.helpers.AbsoluteTimeDateFormat) HumanTaskJobDAO(org.wso2.carbon.humantask.core.dao.HumanTaskJobDAO) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) InvalidJobsInDbException(org.wso2.carbon.humantask.core.api.scheduler.InvalidJobsInDbException) InvalidUpdateRequestException(org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException)

Example 13 with Complete

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

the class PolicyDAOImpl method getSubscriptionPolicyById.

/**
 * Retrieves {@link SubscriptionPolicy} with policy uuid <code>uuid</code>
 * <p>This will retrieve complete details about the ApplicationPolicy with all pipelins and conditions.</p>
 *
 * @param uuid uuid of the policy to retrieve from the database
 * @return {@link SubscriptionPolicy}
 */
private SubscriptionPolicy getSubscriptionPolicyById(String uuid) throws SQLException, APIMgtDAOException {
    final String query = "SELECT NAME, UUID, QUOTA_TYPE, TIME_UNIT, UNIT_TIME, QUOTA, QUOTA_UNIT, DESCRIPTION, " + "DISPLAY_NAME, CUSTOM_ATTRIBUTES, IS_DEPLOYED, RATE_LIMIT_COUNT, RATE_LIMIT_TIME_UNIT, " + "STOP_ON_QUOTA_REACH, BILLING_PLAN FROM AM_SUBSCRIPTION_POLICY WHERE UUID = ?";
    try (Connection conn = DAOUtil.getConnection();
        PreparedStatement statement = conn.prepareStatement(query)) {
        statement.setString(1, uuid);
        statement.execute();
        try (ResultSet rs = statement.getResultSet()) {
            if (rs.next()) {
                return createSubscriptionPolicyFromResultSet(uuid, rs);
            } else {
                // not found
                String msg = "Subscription Policy not found for id: " + uuid;
                log.warn(msg);
                throw new APIMgtDAOException(msg, ExceptionCodes.POLICY_NOT_FOUND);
            }
        }
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 14 with Complete

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

the class FileEncryptionUtilityTestCase method testEncryptFiles.

@Test(priority = 2, description = "Test complete flow of encrypting files")
public void testEncryptFiles() throws Exception {
    FileEncryptionConfigurations config = new FileEncryptionConfigurations();
    List<String> filesToEncrypt = new ArrayList<>();
    filesToEncrypt.add(testFileToEncrypt);
    config.setFilesToEncrypt(filesToEncrypt);
    SecureVault secureVault = Mockito.mock(SecureVault.class);
    FileEncryptionUtility fileEncryptionUtility = FileEncryptionUtility.getInstance();
    fileEncryptionUtility.setConfig(config);
    fileEncryptionUtility.setAesKeyFileLocation();
    fileEncryptionUtility.setSecureVault(secureVault);
    Answer nonEncryptedAesKey = invocation -> {
        Object[] args = invocation.getArguments();
        return args[0];
    };
    Mockito.when(secureVault.encrypt(Mockito.anyString().getBytes())).thenAnswer(nonEncryptedAesKey);
    Mockito.when(secureVault.decrypt(Mockito.anyString().getBytes())).thenAnswer(nonEncryptedAesKey);
    fileEncryptionUtility.createAndStoreAESKey();
    fileEncryptionUtility.encryptFiles();
    Assert.assertTrue(Files.notExists(Paths.get(originalFilePath)));
    Assert.assertEquals(fileEncryptionUtility.readFromEncryptedFile(encryptedFilePath), someText);
}
Also used : AfterClass(org.testng.annotations.AfterClass) Files(java.nio.file.Files) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test) File(java.io.File) APIFileUtils(org.wso2.carbon.apimgt.core.util.APIFileUtils) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) List(java.util.List) Assert(org.testng.Assert) Paths(java.nio.file.Paths) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SecureVault(org.wso2.carbon.secvault.SecureVault) FileEncryptionConfigurations(org.wso2.carbon.apimgt.core.configuration.models.FileEncryptionConfigurations) FileEncryptionConfigurations(org.wso2.carbon.apimgt.core.configuration.models.FileEncryptionConfigurations) Answer(org.mockito.stubbing.Answer) SecureVault(org.wso2.carbon.secvault.SecureVault) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 15 with Complete

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

the class APIGatewayPublisherImpl method deleteAPI.

@Override
public void deleteAPI(API api) throws GatewayException {
    // build the message to send
    APIEvent apiDeleteEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_DELETE);
    apiDeleteEvent.setLabels(api.getLabels());
    apiDeleteEvent.setApiSummary(toAPISummary(api));
    publishToPublisherTopic(apiDeleteEvent);
    if (log.isDebugEnabled()) {
        log.debug("API : " + api.getName() + " deleted event has been successfully published to broker");
    }
    if (api.hasOwnGateway()) {
        // Delete the Gateway - check how we can assume that we complete the deletion
        try {
            List<String> labels = api.getLabels();
            if (labels != null && !labels.isEmpty()) {
                removeContainerBasedGateway(labels.toArray()[0].toString(), api);
            } else {
                log.error("Could not delete container based gateways as labels could not find in the API.");
            }
        } catch (ContainerBasedGatewayException e) {
            String msg = "Error while removing the container based gateway";
            throw new GatewayException(msg, e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED);
        }
    }
}
Also used : APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent) GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)

Aggregations

WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)9 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 List (java.util.List)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)3 RepositoryService (org.activiti.engine.RepositoryService)2 Element (org.w3c.dom.Element)2 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)2 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)2 Application (org.wso2.carbon.apimgt.core.models.Application)2 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)2 Complete (org.wso2.carbon.humantask.core.engine.commands.Complete)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1