Java Code Examples for org.flowable.job.api.Job#getId()

The following examples show how to use org.flowable.job.api.Job#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/cmmn-management/jobs/{jobId}/exception-stacktrace")
public String getJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getJobById(jobId);

    String stackTrace = managementService.getJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 2
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a deadletter job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/management/deadletter-jobs/{jobId}/exception-stacktrace")
public String getDeadLetterJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getDeadLetterJobById(jobId);

    String stackTrace = managementService.getDeadLetterJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Suspended job with id '" + job.getId() + "' does not have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 3
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a suspended job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/management/suspended-jobs/{jobId}/exception-stacktrace")
public String getSuspendedJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getSuspendedJobById(jobId);

    String stackTrace = managementService.getSuspendedJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Suspended job with id '" + job.getId() + "' does not have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 4
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a timer job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/management/timer-jobs/{jobId}/exception-stacktrace")
public String getTimerJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getTimerJobById(jobId);

    String stackTrace = managementService.getTimerJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Timer job with id '" + job.getId() + "' does not have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 5
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/management/jobs/{jobId}/exception-stacktrace")
public String getJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getJobById(jobId);

    String stackTrace = managementService.getJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Job with id '" + job.getId() + "' does not have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 6
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a deadletter job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/cmmn-management/deadletter-jobs/{jobId}/exception-stacktrace")
public String getDeadLetterJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getDeadLetterJobById(jobId);

    String stackTrace = managementService.getDeadLetterJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Suspended job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 7
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a suspended job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/cmmn-management/suspended-jobs/{jobId}/exception-stacktrace")
public String getSuspendedJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getSuspendedJobById(jobId);

    String stackTrace = managementService.getSuspendedJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Suspended job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 8
Source File: JobExceptionStacktraceResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a timer job", tags = { "Jobs" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
        @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job does not have an exception stacktrace. Status-description contains additional information about the error.")
})
@GetMapping("/cmmn-management/timer-jobs/{jobId}/exception-stacktrace")
public String getTimerJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
    Job job = getTimerJobById(jobId);

    String stackTrace = managementService.getTimerJobExceptionStacktrace(job.getId());

    if (stackTrace == null) {
        throw new FlowableObjectNotFoundException("Timer job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
    }

    response.setContentType("text/plain");
    return stackTrace;
}
 
Example 9
Source File: CamelExceptionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/camel/exception/bpmnExceptionInRouteAsynchronous.bpmn20.xml" })
public void testNonBpmnPathAsynchronous() {

    // Signal ThrowBpmnExceptionBean to throw non bpmn exception
    ThrowBpmnExceptionBean.setExceptionType(ThrowBpmnExceptionBean.ExceptionType.NON_BPMN_EXCEPTION);
    runtimeService.startProcessInstanceByKey("exceptionInRouteSynchron");
    assertThat(JobTestHelper.areJobsAvailable(managementService)).isTrue();

    Job job = managementService.createJobQuery().singleResult();
    String jobId = job.getId();
    assertThatThrownBy(() -> managementService.executeJob(jobId))
            .isInstanceOf(Exception.class);

    // The job is now a timer job, to be retried later
    job = managementService.createTimerJobQuery().singleResult();
    assertThat(job.getExceptionMessage()).isEqualTo("Unhandled exception on camel route");

    assertThat(ExceptionServiceMock.isCalled()).isFalse();
    assertThat(NoExceptionServiceMock.isCalled()).isFalse();
}
 
Example 10
Source File: DefaultCmmnJobParentStateResolver.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSuspended(Job job) {
    if (!ScopeTypes.CMMN.equals(job.getScopeType()) || StringUtils.isEmpty(job.getScopeId())) {
        throw new FlowableIllegalArgumentException("Job "+ job.getId() +" parent is not CMMN case");
    }
    CaseInstance caseInstance = this.cmmnEngineConfiguration.cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(job.getScopeId()).singleResult();
    return CaseInstanceState.SUSPENDED.equals(caseInstance.getState());
}
 
