I have a priority queue that lists aload of jobs from an sql database in date order. I then have get the closestDeadlineJob function below that gets the top job, checks if any other jobs have the same date then compare priorities to see which is the top job. I then get returned the top job.
Find original queue top job:
public JobRequest closestDeadlineJob(int freeCPUS) {
// find top job to determine if other jobs for date need to be considered
JobRequest nextJob = scheduledJobs.peek(); // return top most job
if (nextJob != null) {
System.out.println("Found top EDF job:");
printJob( nextJob );
// what is it's date?
Date highestRankedDate = nextJob.getConvertedDeadlineDate();
// create a temporary queue to work out priorities of jobs with same deadline
JobPriorityQueue schedulerPriorityQueue = new JobPriorityQueue();
// add the top job to priority queue
//schedulerPriorityQueue.addJob(nextJob);
for (JobRequest jr : scheduledJobs) {
// go through scheduled jobs looking for all jobs with same date
if (jr.getConvertedDeadlineDate().equals(highestRankedDate)) {
// same date deadline, soadd to scheduler priority queue
schedulerPriorityQueue.addJob(jr);
System.out.println("Adding following job to priority queue:");
printJob(jr);
}
}
JobRequest highestPriorityJob = schedulerPriorityQueue.poll();
// this is the item at the top of the PRIORTY JOB queue to return
// remove that item from scheduledJobs
scheduledJobs.remove(highestPriorityJob);
return highestPriorityJob;
} else {
return null;
}
}
following code to process top jobs into a queue:
public void processNextJob() {
/*
* 1. get # of free CPU's still avaialble
* 2. get top most job from priority queue
* 3. run job - put to CPU queue
* 4. develop a CPU queue here
* 5. count cores against freeCPUS and some sort of calculation to sort run times
*/
int freeCPUS = 500;
int availableCPUS = 0;
Queue q = new PriorityQueue();
// while(freeCPUS >= 500)
// {
//
// }
JobRequest nextJob = schedulerPriorityQueue.closestDeadlineJob(freeCPUS); // returns top job from queue
if (nextJob != null) {
System.out.println("Top priority / edf job:");
System.out.print(nextJob.getUserID() + "-->");
System.out.print(nextJob.getStartDate() + "--START-->");
System.out.print(nextJob.getEndDate() + "---END-->");
System.out.print(nextJob.getDeadDate() + "--DROP-->");
System.out.print(nextJob.getDepartment() + "-->");
System.out.print(nextJob.getProjectName() + "-->");
System.out.print(nextJob.getProjectApplication() + "-->");
System.out.print(nextJob.getPriority() + "--PRIORITY-->");
System.out.print(nextJob.getCores() + "-->");
System.out.print(nextJob.getDiskSpace() + "-->");
System.out.println(nextJob.getAnaylsis());
// now got correct job based on earliest deadline / priority
// implement a FIFO queue here / execution stack
// add next job here
} else {
System.out.println("Job = null");
}
}
What I need to do is fix my poor attempt or adaptation at putting jobs from my closestDeadlineJob into a queue then stop putting them in a queue when I reach my 500 core limit. at the moment I just get stuck in the for loop below the while true and I don't think the way I've set out would even work after leaving the loop.
Any thoughts?
EDIT
public void processNextJob() {
/*
* 1. get # of free CPU's still avaialble
* 2. get top most job from priority queue
* 3. run job - put to CPU queue
* 4. develop a CPU queue here
* 5. count cores against freeCPUS and some sort of calculation to sort run times
*/
int freeCPUS = 500;
int availableCPUS = 0;
JobRequest nextJob = schedulerPriorityQueue.closestDeadlineJob(freeCPUS); // returns top job from queue
if (nextJob != null) {
System.out.println("Top priority / edf job:");
printJob( nextJob );
// go through scheduled jobs looking for all jobs with same date
if (nextJob.getCores() <= freeCPUS) {
// same date deadline, soadd to scheduler priority queue
schedulerPriorityQueue.addJob(nextJob);
System.out.println("Adding following job to execution queue:");
printJob( nextJob );
// can use this to get the next top job but need to add calculations to printout the next top job aslong as CPU less than 500
// schedulerPriorityQueue.closestDeadlineJob(freeCPUS);
// schedulerPriorityQueue.addJob(nextJob);
} else if (nextJob.getCores() > freeCPUS) {
System.out.println("Queue temporarily full");
}
// now got correct job based on earliest deadline / priority
// implement a FIFO queue here / execution stack
// add next job here
} else {
System.out.println("Job = null");
}
}
I imagine I need to implement a loop above and move out the if statements saying take next job, if under 500, loop through again and get another then put it into a new queue of some sort, when 500 cores criteria is met stop adding to the new queue