示例#1
0
    def _execute_workflow(self,
                          deployment_update,
                          workflow_id,
                          parameters=None,
                          allow_custom_parameters=False,
                          force=False):
        """Executes the specified workflow

        :param deployment_update:
        :param workflow_id:
        :param parameters:
        :param allow_custom_parameters:
        :param force:
        :return:
        """
        deployment_id = deployment_update.deployment_id
        deployment = self.sm.get(models.Deployment, deployment_id)
        blueprint_id = deployment.blueprint_id

        if workflow_id not in deployment.workflows:
            raise manager_exceptions.NonexistentWorkflowError(
                'Workflow {0} does not exist in deployment {1}'
                .format(workflow_id, deployment_id))
        workflow = deployment.workflows[workflow_id]

        execution_parameters = \
            ResourceManager._merge_and_validate_execution_parameters(
                workflow, workflow_id, parameters, allow_custom_parameters)

        execution_id = str(uuid.uuid4())

        new_execution = models.Execution(
            id=execution_id,
            status=ExecutionState.PENDING,
            created_at=utils.get_formatted_timestamp(),
            workflow_id=workflow_id,
            error='',
            parameters=ResourceManager._get_only_user_execution_parameters(
                execution_parameters),
            is_system_workflow=False)

        if deployment:
            new_execution.set_deployment(deployment)
            deployment_update.execution = new_execution
        self.sm.put(new_execution)

        # executing the user workflow
        workflow_plugins = \
            deployment_update.deployment_plan[
                constants.WORKFLOW_PLUGINS_TO_INSTALL]
        workflow_executor.execute_workflow(
            workflow_id,
            workflow,
            workflow_plugins=workflow_plugins,
            blueprint_id=blueprint_id,
            deployment_id=deployment_id,
            execution_id=execution_id,
            execution_parameters=execution_parameters)

        return new_execution
示例#2
0
    def get(self, _include=None, **kwargs):
        """
        List nodes
        """
        args = get_args_and_verify_arguments(
            [Argument('deployment_id', required=False),
             Argument('node_id', required=False)]
        )

        deployment_id = args.get('deployment_id')
        node_id = args.get('node_id')
        if deployment_id and node_id:
            try:
                nodes = [get_node(deployment_id, node_id)]
            except manager_exceptions.NotFoundError:
                nodes = []
        else:
            deployment_id_filter = ResourceManager.create_filters_dict(
                deployment_id=deployment_id)
            nodes = get_storage_manager().list(
                models.Node,
                filters=deployment_id_filter,
                include=_include
            ).items
        return nodes
 def get(self, _include=None, **kwargs):
     args = get_args_and_verify_arguments(
         [Argument('deployment_id', required=False)])
     deployment_id_filter = ResourceManager.create_filters_dict(
         deployment_id=args.deployment_id)
     return get_storage_manager().list(models.DeploymentModification,
                                       filters=deployment_id_filter,
                                       include=_include).items
    def _execute_workflow(self,
                          deployment_update,
                          workflow_id,
                          parameters=None,
                          allow_custom_parameters=False):
        deployment = deployment_update.deployment
        if workflow_id not in deployment.workflows:
            raise manager_exceptions.NonexistentWorkflowError(
                'Workflow {0} does not exist in deployment {1}'.format(
                    workflow_id, deployment.id))
        workflow = deployment.workflows[workflow_id]
        execution_parameters = \
            ResourceManager._merge_and_validate_execution_parameters(
                workflow, workflow_id, parameters, allow_custom_parameters)
        execution_id = str(uuid.uuid4())
        new_execution = models.Execution(
            id=execution_id,
            status=ExecutionState.PENDING,
            created_at=utils.get_formatted_timestamp(),
            workflow_id=workflow_id,
            error='',
            parameters=ResourceManager._get_only_user_execution_parameters(
                execution_parameters),
            is_system_workflow=False
        )
        if deployment:
            new_execution.set_deployment(deployment)
            deployment_update.execution = new_execution
        self.sm.put(new_execution)

        # executing the user workflow
        workflow_plugins = deployment_update.deployment_plan[
            constants.WORKFLOW_PLUGINS_TO_INSTALL]
        workflow_executor.execute_workflow(
            workflow_id,
            workflow,
            workflow_plugins=workflow_plugins,
            blueprint_id=deployment.blueprint_id,
            deployment_id=deployment.id,
            execution_id=execution_id,
            execution_parameters=execution_parameters,
            execution_creator=current_user
        )
        return new_execution
 def get(self, _include=None, **kwargs):
     args = get_args_and_verify_arguments(
         [Argument('deployment_id', required=False)]
     )
     deployment_id_filter = ResourceManager.create_filters_dict(
         deployment_id=args.deployment_id)
     return get_storage_manager().list(
         models.DeploymentModification,
         filters=deployment_id_filter,
         include=_include
     ).items
