def _assert_removed_in_previous(self, plan, modification):
     previous_node_instances = plan['node_instances']
     removed_and_related = modification['removed_and_related']
     previous_graph = rel_graph.build_node_graph(previous_node_instances)
     removed_nodes_graph = rel_graph.build_node_graph(removed_and_related)
     for instance_id, data in removed_nodes_graph.nodes_iter(data=True):
         self.assertIn(instance_id, previous_graph)
     for source, target, in removed_nodes_graph.edges_iter():
         self.assertTrue(previous_graph.has_edge(source, target))
 def _assert_removed_in_previous(self, plan, modification):
     previous_node_instances = plan['node_instances']
     removed_and_related = modification['removed_and_related']
     previous_graph = rel_graph.build_node_graph(previous_node_instances)
     removed_nodes_graph = rel_graph.build_node_graph(removed_and_related)
     for instance_id, data in removed_nodes_graph.nodes_iter(data=True):
         self.assertIn(instance_id, previous_graph)
     for source, target, in removed_nodes_graph.edges_iter():
         self.assertTrue(previous_graph.has_edge(source, target))
Ejemplo n.º 3
0
def modify_deployment(nodes, previous_nodes, previous_node_instances,
                      modified_nodes, scaling_groups):
    """
    modifies deployment according to the expected nodes. based on
    previous_node_instances
    :param nodes: the entire set of expected nodes.
    :param previous_node_instances:
    :param modified_nodes: existing nodes whose instance number has changed
     Add a line note
    :return: a dict of add,extended,reduced and removed instances
     Add a line note
    """

    plan_node_graph = rel_graph.build_node_graph(nodes=nodes,
                                                 scaling_groups=scaling_groups)
    previous_plan_node_graph = rel_graph.build_node_graph(
        nodes=previous_nodes, scaling_groups=scaling_groups)
    previous_deployment_node_graph, previous_deployment_contained_graph = \
        rel_graph.build_previous_deployment_node_graph(
            plan_node_graph=previous_plan_node_graph,
            previous_node_instances=previous_node_instances)
    new_deployment_node_graph, ctx = rel_graph.build_deployment_node_graph(
        plan_node_graph=plan_node_graph,
        previous_deployment_node_graph=previous_deployment_node_graph,
        previous_deployment_contained_graph=
        previous_deployment_contained_graph,  # noqa
        modified_nodes=modified_nodes)

    # Any node instances which were added or removed
    added_and_related = rel_graph.extract_added_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph, ctx=ctx)
    removed_and_related = rel_graph.extract_removed_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph, ctx=ctx)

    # Any node instances which had a modification to their relationship.
    # (newly introduced and removed nodes)
    extended_and_related = rel_graph.extract_added_relationships(
        previous_deployment_node_graph, new_deployment_node_graph, ctx=ctx)
    reduced_and_related = rel_graph.extract_removed_relationships(
        previous_deployment_node_graph, new_deployment_node_graph, ctx=ctx)

    # The extracted extended and reduced relationships hold the new and old
    # node instances. These are not required, since the change is on
    # node instance level (and not the relationship level)
    extended_and_related = \
        filter_out_node_instances(added_and_related, extended_and_related)
    reduced_and_related = \
        filter_out_node_instances(removed_and_related, reduced_and_related)

    return {
        constants.ADDED_AND_RELATED: added_and_related,
        constants.EXTENDED_AND_RELATED: extended_and_related,
        constants.REDUCED_AND_RELATED: reduced_and_related,
        constants.REMOVED_AND_RELATED: removed_and_related
    }
 def _assert_added_not_in_previous(self, plan, modification):
     previous_node_instances = plan['node_instances']
     added_and_related = modification['added_and_related']
     previous_graph = rel_graph.build_node_graph(previous_node_instances)
     added_nodes_graph = rel_graph.build_node_graph(added_and_related)
     for instance_id, data in added_nodes_graph.nodes_iter(data=True):
         instance = data['node']
         if instance.get('modification') == 'added':
             self.assertNotIn(instance_id, previous_graph)
         else:
             self.assertIn(instance_id, previous_graph)
     for source, target, in added_nodes_graph.edges_iter():
         self.assertFalse(previous_graph.has_edge(source, target))
 def _assert_added_not_in_previous(self, plan, modification):
     previous_node_instances = plan['node_instances']
     added_and_related = modification['added_and_related']
     previous_graph = rel_graph.build_node_graph(previous_node_instances)
     added_nodes_graph = rel_graph.build_node_graph(added_and_related)
     for instance_id, data in added_nodes_graph.nodes_iter(data=True):
         instance = data['node']
         if instance.get('modification') == 'added':
             self.assertNotIn(instance_id, previous_graph)
         else:
             self.assertIn(instance_id, previous_graph)
     for source, target, in added_nodes_graph.edges_iter():
         self.assertFalse(previous_graph.has_edge(source, target))
