Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Atropos initilization more granular #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions src/simoorg/atropos.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ class Atropos(object):
The Atropos class
"""

@staticmethod
def spawn(*args, **kwargs):
"""
Builder function for the atropos class.
Init class and run it main functionality.
Args: Proxy to the __init__
Return:
None
Raise:
None
"""
instance = Atropos(*args, **kwargs)
scheduler = instance.get_scheduler()
instance.main_loop(scheduler)

def __init__(self, config, config_dir, output_queue,
event_queue, verbose=False, debug=False,
logger_instance=None):
Expand Down Expand Up @@ -130,23 +145,22 @@ def __init__(self, config, config_dir, output_queue,

signal.signal(signal.SIGTERM, self.sigterm_handler)

self.main_loop()

def main_loop(self):
def get_scheduler(self, scheduler_plugin_path=SCHEDULER_PLUGIN_PATH):
"""
Atropos receives the plan from the scheduler and follows
each item in the plan
Args:
None
scheduler_plugin_path - string containing import path
Return:
None
scheduler - scheduler instance
Raise:
AttributeError: If the scheduler class does not exist
ImportError: If the scheduler module can't be imported
AttributeError: If scheduler class isn't at the provided
scheduler module
KeyError: If destiny is malformed (missing important
information)
"""
self.journal = Journal(self.impact_limits,
logger_instance=self.logger_instance)

if self.scheduler_plugin is None:
self.logger_instance.logit("Error",
"Scheduler NOT found")
Expand All @@ -157,7 +171,7 @@ def main_loop(self):
.format(self.scheduler_plugin),
log_level="VERBOSE")
try:
scheduler_module = __import__(SCHEDULER_PLUGIN_PATH + '.' +
scheduler_module = __import__(scheduler_plugin_path + '.' +
self.scheduler_plugin + '.' +
self.scheduler_plugin,
fromlist=self.scheduler_plugin)
Expand All @@ -170,8 +184,7 @@ def main_loop(self):
raise
try:
scheduler_class = getattr(scheduler_module, self.scheduler_plugin)
scheduler = scheduler_class(self.get_scheduler_destiny(),
verbose=True)
return scheduler_class(self.get_scheduler_destiny(), verbose=True)
except (AttributeError, KeyError):
self.logger_instance.logit("Error",
"The scheduler class {0}"
Expand All @@ -180,6 +193,22 @@ def main_loop(self):
log_level="VERBOSE")
raise

def main_loop(self, scheduler):
"""
Atropos receives the plan from the scheduler and follows
each item in the plan
Args:
None
Return:
None
Raise:
AttributeError: If the scheduler class does not exist
KeyError: If destiny is malformed (missing important
information)
"""
self.journal = Journal(self.impact_limits,
logger_instance=self.logger_instance)

# Put all the atropos specific info into the output queue
self.output_queue.put((self.service, self.get_all_nodes(),
scheduler.get_plan()))
Expand Down
6 changes: 4 additions & 2 deletions src/simoorg/moirai.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,14 @@ def spawn_atropos(self):
print ("[FATAl]: Calling finish() due to errors ", exc)
self.finish()
raise

atropos_class = getattr(atropos, 'Atropos')

# Deploy atropos army
for service_name, config in self.atropos_fate_book_configs.iteritems():
if self.verbose:
print "[INFO]: Deploying atropos for:", service_name
handler = getattr(atropos, 'Atropos')
proc = multiprocessing.Process(target=handler,
proc = multiprocessing.Process(target=atropos_class.spawn,
args=(config, self.config_dir,
self.atropos_data_queue,
self.atropos_event_queue,),
Expand Down