Commit b794b61f authored by MOMMESSIN Clement's avatar MOMMESSIN Clement

[code] added condition for onNoMoreEvents call && separated handling of NOP...

[code] added condition for onNoMoreEvents call && separated handling of NOP and REQUESTED_CALL events
parent ae582039
......@@ -423,6 +423,8 @@ class Batsim(object):
finished_received = False
simu_begins_or_ends = False
for event in msg["events"]:
event_type = event["type"]
event_data = event.get("data", {})
......@@ -459,6 +461,7 @@ class Batsim(object):
self.hpst = event_data.get("hpst_host", None)
self.lcst = event_data.get("lcst_host", None)
simu_begins_or_ends = True
self.scheduler.onSimulationBegins()
elif event_type == "SIMULATION_ENDS":
......@@ -466,6 +469,7 @@ class Batsim(object):
self.running_simulation = False
self.logger.info("All jobs have been submitted and completed!")
finished_received = True
simu_begins_or_ends = True
self.scheduler.onSimulationEnds()
elif event_type == "JOB_SUBMITTED":
# Received WORKLOAD_NAME!JOB_ID
......@@ -530,8 +534,7 @@ class Batsim(object):
consumed_energy = event_data["consumed_energy"]
self.scheduler.onReportEnergyConsumed(consumed_energy)
elif event_type == 'REQUESTED_CALL':
self.scheduler.onNOP()
# TODO: separate NOP / REQUESTED_CALL (here and in the algos)
self.scheduler.onRequestedCall()
elif event_type == 'ADD_RESOURCES':
self.scheduler.onAddResources(event_data["resources"])
elif event_type == 'REMOVE_RESOURCES':
......@@ -539,7 +542,8 @@ class Batsim(object):
else:
raise Exception("Unknow event type {}".format(event_type))
self.scheduler.onNoMoreEvents()
if not simu_begins_or_ends:
self.scheduler.onNoMoreEvents()
if self.handle_dynamic_notify and not finished_received:
if (self.nb_jobs_completed == self.nb_jobs_received != 0):
......@@ -703,7 +707,7 @@ class BatsimScheduler(object):
"[PYBATSIM]: Batsim is not responding (maybe deadlocked)")
def onNOP(self):
raise NotImplementedError()
pass
def onJobSubmission(self, job):
raise NotImplementedError()
......@@ -729,5 +733,8 @@ class BatsimScheduler(object):
def onRemoveResources(self, to_remove):
raise NotImplementedError()
def onRequestedCall(self):
raise NotImplementedError()
def onNoMoreEvents(self):
pass
......@@ -204,12 +204,20 @@ class BaseBatsimScheduler(BatsimScheduler):
self._scheduler.on_add_resources(resources)
def onRemoveResources(self, resources):
# TODO Shouldn't be an update_time call here too?
self._scheduler.info(
"Received remove Resources message: {resources}",
resources=resources,
type="remove_resources_received")
self._scheduler.on_remove_resources(resources)
def onRequestedCall(self)
self._scheduler._update_time()
self._scheduler.info(
"Received Requested Call message",
type="requested_call_received")
self._scheduler.on_requested_call()
class Scheduler(metaclass=ABCMeta):
"""The high-level scheduler which should be interited from by concrete scheduler
......@@ -617,6 +625,10 @@ class Scheduler(metaclass=ABCMeta):
"""
pass
def on_requested_call(self):
"""Hook similar to the low-level API."""
pass
def on_event(self, event):
"""Hook called on each event triggered by the scheduler.
......
......@@ -66,6 +66,9 @@ class ValidatingMachine(BatsimScheduler):
def onReportEnergyConsumed(self, consumed_energy):
self.scheduler.onReportEnergyConsumed(consumed_energy)
def onRequestedCall(self):
self.scheduler.onRequestedCall()
def start_jobs_continuous(self, allocs):
for (job, (first_res, last_res)) in allocs:
self.previousAllocations[job.id] = range(first_res, last_res + 1)
......
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