use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.
the class SLAEnforcerTest method slaMaxTest3.
@Test
public void slaMaxTest3() {
Instant now = Instant.now();
int min = 0;
int max = 2;
SLA sla = new SLA(min, max, null, null);
SLAEnforcer slaEnf = new SLAEnforcer(sla);
List<JobInfo> jobList = Lists.newArrayList(new JobInfo(new JobId("cname", 5), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 6), null, now.getMillis(), null, JobState.Launched, null));
// 2 active and 4 accepted jobs, terminate jobs 3,2,1
List<JobId> jobsToDelete = slaEnf.enforceSLAMax(jobList);
assertEquals(3, jobsToDelete.size());
assertTrue(jobsToDelete.contains(new JobId("cname", 1)));
assertTrue(jobsToDelete.contains(new JobId("cname", 2)));
assertTrue(jobsToDelete.contains(new JobId("cname", 3)));
}
use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.
the class SLAEnforcerTest method slaMaxTest.
@Test
public void slaMaxTest() {
Instant now = Instant.now();
int min = 0;
int max = 2;
SLA sla = new SLA(min, max, null, null);
SLAEnforcer slaEnf = new SLAEnforcer(sla);
List<JobInfo> jobList = Lists.newArrayList(new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null));
// 2 active and 2 accepted jobs, sla met at job id 2, hence delete job 1
List<JobId> jobsToDelete = slaEnf.enforceSLAMax(jobList);
assertEquals(1, jobsToDelete.size());
assertEquals("cname-1", jobsToDelete.get(0).getId());
}
use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.
the class SLAEnforcerTest method slaMaxTest4.
@Test
public void slaMaxTest4() {
Instant now = Instant.now();
int min = 0;
int max = 2;
SLA sla = new SLA(min, max, null, null);
SLAEnforcer slaEnf = new SLAEnforcer(sla);
List<JobInfo> jobList = Lists.newArrayList(new JobInfo(new JobId("cname", 4), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 1), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 2), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 6), null, now.getMillis(), null, JobState.Launched, null), new JobInfo(new JobId("cname", 3), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 5), null, now.getMillis(), null, JobState.Accepted, null), new JobInfo(new JobId("cname", 7), null, now.getMillis(), null, JobState.Launched, null));
// 3 active and 4 accepted jobs, terminate jobs 1 & 2 & 3 & 4 & 5
List<JobId> jobsToDelete = slaEnf.enforceSLAMax(jobList);
assertEquals(5, jobsToDelete.size());
assertTrue(jobsToDelete.contains(new JobId("cname", 1)));
assertTrue(jobsToDelete.contains(new JobId("cname", 2)));
assertTrue(jobsToDelete.contains(new JobId("cname", 3)));
assertTrue(jobsToDelete.contains(new JobId("cname", 4)));
assertTrue(jobsToDelete.contains(new JobId("cname", 5)));
}
use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.
the class JobListHelper method getLastSubmittedJobId.
// /**
// * Note: rawResults are already filtered by jobstate and limit has been already applied to reduce unnecessary work
// * @param rawResultList
// * @param request
// * @return
// */
// public static List<JobInfo> getPreFilteredNonTerminalJobList(final List<JobInfo> rawResultList,
// ListJobCriteria request) {
// if(logger.isDebugEnabled()) { logger.debug("Entering getPreFilteredNonTerminalJobList with raw list size {} and criteria {}", rawResultList.size(), request); }
//
// Collections.sort(rawResultList,Comparator.comparingLong(jinfo -> jinfo.submittedAt));
//
// if(request.getLimit().isPresent()) {
// return rawResultList.subList(0, Math.min(rawResultList.size(), request.getLimit().get()));
// }
// if(logger.isDebugEnabled()) { logger.debug("Returning {} jobs in nonterminalstate ", rawResultList.size()); }
// return rawResultList;
// }
//
// public static List<CompletedJob> getPreFilteredTerminalJobList(final List<CompletedJob> rawResultList, ListJobCriteria request) {
// List<CompletedJob> resultList = Lists.newArrayList();
// Observable.from(rawResultList)
// .filter((completedJob) -> {
// if(request.getActiveOnly().isPresent()) {
// return false;
// }
// return true;
// })
// .toSortedList((c1, c2) -> Long.compare(c1.getSubmittedAt(), c2.getSubmittedAt()) )
// .subscribe((cList) -> {
// resultList.addAll(cList);
// });
// if(request.getLimit().isPresent()) {
// return resultList.subList(0, Math.min(resultList.size(), request.getLimit().get()));
// }
// return resultList;
// }
public static Optional<JobId> getLastSubmittedJobId(final List<JobInfo> existingJobsList, final List<CompletedJob> completedJobs) {
if (logger.isTraceEnabled()) {
logger.trace("Entering getLastSubmittedJobDefinition existing jobs {} completedJobs {}", existingJobsList.size(), completedJobs.size());
}
long highestJobNumber = -1;
JobInfo jInfoWithHighestJobNumber = null;
CompletedJob completedJobWithHighestJobNumber = null;
if (logger.isDebugEnabled()) {
logger.debug("No of active jobs: {}", existingJobsList.size());
}
for (JobInfo jInfo : existingJobsList) {
if (jInfo.jobId.getJobNum() > highestJobNumber) {
highestJobNumber = jInfo.jobId.getJobNum();
jInfoWithHighestJobNumber = jInfo;
}
}
if (logger.isDebugEnabled()) {
logger.debug("Highest Active job number: {}", highestJobNumber);
}
if (highestJobNumber != -1) {
return ofNullable(jInfoWithHighestJobNumber.jobId);
} else {
// search in completed Jobs
for (CompletedJob cJob : completedJobs) {
Optional<JobId> completedJobId = JobId.fromId(cJob.getJobId());
if (completedJobId.isPresent() && completedJobId.get().getJobNum() > highestJobNumber) {
highestJobNumber = completedJobId.get().getJobNum();
completedJobWithHighestJobNumber = cJob;
}
}
if (highestJobNumber != -1) {
if (logger.isDebugEnabled()) {
logger.debug("Highest completed job number: {}", highestJobNumber);
}
return (JobId.fromId(completedJobWithHighestJobNumber.getJobId()));
}
}
return empty();
}
use of io.mantisrx.master.jobcluster.JobClusterActor.JobInfo in project mantis by Netflix.
the class SLAEnforcer method enforceSLAMax.
/**
* Walk the set of jobs in descending order (newest jobs first) track no. of running jobs. Once this
* count equals slamax mark the rest of them for deletion.
*
* @param list A sorted (by job number) set of jobs in either running or accepted state
* @return
*/
public List<JobId> enforceSLAMax(List<JobInfo> list) {
Preconditions.checkNotNull(list, "runningOrAcceptedJobSet is null");
List<JobId> jobsToDelete = Lists.newArrayList();
// if no max sla defined;
if (!sla.isPresent() || sla.get().getMax() == 0) {
return jobsToDelete;
}
SortedSet<JobInfo> sortedJobSet = new TreeSet<>(comparator);
sortedJobSet.addAll(list);
JobInfo[] jobIdArray = sortedJobSet.toArray(new JobInfo[list.size()]);
int activeJobCount = 0;
int slaMax = sla.get().getMax();
boolean addToDeleteList = false;
for (int i = jobIdArray.length - 1; i >= 0; i--) {
JobInfo jInfo = jobIdArray[i];
if (addToDeleteList) {
jobsToDelete.add(jInfo.jobId);
} else {
if (jInfo.state.equals(JobState.Launched)) {
activeJobCount++;
if (activeJobCount == slaMax) {
addToDeleteList = true;
}
}
}
}
return jobsToDelete;
}
Aggregations