use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class AutoAckErrorCommand method execute.
@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
ExecutionResults executionResults = new ExecutionResults();
String emfName = (String) ctx.getData("EmfName");
if (emfName == null) {
emfName = "org.jbpm.domain";
}
String singleRun = (String) ctx.getData("SingleRun");
if ("true".equalsIgnoreCase(singleRun)) {
// disable rescheduling
this.nextScheduleTimeAdd = -1;
}
String nextRun = (String) ctx.getData("NextRun");
if (nextRun != null) {
nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun);
}
// get hold of persistence and create instance of audit service
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(emfName);
EntityManager em = emf.createEntityManager();
try {
List<ExecutionErrorInfo> errorsToAck = findErrorsToAck(em);
logger.debug("Found {} jobs that can be auto ack", errorsToAck.size());
errorsToAck.forEach(error -> {
AbstractRuntimeManager manager = (AbstractRuntimeManager) RuntimeManagerRegistry.get().getManager(error.getDeploymentId());
if (manager != null) {
ExecutionErrorManager errorManager = manager.getExecutionErrorManager();
errorManager.getStorage().acknowledge("SYSTEM", error.getErrorId());
logger.debug("Error {} has been auto acknowledged by system based on {}", error.getErrorId(), getAckRule());
} else {
logger.warn("Unable to ack error {} due missing runtime manager for '{}'", error.getErrorId(), error.getDeploymentId());
}
});
} finally {
em.close();
}
return executionResults;
}
use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class LogCleanupCommand method execute.
@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
boolean skipProcessLog = ctx.getData().containsKey("SkipProcessLog") ? Boolean.parseBoolean((String) ctx.getData("SkipProcessLog")) : false;
boolean skipTaskLog = ctx.getData().containsKey("SkipTaskLog") ? Boolean.parseBoolean((String) ctx.getData("SkipTaskLog")) : false;
;
boolean skipExecutorLog = ctx.getData().containsKey("SkipExecutorLog") ? Boolean.parseBoolean((String) ctx.getData("SkipExecutorLog")) : false;
;
SimpleDateFormat formatToUse = DATE_FORMAT;
String dataFormat = (String) ctx.getData("DateFormat");
if (dataFormat != null) {
formatToUse = new SimpleDateFormat(dataFormat);
}
ExecutionResults executionResults = new ExecutionResults();
String emfName = (String) ctx.getData("EmfName");
if (emfName == null) {
emfName = "org.jbpm.domain";
}
String singleRun = (String) ctx.getData("SingleRun");
if ("true".equalsIgnoreCase(singleRun)) {
// disable rescheduling
this.nextScheduleTimeAdd = -1;
}
String nextRun = (String) ctx.getData("NextRun");
if (nextRun != null) {
nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun);
}
// get hold of persistence and create instance of audit service
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(emfName);
ExecutorJPAAuditService auditLogService = new ExecutorJPAAuditService(emf);
// collect parameters
String olderThan = (String) ctx.getData("OlderThan");
String olderThanPeriod = (String) ctx.getData("OlderThanPeriod");
String forProcess = (String) ctx.getData("ForProcess");
String forDeployment = (String) ctx.getData("ForDeployment");
if (olderThanPeriod != null) {
long olderThanDuration = DateTimeUtils.parseDateAsDuration(olderThanPeriod);
Date olderThanDate = new Date(System.currentTimeMillis() - olderThanDuration);
olderThan = formatToUse.format(olderThanDate);
}
if (!skipTaskLog) {
// task tables
long taLogsRemoved = 0l;
taLogsRemoved = auditLogService.auditTaskDelete().processId(forProcess).dateRangeEnd(olderThan == null ? null : formatToUse.parse(olderThan)).deploymentId(forDeployment).build().execute();
logger.info("TaskAuditLogRemoved {}", taLogsRemoved);
executionResults.setData("TaskAuditLogRemoved", taLogsRemoved);
long teLogsRemoved = 0l;
teLogsRemoved = auditLogService.taskEventInstanceLogDelete().dateRangeEnd(olderThan == null ? null : formatToUse.parse(olderThan)).build().execute();
logger.info("TaskEventLogRemoved {}", teLogsRemoved);
executionResults.setData("TaskEventLogRemoved", teLogsRemoved);
}
if (!skipProcessLog) {
// process tables
long niLogsRemoved = 0l;
niLogsRemoved = auditLogService.nodeInstanceLogDelete().processId(forProcess).dateRangeEnd(olderThan == null ? null : formatToUse.parse(olderThan)).externalId(forDeployment).build().execute();
logger.info("NodeInstanceLogRemoved {}", niLogsRemoved);
executionResults.setData("NodeInstanceLogRemoved", niLogsRemoved);
long viLogsRemoved = 0l;
viLogsRemoved = auditLogService.variableInstanceLogDelete().processId(forProcess).dateRangeEnd(olderThan == null ? null : formatToUse.parse(olderThan)).externalId(forDeployment).build().execute();
logger.info("VariableInstanceLogRemoved {}", viLogsRemoved);
executionResults.setData("VariableInstanceLogRemoved", viLogsRemoved);
long piLogsRemoved = 0l;
piLogsRemoved = auditLogService.processInstanceLogDelete().processId(forProcess).status(ProcessInstance.STATE_COMPLETED, ProcessInstance.STATE_ABORTED).endDateRangeEnd(olderThan == null ? null : formatToUse.parse(olderThan)).externalId(forDeployment).build().execute();
logger.info("ProcessInstanceLogRemoved {}", piLogsRemoved);
executionResults.setData("ProcessInstanceLogRemoved", piLogsRemoved);
}
if (!skipExecutorLog) {
// executor tables
long errorInfoLogsRemoved = 0l;
errorInfoLogsRemoved = auditLogService.errorInfoLogDeleteBuilder().dateRangeEnd(olderThan == null ? null : formatToUse.parse(olderThan)).build().execute();
logger.info("ErrorInfoLogsRemoved {}", errorInfoLogsRemoved);
executionResults.setData("ErrorInfoLogsRemoved", errorInfoLogsRemoved);
long requestInfoLogsRemoved = 0l;
requestInfoLogsRemoved = auditLogService.requestInfoLogDeleteBuilder().dateRangeEnd(olderThan == null ? null : formatToUse.parse(olderThan)).status(STATUS.CANCELLED, STATUS.DONE, STATUS.ERROR).build().execute();
logger.info("RequestInfoLogsRemoved {}", requestInfoLogsRemoved);
executionResults.setData("RequestInfoLogsRemoved", requestInfoLogsRemoved);
}
// bam tables
long bamLogsRemoved = 0l;
executionResults.setData("BAMLogRemoved", bamLogsRemoved);
return executionResults;
}
use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class PrintOutCommand method execute.
public ExecutionResults execute(CommandContext ctx) {
logger.info("Command executed on executor with data {}", ctx.getData());
ExecutionResults executionResults = new ExecutionResults();
return executionResults;
}
use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method addAnotherCallbackTest.
@Test
public void addAnotherCallbackTest() throws InterruptedException {
CommandContext commandContext = new CommandContext();
commandContext.setData("businessKey", UUID.randomUUID().toString());
cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
commandContext.setData("callbacks", "org.jbpm.executor.ejb.impl.test.SimpleIncrementCallback");
executorService.scheduleRequest("org.jbpm.executor.ejb.impl.test.AddAnotherCallbackCommand", commandContext);
Thread.sleep(10000);
List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(0, inErrorRequests.size());
List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
assertEquals(0, queuedRequests.size());
List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
assertEquals(1, executedRequests.size());
assertEquals(2, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
ExecutionResults results = null;
byte[] responseData = executedRequests.get(0).getResponseData();
ObjectInputStream in = null;
try {
in = new ObjectInputStream(new ByteArrayInputStream(responseData));
results = (ExecutionResults) in.readObject();
} catch (Exception e) {
logger.warn("Exception while serializing context data", e);
return;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
String result = (String) results.getData("custom");
assertNotNull(result);
assertEquals("custom callback invoked", result);
}
use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class UserCommandWithCallback method execute.
public ExecutionResults execute(CommandContext ctx) {
logger.debug("Command executed on executor with {}", ctx.getData());
WorkItem workItem = (WorkItem) ctx.getData("workItem");
User user = (User) workItem.getParameter("UserIn");
user.setName(user.getName() + " after command execution");
ExecutionResults executionResults = new ExecutionResults();
executionResults.setData("UserOut", user);
String callbacks = (String) ctx.getData("callbacks");
ctx.setData("callbacks", callbacks + ", org.jbpm.test.jobexec.UserCommandCallback");
double item = 0;
for (int i = 0; i < 99; i++) {
logger.debug("User item: {}", item);
item++;
}
return executionResults;
}
Aggregations