本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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)
示例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
示例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)
示例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)
示例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
示例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)
示例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.')
示例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
示例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
示例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.')
示例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
示例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
示例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