X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fexecution%2Fec.py;h=d93ef7a7037a99c1695f90b55c07e1729bbfa6ab;hb=58a2b493f8df1072a1faa653c8abb6a3f9ba21fa;hp=58ece229e25b4fe8076376c46587806c607a2742;hpb=d8144cd833c3a8e82d9580655787b491e768e4f8;p=nepi.git diff --git a/src/nepi/execution/ec.py b/src/nepi/execution/ec.py index 58ece229..d93ef7a7 100644 --- a/src/nepi/execution/ec.py +++ b/src/nepi/execution/ec.py @@ -3,9 +3,8 @@ # Copyright (C) 2013 INRIA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -41,7 +40,7 @@ import threading import weakref class FailureLevel(object): - """ Describes the system failure state """ + """ Possible failure states for the experiment """ OK = 1 RM_FAILURE = 2 EC_FAILURE = 3 @@ -49,20 +48,20 @@ class FailureLevel(object): class FailureManager(object): """ The FailureManager is responsible for handling errors and deciding whether an experiment should be aborted or not - """ - def __init__(self, ec): - self._ec = weakref.ref(ec) + def __init__(self): + self._ec = None self._failure_level = FailureLevel.OK self._abort = False + def set_ec(self, ec): + self._ec = weakref.ref(ec) + @property def ec(self): """ Returns the ExperimentController associated to this FailureManager - """ - return self._ec() @property @@ -70,6 +69,15 @@ class FailureManager(object): return self._abort def eval_failure(self, guid): + """ Implements failure policy and sets the abort state of the + experiment based on the failure state and criticality of + the RM + + :param guid: Guid of the RM upon which the failure of the experiment + is evaluated + :type guid: int + + """ if self._failure_level == FailureLevel.OK: rm = self.ec.get_resource(guid) state = rm.state @@ -85,7 +93,7 @@ class FailureManager(object): self._failure_level = FailureLevel.EC_FAILURE class ECState(object): - """ Possible states for an ExperimentController + """ Possible states of the ExperimentController """ RUNNING = 1 @@ -95,11 +103,6 @@ class ECState(object): class ExperimentController(object): """ - .. class:: Class Args : - - :param exp_id: Human readable identifier for the experiment scenario. - :type exp_id: str - .. note:: An experiment, or scenario, is defined by a concrete set of resources, @@ -162,7 +165,8 @@ class ExperimentController(object): return ec def __init__(self, exp_id = None, local_dir = None, persist = False, - add_node_callback = None, add_edge_callback = None, **kwargs): + fm = None, add_node_callback = None, add_edge_callback = None, + **kwargs): """ ExperimentController entity to model an execute a network experiment. @@ -177,6 +181,10 @@ class ExperimentController(object): completion at local_dir :type persist: bool + :param fm: FailureManager object. If None is given, the default + FailureManager class will be used + :type fm: FailureManager + :param add_node_callback: Callback to invoke for node instantiation when automatic topology creation mode is used :type add_node_callback: function @@ -238,7 +246,9 @@ class ExperimentController(object): self._stop = False # Entity in charge of managing system failures - self._fm = FailureManager(self) + if not fm: + self._fm = FailureManager() + self._fm.set_ec(self) # EC state self._state = ECState.RUNNING @@ -267,6 +277,14 @@ class ExperimentController(object): """ return self._logger + @property + def fm(self): + """ Returns the failure manager + + """ + + return self._fm + @property def failure_level(self): """ Returns the level of FAILURE of th experiment @@ -520,7 +538,7 @@ class ExperimentController(object): """ rms = [] - for guid, rm in self._resources.iteritems(): + for guid, rm in self._resources.items(): if rm.get_rtype() == rtype: rms.append(rm) return rms @@ -536,7 +554,7 @@ class ExperimentController(object): :rtype: list """ - keys = self._resources.keys() + keys = list(self._resources.keys()) return keys @@ -550,7 +568,7 @@ class ExperimentController(object): """ rms = [] - for guid, rm in self._resources.iteritems(): + for guid, rm in self._resources.items(): if rm.get_rtype() == rtype: rms.append(rm.guid) return rms @@ -955,7 +973,7 @@ class ExperimentController(object): if not guids: # If no guids list was passed, all 'NEW' RMs will be deployed guids = [] - for guid, rm in self._resources.iteritems(): + for guid, rm in self._resources.items(): if rm.state == ResourceState.NEW: guids.append(guid) @@ -1035,7 +1053,7 @@ class ExperimentController(object): """ if self._state == ECState.RELEASED: - return + return if isinstance(guids, int): guids = [guids]