Search in sources :

Example 1 with ExecutorJPAAuditService

use of org.jbpm.executor.impl.jpa.ExecutorJPAAuditService in project jbpm by kiegroup.

the class BasicExecutorBaseTest method cleanupLogExecutionTest.

@Test(timeout = 10000)
public void cleanupLogExecutionTest() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(1, queuedRequests.size());
    List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(3, executedRequests.size());
    executorService.cancelRequest(requestId + 3);
    List<RequestInfo> canceled = executorService.getCancelledRequests(new QueryContext());
    ExecutorJPAAuditService auditService = new ExecutorJPAAuditService(emf);
    int resultCount = auditService.requestInfoLogDeleteBuilder().date(canceled.get(0).getTime()).status(STATUS.ERROR).build().execute();
    assertEquals(0, resultCount);
    resultCount = auditService.errorInfoLogDeleteBuilder().date(canceled.get(0).getTime()).build().execute();
    assertEquals(0, resultCount);
    ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("SingleRun", "true");
    ctxCMD.setData("EmfName", "org.jbpm.executor");
    ctxCMD.setData("SkipProcessLog", "true");
    ctxCMD.setData("SkipTaskLog", "true");
    executorService.scheduleRequest("org.jbpm.executor.commands.LogCleanupCommand", ctxCMD);
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(0, queuedRequests.size());
    executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(1, executedRequests.size());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) CommandContext(org.kie.api.executor.CommandContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryContext(org.kie.api.runtime.query.QueryContext) ExecutorJPAAuditService(org.jbpm.executor.impl.jpa.ExecutorJPAAuditService) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 2 with ExecutorJPAAuditService

use of org.jbpm.executor.impl.jpa.ExecutorJPAAuditService in project jbpm by kiegroup.

the class BasicExecutorIntegrationTest method cleanupLogExcecutionTest.

@Test
public void cleanupLogExcecutionTest() throws InterruptedException {
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);
    Thread.sleep(3000);
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(1, queuedRequests.size());
    List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(3, executedRequests.size());
    executorService.cancelRequest(requestId + 3);
    List<RequestInfo> canceled = executorService.getCancelledRequests(new QueryContext());
    ExecutorJPAAuditService auditService = new ExecutorJPAAuditService(emf);
    int resultCount = auditService.requestInfoLogDeleteBuilder().date(canceled.get(0).getTime()).status(STATUS.ERROR).build().execute();
    assertEquals(0, resultCount);
    resultCount = auditService.errorInfoLogDeleteBuilder().date(canceled.get(0).getTime()).build().execute();
    assertEquals(0, resultCount);
    ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("SingleRun", "true");
    ctxCMD.setData("EmfName", "org.jbpm.domain");
    ctxCMD.setData("SkipProcessLog", "true");
    ctxCMD.setData("SkipTaskLog", "true");
    executorService.scheduleRequest("org.jbpm.executor.commands.LogCleanupCommand", ctxCMD);
    Thread.sleep(5000);
    inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(0, queuedRequests.size());
    executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(1, executedRequests.size());
}
Also used : CommandContext(org.kie.api.executor.CommandContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryContext(org.kie.api.runtime.query.QueryContext) ExecutorJPAAuditService(org.jbpm.executor.impl.jpa.ExecutorJPAAuditService) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 3 with ExecutorJPAAuditService

use of org.jbpm.executor.impl.jpa.ExecutorJPAAuditService 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;
}
Also used : ExecutionResults(org.kie.api.executor.ExecutionResults) EntityManagerFactory(javax.persistence.EntityManagerFactory) ExecutorJPAAuditService(org.jbpm.executor.impl.jpa.ExecutorJPAAuditService) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with ExecutorJPAAuditService

use of org.jbpm.executor.impl.jpa.ExecutorJPAAuditService in project jbpm by kiegroup.

the class ExecutorLogCleanTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    auditService = new ExecutorJPAAuditService(getEmf());
    auditService.clear();
}
Also used : ExecutorJPAAuditService(org.jbpm.executor.impl.jpa.ExecutorJPAAuditService)

Aggregations

ExecutorJPAAuditService (org.jbpm.executor.impl.jpa.ExecutorJPAAuditService)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)2 CommandContext (org.kie.api.executor.CommandContext)2 RequestInfo (org.kie.api.executor.RequestInfo)2 QueryContext (org.kie.api.runtime.query.QueryContext)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)1 ExecutionResults (org.kie.api.executor.ExecutionResults)1