Commit 4823b0e1 authored by David Glesser's avatar David Glesser
Browse files

Add a validating machine option to pyBatsim allowing to check the behavior of the scheduler.

parent 76d12656
......@@ -5,13 +5,18 @@ import struct
import socket
import sys
class Batsim(object):
def __init__(self, json_file, scheduler, server_address = '/tmp/bat_socket', verbose=0):
def __init__(self, json_file, scheduler, validatingmachine=None, server_address = '/tmp/bat_socket', verbose=0):
self.server_address = server_address
self.verbose = verbose
self.scheduler = scheduler
if validatingmachine is None:
self.scheduler = scheduler
else:
self.scheduler = validatingmachine(scheduler)
#load json file
self._load_json_workload_profile(json_file)
......@@ -93,7 +98,9 @@ class Batsim(object):
if data[1] == 'S':
self.scheduler.onJobSubmission(self.jobs[int(data[2])])
elif data[1] == 'C':
self.scheduler.onJobCompletion(self.jobs[int(data[2])])
j = self.jobs[int(data[2])]
j.finish_time = float(data[0])
self.scheduler.onJobCompletion(j)
elif data[1] == 'p':
opts = data[2].split('=')
self.scheduler.onMachinePStateChanged(int(opts[0]), int(opts[1]))
......@@ -134,6 +141,7 @@ class Job(object):
self.requested_time = walltime
self.requested_resources = res
self.profile = profile
self.finish_time = None#will be set on completion by batsim
class BatsimScheduler(object):
......
from batsim import BatsimScheduler
from sortedcontainers import SortedSet
class ValidatingMachine(BatsimScheduler):
"""
This class tries to do a lot of checks to prevent from stupid and invisible errors.
You should use this when you are developping and testing a scheduler.
It checks that:
- not 2 jobs use the same resource as the same time
- a job is only started once
- a job is launched after his submit time
"""
def __init__(self, scheduler):
self.scheduler = scheduler
def onAfterBatsimInit(self):
self.nb_res = self.bs.nb_res
self.availableResources = SortedSet(range(self.nb_res))
self.jobs_waiting = []
self.previousAllocations = dict()
#intercept job start
self.bs_start_job = self.bs.start_job
self.bs.start_job = self.start_job
self.bs_start_jobs = self.bs.start_jobs
self.bs.start_jobs = self.start_jobs
self.scheduler.bs = self.bs
self.scheduler.onAfterBatsimInit()
def onJobRejection(self):
self.scheduler.onJobRejection()
def onNOP(self):
self.scheduler.onNOP()
def onJobSubmission(self, job):
self.jobs_waiting.append(job)
self.scheduler.onJobSubmission(job)
def onJobCompletion(self, job):
for res in self.previousAllocations[job.id]:
self.availableResources.add(res)
self.previousAllocations.pop(job.id)
self.scheduler.onJobCompletion(job)
def onMachinePStateChanged(self, nodeid, pstate):
self.scheduler.onMachinePStateChanged(nodeid, pstate)
def start_job(self, job, res):
self.previousAllocations[job.id] = res
self.jobs_waiting.remove(job)
for r in res:
self.availableResources.remove(r)
self.bs_start_job(job, res)
def start_jobs(self, jobs, res):
for j in jobs:
self.jobs_waiting.remove(j)
self.previousAllocations[j.id] = res[j.id]
for r in res[j.id]:
self.availableResources.remove(r)
self.bs_start_jobs(jobs, res)
......@@ -5,6 +5,7 @@
import sys
from batsim.batsim import Batsim
from batsim.validatingmachine import ValidatingMachine
......@@ -43,6 +44,9 @@ def instanciate_scheduler(name):
scheduler = instanciate_scheduler(scheduler_filename)
bs = Batsim(json_filename, scheduler, verbose=999)
#vm = None
vm = ValidatingMachine
bs = Batsim(json_filename, scheduler, validatingmachine=vm, verbose=999)
bs.start()
\ No newline at end of file
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