Commit eb1a2d74 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Improve getJobState method to trace scaling in/out actions state aswell as first deployment

parent 8b848d6d
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;
......@@ -1033,6 +1034,7 @@ public class PAGateway {
long submittedJobId = schedulerGateway.submit(paJob).longValue();
job.setSubmittedJobId(submittedJobId);
job.setSubmittedJobType(SubmittedJobType.SCALE_OUT);
EntityManagerHelper.persist(job);
EntityManagerHelper.commit();
......@@ -1323,6 +1325,7 @@ public class PAGateway {
long submittedJobId = schedulerGateway.submit(paJob).longValue();
job.setSubmittedJobId(submittedJobId);
job.setSubmittedJobType(SubmittedJobType.SCALE_IN);
EntityManagerHelper.persist(job);
EntityManagerHelper.commit();
......@@ -1500,6 +1503,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.");
......@@ -1526,13 +1530,19 @@ public class PAGateway {
* @param jobId A job ID
* @return The job state
*/
public JobState getJobState(String jobId) {
public Pair<SubmittedJobType, JobState> 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<Job> 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);
}
/**
......
......@@ -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<Task> tasks;
......
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;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment