Skip to content

Commit

Permalink
[incubator-kie-issues-1551] Deadlines for Human Task
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Nov 13, 2024
1 parent 92d9570 commit 63fe004
Show file tree
Hide file tree
Showing 79 changed files with 2,515 additions and 595 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.time.temporal.ChronoUnit;

import org.kie.kogito.jobs.ProcessInstanceJobDescription;
import org.kie.kogito.jobs.JobDescription;
import org.kie.kogito.jobs.service.api.TemporalUnit;
import org.kie.kogito.jobs.service.api.recipient.http.HttpRecipient;
import org.kie.kogito.jobs.service.api.recipient.http.HttpRecipientJsonPayloadData;
Expand Down Expand Up @@ -53,25 +53,16 @@ public class JobCallbackResourceDef {

public static final String LIMIT_DEFAULT_VALUE = "0";

public static final String JOBS_CALLBACK_URI = "/management/jobs";

public static final String JOBS_CALLBACK_POST_URI = "{" + PROCESS_ID + "}/instances/{" + PROCESS_INSTANCE_ID + "}/timers/{" + TIMER_ID + "}";

private JobCallbackResourceDef() {
}

public static String buildCallbackURI(ProcessInstanceJobDescription description, String jobsCallbackEndpoint) {
return URIBuilder.toURI(jobsCallbackEndpoint
+ JOBS_CALLBACK_URI + "/"
+ description.processId()
+ "/instances/"
+ description.processInstanceId()
+ "/timers/"
+ description.timerId())
.toString();
public static String buildCallbackURI(JobDescription description, String jobsCallbackEndpoint) {
return URIBuilder.toURI(jobsCallbackEndpoint + description.path()).toString();
}

public static org.kie.kogito.jobs.service.api.Job buildCallbackPatternJob(ProcessInstanceJobDescription description,
public static org.kie.kogito.jobs.service.api.Job buildCallbackPatternJob(JobDescription description,
String callback, ObjectMapper objectMapper) {
return org.kie.kogito.jobs.service.api.Job.builder()
.id(description.id())
Expand All @@ -81,25 +72,20 @@ public static org.kie.kogito.jobs.service.api.Job buildCallbackPatternJob(Proces
.build();
}

private static HttpRecipient<HttpRecipientJsonPayloadData> buildRecipient(ProcessInstanceJobDescription description, String callback, ObjectMapper objectMapper) {
private static HttpRecipient<HttpRecipientJsonPayloadData> buildRecipient(JobDescription description, String callback, ObjectMapper objectMapper) {
return HttpRecipient.builder()
.forJsonPayload()
.payload(HttpRecipientJsonPayloadData.from(buildPayload(description, objectMapper)))
.url(callback)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.header(PROCESS_ID, description.processId())
.header(PROCESS_INSTANCE_ID, description.processInstanceId())
.header(ROOT_PROCESS_ID, description.rootProcessId())
.header(ROOT_PROCESS_INSTANCE_ID, description.rootProcessInstanceId())
.header(NODE_INSTANCE_ID, description.nodeInstanceId())
.build();
}

private static JsonNode buildPayload(ProcessInstanceJobDescription description, ObjectMapper objectMapper) {
private static JsonNode buildPayload(JobDescription description, ObjectMapper objectMapper) {
return objectMapper.valueToTree(new JobCallbackPayload(description.id()));
}

public static TimerSchedule buildSchedule(ProcessInstanceJobDescription description) {
public static TimerSchedule buildSchedule(JobDescription description) {
return TimerSchedule.builder()
.startTime(description.expirationTime().get().toOffsetDateTime().truncatedTo(ChronoUnit.MILLIS))
.repeatCount(translateLimit(description.expirationTime().repeatLimit()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.jupiter.api.Test;
import org.kie.kogito.jobs.ExactExpirationTime;
import org.kie.kogito.jobs.ExpirationTime;
import org.kie.kogito.jobs.ProcessInstanceJobDescription;
import org.kie.kogito.jobs.descriptors.ProcessInstanceJobDescription;
import org.kie.kogito.jobs.service.api.recipient.http.HttpRecipient;
import org.kie.kogito.jobs.service.api.schedule.timer.TimerSchedule;
import org.kie.kogito.jobs.service.api.serlialization.SerializationUtils;
Expand Down Expand Up @@ -71,13 +71,8 @@ void buildCallbackPatternJob() {
assertThat(httpRecipient.getMethod()).isEqualTo("POST");
assertThat(httpRecipient.getUrl()).isEqualTo(CALLBACK);
assertThat(httpRecipient.getHeaders())
.hasSize(6)
.containsEntry(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.containsEntry("processId", PROCESS_ID)
.containsEntry("processInstanceId", PROCESS_INSTANCE_ID)
.containsEntry("rootProcessId", ROOT_PROCESS_ID)
.containsEntry("rootProcessInstanceId", ROOT_PROCESS_INSTANCE_ID)
.containsEntry("nodeInstanceId", NODE_INSTANCE_ID);
.hasSize(1)
.containsEntry(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
assertThat(httpRecipient.getPayload()).isNotNull();
assertThat(httpRecipient.getPayload().getData()).isNotNull();
assertThat(httpRecipient.getPayload().getData()).isInstanceOf(JsonNode.class);
Expand All @@ -91,7 +86,7 @@ void buildCallbackPatternJob() {
}

private ProcessInstanceJobDescription mockProcessInstanceJobDescription() {
return ProcessInstanceJobDescription.builder()
return ProcessInstanceJobDescription.newProcessInstanceJobDescriptionBuilder()
.id(JOB_ID)
.timerId(TIMER_ID)
.expirationTime(EXPIRATION_TIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.net.URI;
import java.util.Objects;

import org.kie.kogito.jobs.JobDescription;
import org.kie.kogito.jobs.JobsService;
import org.kie.kogito.jobs.ProcessInstanceJobDescription;
import org.kie.kogito.jobs.api.URIBuilder;
import org.kie.kogito.jobs.service.api.Job;

Expand All @@ -46,7 +46,7 @@ public RestJobsService(String jobServiceUrl, String callbackEndpoint, ObjectMapp
this.objectMapper = objectMapper;
}

public String getCallbackEndpoint(ProcessInstanceJobDescription description) {
public String getCallbackEndpoint(JobDescription description) {
return buildCallbackURI(description, callbackEndpoint);
}

Expand All @@ -58,7 +58,7 @@ public URI getJobsServiceUri() {
return jobsServiceUri;
}

public Job buildJob(ProcessInstanceJobDescription description, String callback) {
public Job buildJob(JobDescription description, String callback) {
return buildCallbackPatternJob(description, callback, objectMapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.kie.kogito.jobs.ExactExpirationTime;
import org.kie.kogito.jobs.ProcessInstanceJobDescription;
import org.kie.kogito.jobs.ProcessJobDescription;
import org.kie.kogito.jobs.api.JobCallbackPayload;
import org.kie.kogito.jobs.descriptors.ProcessInstanceJobDescription;
import org.kie.kogito.jobs.service.api.Job;
import org.kie.kogito.jobs.service.api.recipient.http.HttpRecipient;
import org.kie.kogito.jobs.service.api.recipient.http.HttpRecipientJsonPayloadData;
Expand All @@ -37,7 +36,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public abstract class RestJobsServiceTest<T extends RestJobsService> {

Expand All @@ -64,7 +62,7 @@ void setUp() {

@Test
void testGetCallbackEndpoint() {
ProcessInstanceJobDescription description = ProcessInstanceJobDescription.builder()
ProcessInstanceJobDescription description = ProcessInstanceJobDescription.newProcessInstanceJobDescriptionBuilder()
.id(JOB_ID)
.timerId(TIMER_ID)
.expirationTime(ExactExpirationTime.now())
Expand All @@ -86,17 +84,8 @@ void testGetJobsServiceUri() {
assertThat(jobsServiceUri).hasToString(JOB_SERVICE_URL + "/v2/jobs");
}

@Test
void testScheduleProcessJob() {
ProcessJobDescription processJobDescription = ProcessJobDescription.of(ExactExpirationTime.of(EXPIRATION_TIME),
1,
PROCESS_ID);
assertThatThrownBy(() -> tested.scheduleProcessJob(processJobDescription))
.isInstanceOf(UnsupportedOperationException.class);
}

protected ProcessInstanceJobDescription buildProcessInstanceJobDescription() {
return ProcessInstanceJobDescription.builder()
return ProcessInstanceJobDescription.newProcessInstanceJobDescriptionBuilder()
.id(JOB_ID)
.timerId(TIMER_ID)
.expirationTime(ExactExpirationTime.of(EXPIRATION_TIME))
Expand All @@ -122,12 +111,7 @@ protected void assertExpectedJob(Job job, String expectedJobId) {
PROCESS_INSTANCE_ID,
TIMER_ID);
assertThat(httpRecipient.getHeaders())
.hasSize(6)
.containsEntry("processId", PROCESS_ID)
.containsEntry("processInstanceId", PROCESS_INSTANCE_ID)
.containsEntry("rootProcessId", ROOT_PROCESS_ID)
.containsEntry("rootProcessInstanceId", ROOT_PROCESS_INSTANCE_ID)
.containsEntry("nodeInstanceId", NODE_INSTANCE_ID)
.hasSize(1)
.containsEntry("Content-Type", "application/json");
assertThat(httpRecipient.getPayload()).isNotNull();
assertThat(httpRecipient.getPayload()).isInstanceOf(HttpRecipientJsonPayloadData.class);
Expand Down
27 changes: 19 additions & 8 deletions api/kogito-api/src/main/java/org/kie/kogito/StaticConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,33 @@
*/
package org.kie.kogito;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static java.util.Arrays.asList;

public class StaticConfig implements Config {

private final Addons addons;
private final Map<Class<? extends KogitoConfig>, KogitoConfig> configMap = new HashMap<>();
private Addons addons;
private Map<Class<? extends KogitoConfig>, KogitoConfig> configMap = new HashMap<>();

public StaticConfig() {
addons = Addons.EMTPY;
}

public StaticConfig(Addons addons, KogitoConfig... configs) {
init(addons, configs);
}

protected StaticConfig(Addons addons, Iterable<KogitoConfig> configs) {
init(addons, configs);
}

public StaticConfig(Addons addons,
KogitoConfig... configs) {
this(addons, Arrays.asList(configs));
protected void init(Addons addons, KogitoConfig... configs) {
init(addons, asList(configs));
}

protected StaticConfig(Addons addons,
Iterable<KogitoConfig> configs) {
protected void init(Addons addons, Iterable<KogitoConfig> configs) {
this.addons = addons;
configs.forEach(this::loadConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@

public interface JobDescription {

static final String JOBS_CALLBACK_URI = "/management/jobs";

String id();

ExpirationTime expirationTime();

Integer priority();

String path();

}
12 changes: 2 additions & 10 deletions api/kogito-api/src/main/java/org/kie/kogito/jobs/JobsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@ public interface JobsService {
* Schedules process job that is responsible for starting new process instances
* based on the given description.
*
* @param context of the job
* @param description defines what kind of process should be started upon expiration time
* @return returns unique id of the job
*/
String scheduleProcessJob(ProcessJobDescription description);

/**
* Schedules process instance related job that will signal exact same process instance
* upon expiration time.
*
* @param description defines the context of the process instance that should be signaled
* @return returns unique id of the job
*/
String scheduleProcessInstanceJob(ProcessInstanceJobDescription description);
String scheduleJob(JobDescription description);

/**
* Cancels given job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.kogito.jobs;
package org.kie.kogito.jobs.descriptors;

import org.kie.kogito.jobs.ExpirationTime;
import org.kie.kogito.jobs.JobDescription;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -93,10 +96,21 @@ public String nodeInstanceId() {
return nodeInstanceId;
}

public static ProcessInstanceJobDescriptionBuilder builder() {
public static ProcessInstanceJobDescriptionBuilder newProcessInstanceJobDescriptionBuilder() {
return new ProcessInstanceJobDescriptionBuilder();
}

@Override
public String path() {
return JOBS_CALLBACK_URI + "/"
+ processId()
+ "/instances/"
+ processInstanceId()
+ "/timers/"
+ timerId();

}

@Override
public String toString() {
return "ProcessInstanceJobDescription{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.kogito.jobs;
package org.kie.kogito.jobs.descriptors;

import java.util.UUID;

import org.kie.kogito.jobs.ExpirationTime;

public class ProcessInstanceJobDescriptionBuilder {

private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.kogito.jobs;
package org.kie.kogito.jobs.descriptors;

import java.util.UUID;

import org.kie.kogito.jobs.ExpirationTime;
import org.kie.kogito.jobs.JobDescription;
import org.kie.kogito.process.Process;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -87,4 +89,9 @@ public String processId() {
public Process<?> process() {
return process;
}

@Override
public String path() {
return "";
}
}
Loading

0 comments on commit 63fe004

Please sign in to comment.