示例#6
0
 def get(self, _include=None, **kwargs):
     """List executions"""
     args = get_args_and_verify_arguments([
         Argument('deployment_id', required=False),
         Argument('include_system_workflows', type=boolean, default=False)
     ])
     deployment_id_filter = ResourceManager.create_filters_dict(
         deployment_id=args.deployment_id)
     return get_resource_manager().list_executions(
         is_include_system_workflows=args.include_system_workflows,
         include=_include,
         filters=deployment_id_filter).items
 def get(self, _include=None, **kwargs):
     """List executions"""
     args = get_args_and_verify_arguments(
         [Argument('deployment_id', required=False),
          Argument('include_system_workflows', type=boolean,
                   default=False)]
     )
     deployment_id_filter = ResourceManager.create_filters_dict(
         deployment_id=args.deployment_id)
     return get_resource_manager().list_executions(
         is_include_system_workflows=args.include_system_workflows,
         include=_include,
         filters=deployment_id_filter).items
示例#8
0
 def get(self, _include=None, **kwargs):
     """
     List node instances
     """
     args = get_args_and_verify_arguments([
         Argument('deployment_id', type=str, required=False),
         Argument('node_name', type=str, required=False)
     ])
     deployment_id = args.get('deployment_id')
     node_id = args.get('node_name')
     params_filter = ResourceManager.create_filters_dict(
         deployment_id=deployment_id, node_id=node_id)
     return get_storage_manager().list(models.NodeInstance,
                                       filters=params_filter,
                                       include=_include).items
示例#9
0
 def get(self, _include=None, **kwargs):
     """
     List node instances
     """
     args = get_args_and_verify_arguments(
         [Argument('deployment_id', required=False),
          Argument('node_name', required=False)]
     )
     deployment_id = args.get('deployment_id')
     node_id = args.get('node_name')
     params_filter = ResourceManager.create_filters_dict(
         deployment_id=deployment_id, node_id=node_id)
     return get_storage_manager().list(
         models.NodeInstance,
         filters=params_filter,
         include=_include
     ).items
示例#10
0
def cleanup_deployment(depl_id, get_all):
    with setup_flask_app().app_context():
        sm = get_storage_manager()
        params_filter = ResourceManager.create_filters_dict(
            deployment_id=depl_id)
        list_kwargs = {'filters': params_filter, 'include': None}
        if get_all:
            list_kwargs['get_all_results'] = True

        instances = get_storage_manager().list(models.NodeInstance,
                                               **list_kwargs).items
        alive_instances = []
        delete_instances = []
        count_instances = {}
        for instance in instances:
            if instance.node_id not in count_instances:
                count_instances[instance.node_id] = 0
            if instance.state not in ('uninitialized', 'deleted'):
                alive_instances.append(instance.id)
                # update count of instances internaly
                count_instances[instance.node_id] += 1
            else:
                delete_instances.append(instance.id)
                sm.delete(instance)
        sys.stderr.write("For save as alive: {}\n".format(
            repr(alive_instances)))
        sys.stderr.write("For delete as uninitialized: {}\n".format(
            repr(delete_instances)))
        # cleanup instances relationships
        for instance in instances:
            if instance.id in alive_instances:
                sys.stderr.write("{}:Before relationships{}\n".format(
                    instance.id, repr(instance.relationships)))
                relationships = []
                for relationship in instance.relationships:
                    if relationship['target_id'] in alive_instances:
                        relationships.append(relationship)
                instance.relationships = relationships
                sys.stderr.write("{}:After relationships{}\n".format(
                    instance.id, repr(instance.relationships)))
                sm.update(instance)
        # cleanup nodes
        nodes = get_storage_manager().list(models.Node, **list_kwargs).items
        for node in nodes:
            if node.id in count_instances:
                node.number_of_instances = count_instances[node.id]
                sm.update(node)
        sys.stderr.write("Count instances after cleanup: {}\n".format(
            repr(count_instances)))
        # deployemnts update
        deployment = sm.get(models.Deployment, depl_id)
        sys.stderr.write("Scaling groups before: {}\n".format(
            repr(deployment.scaling_groups)))
        scaling_groups = deepcopy(deployment.scaling_groups)
        for scaling_group_name in scaling_groups:
            scaling_group = scaling_groups[scaling_group_name]
            instances_count = 0
            for node in scaling_group['members']:
                if instances_count < count_instances.get(node, 0):
                    instances_count = count_instances[node]
            scaling_group['properties']['planned_instances'] = instances_count
            scaling_group['properties']['current_instances'] = instances_count
        deployment.scaling_groups = scaling_groups
        sm.update(deployment)
        sys.stderr.write("Scaling groups after: {}\n".format(
            repr(scaling_groups)))