Exemplo n.º 1
0
    def put(self):
        """Creates an inter-deployment dependency.

        :param dependency_creator: a string representing the entity that
         is responsible for this dependency (e.g. an intrinsic function
         blueprint path, 'node_instances.some_node_instance', etc.).
        :param source_deployment: source deployment that depends on the target
         deployment.
        :param target_deployment: the deployment that the source deployment
         depends on.
        :return: an InterDeploymentDependency object containing the information
         of the dependency.
        """
        sm = get_storage_manager()
        params = self._get_put_dependency_params(sm)
        now = utils.get_formatted_timestamp()

        # assert no cyclic dependencies are created
        dep_greph = rest_utils.RecursiveDeploymentDependencies(sm)
        source_id = str(params[SOURCE_DEPLOYMENT].id)
        target_id = str(params[TARGET_DEPLOYMENT].id)
        dep_greph.create_dependencies_graph()
        dep_greph.assert_no_cyclic_dependencies(source_id, target_id)

        deployment_dependency = models.InterDeploymentDependencies(
            id=str(uuid.uuid4()),
            dependency_creator=params[DEPENDENCY_CREATOR],
            source_deployment=params[SOURCE_DEPLOYMENT],
            target_deployment=params[TARGET_DEPLOYMENT],
            created_at=now)
        return sm.put(deployment_dependency)
Exemplo n.º 2
0
def update_deployment_dependencies_from_plan(deployment_id,
                                             deployment_plan,
                                             storage_manager,
                                             dep_plan_filter_func,
                                             curr_dependencies=None):
    curr_dependencies = {} if curr_dependencies is None else curr_dependencies

    new_dependencies = deployment_plan.setdefault(
        INTER_DEPLOYMENT_FUNCTIONS, {})
    new_dependencies_dict = {
        creator: target
        for creator, target in new_dependencies.items()
        if dep_plan_filter_func(creator)
    }
    dep_graph = RecursiveDeploymentDependencies(storage_manager)
    dep_graph.create_dependencies_graph()

    for dependency_creator, target_deployment_id \
            in new_dependencies_dict.items():
        target_deployment = storage_manager.get(
            models.Deployment, target_deployment_id) \
            if target_deployment_id else None
        source_deployment = storage_manager.get(
            models.Deployment, deployment_id)
        if dependency_creator not in curr_dependencies:
            now = get_formatted_timestamp()
            storage_manager.put(models.InterDeploymentDependencies(
                dependency_creator=dependency_creator,
                source_deployment=source_deployment,
                target_deployment=target_deployment,
                created_at=now,
                id=str(uuid.uuid4())
            ))
            continue
        if not target_deployment_id:
            # New target deployment is unknown, keep the current value
            continue

        curr_target_deployment = \
            curr_dependencies[dependency_creator].target_deployment
        if curr_target_deployment == target_deployment_id:
            continue

        curr_dependencies[dependency_creator].target_deployment = \
            target_deployment
        storage_manager.update(curr_dependencies[dependency_creator])
        # verify that the new dependency doesn't create a cycle,
        # and update the dependencies graph accordingly
        if not hasattr(source_deployment, 'id'):
            continue
            # upcoming: handle the case of external dependencies
        source_id = source_deployment.id
        target_id = target_deployment.id
        old_target_id = curr_target_deployment.id
        dep_graph.assert_no_cyclic_dependencies(source_id, target_id)
        if target_deployment not in new_dependencies_dict.values():
            dep_graph.remove_dependency_from_graph(source_id, old_target_id)
        dep_graph.add_dependency_to_graph(source_id, target_id)
    return new_dependencies_dict
Exemplo n.º 3
0
 def _put_deployment_dependency(source_deployment, target_deployment,
                                dependency_creator, sm):
     now = utils.get_formatted_timestamp()
     deployment_dependency = models.InterDeploymentDependencies(
         id=str(uuid.uuid4()),
         dependency_creator=dependency_creator,
         source_deployment=source_deployment,
         target_deployment=target_deployment,
         created_at=now)
     sm.put(deployment_dependency)
Exemplo n.º 4
0
    def put(self):
        """Creates an inter-deployment dependency.

        :param dependency_creator: a string representing the entity that
         is responsible for this dependency (e.g. an intrinsic function
         blueprint path, 'node_instances.some_node_instance', etc.).
        :param source_deployment: source deployment that depends on the target
         deployment.
        :param target_deployment: the deployment that the source deployment
         depends on.
        :param external_source: metadata, in JSON format, of the source
        deployment (deployment name, tenant name, and the manager host(s)),
        in case it resides on an external manager. None otherwise
        :param external_target: metadata, in JSON format, of the target
        deployment (deployment name, tenant name, and the manager host(s)),
        in case it resides on an external manager. None otherwise
        :return: an InterDeploymentDependency object containing the information
         of the dependency.
        """
        sm = get_storage_manager()

        params = self._get_put_dependency_params(sm)
        now = utils.get_formatted_timestamp()

        if (EXTERNAL_SOURCE not in params) and (EXTERNAL_TARGET not in params):
            # assert no cyclic dependencies are created
            dep_greph = rest_utils.RecursiveDeploymentDependencies(sm)
            source_id = str(params[SOURCE_DEPLOYMENT].id)
            target_id = str(params[TARGET_DEPLOYMENT].id)
            dep_greph.create_dependencies_graph()
            dep_greph.assert_no_cyclic_dependencies(source_id, target_id)

        deployment_dependency = models.InterDeploymentDependencies(
            id=str(uuid.uuid4()),
            dependency_creator=params[DEPENDENCY_CREATOR],
            source_deployment=params[SOURCE_DEPLOYMENT],
            target_deployment=params.get(TARGET_DEPLOYMENT),
            external_source=params.get(EXTERNAL_SOURCE),
            external_target=params.get(EXTERNAL_TARGET),
            created_at=now)
        return sm.put(deployment_dependency)