Skip to content

Commit

Permalink
Initial Job Service implementation (#1)
Browse files Browse the repository at this point in the history
* Initial Job Service implementation

Initial Job Service implementation

inserting swagger

* Apply PR comments and some code refactoring, test

* Fix JobScheduler when cancelling job

* Fixing cancel already scheduled job when re-scheduling
  • Loading branch information
tiagodolphine authored and mswiderski committed Nov 15, 2019
1 parent 5f01ac7 commit ce7b785
Show file tree
Hide file tree
Showing 25 changed files with 1,459 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
package org.kie.kogito.jobs.api;

import java.time.ZonedDateTime;
import java.util.Objects;

/**
* Job describes the actual entity that should be scheduled and executed
* Job describes the actual entity that should be scheduled and executed
* upon given expiration time. The job requires following information
* <ul>
* <li>id - unique UUID based identifier</li>
* <li>expirationTime - the time when this job should be executed</li>
* <li>callbackEndpoint - the callback endpoint (http/https) that will be invoked upon expiration</li>
* </ul>
*
*
* On top of that there are additional meta data that points the job to the owner - such as process instance.
* <ul>
* <li>processInstanceId - process instance that owns the job</li>
Expand All @@ -49,6 +50,20 @@ public class Job {
private String processId;
private String rootProcessId;

public Job() {
}

public Job(String id, ZonedDateTime expirationTime, Integer priority, String callbackEndpoint, String processInstanceId, String rootProcessInstanceId, String processId, String rootProcessId) {
this.id = id;
this.expirationTime = expirationTime;
this.priority = priority;
this.callbackEndpoint = callbackEndpoint;
this.processInstanceId = processInstanceId;
this.rootProcessInstanceId = rootProcessInstanceId;
this.processId = processId;
this.rootProcessId = rootProcessId;
}

public String getId() {
return id;
}
Expand Down Expand Up @@ -113,6 +128,30 @@ public void setRootProcessId(String rootProcessId) {
this.rootProcessId = rootProcessId;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Job)) {
return false;
}
Job job = (Job) o;
return Objects.equals(getId(), job.getId()) &&
Objects.equals(getExpirationTime(), job.getExpirationTime()) &&
Objects.equals(getPriority(), job.getPriority()) &&
Objects.equals(getCallbackEndpoint(), job.getCallbackEndpoint()) &&
Objects.equals(getProcessInstanceId(), job.getProcessInstanceId()) &&
Objects.equals(getRootProcessInstanceId(), job.getRootProcessInstanceId()) &&
Objects.equals(getProcessId(), job.getProcessId()) &&
Objects.equals(getRootProcessId(), job.getRootProcessId());
}

@Override
public int hashCode() {
return Objects.hash(getId(), getExpirationTime(), getPriority(), getCallbackEndpoint(), getProcessInstanceId(), getRootProcessInstanceId(), getProcessId(), getRootProcessId());
}

@Override
public String toString() {
return "Job [id=" + id + ", expirationTime=" + expirationTime + ", priority=" + priority + ", callbackEndpoint=" + callbackEndpoint + ", processInstanceId=" + processInstanceId + ", rootProcessInstanceId=" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.kogito.jobs.api;

import java.time.ZonedDateTime;

public class JobBuilder {

private String id;
private ZonedDateTime expirationTime;
private Integer priority;
private String callbackEndpoint;
private String processInstanceId;
private String rootProcessInstanceId;
private String processId;
private String rootProcessId;

public JobBuilder id(String id) {
this.id = id;
return this;
}

public JobBuilder expirationTime(ZonedDateTime expirationTime) {
this.expirationTime = expirationTime;
return this;
}

public JobBuilder priority(Integer priority) {
this.priority = priority;
return this;
}

public JobBuilder callbackEndpoint(String callbackEndpoint) {
this.callbackEndpoint = callbackEndpoint;
return this;
}

public JobBuilder processInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
return this;
}

public JobBuilder rootProcessInstanceId(String rootProcessInstanceId) {
this.rootProcessInstanceId = rootProcessInstanceId;
return this;
}

public JobBuilder processId(String processId) {
this.processId = processId;
return this;
}

public JobBuilder rootProcessId(String rootProcessId) {
this.rootProcessId = rootProcessId;
return this;
}

public Job build() {
return new Job(id, expirationTime, priority, callbackEndpoint, processInstanceId, rootProcessInstanceId, processId, rootProcessId);
}

public static JobBuilder builder(){
return new JobBuilder();
}
}
2 changes: 2 additions & 0 deletions addons/jobs/jobs-service/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ target/
/*.ipr
/*.iws
*.iml
*.log


137 changes: 134 additions & 3 deletions addons/jobs/jobs-service/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
Expand All @@ -7,5 +9,134 @@
</parent>
<artifactId>jobs-service</artifactId>
<name>Jobs Service</name>
<description>Jobs Service (timers and async jobs)</description>
</project>
<description>Jobs Service (Timers and Async Jobs)</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${version.io.quarkus}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>jobs-api</artifactId>
<version>8.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-axle-web-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>

<!-- Testing -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
31 changes: 31 additions & 0 deletions addons/jobs/jobs-service/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
#
# Before building the docker image run:
#
# mvn package
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/jobs-service-jvm .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/jobs-service-jvm
#
###
FROM fabric8/java-alpine-openjdk8-jre
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV AB_ENABLED=jmx_exporter
COPY target/lib/* /deployments/lib/
COPY target/*-runner.jar /deployments/app.jar
EXPOSE 8080

# run with user 1001 and be prepared for be running in OpenShift too
RUN adduser -G root --no-create-home --disabled-password 1001 \
&& chown -R 1001 /deployments \
&& chmod -R "g+rwX" /deployments \
&& chown -R 1001:root /deployments
USER 1001

ENTRYPOINT [ "/deployments/run-java.sh" ]
22 changes: 22 additions & 0 deletions addons/jobs/jobs-service/src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
####
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode
#
# Before building the docker image run:
#
# mvn package -Pnative -Dnative-image.docker-build=true
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.native -t quarkus/jobs-service .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/jobs-service
#
###
FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /work/
COPY target/*-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
Loading

0 comments on commit ce7b785

Please sign in to comment.