def update_status(self, status): ''' Update the current service's status and whether all of his parents dependencies are solved start children dependencies. ''' self.status = status if not self.simulate: call_back_self().notify(self, EV_STATUS_CHANGED) # I got a status so I'm DONE or DEP_ERROR and I'm not the calling point if self.status not in (NO_STATUS, WAITING_STATUS) and not self.origin: # Trigger each service which depend on me as soon as it does not # have WAITING_STATUS parents deps = self.children if self._algo_reversed: deps = self.parents for dep in deps.values(): tgt = dep.target # Propagate this info, even if 'tgt' will not be run right now dep.filter_nodes(self.failed_nodes) if tgt.status is NO_STATUS and tgt.is_ready() and tgt._tagged: if not self.simulate: call_back_self().notify((self, tgt), EV_TRIGGER_DEP) tgt.prepare()
def remove_task(self, task): """ Fanout goes up whether the current task represents the lower fanout available and not any task owns the same fanout """ assert task, 'You cannot take out a None task' # Task given as parameter is not already running if self._is_running_task(task): # Checkout the right value for the fanout fnt = task.fanout or self.default_fanout # Remove task self.entities[fnt].remove(task) call_back_self().notify(task.parent, EV_COMPLETE) # Category is empty so we delete it and we update # the value of the current fanout if len(self.entities[fnt]) == 0: del self.entities[fnt] if self.entities: self.fanout = sorted(self.entities.keys())[0] self._master_task.set_info('fanout', self.fanout) else: self.fanout = None # Current number of task is decremented self._tasks_count -= 1 if not self.tasks_count: call_back_self().notify(task.parent, EV_FINISHED)
def perform_action(self, action): """Perform an immediate action""" assert not action.to_skip(), "Action should be already SKIPPED" if not action.parent.simulate: self.add_task(action) call_back_self().notify(action.parent, EV_STARTED) nodes = None if action.mode != 'delegate': nodes = action.target # In dry-run mode, all commands are replaced by a simple ':' command = ':' if not self.dryrun: command = action.command if action.mode == 'exec': wkr = ExecWorker(nodes=nodes, handler=ActionEventHandler(action), timeout=action.timeout, command=command, remote=action.remote) self._master_task.schedule(wkr) else: self._master_task.shell(command, nodes=nodes, timeout=action.timeout, handler=ActionEventHandler(action), remote=action.remote)
def __init__(self): CoreEvent.__init__(self) # Parser which reads the command line self._mop = None # Store the options parsed self._options = None # Store the configuration parsed self._conf = None # Store the arguments parsed self._args = None # Store executed actions self.actions = [] # Displayer self._console = ConsoleDisplay() # Store interactive mode self.interactive = Terminal.isinteractive() # Useful for tests self.manager = None self._logger = ConfigParser.install_logger() call_back_self().attach(self) self.inter_thread = InteractiveThread(self._console)
def perform_delayed_action(self, action): """Perform a delayed action and add it to the running tasks""" assert action, 'You cannot perform a NoneType object' assert isinstance(action, Action), 'Object should be an action' if not action.parent.simulate: self.add_task(action) call_back_self().notify(action, EV_DELAYED) self._master_task.timer(handler=ActionEventHandler(action), fire=action.delay)
def perform_action(self, action): """Perform an immediate action""" assert not action.to_skip(), "Action should be already SKIPPED" if not action.parent.simulate: self.add_task(action) call_back_self().notify(action.parent, EV_STARTED) nodes = None if action.mode != 'delegate': nodes = action.target # In dry-run mode, all commands are replaced by a simple ':' command = ':' if not self.dryrun: command = action.resolve_property('command') self._master_task.shell(command, nodes=nodes, timeout=action.timeout, handler=ActionEventHandler(action))
def update_status(self, status): ''' This method update the current status of an action. Whether the a status meaning that the action is done is specified, the current action triggers her direct dependencies. ''' self.status = status call_back_self().notify(self, EV_STATUS_CHANGED) if status not in (NO_STATUS, WAITING_STATUS): if not self.parent.simulate: call_back_self().notify(self, EV_COMPLETE) if self.children: for dep in self.children.values(): if dep.target.is_ready(): if not self.parent.simulate: call_back_self().notify((self, dep.target), EV_TRIGGER_DEP) dep.target.prepare() else: self.parent.update_status(self.status)
def ev_start(self, worker): '''Command has been started on a nodeset''' if not self._action.parent.simulate: call_back_self().notify(self._action, EV_STARTED)