Ejemplo n.º 1
0
def _removal_candidate_computation_info(
        orphan: str, departed: List[str], cg: ComputationGraph,
        discovery: Discovery) \
        -> Tuple[List[str], Dict[str, str], Dict[str, List[str]]]:
    """
    All info needed by an agent to participate in negotiation about hosting
    the computation `comp`

    :param orphan: the candidate computation that must be hosted
    :param departed: the agent that left the system
    :param cg: the computation graph
    :param discovery: the distribution of computation on agents

    :return: a triple ( candidate_agents, fixed_neighbors, candidates_neighbors)
    where:

    * candidate agents is a list of agents that could host this computation
    * fixed_neighbors is a map comp->agent that indicates, for each
      neighbor computation of `comp` that is not a candidate (orphaned),
      its host agent
    * candidates_neighbors is a map comp -> List[agt] indicating which agent
      could host each of the neighbor computation that is also a candidate
      computation.

    """
    orphaned_computation = _removal_orphaned_computations(departed, discovery)

    candidate_agents = list(
        discovery.replica_agents(orphan).difference(departed))
    fixed_neighbors = {}
    candidates_neighbors = {}
    for n in cg.neighbors(orphan):
        if n == orphan:
            continue
        if n in orphaned_computation:
            candidates_neighbors[n] = \
                list(discovery.replica_agents(n).difference(departed))
        else:
            fixed_neighbors[n] = discovery.computation_agent(n)

    return candidate_agents, fixed_neighbors, candidates_neighbors
Ejemplo n.º 2
0
def _removal_candidate_computations_for_agt(agt, orphaned_computations,
                                            discovery: Discovery):
    """

    :param agt:
    :param orphaned_computations:

    :return: The list of orphaned computations that could potentially be
    hosted on agt (because agt has their replica)
    """
    comps = []
    for o in orphaned_computations:
        if agt in discovery.replica_agents(o):
            comps.append(o)
    return comps
Ejemplo n.º 3
0
def _removal_candidate_agents(departed: List[str],
                              discovery: Discovery) \
        -> List[str]:
    """

    :param departed: a list of agents
    :param discovery

    :return: the candidate agents as a list of agents involved in the
    reparation process, i.e. candidates that could host one the the orphaned
    computation from the departed agents

    """
    orphaned = _removal_orphaned_computations(departed, discovery)
    candidate_agents = []

    for o in orphaned:
        candidate_agents += list(discovery.replica_agents(o))
    candidate_agents = list(set(candidate_agents).difference(set(departed)))

    return candidate_agents