def modify_deployment(nodes, previous_node_instances, modified_nodes):
    plan_node_graph = rel_graph.build_node_graph(nodes)
    previous_deployment_node_graph = rel_graph.build_node_graph(
        previous_node_instances)
    new_deployment_node_graph = rel_graph.build_deployment_node_graph(
        plan_node_graph, previous_deployment_node_graph, modified_nodes)

    added_and_related = rel_graph.extract_added_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph)
    removed_and_related = rel_graph.extract_removed_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph)

    return {
        'added_and_related': added_and_related,
        'removed_and_related': removed_and_related
    }
def modify_deployment(nodes, previous_node_instances, modified_nodes):
    plan_node_graph = rel_graph.build_node_graph(nodes)
    previous_deployment_node_graph = rel_graph.build_node_graph(
        previous_node_instances)
    new_deployment_node_graph = rel_graph.build_deployment_node_graph(
        plan_node_graph,
        previous_deployment_node_graph,
        modified_nodes)

    added_and_related = rel_graph.extract_added_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph)
    removed_and_related = rel_graph.extract_removed_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph)

    return {
        'added_and_related': added_and_related,
        'removed_and_related': removed_and_related
    }
def create_deployment_plan(plan):
    """
    Expand node instances based on number of instances to deploy and
    defined relationships
    """
    plan_node_graph = rel_graph.build_node_graph(plan['nodes'])
    deployment_node_graph = rel_graph.build_deployment_node_graph(
        plan_node_graph)
    node_instances = rel_graph.extract_node_instances(
        node_instances_graph=deployment_node_graph)
    deployment_plan = copy.deepcopy(plan)
    deployment_plan[constants.NODE_INSTANCES] = node_instances
    return models.Plan(deployment_plan)
def create_deployment_plan(plan):
    """
    Expand node instances based on number of instances to deploy and
    defined relationships
    """
    plan_node_graph = rel_graph.build_node_graph(plan['nodes'])
    deployment_node_graph = rel_graph.build_deployment_node_graph(
        plan_node_graph)
    node_instances = rel_graph.extract_node_instances(
        node_instances_graph=deployment_node_graph)
    deployment_plan = copy.deepcopy(plan)
    deployment_plan[constants.NODE_INSTANCES] = node_instances
    return models.Plan(deployment_plan)
Ejemplo n.º 10
0
 def _assert_removed_in_previous(self, plan, modification):
     plan_node_graph = rel_graph.build_node_graph(
         nodes=plan['nodes'], scaling_groups=plan['scaling_groups'])
     previous_node_instances = plan['node_instances']
     removed_and_related = modification[constants.REMOVED_AND_RELATED]
     previous_graph, _ = rel_graph.build_previous_deployment_node_graph(
         plan_node_graph=plan_node_graph,
         previous_node_instances=previous_node_instances)
     removed_nodes_graph, _ = rel_graph.build_previous_deployment_node_graph(  # noqa
         plan_node_graph=plan_node_graph,
         previous_node_instances=removed_and_related)
     for instance_id, data in removed_nodes_graph.nodes_iter(data=True):
         self.assertIn(instance_id, previous_graph)
     for source, target, in removed_nodes_graph.edges_iter():
         self.assertTrue(previous_graph.has_edge(source, target))
Ejemplo n.º 11
0
def create_deployment_plan(plan, existing_ni_ids=None):
    """
    Expand node instances based on number of instances to deploy and
    defined relationships
    """
    deployment_plan = copy.deepcopy(plan)
    plan_node_graph = rel_graph.build_node_graph(
        nodes=deployment_plan['nodes'],
        scaling_groups=deployment_plan['scaling_groups'])
    deployment_node_graph, ctx = rel_graph.build_deployment_node_graph(
        plan_node_graph, existing_ni_ids=existing_ni_ids)
    node_instances = rel_graph.extract_node_instances(
        node_instances_graph=deployment_node_graph, ctx=ctx)
    deployment_plan[constants.NODE_INSTANCES] = node_instances
    return models.Plan(deployment_plan)
