• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python action_db.get_runnertype_by_name函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中st2common.util.action_db.get_runnertype_by_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_runnertype_by_name函数的具体用法?Python get_runnertype_by_name怎么用?Python get_runnertype_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_runnertype_by_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: dispatch

    def dispatch(self, liveaction_db):
        action_db = get_action_by_ref(liveaction_db.action)
        if not action_db:
            raise Exception('Action %s not found in dB.' % liveaction_db.action)
        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
        runner_type = runnertype_db.name

        LOG.info('Dispatching Action to runner \n%s',
                 json.dumps(liveaction_db.to_serializable_dict(), indent=4))
        LOG.debug('    liverunner_type: %s', runner_type)
        LOG.debug('    RunnerType: %s', runnertype_db)

        # Get runner instance.
        runner = get_runner(runnertype_db.runner_module)
        LOG.debug('Runner instance for RunnerType "%s" is: %s', runnertype_db.name, runner)

        # Invoke pre_run, run, post_run cycle.
        liveaction_db = self._do_run(runner, runnertype_db, action_db, liveaction_db)
        LOG.debug('runner do_run result: %s', liveaction_db.result)

        liveaction_serializable = liveaction_db.to_serializable_dict()

        extra = {'liveaction_db': liveaction_db}
        LOG.audit('liveaction complete.', extra=extra)
        LOG.info('result :\n%s.', json.dumps(liveaction_serializable.get('result', None), indent=4))

        return liveaction_db.result
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:27,代码来源:base.py


示例2: get_schema_for_action_parameters

def get_schema_for_action_parameters(action_db):
    """
    Dynamically construct JSON schema for the provided action from the parameters metadata.

    Note: This schema is used to validate parameters which are passed to the action.
    """
    from st2common.util.action_db import get_runnertype_by_name
    runner_type = get_runnertype_by_name(action_db.runner_type['name'])

    parameters_schema = copy.deepcopy(runner_type.runner_parameters)

    for name, schema in six.iteritems(action_db.parameters):
        if name not in parameters_schema.keys():
            parameters_schema.update({name: schema})
        else:
            for attribute, value in six.iteritems(schema):
                validate_runner_parameter_attribute_override(
                    action_db.ref, name, attribute,
                    value, parameters_schema[name].get(attribute))

                parameters_schema[name][attribute] = value

    schema = get_schema_for_resource_parameters(parameters_schema=parameters_schema)

    if parameters_schema:
        schema['title'] = action_db.name
        if action_db.description:
            schema['description'] = action_db.description

    return schema
开发者ID:logikal,项目名称:st2,代码行数:30,代码来源:__init__.py


示例3: _do_enforce

    def _do_enforce(self):
        # TODO: Refactor this to avoid additional lookup in cast_params
        action_ref = self.rule.action['ref']

        # Verify action referenced in the rule exists in the database
        action_db = action_utils.get_action_by_ref(action_ref)
        if not action_db:
            raise ValueError('Action "%s" doesn\'t exist' % (action_ref))

        runnertype_db = action_utils.get_runnertype_by_name(action_db.runner_type['name'])

        params = self.rule.action.parameters
        LOG.info('Invoking action %s for trigger_instance %s with params %s.',
                 self.rule.action.ref, self.trigger_instance.id,
                 json.dumps(params))

        # update trace before invoking the action.
        trace_context = self._update_trace()
        LOG.debug('Updated trace %s with rule %s.', trace_context, self.rule.id)

        context, additional_contexts = self.get_action_execution_context(
            action_db=action_db,
            trace_context=trace_context)

        return self._invoke_action(action_db=action_db, runnertype_db=runnertype_db, params=params,
                                   context=context,
                                   additional_contexts=additional_contexts)
开发者ID:StackStorm,项目名称:st2,代码行数:27,代码来源:enforcer.py


