示例#1
0
    def restore(self, graph, state=None, log=None, errors=None, flow=None,
                inputs=None, outputs=None, context=None):
        if not graph or not isinstance(graph, graphing.WorkflowGraph):
            raise ValueError('The value of "graph" is not type of WorkflowGraph.')

        if not flow or not isinstance(flow, TaskFlow):
            raise ValueError('The value of "flow" is not type of TaskFlow.')

        if state and not states.is_valid(state):
            raise exc.InvalidState(state)

        if inputs is not None and not isinstance(inputs, dict):
            raise ValueError('The value of "inputs" is not type of dict.')

        if outputs is not None and not isinstance(outputs, dict):
            raise ValueError('The value of "outputs" is not type of dict.')

        self._workflow_state = state
        self._graph = graph
        self._flow = flow
        self._parent_ctx = context or {}
        self._inputs = inputs or {}
        self._outputs = outputs
        self._errors = errors or []
        self._log = log or []
示例#2
0
    def process_workflow_event(cls, conductor, task_flow_entry, wf_ex_event):
        # Check if event is valid.
        if wf_ex_event.name not in events.WORKFLOW_EXECUTION_EVENTS:
            raise exc.InvalidEvent(wf_ex_event.name)

        # Append additional task context to the event.
        task_id = task_flow_entry['id']
        event_name = cls.add_context_to_workflow_event(conductor, task_id,
                                                       wf_ex_event)

        # Identify current task state.
        current_task_state = task_flow_entry.get('state', states.UNSET)

        if current_task_state is None:
            current_task_state = states.UNSET

        if current_task_state not in states.ALL_STATES:
            raise exc.InvalidState(current_task_state)

        if current_task_state not in TASK_STATE_MACHINE_DATA:
            raise exc.InvalidTaskStateTransition(current_task_state,
                                                 event_name)

        # If no transition is identified, then there is no state change.
        if event_name not in TASK_STATE_MACHINE_DATA[current_task_state]:
            return

        new_task_state = TASK_STATE_MACHINE_DATA[current_task_state][
            event_name]

        # Assign new state to the task flow entry.
        task_flow_entry['state'] = new_task_state
示例#3
0
文件: events.py 项目: batk0/orquesta
    def __init__(self, name, state, result=None, context=None):
        if not states.is_valid(state):
            raise exc.InvalidState(state)

        self.name = name
        self.state = state
        self.result = result
        self.context = context
示例#4
0
    def is_transition_valid(cls, old_state, new_state):
        if old_state is None:
            old_state = 'null'

        if new_state is None:
            new_state = 'null'

        if not states.is_valid(old_state):
            raise exc.InvalidState(old_state)

        if not states.is_valid(new_state):
            raise exc.InvalidState(new_state)

        if old_state not in WORKFLOW_STATE_MACHINE_DATA.keys():
            return False

        if old_state == new_state or new_state in WORKFLOW_STATE_MACHINE_DATA[
                old_state].values():
            return True

        return False