Ejemplo n.º 12
0
 def _assert_removed_in_previous(self, plan, modification):
     plan_node_graph = rel_graph.build_node_graph(
         nodes=plan['nodes'],
         scaling_groups=plan['scaling_groups'])
     previous_node_instances = plan['node_instances']
     removed_and_related = modification['removed_and_related']
     previous_graph, _ = rel_graph.build_previous_deployment_node_graph(
         plan_node_graph=plan_node_graph,
         previous_node_instances=previous_node_instances)
     removed_nodes_graph, _ = rel_graph.build_previous_deployment_node_graph(  # noqa
         plan_node_graph=plan_node_graph,
         previous_node_instances=removed_and_related)
     for instance_id, data in removed_nodes_graph.nodes_iter(data=True):
         self.assertIn(instance_id, previous_graph)
     for source, target, in removed_nodes_graph.edges_iter():
         self.assertTrue(previous_graph.has_edge(source, target))
Ejemplo n.º 13
0
 def _assert_added_not_in_previous(self, plan, modification):
     plan_node_graph = rel_graph.build_node_graph(
         nodes=plan['nodes'], scaling_groups=plan['scaling_groups'])
     previous_node_instances = plan['node_instances']
     added_and_related = modification[constants.ADDED_AND_RELATED]
     previous_graph, _ = rel_graph.build_previous_deployment_node_graph(
         plan_node_graph=plan_node_graph,
         previous_node_instances=previous_node_instances)
     added_nodes_graph, _ = rel_graph.build_previous_deployment_node_graph(
         plan_node_graph=plan_node_graph,
         previous_node_instances=added_and_related)
     for instance_id, data in added_nodes_graph.nodes_iter(data=True):
         instance = data['node']
         if instance.get('modification') == 'added':
             self.assertNotIn(instance_id, previous_graph)
         else:
             self.assertIn(instance_id, previous_graph)
     for source, target, in added_nodes_graph.edges_iter():
         self.assertFalse(previous_graph.has_edge(source, target))
def modify_deployment(nodes,
                      previous_nodes,
                      previous_node_instances,
                      modified_nodes,
                      scaling_groups):
    """
    modifies deployment according to the expected nodes. based on
    previous_node_instances
    :param nodes: the entire set of expected nodes.
    :param previous_node_instances:
    :param modified_nodes: existing nodes whose instance number has changed
     Add a line note
    :return: a dict of add,extended,reduced and removed instances
     Add a line note
    """

    plan_node_graph = rel_graph.build_node_graph(
        nodes=nodes,
        scaling_groups=scaling_groups)
    previous_plan_node_graph = rel_graph.build_node_graph(
        nodes=previous_nodes,
        scaling_groups=scaling_groups)
    previous_deployment_node_graph, previous_deployment_contained_graph = \
        rel_graph.build_previous_deployment_node_graph(
            plan_node_graph=previous_plan_node_graph,
            previous_node_instances=previous_node_instances)
    new_deployment_node_graph, ctx = rel_graph.build_deployment_node_graph(
        plan_node_graph=plan_node_graph,
        previous_deployment_node_graph=previous_deployment_node_graph,
        previous_deployment_contained_graph=previous_deployment_contained_graph,  # noqa
        modified_nodes=modified_nodes)

    # Any node instances which were added or removed
    added_and_related = rel_graph.extract_added_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph,
        ctx=ctx)
    removed_and_related = rel_graph.extract_removed_node_instances(
        previous_deployment_node_graph, new_deployment_node_graph,
        ctx=ctx)

    # Any node instances which had a modification to their relationship.
    # (newly introduced and removed nodes)
    extended_and_related = rel_graph.extract_added_relationships(
        previous_deployment_node_graph, new_deployment_node_graph,
        ctx=ctx)
    reduced_and_related = rel_graph.extract_removed_relationships(
        previous_deployment_node_graph, new_deployment_node_graph,
        ctx=ctx)

    # The extracted extended and reduced relationships hold the new and old
    # node instances. These are not required, since the change is on
    # node instance level (and not the relationship level)
    extended_and_related = \
        filter_out_node_instances(added_and_related, extended_and_related)
    reduced_and_related = \
        filter_out_node_instances(removed_and_related, reduced_and_related)

    return {
        'added_and_related': added_and_related,
        'extended_and_related': extended_and_related,
        'reduced_and_related': reduced_and_related,
        'removed_and_related': removed_and_related
    }