def search_for_machine(filename='fsm.yaml'): """ Searches the .yaml hierarchy for the correct machine. :param filename: a path to a fsm.yaml file :return: """ for machine_dict in get_current_configuration(filename=filename)[CONFIG.MACHINES]: if CONFIG.IMPORT in machine_dict: search_for_machine(filename=machine_dict[CONFIG.IMPORT]) continue if machine_dict[CONFIG.NAME] == args.machine_name: data = output_machine_dict(machine_dict) print json.dumps(data, indent=2) return
def __init__(self, config_dict=None): """ Constructs the factory and initializes the State/Transition caches. :param config_dict: a dict as returned by aws_lambda_fsm.config.get_current_configuration """ reload_machines = (config_dict is not None) if not reload_machines: config_dict = get_current_configuration() with _lock: if _local.machines is None or reload_machines: self.machines = None self._init_(config_dict=config_dict) _local.machines = self.machines else: self.machines = _local.machines
def search_for_machine(filename='fsm.yaml'): """ Searches the .yaml hierarchy for the correct machine. :param filename: a path to a fsm.yaml file :return: """ for machine_dict in get_current_configuration(filename=filename)[CONFIG.MACHINES]: if CONFIG.IMPORT in machine_dict: search_for_machine(filename=machine_dict[CONFIG.IMPORT]) continue if machine_dict[CONFIG.NAME] == args.machine_name: chl = output_machine_dict(machine_dict) if args.format == 'dot': print chl else: print 'https://chart.googleapis.com/chart?cht=gv&chl=%(chl)s' % {'chl': urllib.quote_plus(chl)}
def _init_(self, config_dict): """ Initializes the State/Transition caches. :param config_dict: a dict as returned by aws_lambda_fsm.config.get_current_configuration """ self.machines = {} if (self.machines is None) else self.machines for machine_dict in config_dict[CONFIG.MACHINES]: if 'import' in machine_dict: another_config_dict = get_current_configuration( filename=machine_dict[CONFIG.IMPORT]) self._init_(another_config_dict) continue try: # initialize the machine dict machine_name = machine_dict[CONFIG.NAME] if machine_name not in self.machines: self.machines[machine_name] = { MACHINE.STATES: {}, MACHINE.TRANSITIONS: {} } # pseudo-init, pseudo-final self.machines[machine_name][MACHINE.STATES][ STATE.PSEUDO_INIT] = State(STATE.PSEUDO_INIT) self.machines[machine_name][MACHINE.STATES][ STATE.PSEUDO_FINAL] = State(STATE.PSEUDO_FINAL) # set the max-retries self.machines[machine_name][MACHINE.MAX_RETRIES] = \ int(machine_dict.get(CONFIG.MAX_RETRIES, CONFIG.DEFAULT_MAX_RETRIES)) # fetch these for use later pseudo_init = self.machines[machine_name][MACHINE.STATES][ STATE.PSEUDO_INIT] pseudo_final = self.machines[machine_name][MACHINE.STATES][ STATE.PSEUDO_FINAL] # iterate over each state, creating a singleton for state_dict in machine_dict[CONFIG.STATES]: state_name = state_dict[CONFIG.NAME] entry_action = self._get_action( state_dict.get(CONFIG.ENTRY_ACTION)) do_action = self._get_action( state_dict.get(CONFIG.DO_ACTION)) exit_action = self._get_action( state_dict.get(CONFIG.EXIT_ACTION)) state = State(state_name, entry_action=entry_action, do_action=do_action, exit_action=exit_action, initial=state_dict.get(CONFIG.INITIAL), final=state_dict.get(CONFIG.FINAL)) self.machines[machine_name][ MACHINE.STATES][state_name] = state # pseudo-transitions if state_dict.get(CONFIG.INITIAL): self._add_transition(machine_name, pseudo_init, state, STATE.PSEUDO_INIT) if state_dict.get(CONFIG.FINAL): self._add_transition(machine_name, state, pseudo_final, STATE.PSEUDO_FINAL) # iterate over each transition, creating a singleton for state_dict in machine_dict[CONFIG.STATES]: state_name = state_dict[CONFIG.NAME] state = self.machines[machine_name][ MACHINE.STATES][state_name] for transition_dict in state_dict.get( CONFIG.TRANSITIONS, []): action = self._get_action( transition_dict.get(CONFIG.ACTION)) event = transition_dict[CONFIG.EVENT] target_name = transition_dict[CONFIG.TARGET] target = self.machines[machine_name][ MACHINE.STATES][target_name] self._add_transition(machine_name, state, target, event, action=action) except (ImportError, ValueError), e: # pragma: no cover logger.warning('Problem importing machine "%s": %s', machine_name, e) self.machines.pop(machine_name, None)
def test_get_current_configuration(self): aws_lambda_fsm.config._config = {} get_current_configuration()
def setUp(self): AWS.reset() FSM(get_current_configuration('./fsm.yaml'))
def setUp(self): AWS.reset() FSM(get_current_configuration('tests/integration/fsm.yaml'))
def setUp(self): AWS.reset() FSM(get_current_configuration('tests/functional/fsm.yaml'))