@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) ); List<JobId> jobsToDelete = slaEnf.enforceSLAMax(jobList); assertEquals(1, jobsToDelete.size()); assertEquals("cname-1", jobsToDelete.get(0).getId()); }
public List<JobId> enforceSLAMax(List<JobInfo> list) { Preconditions.checkNotNull(list, "runningOrAcceptedJobSet is null"); List<JobId> jobsToDelete = Lists.newArrayList(); 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; }
SLAEnforcer { public List<JobId> enforceSLAMax(List<JobInfo> list) { Preconditions.checkNotNull(list, "runningOrAcceptedJobSet is null"); List<JobId> jobsToDelete = Lists.newArrayList(); 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; } }
SLAEnforcer { public List<JobId> enforceSLAMax(List<JobInfo> list) { Preconditions.checkNotNull(list, "runningOrAcceptedJobSet is null"); List<JobId> jobsToDelete = Lists.newArrayList(); 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; } SLAEnforcer(SLA sla); }
SLAEnforcer { public List<JobId> enforceSLAMax(List<JobInfo> list) { Preconditions.checkNotNull(list, "runningOrAcceptedJobSet is null"); List<JobId> jobsToDelete = Lists.newArrayList(); 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; } SLAEnforcer(SLA sla); int enforceSLAMin(int activeJobsCount, int acceptedJobsCount); List<JobId> enforceSLAMax(List<JobInfo> list); boolean hasSLA(); }
SLAEnforcer { public List<JobId> enforceSLAMax(List<JobInfo> list) { Preconditions.checkNotNull(list, "runningOrAcceptedJobSet is null"); List<JobId> jobsToDelete = Lists.newArrayList(); 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; } SLAEnforcer(SLA sla); int enforceSLAMin(int activeJobsCount, int acceptedJobsCount); List<JobId> enforceSLAMax(List<JobInfo> list); boolean hasSLA();  }