Commit 76d12656 authored by David Glesser's avatar David Glesser
Browse files

Pybatsim: the API now use the Job class instead of jobids.

parent d3d3ddb3
......@@ -3,6 +3,7 @@
import json
import struct
import socket
import sys
class Batsim(object):
......@@ -40,14 +41,14 @@ class Batsim(object):
return self._current_time
def start_job(self, jobid, res):
self._msgs_to_send.append( ( self.time(), "J:"+str(jobid)+"="+ ",".join([str(i) for i in res]) ) )
def start_job(self, job, res):
self._msgs_to_send.append( ( self.time(), "J:"+str(job.id)+"="+ ",".join([str(i) for i in res]) ) )
def start_jobs(self, jobids, res):
def start_jobs(self, jobs, res):
msg = "J:"
for jid in jobids:
msg += str(jid) + "="
for r in res[jid]:
for j in jobs:
msg += str(j.id) + "="
for r in res[j.id]:
msg += str(r) + ","
msg = msg[:-1] + ";" # replace last comma by semicolon separtor between jobs
msg = msg[:-1] # remove last semicolon
......@@ -90,9 +91,9 @@ class Batsim(object):
if data[1] == 'N':
self.scheduler.onNOP()
if data[1] == 'S':
self.scheduler.onJobSubmission(int(data[2]))
self.scheduler.onJobSubmission(self.jobs[int(data[2])])
elif data[1] == 'C':
self.scheduler.onJobCompletion(int(data[2]))
self.scheduler.onJobCompletion(self.jobs[int(data[2])])
elif data[1] == 'p':
opts = data[2].split('=')
self.scheduler.onMachinePStateChanged(int(opts[0]), int(opts[1]))
......
......@@ -36,12 +36,12 @@ class FillerSched(BatsimScheduler):
# Iterating over a copy to be able to remove jobs from openJobs at traversal
for job in set(self.openJobs):
nb_res_req = self.bs.jobs[job].requested_resources
nb_res_req = job.requested_resources
if nb_res_req <= len(self.availableResources):
res = self.availableResources[:nb_res_req]
self.jobs_res[job] = res
self.previousAllocations[job] = res
self.jobs_res[job.id] = res
self.previousAllocations[job.id] = res
scheduledJobs.append(job)
for r in res:
......@@ -66,7 +66,7 @@ class FillerSched(BatsimScheduler):
self.scheduleJobs()
def onJobCompletion(self, job):
for res in self.previousAllocations[job]:
for res in self.previousAllocations[job.id]:
self.availableResources.add(res)
self.previousAllocations.pop(job)
self.previousAllocations.pop(job.id)
self.scheduleJobs()
Markdown is supported
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