Example 11
Source File: DefaultProcessJobParentStateResolver.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSuspended(Job job) {
    if (StringUtils.isEmpty(job.getProcessInstanceId())) {
        throw new FlowableIllegalArgumentException("Job " + job.getId() + " parent is not process instance");
    }
    ProcessInstance processInstance = this.processEngineConfiguration.getRuntimeService().createProcessInstanceQuery().processInstanceId(job.getProcessInstanceId()).singleResult();
    return processInstance.isSuspended();
}
 
Example 12
Source File: JobExecutorCmdExceptionTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobCommandsWith2Exceptions() {
    commandExecutor.execute(new Command<String>() {

        @Override
        public String execute(CommandContext commandContext) {
            JobEntity message = createTweetExceptionMessage();
            CommandContextUtil.getJobService(commandContext).scheduleAsyncJob(message);
            return message.getId();
        }
    });

    Job job = managementService.createJobQuery().singleResult();
    assertThat(job.getRetries()).isEqualTo(3);

    String jobId = job.getId();
    assertThatThrownBy(() -> managementService.executeJob(jobId))
            .isInstanceOf(Exception.class);

    job = managementService.createTimerJobQuery().singleResult();
    assertThat(job.getRetries()).isEqualTo(2);

    assertThatThrownBy(() -> {
        managementService.moveTimerToExecutableJob(jobId);
        managementService.executeJob(jobId);
    })
            .isInstanceOf(Exception.class);

    job = managementService.createTimerJobQuery().singleResult();
    assertThat(job.getRetries()).isEqualTo(1);

    managementService.moveTimerToExecutableJob(job.getId());
    managementService.executeJob(job.getId());
}
 
Example 13
Source File: JobExecutorCmdExceptionTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testJobCommandsWith3Exceptions() {
    tweetExceptionHandler.setExceptionsRemaining(3);

    commandExecutor.execute(new Command<String>() {

        @Override
        public String execute(CommandContext commandContext) {
            JobEntity message = createTweetExceptionMessage();
            CommandContextUtil.getJobService(commandContext).scheduleAsyncJob(message);
            return message.getId();
        }
    });

    Job job = managementService.createJobQuery().singleResult();
    assertThat(job.getRetries()).isEqualTo(3);
    String jobId = job.getId();
    assertThatThrownBy(() -> managementService.executeJob(jobId))
            .isInstanceOf(Exception.class);

    job = managementService.createTimerJobQuery().singleResult();
    assertThat(job.getRetries()).isEqualTo(2);

    assertThatThrownBy(() -> {
        managementService.moveTimerToExecutableJob(jobId);
        managementService.executeJob(jobId);
    })
            .isInstanceOf(Exception.class);

    job = managementService.createTimerJobQuery().singleResult();
    assertThat(job.getRetries()).isEqualTo(1);

    assertThatThrownBy(() -> {
        managementService.moveTimerToExecutableJob(jobId);
        managementService.executeJob(jobId);
    })
            .isInstanceOf(Exception.class);

    job = managementService.createDeadLetterJobQuery().singleResult();
    assertThat(job).isNotNull();

    managementService.deleteDeadLetterJob(job.getId());
}
 
