Search in sources :

Example 1 with CancelJobRequestEvent

use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-apps by kiegroup.

the class BaseMessagingApiIT method cancelJob.

@Test
@Timeout(value = 10, unit = TimeUnit.MINUTES)
protected void cancelJob() {
    assertCallbackResource();
    // create a job service request event and send it to the jobs service.
    ZonedDateTime expiration = ZonedDateTime.now().plusDays(1);
    String callback = buildCallbackEndpoint(getCallbackResourceURL(), PROCESS_ID, PROCESS_INSTANCE_ID, NODE_INSTANCE_ID_2);
    CreateProcessInstanceJobRequestEvent createJobEvent = CreateProcessInstanceJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).job(new Job(JOB_ID_2, expiration, PRIORITY, callback, PROCESS_INSTANCE_ID, ROOT_PROCESS_INSTANCE_ID, PROCESS_ID, ROOT_PROCESS_ID, REPEAT_INTERVAL, REPEAT_LIMIT, NODE_INSTANCE_ID_2)).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).rootProcessInstanceId(ROOT_PROCESS_INSTANCE_ID).rootProcessId(ROOT_PROCESS_ID).kogitoAddons(KOGITO_ADDONS).build();
    String createJobEventJson = serializer.serialize(createJobEvent);
    jobEventsEmitter.send(createJobEventJson);
    // wait until the job is created or fail if the CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS elapsed.
    String jobUrl = "/jobs/" + JOB_ID_2;
    waitUntilResult(() -> getJob(jobUrl), response -> expectedJobExists(JOB_ID_2, response), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
    // create a job service cancel event and send it to the jobs service.
    CancelJobRequestEvent cancelJobEvent = CancelJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).jobId(JOB_ID_2).build();
    String cancelJobEventJson = serializer.serialize(cancelJobEvent);
    jobEventsEmitter.send(cancelJobEventJson);
    // wait until the job was canceled or fail if CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS elapsed.
    waitUntilResult(() -> getJob(jobUrl), response -> expectedJobDontExists(JOB_ID_2, response), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) ZonedDateTime(java.time.ZonedDateTime) CancelJobRequestEvent(org.kie.kogito.jobs.api.event.CancelJobRequestEvent) Job(org.kie.kogito.jobs.api.Job) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 2 with CancelJobRequestEvent

use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-apps by kiegroup.

the class ReactiveMessagingEventConsumerTest method prepareCancelJobWithExistingJob.

private void prepareCancelJobWithExistingJob(JobDetails existingJob) {
    CancelJobRequestEvent event = CancelJobRequestEvent.builder().jobId(JOB_ID).build();
    doReturn(event).when(message).getPayload();
    CompletionStage<JobDetails> completionStage = CompletableFuture.completedFuture(existingJob);
    doReturn(completionStage).when(scheduler).cancel(JOB_ID);
}
Also used : CancelJobRequestEvent(org.kie.kogito.jobs.api.event.CancelJobRequestEvent) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails)

Example 3 with CancelJobRequestEvent

use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-runtimes by kiegroup.

the class JobCloudEventSerializerTest method serializeCancelJobRequestEvent.

@Test
void serializeCancelJobRequestEvent() throws Exception {
    CancelJobRequestEvent event = CancelJobRequestEvent.builder().id(ID).specVersion(SPEC_VERSION).source(SOURCE).time(TIME).subject(SUBJECT).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).rootProcessInstanceId(ROOT_PROCESS_INSTANCE_ID).rootProcessId(ROOT_PROCESS_ID).kogitoAddons(KOGITO_ADDONS).jobId(JOB_ID).build();
    String json = serializer.serialize(event);
    assertThat(json).isNotNull();
    JsonNode jsonNode = OBJECT_MAPPER.readTree(json);
    assertHasTotalFields(jsonNode, 12);
    assertHasFieldWithValue(jsonNode, "type", CANCEL_JOB_REQUEST);
    assertHasBaseFields(jsonNode);
    assertHasProcessContextFields(jsonNode);
    JsonNode dataJsonNode = jsonNode.get("data");
    assertThat(dataJsonNode).isNotNull();
    assertHasTotalFields(dataJsonNode, 1);
    assertHasFieldWithValue(dataJsonNode, "id", JOB_ID);
}
Also used : CancelJobRequestEvent(org.kie.kogito.jobs.api.event.CancelJobRequestEvent) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 4 with CancelJobRequestEvent

use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-runtimes by kiegroup.

the class ReactiveMessagingJobsService method cancelJob.

@Override
public boolean cancelJob(String id) {
    LOGGER.debug("cancelJob, id: {}", id);
    CancelJobRequestEvent event = CancelJobRequestEvent.builder().source(serviceUrl).jobId(id).kogitoAddons(KOGITO_ADDON).build();
    emitEvent(event);
    return true;
}
Also used : CancelJobRequestEvent(org.kie.kogito.jobs.api.event.CancelJobRequestEvent)

Example 5 with CancelJobRequestEvent

use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-apps by kiegroup.

the class ReactiveMessagingEventConsumerTest method onCancelJobWithError.

@Test
void onCancelJobWithError() {
    CancelJobRequestEvent event = CancelJobRequestEvent.builder().jobId(JOB_ID).build();
    doReturn(event).when(message).getPayload();
    CompletionStage<JobDetails> completionStage = CompletableFuture.failedFuture(new Exception(INTERNAL_ERROR));
    doReturn(completionStage).when(scheduler).cancel(JOB_ID);
    executeFailedExecution(INTERNAL_ERROR);
    verify(scheduler).cancel(JOB_ID);
}
Also used : CancelJobRequestEvent(org.kie.kogito.jobs.api.event.CancelJobRequestEvent) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails) JobServiceException(org.kie.kogito.jobs.service.exception.JobServiceException) Test(org.junit.jupiter.api.Test)

Aggregations

CancelJobRequestEvent (org.kie.kogito.jobs.api.event.CancelJobRequestEvent)6 Test (org.junit.jupiter.api.Test)4 JobDetails (org.kie.kogito.jobs.service.model.job.JobDetails)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ZonedDateTime (java.time.ZonedDateTime)1 Timeout (org.junit.jupiter.api.Timeout)1 Job (org.kie.kogito.jobs.api.Job)1 CreateProcessInstanceJobRequestEvent (org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent)1 JobServiceException (org.kie.kogito.jobs.service.exception.JobServiceException)1