diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java index e5f03958649e1974670406e0cdf7136080a0d57b..90383b2aa0103ae984f6aa9536a71e468249ae71 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java @@ -1,6 +1,7 @@ package org.activeeon.morphemic; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.tuple.Pair; import lombok.extern.slf4j.Slf4j; import org.activeeon.morphemic.application.deployment.PAFactory; import org.activeeon.morphemic.application.deployment.PASchedulerGateway; @@ -1019,6 +1020,7 @@ public class PAGateway { long submittedJobId = schedulerGateway.submit(paJob).longValue(); job.setSubmittedJobId(submittedJobId); + job.setSubmittedJobType(SubmittedJobType.SCALE_OUT); EntityManagerHelper.persist(job); EntityManagerHelper.commit(); @@ -1309,6 +1311,7 @@ public class PAGateway { long submittedJobId = schedulerGateway.submit(paJob).longValue(); job.setSubmittedJobId(submittedJobId); + job.setSubmittedJobType(SubmittedJobType.SCALE_IN); EntityManagerHelper.persist(job); EntityManagerHelper.commit(); @@ -1486,6 +1489,7 @@ public class PAGateway { if (!paJob.getTasks().isEmpty()) { submittedJobId = schedulerGateway.submit(paJob).longValue(); jobToSubmit.setSubmittedJobId(submittedJobId); + jobToSubmit.setSubmittedJobType(SubmittedJobType.FIRST_DEPLOYMENT); LOGGER.info("Job submitted successfully. ID = " + submittedJobId); } else { LOGGER.warn("The job " + jobId + " is already deployed. Nothing to be submitted here."); @@ -1512,13 +1516,19 @@ public class PAGateway { * @param jobId A job ID * @return The job state */ - public JobState getJobState(String jobId) { + public Pair getJobState(String jobId) { LOGGER.info("Getting job " + jobId + " state "); - Job submittedJob = EntityManagerHelper.find(Job.class, jobId); - LOGGER.info("Job skeleton " + jobId + " mapped to the submitted ProActive job: " + submittedJob.getSubmittedJobId()); + Optional optJob = Optional.ofNullable(EntityManagerHelper.find(Job.class, jobId)); + if (!optJob.isPresent()) { + LOGGER.error(String.format("Job [%s] not found", jobId)); + return Pair.of(SubmittedJobType.UNKNOWN, null); + } + Job submittedJob = optJob.get(); + LOGGER.info("Job " + jobId + " mapped to the submitted ProActive job: " + submittedJob.getSubmittedJobId() + + " of type: " + submittedJob.getSubmittedJobType().toString()); JobState jobState = schedulerGateway.getJobState(String.valueOf(submittedJob.getSubmittedJobId())); LOGGER.info("Returned state: " + jobState.getStatus().toString() + " for job: " + jobId); - return jobState; + return Pair.of(submittedJob.getSubmittedJobType(), jobState); } /** diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/Job.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/Job.java index 0982f33742d386423a12c2d517050812ad86c21f..6ca8b0039fbf6e2ebccba44286b47b0e31e195d0 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/Job.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/Job.java @@ -33,6 +33,10 @@ public class Job implements Serializable { @Column(name = "SUBMITTED_JOB_ID") private long submittedJobId; + @Column(name = "SUBMITTED_JOB_TYPE") + @Enumerated(EnumType.STRING) + private SubmittedJobType submittedJobType; + @OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.REFRESH) private List tasks; diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/SubmittedJobType.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/SubmittedJobType.java new file mode 100644 index 0000000000000000000000000000000000000000..c8f3cbbe90ba92f0de62e45672ef21244da1d668 --- /dev/null +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/SubmittedJobType.java @@ -0,0 +1,37 @@ +package org.activeeon.morphemic.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import lombok.Getter; +import lombok.ToString; + +import java.util.Locale; + +@Getter +@ToString(callSuper = true) +public enum SubmittedJobType { + FIRST_DEPLOYMENT("FIRST_DEPLOYMENT"), + + SCALE_OUT("SCALE_OUT"), + + SCALE_IN("SCALE_IN"), + + STOP("STOP"), + + UNKNOWN("UNKNOWN"); + + private final String value; + + SubmittedJobType(String value) { + this.value = value; + } + + @JsonCreator + public static SubmittedJobType fromValue(String text) { + for (SubmittedJobType b : SubmittedJobType.values()) { + if (String.valueOf(b.value).equals(text.toUpperCase(Locale.ROOT))) { + return b; + } + } + return UNKNOWN; + } +}