示例4: dispatch

    def dispatch(self, actionexec_db):
        action_ref = ResourceReference.from_string_reference(ref=actionexec_db.action)
        (action_db, _) = get_action_by_dict(
            {'name': action_ref.name, 'pack': action_ref.pack})
        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
        runner_type = runnertype_db.name

        LOG.info('Dispatching runner for Action "%s"', actionexec_db)
        LOG.debug('    liverunner_type: %s', runner_type)
        LOG.debug('    RunnerType: %s', runnertype_db)
        LOG.debug('    ActionExecution: %s', actionexec_db)

        # Get runner instance.
        runner = self._get_runner(runnertype_db)
        LOG.debug('Runner instance for RunnerType "%s" is: %s', runnertype_db.name, runner)

        # Invoke pre_run, run, post_run cycle.
        result, actionexec_db = self._do_run(runner, runnertype_db, action_db, actionexec_db)
        LOG.debug('runner do_run result: %s', result)

        actionsensor.post_trigger(actionexec_db)
        LOG.audit('ActionExecution complete.',
                  extra={'actionexecution': actionexec_db.to_serializable_dict()})

        return result
开发者ID:nagyist,项目名称:StackStorm-st2,代码行数:25,代码来源:base.py


示例5: _schedule_execution

    def _schedule_execution(self, liveaction):
        # Initialize execution context if it does not exist.
        if not hasattr(liveaction, 'context'):
            liveaction.context = dict()

        liveaction.context['user'] = get_requester()
        LOG.debug('User is: %s' % liveaction.context['user'])

        # Retrieve other st2 context from request header.
        if 'st2-context' in pecan.request.headers and pecan.request.headers['st2-context']:
            context = jsonify.try_loads(pecan.request.headers['st2-context'])
            if not isinstance(context, dict):
                raise ValueError('Unable to convert st2-context from the headers into JSON.')
            liveaction.context.update(context)

        # Schedule the action execution.
        liveaction_db = LiveActionAPI.to_model(liveaction)
        liveaction_db, actionexecution_db = action_service.create_request(liveaction_db)

        action_db = action_utils.get_action_by_ref(liveaction_db.action)
        runnertype_db = action_utils.get_runnertype_by_name(action_db.runner_type['name'])

        try:
            liveaction_db.parameters = param_utils.render_live_params(
                runnertype_db.runner_parameters, action_db.parameters, liveaction_db.parameters,
                liveaction_db.context)
        except ParamException as e:
            raise ValueValidationException(str(e))

        liveaction_db = LiveAction.add_or_update(liveaction_db, publish=False)

        _, actionexecution_db = action_service.publish_request(liveaction_db, actionexecution_db)
        from_model_kwargs = self._get_from_model_kwargs_for_request(request=pecan.request)
        return ActionExecutionAPI.from_model(actionexecution_db, from_model_kwargs)
开发者ID:azamsheriff,项目名称:st2,代码行数:34,代码来源:actionexecutions.py


示例6: _invoke_post_run

    def _invoke_post_run(self, actionexec_db, action_db):
        LOG.info(
            "Invoking post run for action execution %s. Action=%s; Runner=%s",
            actionexec_db.id,
            action_db.name,
            action_db.runner_type["name"],
        )

        # Get an instance of the action runner.
        runnertype_db = get_runnertype_by_name(action_db.runner_type["name"])
        runner = get_runner(runnertype_db.runner_module)

        # Configure the action runner.
        runner.container_service = RunnerContainerService()
        runner.action = action_db
        runner.action_name = action_db.name
        runner.action_execution_id = str(actionexec_db.id)
        runner.entry_point = RunnerContainerService.get_entry_point_abs_path(
            pack=action_db.pack, entry_point=action_db.entry_point
        )
        runner.context = getattr(actionexec_db, "context", dict())
        runner.callback = getattr(actionexec_db, "callback", dict())
        runner.libs_dir_path = RunnerContainerService.get_action_libs_abs_path(
            pack=action_db.pack, entry_point=action_db.entry_point
        )

        # Invoke the post_run method.
        runner.post_run(actionexec_db.status, actionexec_db.result)
开发者ID:Pulsant,项目名称:st2,代码行数:28,代码来源:base.py


