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);
}
}
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");
}
}
}
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);
}
}
}
}
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);
}
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);
}
}
}
Aggregations