示例#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
    def execute_workflow(self,
                         deployment_id,
                         workflow_id,
                         parameters=None,
                         allow_custom_parameters=False,
                         force=False):
        deployment = self.get_deployment(deployment_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]

        self._verify_deployment_environment_created_successfully(deployment_id)

        # validate no execution is currently in progress
        if not force:
            executions = get_storage_manager().executions_list(
                deployment_id=deployment_id)
            running = [
                e.id for e in executions
                if get_storage_manager().get_execution(e.id).status not in
                models.Execution.END_STATES
            ]
            if len(running) > 0:
                raise manager_exceptions.ExistingRunningExecutionError(
                    'The following executions are currently running for this '
                    'deployment: {0}. To execute this workflow anyway, pass '
                    '"force=true" as a query parameter to this request'.format(
                        running))

        execution_parameters = \
            BlueprintsManager._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=models.Execution.PENDING,
            created_at=str(datetime.now()),
            blueprint_id=deployment.blueprint_id,
            workflow_id=workflow_id,
            deployment_id=deployment_id,
            error='',
            parameters=self._get_only_user_execution_parameters(
                execution_parameters))

        get_storage_manager().put_execution(new_execution.id, new_execution)

        workflow_client().execute_workflow(
            workflow_id,
            workflow,
            blueprint_id=deployment.blueprint_id,
            deployment_id=deployment_id,
            execution_id=execution_id,
            execution_parameters=execution_parameters)

        return new_execution
    def execute_workflow(self, deployment_id, workflow_id,
                         parameters=None,
                         allow_custom_parameters=False, force=False):
        deployment = self.get_deployment(deployment_id)
        blueprint = self.get_blueprint(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]

        self._verify_deployment_environment_created_successfully(deployment_id)

        self._check_for_active_system_wide_execution()
        self._check_for_active_executions(deployment_id, force)

        execution_parameters = \
            BlueprintsManager._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=models.Execution.PENDING,
            created_at=str(datetime.now()),
            blueprint_id=deployment.blueprint_id,
            workflow_id=workflow_id,
            deployment_id=deployment_id,
            error='',
            parameters=self._get_only_user_execution_parameters(
                execution_parameters),
            is_system_workflow=False)

        self.sm.put_execution(new_execution.id, new_execution)

        # executing the user workflow
        workflow_plugins = blueprint.plan[
            constants.WORKFLOW_PLUGINS_TO_INSTALL]
        self.workflow_client.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)

        return new_execution
    def execute_workflow(self,
                         deployment_id,
                         workflow_id,
                         parameters=None,
                         allow_custom_parameters=False,
                         force=False):
        deployment = self.get_deployment(deployment_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]

        self._verify_deployment_environment_created_successfully(deployment_id)

        transient_workers_config =\
            self._get_transient_deployment_workers_mode_config()
        is_transient_workers_enabled = transient_workers_config['enabled']

        self._check_for_active_system_wide_execution()
        self._check_for_active_executions(deployment_id, force,
                                          transient_workers_config)

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

        if is_transient_workers_enabled:
            # in this mode, we push the user execution object to storage
            # before executing the "_start_deployment_environment" system
            # workflow, to prevent from other executions to start running in
            # between the system workflow and the user workflow execution.
            # to keep correct chronological order, the system workflow's
            # "created_at" field is generated here.
            start_deployment_env_created_at_time = str(datetime.now())

        execution_id = str(uuid.uuid4())

        new_execution = models.Execution(
            id=execution_id,
            status=models.Execution.PENDING,
            created_at=str(datetime.now()),
            blueprint_id=deployment.blueprint_id,
            workflow_id=workflow_id,
            deployment_id=deployment_id,
            error='',
            parameters=self._get_only_user_execution_parameters(
                execution_parameters),
            is_system_workflow=False)

        self.sm.put_execution(new_execution.id, new_execution)

        if is_transient_workers_enabled:
            # initiating a workflow to start deployment workers
            wf_id = '_start_deployment_environment'
            deployment_env_start_task_name = \
                'cloudify_system_workflows.deployment_environment.start'

            self._execute_system_workflow(
                wf_id=wf_id,
                task_mapping=deployment_env_start_task_name,
                deployment=deployment,
                timeout=300,
                created_at=start_deployment_env_created_at_time)

        # executing the user workflow
        self.workflow_client.execute_workflow(
            workflow_id,
            workflow,
            blueprint_id=deployment.blueprint_id,
            deployment_id=deployment_id,
            execution_id=execution_id,
            execution_parameters=execution_parameters)

        return new_execution