示例7: cast_params

def cast_params(action_ref, params):
    """
    """
    action_db = action_db_util.get_action_by_ref(action_ref)
    action_parameters_schema = action_db.parameters
    runnertype_db = action_db_util.get_runnertype_by_name(action_db.runner_type['name'])
    runner_parameters_schema = runnertype_db.runner_parameters
    # combine into 1 list of parameter schemas
    parameters_schema = {}
    if runner_parameters_schema:
        parameters_schema.update(runner_parameters_schema)
    if action_parameters_schema:
        parameters_schema.update(action_parameters_schema)
    # cast each param individually
    for k, v in six.iteritems(params):
        parameter_schema = parameters_schema.get(k, None)
        if not parameter_schema:
            LOG.debug('Will skip cast of param[name: %s, value: %s]. No schema.', k, v)
            continue
        parameter_type = parameter_schema.get('type', None)
        if not parameter_type:
            LOG.debug('Will skip cast of param[name: %s, value: %s]. No type.', k, v)
            continue
        cast = get_cast(cast_type=parameter_type)
        if not cast:
            LOG.debug('Will skip cast of param[name: %s, value: %s]. No cast for %s.', k, v,
                      parameter_type)
            continue
        LOG.debug('Casting param: %s of type %s to type: %s', v, type(v), parameter_type)
        params[k] = cast(v)
    return params
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:31,代码来源:action_param_utils.py


示例8: test_get_runnertype_existing

 def test_get_runnertype_existing(self):
     # Lookup by id and verify name equals.
     runner = action_db_utils.get_runnertype_by_id(ActionDBUtilsTestCase.runnertype_db.id)
     self.assertEqual(runner.name, ActionDBUtilsTestCase.runnertype_db.name)
     # Lookup by name and verify id equals.
     runner = action_db_utils.get_runnertype_by_name(ActionDBUtilsTestCase.runnertype_db.name)
     self.assertEqual(runner.id, ActionDBUtilsTestCase.runnertype_db.id)
开发者ID:StackStorm,项目名称:st2,代码行数:7,代码来源:test_action_db_utils.py


示例9: register_runner_types

def register_runner_types():
    LOG.debug('Start : register default RunnerTypes.')

    for runnertype in RUNNER_TYPES:
        try:
            runnertype_db = get_runnertype_by_name(runnertype['name'])
            update = True
        except StackStormDBObjectNotFoundError:
            runnertype_db = None
            update = False

        runnertype_api = RunnerTypeAPI(**runnertype)
        runnertype_api.validate()
        runner_type_model = RunnerTypeAPI.to_model(runnertype_api)

        if runnertype_db:
            runner_type_model.id = runnertype_db.id

        try:
            runnertype_db = RunnerType.add_or_update(runner_type_model)

            extra = {'runnertype_db': runnertype_db}
            if update:
                LOG.audit('RunnerType updated. RunnerType %s', runnertype_db, extra=extra)
            else:
                LOG.audit('RunnerType created. RunnerType %s', runnertype_db, extra=extra)
        except Exception:
            LOG.exception('Unable to register runner type %s.', runnertype['name'])

    LOG.debug('End : register default RunnerTypes.')
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:30,代码来源:runnersregistrar.py


示例10: dispatch

    def dispatch(self, liveaction_db):
        action_db = get_action_by_ref(liveaction_db.action)
        if not action_db:
            raise Exception("Action %s not found in DB." % (liveaction_db.action))

        runnertype_db = get_runnertype_by_name(action_db.runner_type["name"])

        extra = {"liveaction_db": liveaction_db, "runnertype_db": runnertype_db}
        LOG.info("Dispatching Action to a runner", extra=extra)

        # Get runner instance.
        runner = self._get_runner(runnertype_db, action_db, liveaction_db)
        LOG.debug('Runner instance for RunnerType "%s" is: %s', runnertype_db.name, runner)

        # Process the request.
        if liveaction_db.status == action_constants.LIVEACTION_STATUS_CANCELING:
            liveaction_db = self._do_cancel(
                runner=runner, runnertype_db=runnertype_db, action_db=action_db, liveaction_db=liveaction_db
            )
        else:
            liveaction_db = self._do_run(
                runner=runner, runnertype_db=runnertype_db, action_db=action_db, liveaction_db=liveaction_db
            )

        return liveaction_db.result
