Merge "Use batch 'get_atoms_states' where we can"

This commit is contained in:
Jenkins
2015-11-18 17:18:08 +00:00
committed by Gerrit Code Review
3 changed files with 31 additions and 17 deletions

View File

@@ -135,7 +135,7 @@ class Analyzer(object):
if atom is None: if atom is None:
return iter_utils.unique_seen(self.browse_atoms_for_execute(), return iter_utils.unique_seen(self.browse_atoms_for_execute(),
self.browse_atoms_for_revert()) self.browse_atoms_for_revert())
state = self.get_state(atom) state = self._storage.get_atom_state(atom.name)
intention = self._storage.get_atom_intention(atom.name) intention = self._storage.get_atom_intention(atom.name)
if state == st.SUCCESS: if state == st.SUCCESS:
if intention == st.REVERT: if intention == st.REVERT:
@@ -195,7 +195,7 @@ class Analyzer(object):
def _get_maybe_ready(self, atom, transition_to, allowed_intentions, def _get_maybe_ready(self, atom, transition_to, allowed_intentions,
connected_fetcher, connected_checker, connected_fetcher, connected_checker,
decider_fetcher): decider_fetcher):
state = self.get_state(atom) state = self._storage.get_atom_state(atom.name)
ok_to_transition = self._runtime.check_atom_transition(atom, state, ok_to_transition = self._runtime.check_atom_transition(atom, state,
transition_to) transition_to)
if not ok_to_transition: if not ok_to_transition:
@@ -261,8 +261,15 @@ class Analyzer(object):
If no state is provided it will yield back all retry atoms. If no state is provided it will yield back all retry atoms.
""" """
for atom in self.iterate_nodes((co.RETRY,)): if state:
if not state or self.get_state(atom) == state: atoms = list(self.iterate_nodes((co.RETRY,)))
atom_states = self._storage.get_atoms_states(atom.name
for atom in atoms)
for atom in atoms:
if atom_states[atom.name][0] == state:
yield atom
else:
for atom in self.iterate_nodes((co.RETRY,)):
yield atom yield atom
def iterate_nodes(self, allowed_kinds): def iterate_nodes(self, allowed_kinds):
@@ -277,14 +284,13 @@ class Analyzer(object):
def is_success(self): def is_success(self):
"""Checks if all atoms in the execution graph are in 'happy' state.""" """Checks if all atoms in the execution graph are in 'happy' state."""
for atom in self.iterate_nodes(co.ATOMS): atoms = list(self.iterate_nodes(co.ATOMS))
atom_state = self.get_state(atom) atom_states = self._storage.get_atoms_states(atom.name
for atom in atoms)
for atom in atoms:
atom_state = atom_states[atom.name][0]
if atom_state == st.IGNORE: if atom_state == st.IGNORE:
continue continue
if atom_state != st.SUCCESS: if atom_state != st.SUCCESS:
return False return False
return True return True
def get_state(self, atom):
"""Gets the state of a given atom (from the backend storage unit)."""
return self._storage.get_atom_state(atom.name)

View File

@@ -139,14 +139,21 @@ class Completer(object):
atoms that were previously not finished (due to a RUNNING or REVERTING atoms that were previously not finished (due to a RUNNING or REVERTING
attempt not previously finishing). attempt not previously finishing).
""" """
for atom in self._analyzer.iterate_nodes(co.ATOMS): atoms = list(self._analyzer.iterate_nodes(co.ATOMS))
if self._analyzer.get_state(atom) == st.FAILURE: atom_states = self._storage.get_atoms_states(atom.name
for atom in atoms)
for atom in atoms:
atom_state = atom_states[atom.name][0]
if atom_state == st.FAILURE:
self._process_atom_failure(atom, self._storage.get(atom.name)) self._process_atom_failure(atom, self._storage.get(atom.name))
for retry in self._analyzer.iterate_retries(st.RETRYING): for retry in self._analyzer.iterate_retries(st.RETRYING):
self._runtime.retry_subflow(retry) for atom, state, intention in self._runtime.retry_subflow(retry):
if state:
atom_states[atom.name] = (state, intention)
unfinished_atoms = set() unfinished_atoms = set()
for atom in self._analyzer.iterate_nodes(co.ATOMS): for atom in atoms:
if self._analyzer.get_state(atom) in (st.RUNNING, st.REVERTING): atom_state = atom_states[atom.name][0]
if atom_state in (st.RUNNING, st.REVERTING):
unfinished_atoms.add(atom) unfinished_atoms.add(atom)
return unfinished_atoms return unfinished_atoms

View File

@@ -249,5 +249,6 @@ class Runtime(object):
subgraph (its successors) to the ``PENDING`` state with an ``EXECUTE`` subgraph (its successors) to the ``PENDING`` state with an ``EXECUTE``
intention. intention.
""" """
self.storage.set_atom_intention(retry.name, st.EXECUTE) tweaked = self.reset_atoms([retry], state=None, intention=st.EXECUTE)
self.reset_subgraph(retry) tweaked.extend(self.reset_subgraph(retry))
return tweaked