Esempio n. 1
0
 def _retrigger_replaced(self, is_update, rsrc, stack, check_resource):
     graph = stack.convergence_dependencies.graph()
     key = parser.ConvergenceNode(rsrc.id, is_update)
     if key not in graph and rsrc.replaces is not None:
         # This resource replaces old one and is not needed in
         # current traversal. You need to mark the resource as
         # DELETED so that it gets cleaned up in purge_db.
         values = {'action': rsrc.DELETE}
         db_api.resource_update_and_save(stack.context, rsrc.id, values)
         # The old resource might be in the graph (a rollback case);
         # just re-trigger it.
         key = parser.ConvergenceNode(rsrc.replaces, is_update)
         check_resource.retrigger_check_resource(stack.context, is_update,
                                                 key.rsrc_id, stack)
Esempio n. 2
0
    def retrigger_check_resource(self, cnxt, resource_id, stack):
        current_traversal = stack.current_traversal
        graph = stack.convergence_dependencies.graph()

        # When re-trigger received for latest traversal, first check if update
        # key is available in graph. If yes, the latest traversal is waiting
        # for update, otherwise it is waiting for delete. This is the case
        # regardless of which action (update or cleanup) from the previous
        # traversal was blocking it.
        update_key = parser.ConvergenceNode(resource_id, True)
        key = parser.ConvergenceNode(resource_id, update_key in graph)

        LOG.info('Re-trigger resource: %s', key)
        predecessors = set(graph[key])

        try:
            propagate_check_resource(cnxt, self._rpc_client, resource_id,
                                     current_traversal, predecessors, key,
                                     None, key.is_update, None)
        except exception.EntityNotFound as e:
            if e.entity != "Sync Point":
                raise
Esempio n. 3
0
def check_stack_complete(cnxt, stack, current_traversal, sender_id, deps,
                         is_update):
    """Mark the stack complete if the update is complete.

    Complete is currently in the sense that all desired resources are in
    service, not that superfluous ones have been cleaned up.
    """
    roots = set(deps.roots())

    if (sender_id, is_update) not in roots:
        return

    def mark_complete(stack_id, data):
        stack.mark_complete()

    sender_key = parser.ConvergenceNode(sender_id, is_update)
    sync_point.sync(cnxt, stack.id, current_traversal, True, mark_complete,
                    roots, {sender_key: None})
Esempio n. 4
0
    def _initiate_propagate_resource(self, cnxt, resource_id,
                                     current_traversal, is_update, rsrc,
                                     stack):
        deps = stack.convergence_dependencies
        graph = deps.graph()
        graph_key = parser.ConvergenceNode(resource_id, is_update)

        if graph_key not in graph and rsrc.replaces is not None:
            # If we are a replacement, impersonate the replaced resource for
            # the purposes of calculating whether subsequent resources are
            # ready, since everybody has to work from the same version of the
            # graph. Our real resource ID is sent in the input_data, so the
            # dependencies will get updated to point to this resource in time
            # for the next traversal.
            graph_key = parser.ConvergenceNode(rsrc.replaces, is_update)

        def _get_input_data(req_node, input_forward_data=None):
            if req_node.is_update:
                if input_forward_data is None:
                    return rsrc.node_data().as_dict()
                else:
                    # do not re-resolve attrs
                    return input_forward_data
            else:
                # Don't send data if initiating clean-up for self i.e.
                # initiating delete of a replaced resource
                if req_node.rsrc_id != graph_key.rsrc_id:
                    # send replaced resource as needed_by if it exists
                    return (rsrc.replaced_by
                            if rsrc.replaced_by is not None
                            else resource_id)
            return None

        try:
            input_forward_data = None
            for req_node in deps.required_by(graph_key):
                input_data = _get_input_data(req_node, input_forward_data)
                if req_node.is_update:
                    input_forward_data = input_data
                propagate_check_resource(
                    cnxt, self._rpc_client, req_node.rsrc_id,
                    current_traversal, set(graph[req_node]),
                    graph_key, input_data, req_node.is_update,
                    stack.adopt_stack_data)
            if is_update:
                if input_forward_data is None:
                    # we haven't resolved attribute data for the resource,
                    # so clear any old attributes so they may be re-resolved
                    rsrc.clear_stored_attributes()
                else:
                    rsrc.store_attributes()
            check_stack_complete(cnxt, stack, current_traversal,
                                 graph_key.rsrc_id, deps, graph_key.is_update)
        except exception.EntityNotFound as e:
            if e.entity == "Sync Point":
                # Reload the stack to determine the current traversal, and
                # check the SyncPoint for the current node to determine if
                # it is ready. If it is, then retrigger the current node
                # with the appropriate data for the latest traversal.
                stack = parser.Stack.load(cnxt, stack_id=rsrc.stack.id,
                                          force_reload=True)
                if current_traversal == stack.current_traversal:
                    LOG.debug('[%s] Traversal sync point missing.',
                              current_traversal)
                    return

                self.retrigger_check_resource(cnxt, is_update,
                                              resource_id, stack)
            else:
                raise