开发者ID:pixelrebel,项目名称:st2,代码行数:25,代码来源:base.py


示例11: _mark_inquiry_complete

    def _mark_inquiry_complete(self, inquiry_id, result):
        """Mark Inquiry as completed

        This function updates the local LiveAction and Execution with a successful
        status as well as call the "post_run" function for the Inquirer runner so that
        the appropriate callback function is executed

        :param inquiry: The Inquiry for which the response is given
        :param requester_user: The user providing the response

        :rtype: bool - True if requester_user is able to respond. False if not.
        """

        # Update inquiry's execution result with a successful status and the validated response
        liveaction_db = action_utils.update_liveaction_status(
            status=action_constants.LIVEACTION_STATUS_SUCCEEDED,
            runner_info=system_info.get_process_info(),
            result=result,
            liveaction_id=inquiry_id)
        executions.update_execution(liveaction_db)

        # Call Inquiry runner's post_run to trigger callback to workflow
        runner_container = get_runner_container()
        action_db = get_action_by_ref(liveaction_db.action)
        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
        runner = runner_container._get_runner(runnertype_db, action_db, liveaction_db)
        runner.post_run(status=action_constants.LIVEACTION_STATUS_SUCCEEDED, result=result)

        return liveaction_db
开发者ID:lyandut,项目名称:st2,代码行数:29,代码来源:inquiries.py


示例12: register_runner_types

def register_runner_types(experimental=False):
    """
    :param experimental: True to also register experimental runners.
    :type experimental: ``bool``
    """
    LOG.debug('Start : register default RunnerTypes.')

    for runner_type in RUNNER_TYPES:
        runner_type = copy.deepcopy(runner_type)

        # For backward compatibility reasons, we also register runners under the old names
        runner_names = [runner_type['name']] + runner_type.get('aliases', [])
        for runner_name in runner_names:
            runner_type['name'] = runner_name
            runner_experimental = runner_type.get('experimental', False)

            if runner_experimental and not experimental:
                LOG.debug('Skipping experimental runner "%s"' % (runner_name))
                continue

            # Remove additional, non db-model attributes
            non_db_attributes = ['experimental', 'aliases']
            for attribute in non_db_attributes:
                if attribute in runner_type:
                    del runner_type[attribute]

            try:
                runner_type_db = get_runnertype_by_name(runner_name)
                update = True
            except StackStormDBObjectNotFoundError:
                runner_type_db = None
                update = False

            # Note: We don't want to overwrite "enabled" attribute which is already in the database
            # (aka we don't want to re-enable runner which has been disabled by the user)
            if runner_type_db and runner_type_db['enabled'] != runner_type['enabled']:
                runner_type['enabled'] = runner_type_db['enabled']

            runner_type_api = RunnerTypeAPI(**runner_type)
            runner_type_api.validate()
            runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

            if runner_type_db:
                runner_type_model.id = runner_type_db.id

            try:
                runner_type_db = RunnerType.add_or_update(runner_type_model)

                extra = {'runner_type_db': runner_type_db}
                if update:
                    LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra)
                else:
                    LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra)
            except Exception:
                LOG.exception('Unable to register runner type %s.', runner_type['name'])

    LOG.debug('End : register default RunnerTypes.')
开发者ID:Bala96,项目名称:st2,代码行数:57,代码来源:runnersregistrar.py


示例13: _get_runner_model

def _get_runner_model(action_api):
    runner_db = None
    # Check if runner exists.
    try:
        runner_db = get_runnertype_by_name(action_api.runner_type)
    except StackStormDBObjectNotFoundError:
        msg = 'RunnerType %s is not found.' % action_api.runner_type
        raise ValueValidationException(msg)
    return runner_db
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:9,代码来源:action.py


