Commit fa0e85cb authored by MERCIER Michael's avatar MERCIER Michael

[core] make event socket optional

parent 48d7370a
......@@ -22,21 +22,23 @@ class Batsim(object):
WORKLOAD_JOB_SEPARATOR_REPLACEMENT = "%"
def __init__(self, scheduler,
network_handler=None,
event_handler=None,
network_endpoint,
timeout,
event_endpoint=None,
validatingmachine=None):
self.logger = logging.getLogger(__name__)
self.running_simulation = False
if network_handler is None:
network_handler = NetworkHandler('tcp://*:28000')
if event_handler is None:
event_handler = NetworkHandler(
'tcp://127.0.0.1:28001', type=zmq.PUB)
self.network = network_handler
self.event_publisher = event_handler
self.network = NetworkHandler(network_endpoint, timeout=timeout)
self.network.bind()
# event hendler is optional
self.event_publisher = None
if event_endpoint is not None:
self.event_publisher = NetworkHandler(event_endpoint, type=zmq.PUB)
self.event_publisher.bind()
self.jobs = dict()
......@@ -64,9 +66,6 @@ class Batsim(object):
self.no_more_static_jobs = False
self.network.bind()
self.event_publisher.bind()
self.scheduler.bs = self
# import pdb; pdb.set_trace()
# Wait the "simulation starts" message to read the number of machines
......@@ -78,7 +77,8 @@ class Batsim(object):
"""Sends a message to subscribed event listeners (e.g. external processes which want to
observe the simulation).
"""
self.event_publisher.send_string(event)
if self.event_publisher is not None:
self.event_publisher.send_string(event)
def time(self):
return self._current_time
......@@ -592,7 +592,8 @@ class Batsim(object):
if finished_received:
self.network.close()
self.event_publisher.close()
if self.event_publisher is not None:
self.event_publisher.close()
return not finished_received
......
......@@ -11,7 +11,7 @@ Options:
-d --debug Be more verbose.
-p --protect Protect the scheduler using a validating machine.
-s --socket-endpoint=<endpoint> Batsim socket endpoint to use [default: tcp://*:28000]
-e --event-socket-endpoint=<endpoint> Socket endpoint to use to publish scheduler events [default: tcp://*:29000]
-e --event-socket-endpoint=<endpoint> Socket endpoint to use to publish scheduler events
-o --options=<options_string> A Json string to pass to the scheduler [default: {}]
-O --options-file=<options_file> A file containing the json options
-t --timeout=<timeout> How long to wait for responses from Batsim [default: 2000]
......
......@@ -100,11 +100,11 @@ def instanciate_scheduler(name, options):
def launch_scheduler(scheduler,
socket_endpoint="tcp://*:28000",
event_socket_endpoint="tcp://*:28001",
options={},
timeout=2000,
protect=True):
socket_endpoint,
event_socket_endpoint,
options,
timeout,
protect):
if protect:
vm = ValidatingMachine
......@@ -116,8 +116,9 @@ def launch_scheduler(scheduler,
#try:
bs = Batsim(scheduler,
NetworkHandler(socket_endpoint, timeout),
NetworkHandler(event_socket_endpoint, type=zmq.PUB),
socket_endpoint,
timeout,
event_socket_endpoint,
validatingmachine=vm)
aborted = False
# try:
......
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