Example 14
Source File: TimerEventSubprocessTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
@Deployment
public void testStartingAdditionalTasks() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startingAdditionalTasks");
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(3);

    Job job = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(job).isNotNull();
    String firstTimerJobId = job.getId();

    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);

    // now let's first complete the task in the main flow:
    org.flowable.task.api.Task task = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
    taskService.complete(task.getId());

    List<Job> jobs = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).list();
    assertThat(jobs).hasSize(2);
    
    String secondTimerJobId = null;
    for (Job timerJob : jobs) {
        if (!timerJob.getId().equals(firstTimerJobId)) {
            secondTimerJobId = timerJob.getId();
        }
    }

    job = managementService.moveTimerToExecutableJob(secondTimerJobId);
    managementService.executeJob(job.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(2);
    
    job = managementService.moveTimerToExecutableJob(firstTimerJobId);
    managementService.executeJob(job.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(3);
    
    task = taskService.createTaskQuery().taskDefinitionKey("additionalTask").singleResult();
    taskService.complete(task.getId());

    assertThat(taskService.createTaskQuery().count()).isEqualTo(2);
    
    task = taskService.createTaskQuery().taskDefinitionKey("subTask1").singleResult();
    taskService.complete(task.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    task = taskService.createTaskQuery().taskDefinitionKey("additionalSubTask").singleResult();
    taskService.complete(task.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    task = taskService.createTaskQuery().taskDefinitionKey("task2").singleResult();
    taskService.complete(task.getId());

    // done!
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero();
}
 
Example 15
Source File: TimerEventSubprocessTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
@Deployment(resources="org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testStartingAdditionalTasks.bpmn20.xml")
public void testStartingAdditionalTasksWithNestedEventSubProcess() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startingAdditionalTasks");
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    Job job = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(job).isNotNull();
    String firstTimerJobId = job.getId();

    // now let's first complete the task in the main flow:
    org.flowable.task.api.Task task = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
    taskService.complete(task.getId());

    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    List<Job> jobs = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).list();
    assertThat(jobs).hasSize(2);
    
    String secondTimerJobId = null;
    for (Job timerJob : jobs) {
        if (!timerJob.getId().equals(firstTimerJobId)) {
            secondTimerJobId = timerJob.getId();
        }
    }

    job = managementService.moveTimerToExecutableJob(secondTimerJobId);
    managementService.executeJob(job.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(2);
    
    task = taskService.createTaskQuery().taskDefinitionKey("subTask1").singleResult();
    taskService.complete(task.getId());
    
    job = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(job).isNotNull();
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    task = taskService.createTaskQuery().taskDefinitionKey("additionalSubTask").singleResult();
    taskService.complete(task.getId());
    
    job = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(job).isNotNull();
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    job = managementService.moveTimerToExecutableJob(job.getId());
    managementService.executeJob(job.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(2);
    
    task = taskService.createTaskQuery().taskDefinitionKey("task2").singleResult();
    taskService.complete(task.getId());
    
    assertThat(managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).count()).isZero();
    
    task = taskService.createTaskQuery().taskDefinitionKey("additionalTask").singleResult();
    taskService.complete(task.getId());

    // done!
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero();
}
 
Example 16
Source File: TimerEventSubprocessTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
@Deployment
public void testStartingAdditionalTasksInterrupting() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startingAdditionalTasks");
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(3);

    Job job = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(job).isNotNull();
    String firstTimerJobId = job.getId();

    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);

    // now let's first complete the task in the main flow:
    org.flowable.task.api.Task task = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
    taskService.complete(task.getId());

    List<Job> jobs = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).list();
    assertThat(jobs).hasSize(2);

    String secondTimerJobId = null;
    for (Job timerJob : jobs) {
        if (!timerJob.getId().equals(firstTimerJobId)) {
            secondTimerJobId = timerJob.getId();
        }
    }

    job = managementService.moveTimerToExecutableJob(secondTimerJobId);
    managementService.executeJob(job.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    task = taskService.createTaskQuery().taskDefinitionKey("additionalSubTask").singleResult();
    taskService.complete(task.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    task = taskService.createTaskQuery().taskDefinitionKey("task2").singleResult();
    taskService.complete(task.getId());

    // done!
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero();
}
 
Example 17
Source File: TimerEventSubprocessTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
@Deployment(resources="org/flowable/engine/test/bpmn/event/timer/TimerEventSubprocessTest.testStartingAdditionalTasksInterrupting.bpmn20.xml")
public void testStartingAdditionalTasksInterruptingWithMainEventSubProcessInterrupt() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startingAdditionalTasks");
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(3);

    Job job = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(job).isNotNull();
    String firstTimerJobId = job.getId();

    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    // now let's first complete the task in the main flow:
    org.flowable.task.api.Task task = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
    taskService.complete(task.getId());

    List<Job> jobs = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).list();
    assertThat(jobs).hasSize(2);

    String secondTimerJobId = null;
    for (Job timerJob : jobs) {
        if (!timerJob.getId().equals(firstTimerJobId)) {
            secondTimerJobId = timerJob.getId();
        }
    }

    job = managementService.moveTimerToExecutableJob(secondTimerJobId);
    managementService.executeJob(job.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    job = managementService.moveTimerToExecutableJob(firstTimerJobId);
    managementService.executeJob(job.getId());
    
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);
    
    task = taskService.createTaskQuery().taskDefinitionKey("additionalTask").singleResult();
    taskService.complete(task.getId());

    // done!
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero();
}