示例14: respond

def respond(inquiry, response, requester=None):
    # Set requester to system user is not provided.
    if not requester:
        requester = cfg.CONF.system_user.user

    # Retrieve the liveaction from the database.
    liveaction_db = lv_db_access.LiveAction.get_by_id(inquiry.liveaction.get('id'))

    # Resume the parent workflow first. If the action execution for the inquiry is updated first,
    # it triggers handling of the action execution completion which will interact with the paused
    # parent workflow. The resuming logic that is executed here will then race with the completion
    # of the inquiry action execution, which will randomly result in the parent workflow stuck in
    # paused state.
    if liveaction_db.context.get('parent'):
        LOG.debug('Resuming workflow parent(s) for inquiry "%s".' % str(inquiry.id))

        # For action execution under Action Chain and Mistral workflows, request the entire
        # workflow to resume. Orquesta handles resume differently and so does not require root
        # to resume. Orquesta allows for specifc branches to resume while other is paused. When
        # there is no other paused branches, the conductor will resume the rest of the workflow.
        resume_target = (
            action_service.get_parent_liveaction(liveaction_db)
            if workflow_service.is_action_execution_under_workflow_context(liveaction_db)
            else action_service.get_root_liveaction(liveaction_db)
        )

        if resume_target.status in action_constants.LIVEACTION_PAUSE_STATES:
            action_service.request_resume(resume_target, requester)

    # Succeed the liveaction and update result with the inquiry response.
    LOG.debug('Updating response for inquiry "%s".' % str(inquiry.id))

    result = copy.deepcopy(inquiry.result)
    result['response'] = response

    liveaction_db = action_utils.update_liveaction_status(
        status=action_constants.LIVEACTION_STATUS_SUCCEEDED,
        end_timestamp=date_utils.get_datetime_utc_now(),
        runner_info=sys_info_utils.get_process_info(),
        result=result,
        liveaction_id=str(liveaction_db.id)
    )

    # Sync the liveaction with the corresponding action execution.
    execution_service.update_execution(liveaction_db)

    # Invoke inquiry post run to trigger a callback to parent workflow.
    LOG.debug('Invoking post run for inquiry "%s".' % str(inquiry.id))
    runner_container = container.get_runner_container()
    action_db = action_utils.get_action_by_ref(liveaction_db.action)
    runnertype_db = action_utils.get_runnertype_by_name(action_db.runner_type['name'])
    runner = runner_container._get_runner(runnertype_db, action_db, liveaction_db)
    runner.post_run(status=action_constants.LIVEACTION_STATUS_SUCCEEDED, result=result)

    return liveaction_db
开发者ID:nzlosh,项目名称:st2,代码行数:55,代码来源:inquiry.py


示例15: register_runner

def register_runner(runner_type, experimental):
    # For backward compatibility reasons, we also register runners under the old names
    runner_names = [runner_type['name']] + runner_type.get('aliases', [])
    for runner_name in runner_names:
        runner_type['name'] = runner_name
        runner_experimental = runner_type.get('experimental', False)

        if runner_experimental and not experimental:
            LOG.debug('Skipping experimental runner "%s"' % (runner_name))
            continue

        # Remove additional, non db-model attributes
        non_db_attributes = ['experimental', 'aliases']
        for attribute in non_db_attributes:
            if attribute in runner_type:
                del runner_type[attribute]

        try:
            runner_type_db = get_runnertype_by_name(runner_name)
            update = True
        except StackStormDBObjectNotFoundError:
            runner_type_db = None
            update = False

        # Note: We don't want to overwrite "enabled" attribute which is already in the database
        # (aka we don't want to re-enable runner which has been disabled by the user)
        if runner_type_db and runner_type_db['enabled'] != runner_type['enabled']:
            runner_type['enabled'] = runner_type_db['enabled']

        # If package is not provided, assume it's the same as module name for backward
        # compatibility reasons
        if not runner_type.get('runner_package', None):
            runner_type['runner_package'] = runner_type['runner_module']

        runner_type_api = RunnerTypeAPI(**runner_type)
        runner_type_api.validate()
        runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

        if runner_type_db:
            runner_type_model.id = runner_type_db.id

        try:

            runner_type_db = RunnerType.add_or_update(runner_type_model)

            extra = {'runner_type_db': runner_type_db}
            if update:
                LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra)
            else:
                LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra)
        except Exception:
            LOG.exception('Unable to register runner type %s.', runner_type['name'])
            return 0
    return 1
