From e6e5955d3f29d6eea5b8d685295f4612928c13c4 Mon Sep 17 00:00:00 2001 From: mklkun Date: Fri, 2 Jul 2021 11:04:24 +0100 Subject: [PATCH 1/2] Improve getJobState method to trace scaling in/out actions state aswell as first deployment --- .../org/activeeon/morphemic/PAGateway.java | 18 +++++++-- .../org/activeeon/morphemic/model/Job.java | 4 ++ .../morphemic/model/SubmittedJobType.java | 37 +++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/model/SubmittedJobType.java 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 e5f03958..0b2c654b 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 javafx.util.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 new Pair<>(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 new Pair<>(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 0982f337..6ca8b003 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 00000000..c8f3cbbe --- /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; + } +} -- GitLab From 97693cf45947a6087f35536d3e2c898ea30c602b Mon Sep 17 00:00:00 2001 From: mklkun Date: Fri, 2 Jul 2021 14:57:39 +0100 Subject: [PATCH 2/2] Change the use of apache Pair instead of javafx one --- .../src/main/java/org/activeeon/morphemic/PAGateway.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 0b2c654b..90383b2a 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,7 +1,7 @@ package org.activeeon.morphemic; import com.fasterxml.jackson.databind.ObjectMapper; -import javafx.util.Pair; +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; @@ -1521,14 +1521,14 @@ public class PAGateway { Optional optJob = Optional.ofNullable(EntityManagerHelper.find(Job.class, jobId)); if (!optJob.isPresent()) { LOGGER.error(String.format("Job [%s] not found", jobId)); - return new Pair<>(SubmittedJobType.UNKNOWN, null); + 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 new Pair<>(submittedJob.getSubmittedJobType(), jobState); + return Pair.of(submittedJob.getSubmittedJobType(), jobState); } /** -- GitLab