开发者ID:lyandut,项目名称:st2,代码行数:54,代码来源:runnersregistrar.py


示例16: get_runner_model

def get_runner_model(action_api):
    runner_db = None
    # Check if runner exists.
    try:
        runner_db = get_runnertype_by_name(action_api.runner_type)
    except StackStormDBObjectNotFoundError:
        msg = ('RunnerType %s is not found. If you are using old and deprecated runner name, you '
               'need to switch to a new one. For more information, please see '
               'https://docs.stackstorm.com/upgrade_notes.html#st2-v0-9' % (action_api.runner_type))
        raise ValueValidationException(msg)
    return runner_db
开发者ID:StackStorm,项目名称:st2,代码行数:11,代码来源:action.py


示例17: register_runner_types

def register_runner_types(experimental=False):
    """
    :param experimental: True to also register experimental runners.
    :type experimental: ``bool``
    """
    LOG.debug("Start : register default RunnerTypes.")

    for runner_type in RUNNER_TYPES:
        runner_type = copy.deepcopy(runner_type)

        # For backward compatibility reasons, we also register runners under the old names
        runner_names = [runner_type["name"]] + runner_type.get("aliases", [])
        for runner_name in runner_names:
            runner_type["name"] = runner_name
            runner_experimental = runner_type.get("experimental", False)

            if runner_experimental and not experimental:
                LOG.debug('Skipping experimental runner "%s"' % (runner_name))
                continue

            # Remove additional, non db-model attributes
            non_db_attributes = ["experimental", "aliases"]
            for attribute in non_db_attributes:
                if attribute in runner_type:
                    del runner_type[attribute]

            try:
                runner_type_db = get_runnertype_by_name(runner_name)
                update = True
            except StackStormDBObjectNotFoundError:
                runner_type_db = None
                update = False

            runner_type_api = RunnerTypeAPI(**runner_type)
            runner_type_api.validate()
            runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

            if runner_type_db:
                runner_type_model.id = runner_type_db.id

            try:
                runner_type_db = RunnerType.add_or_update(runner_type_model)

                extra = {"runner_type_db": runner_type_db}
                if update:
                    LOG.audit("RunnerType updated. RunnerType %s", runner_type_db, extra=extra)
                else:
                    LOG.audit("RunnerType created. RunnerType %s", runner_type_db, extra=extra)
            except Exception:
                LOG.exception("Unable to register runner type %s.", runner_type["name"])

    LOG.debug("End : register default RunnerTypes.")
开发者ID:ruslantum,项目名称:st2,代码行数:52,代码来源:runnersregistrar.py


示例18: request

def request(wf_def, ac_ex_db):
    # Load workflow definition into workflow spec model.
    spec_module = specs_loader.get_spec_module('native')
    wf_spec = spec_module.instantiate(wf_def)

    # Inspect the workflow spec.
    wf_spec.inspect(raise_exception=True)

    # Identify the action to execute.
    action_db = ac_db_util.get_action_by_ref(ref=ac_ex_db.action['ref'])

    if not action_db:
        error = 'Unable to find action "%s".' % ac_ex_db.action['ref']
        raise ac_exc.InvalidActionReferencedException(error)

    # Identify the runner for the action.
    runner_type_db = ac_db_util.get_runnertype_by_name(action_db.runner_type['name'])

    # Render action execution parameters.
    runner_params, action_params = param_utils.render_final_params(
        runner_type_db.runner_parameters,
        action_db.parameters,
        ac_ex_db.parameters,
        ac_ex_db.context
    )

    # Instantiate the workflow conductor.
    conductor = conducting.WorkflowConductor(wf_spec, **action_params)
    conductor.set_workflow_state(states.REQUESTED)

    # Serialize the conductor which initializes some internal values.
    data = conductor.serialize()

    # Create a record for workflow execution.
    wf_ex_db = wf_db_models.WorkflowExecutionDB(
        action_execution=str(ac_ex_db.id),
        spec=data['spec'],
        graph=data['graph'],
        flow=data['flow'],
        input=data['input'],
        output=data['output'],
        errors=data['errors'],
        status=data['state']
    )

    # Insert new record into the database and publish to the message bus.
    wf_ex_db = wf_db_access.WorkflowExecution.insert(wf_ex_db, publish=True)

    return wf_ex_db
开发者ID:lyandut,项目名称:st2,代码行数:49,代码来源:workflows.py


示例19: cast_params

def cast_params(action_ref, params, cast_overrides=None):
    """
    """
    params = params or {}
    action_db = action_db_util.get_action_by_ref(action_ref)

    if not action_db:
        raise ValueError('Action with ref "%s" doesn\'t exist' % (action_ref))

    action_parameters_schema = action_db.parameters
    runnertype_db = action_db_util.get_runnertype_by_name(action_db.runner_type['name'])
    runner_parameters_schema = runnertype_db.runner_parameters
    # combine into 1 list of parameter schemas
    parameters_schema = {}
    if runner_parameters_schema:
        parameters_schema.update(runner_parameters_schema)
    if action_parameters_schema:
        parameters_schema.update(action_parameters_schema)
    # cast each param individually
    for k, v in six.iteritems(params):
        parameter_schema = parameters_schema.get(k, None)
        if not parameter_schema:
            LOG.debug('Will skip cast of param[name: %s, value: %s]. No schema.', k, v)
            continue
        parameter_type = parameter_schema.get('type', None)
        if not parameter_type:
            LOG.debug('Will skip cast of param[name: %s, value: %s]. No type.', k, v)
            continue
        # Pick up cast from teh override and then from the system suppied ones.
        cast = cast_overrides.get(parameter_type, None) if cast_overrides else None
        if not cast:
            cast = get_cast(cast_type=parameter_type)
        if not cast:
            LOG.debug('Will skip cast of param[name: %s, value: %s]. No cast for %s.', k, v,
                      parameter_type)
            continue
        LOG.debug('Casting param: %s of type %s to type: %s', v, type(v), parameter_type)

        try:
            params[k] = cast(v)
        except Exception as e:
            v_type = type(v).__name__
            msg = ('Failed to cast value "%s" (type: %s) for parameter "%s" of type "%s": %s. '
                   'Perhaphs the value is of an invalid type?' %
                   (v, v_type, k, parameter_type, str(e)))
            raise ValueError(msg)

    return params
开发者ID:E-LLP,项目名称:st2,代码行数:48,代码来源:action_param_utils.py


示例20: get_parameter_schema

def get_parameter_schema(model):
    # Dynamically construct JSON schema from the parameters metadata.
    schema = {}
    from st2common.util.action_db import get_runnertype_by_name
    runner_type = get_runnertype_by_name(model.runner_type['name'])
    normalize = lambda x: {k: v if v else SCHEMA_ANY_TYPE for k, v in six.iteritems(x)}
    properties = normalize(runner_type.runner_parameters)
    properties.update(normalize(model.parameters))
    if properties:
        schema['title'] = model.name
        if model.description:
            schema['description'] = model.description
        schema['type'] = 'object'
        schema['properties'] = properties
        schema['additionalProperties'] = False
    return schema
开发者ID:bjoernbessert,项目名称:st2,代码行数:16,代码来源:__init__.py



注:本文中的st2common.util.action_db.get_runnertype_by_name函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python action_db.update_liveaction_status函数代码示例发布时间:2022-05-27
下一篇:
Python action_db.get_liveaction_by_id函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap