本文整理汇总了Python中st2common.models.api.execution.ActionExecutionAPI类的典型用法代码示例。如果您正苦于以下问题:Python ActionExecutionAPI类的具体用法?Python ActionExecutionAPI怎么用?Python ActionExecutionAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActionExecutionAPI类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _schedule_execution
def _schedule_execution(self, action_alias_db, params, notify, context):
action_ref = action_alias_db.action_ref
action_db = action_utils.get_action_by_ref(action_ref)
if not action_db:
raise StackStormDBObjectNotFoundError('Action with ref "%s" not found ' % (action_ref))
assert_request_user_has_resource_db_permission(request=pecan.request, resource_db=action_db,
permission_type=PermissionType.ACTION_EXECUTE)
try:
# prior to shipping off the params cast them to the right type.
params = action_param_utils.cast_params(action_ref=action_alias_db.action_ref,
params=params,
cast_overrides=CAST_OVERRIDES)
if not context:
context = {
'action_alias_ref': reference.get_ref_from_model(action_alias_db),
'user': get_system_username()
}
liveaction = LiveActionDB(action=action_alias_db.action_ref, context=context,
parameters=params, notify=notify)
_, action_execution_db = action_service.request(liveaction)
return ActionExecutionAPI.from_model(action_execution_db)
except ValueError as e:
LOG.exception('Unable to execute action.')
pecan.abort(http_client.BAD_REQUEST, str(e))
except jsonschema.ValidationError as e:
LOG.exception('Unable to execute action. Parameter validation failed.')
pecan.abort(http_client.BAD_REQUEST, str(e))
except Exception as e:
LOG.exception('Unable to execute action. Unexpected error encountered.')
pecan.abort(http_client.INTERNAL_SERVER_ERROR, str(e))
开发者ID:automotola,项目名称:st2,代码行数:33,代码来源:aliasexecution.py
示例2: test_crud_complete
def test_crud_complete(self):
# Create the DB record.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_workflow))
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
model = ActionExecution.get_by_id(obj.id)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(model.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(model.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(model.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(model.action, self.fake_history_workflow['action'])
self.assertDictEqual(model.runner, self.fake_history_workflow['runner'])
doc = copy.deepcopy(self.fake_history_workflow['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertIsNone(getattr(model, 'parent', None))
self.assertListEqual(model.children, self.fake_history_workflow['children'])
# Update the DB record.
children = [str(bson.ObjectId()), str(bson.ObjectId())]
model.children = children
ActionExecution.add_or_update(model)
model = ActionExecution.get_by_id(obj.id)
self.assertListEqual(model.children, children)
# Delete the DB record.
ActionExecution.delete(model)
self.assertRaises(ValueError, ActionExecution.get_by_id, obj.id)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:29,代码来源:test_executions.py
示例3: _schedule_execution
def _schedule_execution(self, liveaction):
# Initialize execution context if it does not exist.
if not hasattr(liveaction, "context"):
liveaction.context = dict()
# Retrieve username of the authed user (note - if auth is disabled, user will not be
# set so we fall back to the system user name)
request_token = pecan.request.context.get("token", None)
if request_token:
user = request_token.user
else:
user = cfg.CONF.system_user.user
liveaction.context["user"] = user
LOG.debug("User is: %s" % 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.
liveactiondb = LiveActionAPI.to_model(liveaction)
_, actionexecutiondb = action_service.request(liveactiondb)
from_model_kwargs = self._get_from_model_kwargs_for_request(request=pecan.request)
return ActionExecutionAPI.from_model(actionexecutiondb, from_model_kwargs)
开发者ID:jonico,项目名称:st2,代码行数:29,代码来源:actionexecutions.py
示例4: test_crud_partial
def test_crud_partial(self):
# Create the DB record.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_subtasks[0]))
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
model = ActionExecution.get_by_id(obj.id)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, {})
self.assertDictEqual(model.trigger_type, {})
self.assertDictEqual(model.trigger_instance, {})
self.assertDictEqual(model.rule, {})
self.assertDictEqual(model.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(model.runner, self.fake_history_subtasks[0]['runner'])
doc = copy.deepcopy(self.fake_history_subtasks[0]['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertEqual(model.parent, self.fake_history_subtasks[0]['parent'])
self.assertListEqual(model.children, [])
# Update the DB record.
children = [str(bson.ObjectId()), str(bson.ObjectId())]
model.children = children
ActionExecution.add_or_update(model)
model = ActionExecution.get_by_id(obj.id)
self.assertListEqual(model.children, children)
# Delete the DB record.
ActionExecution.delete(model)
self.assertRaises(StackStormDBObjectNotFoundError, ActionExecution.get_by_id, obj.id)
开发者ID:lyandut,项目名称:st2,代码行数:29,代码来源:test_executions.py
示例5: process
def process(self, execution):
LOG.debug('Got execution from queue: %s', execution)
if execution.status not in COMPLETION_STATUSES:
return
execution_api = ActionExecutionAPI.from_model(execution, mask_secrets=True)
self.pending_executions.put_nowait(execution_api)
LOG.debug("Added execution to queue.")
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:7,代码来源:worker.py
示例6: _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
示例7: _schedule_execution
def _schedule_execution(self, execution):
# Initialize execution context if it does not exist.
if not hasattr(execution, 'context'):
execution.context = dict()
# Retrieve username of the authed user (note - if auth is disabled, user will not be
# set so we fall back to the system user name)
request_token = pecan.request.context.get('token', None)
if request_token:
user = request_token.user
else:
user = cfg.CONF.system_user.user
execution.context['user'] = 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.')
execution.context.update(context)
# Schedule the action execution.
liveactiondb = LiveActionAPI.to_model(execution)
_, actionexecutiondb = action_service.request(liveactiondb)
return ActionExecutionAPI.from_model(actionexecutiondb)
开发者ID:SamMarkowitz,项目名称:st2,代码行数:27,代码来源:actionexecutions.py
示例8: test_model_partial
def test_model_partial(self):
# Create API object.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_subtasks[0]))
self.assertIsNone(getattr(obj, 'trigger', None))
self.assertIsNone(getattr(obj, 'trigger_type', None))
self.assertIsNone(getattr(obj, 'trigger_instance', None))
self.assertIsNone(getattr(obj, 'rule', None))
self.assertDictEqual(obj.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(obj.runner, self.fake_history_subtasks[0]['runner'])
self.assertDictEqual(obj.liveaction, self.fake_history_subtasks[0]['liveaction'])
self.assertEqual(obj.parent, self.fake_history_subtasks[0]['parent'])
self.assertIsNone(getattr(obj, 'children', None))
# Convert API object to DB model.
model = ActionExecutionAPI.to_model(obj)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, {})
self.assertDictEqual(model.trigger_type, {})
self.assertDictEqual(model.trigger_instance, {})
self.assertDictEqual(model.rule, {})
self.assertDictEqual(model.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(model.runner, self.fake_history_subtasks[0]['runner'])
doc = copy.deepcopy(self.fake_history_subtasks[0]['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertEqual(model.parent, self.fake_history_subtasks[0]['parent'])
self.assertListEqual(model.children, [])
# Convert DB model to API object.
obj = ActionExecutionAPI.from_model(model)
self.assertEqual(str(model.id), obj.id)
self.assertIsNone(getattr(obj, 'trigger', None))
self.assertIsNone(getattr(obj, 'trigger_type', None))
self.assertIsNone(getattr(obj, 'trigger_instance', None))
self.assertIsNone(getattr(obj, 'rule', None))
self.assertDictEqual(obj.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(obj.runner, self.fake_history_subtasks[0]['runner'])
self.assertDictEqual(obj.liveaction, self.fake_history_subtasks[0]['liveaction'])
self.assertEqual(obj.parent, self.fake_history_subtasks[0]['parent'])
self.assertIsNone(getattr(obj, 'children', None))
开发者ID:lyandut,项目名称:st2,代码行数:42,代码来源:test_executions.py
示例9: test_model_complete
def test_model_complete(self):
# Create API object.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_workflow))
self.assertDictEqual(obj.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(obj.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(obj.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
self.assertEquals(obj.liveaction, self.fake_history_workflow['liveaction'])
self.assertIsNone(getattr(obj, 'parent', None))
self.assertListEqual(obj.children, self.fake_history_workflow['children'])
# Convert API object to DB model.
model = ActionExecutionAPI.to_model(obj)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(model.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(model.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(model.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(model.action, self.fake_history_workflow['action'])
self.assertDictEqual(model.runner, self.fake_history_workflow['runner'])
doc = copy.deepcopy(self.fake_history_workflow['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertIsNone(getattr(model, 'parent', None))
self.assertListEqual(model.children, self.fake_history_workflow['children'])
# Convert DB model to API object.
obj = ActionExecutionAPI.from_model(model)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(obj.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(obj.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(obj.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
self.assertDictEqual(obj.liveaction, self.fake_history_workflow['liveaction'])
self.assertIsNone(getattr(obj, 'parent', None))
self.assertListEqual(obj.children, self.fake_history_workflow['children'])
开发者ID:lyandut,项目名称:st2,代码行数:42,代码来源:test_executions.py
示例10: test_get_one
def test_get_one(self):
obj_id = random.choice(list(self.refs.keys()))
response = self.app.get('/v1/executions/%s' % obj_id)
self.assertEqual(response.status_int, 200)
self.assertIsInstance(response.json, dict)
record = response.json
fake_record = ActionExecutionAPI.from_model(self.refs[obj_id])
self.assertEqual(record['id'], obj_id)
self.assertDictEqual(record['action'], fake_record.action)
self.assertDictEqual(record['runner'], fake_record.runner)
self.assertDictEqual(record['liveaction'], fake_record.liveaction)
开发者ID:StackStorm,项目名称:st2,代码行数:11,代码来源:test_executions_filters.py
示例11: setUpClass
def setUpClass(cls):
super(TestActionExecutionFilters, cls).setUpClass()
cls.dt_base = date_utils.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
cls.num_records = 100
cls.refs = {}
cls.start_timestamps = []
cls.fake_types = [
{
'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance']),
'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
'action': copy.deepcopy(fixture.ARTIFACTS['actions']['chain']),
'runner': copy.deepcopy(fixture.ARTIFACTS['runners']['action-chain']),
'liveaction': copy.deepcopy(fixture.ARTIFACTS['liveactions']['workflow']),
'context': copy.deepcopy(fixture.ARTIFACTS['context']),
'children': []
},
{
'action': copy.deepcopy(fixture.ARTIFACTS['actions']['local']),
'runner': copy.deepcopy(fixture.ARTIFACTS['runners']['run-local']),
'liveaction': copy.deepcopy(fixture.ARTIFACTS['liveactions']['task1'])
}
]
def assign_parent(child):
candidates = [v for k, v in cls.refs.items() if v.action['name'] == 'chain']
if candidates:
parent = random.choice(candidates)
child['parent'] = str(parent.id)
parent.children.append(child['id'])
cls.refs[str(parent.id)] = ActionExecution.add_or_update(parent)
for i in range(cls.num_records):
obj_id = str(bson.ObjectId())
timestamp = cls.dt_base + datetime.timedelta(seconds=i)
fake_type = random.choice(cls.fake_types)
data = copy.deepcopy(fake_type)
data['id'] = obj_id
data['start_timestamp'] = isotime.format(timestamp, offset=False)
data['end_timestamp'] = isotime.format(timestamp, offset=False)
data['status'] = data['liveaction']['status']
data['result'] = data['liveaction']['result']
if fake_type['action']['name'] == 'local' and random.choice([True, False]):
assign_parent(data)
wb_obj = ActionExecutionAPI(**data)
db_obj = ActionExecutionAPI.to_model(wb_obj)
cls.refs[obj_id] = ActionExecution.add_or_update(db_obj)
cls.start_timestamps.append(timestamp)
cls.start_timestamps = sorted(cls.start_timestamps)
开发者ID:StackStorm,项目名称:st2,代码行数:53,代码来源:test_executions_filters.py
示例12: setUpClass
def setUpClass(cls):
super(TestActionExecutionFilters, cls).setUpClass()
cls.dt_base = date_utils.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
cls.num_records = 100
cls.refs = {}
cls.start_timestamps = []
cls.fake_types = [
{
"trigger": copy.deepcopy(fixture.ARTIFACTS["trigger"]),
"trigger_type": copy.deepcopy(fixture.ARTIFACTS["trigger_type"]),
"trigger_instance": copy.deepcopy(fixture.ARTIFACTS["trigger_instance"]),
"rule": copy.deepcopy(fixture.ARTIFACTS["rule"]),
"action": copy.deepcopy(fixture.ARTIFACTS["actions"]["chain"]),
"runner": copy.deepcopy(fixture.ARTIFACTS["runners"]["action-chain"]),
"liveaction": copy.deepcopy(fixture.ARTIFACTS["liveactions"]["workflow"]),
"context": copy.deepcopy(fixture.ARTIFACTS["context"]),
"children": [],
},
{
"action": copy.deepcopy(fixture.ARTIFACTS["actions"]["local"]),
"runner": copy.deepcopy(fixture.ARTIFACTS["runners"]["run-local"]),
"liveaction": copy.deepcopy(fixture.ARTIFACTS["liveactions"]["task1"]),
},
]
def assign_parent(child):
candidates = [v for k, v in cls.refs.iteritems() if v.action["name"] == "chain"]
if candidates:
parent = random.choice(candidates)
child["parent"] = str(parent.id)
parent.children.append(child["id"])
cls.refs[str(parent.id)] = ActionExecution.add_or_update(parent)
for i in range(cls.num_records):
obj_id = str(bson.ObjectId())
timestamp = cls.dt_base + datetime.timedelta(seconds=i)
fake_type = random.choice(cls.fake_types)
data = copy.deepcopy(fake_type)
data["id"] = obj_id
data["start_timestamp"] = isotime.format(timestamp, offset=False)
data["end_timestamp"] = isotime.format(timestamp, offset=False)
data["status"] = data["liveaction"]["status"]
data["result"] = data["liveaction"]["result"]
if fake_type["action"]["name"] == "local" and random.choice([True, False]):
assign_parent(data)
wb_obj = ActionExecutionAPI(**data)
db_obj = ActionExecutionAPI.to_model(wb_obj)
cls.refs[obj_id] = ActionExecution.add_or_update(db_obj)
cls.start_timestamps.append(timestamp)
cls.start_timestamps = sorted(cls.start_timestamps)
开发者ID:costingalan,项目名称:st2,代码行数:53,代码来源:test_executions_filters.py
示例13: delete
def delete(self, id, requester_user, show_secrets=False):
"""
Stops a single execution.
Handles requests:
DELETE /executions/<id>
"""
if not requester_user:
requester_user = UserDB(cfg.CONF.system_user.user)
from_model_kwargs = {
'mask_secrets': self._get_mask_secrets(requester_user, show_secrets=show_secrets)
}
execution_api = self._get_one_by_id(id=id, requester_user=requester_user,
from_model_kwargs=from_model_kwargs,
permission_type=PermissionType.EXECUTION_STOP)
if not execution_api:
abort(http_client.NOT_FOUND, 'Execution with id %s not found.' % id)
liveaction_id = execution_api.liveaction['id']
if not liveaction_id:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
try:
liveaction_db = LiveAction.get_by_id(liveaction_id)
except:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
if liveaction_db.status == action_constants.LIVEACTION_STATUS_CANCELED:
LOG.info(
'Action %s already in "canceled" state; \
returning execution object.' % liveaction_db.id
)
return execution_api
if liveaction_db.status not in action_constants.LIVEACTION_CANCELABLE_STATES:
abort(http_client.OK, 'Action cannot be canceled. State = %s.' % liveaction_db.status)
try:
(liveaction_db, execution_db) = action_service.request_cancellation(
liveaction_db, requester_user.name or cfg.CONF.system_user.user)
except:
LOG.exception('Failed requesting cancellation for liveaction %s.', liveaction_db.id)
abort(http_client.INTERNAL_SERVER_ERROR, 'Failed canceling execution.')
return ActionExecutionAPI.from_model(execution_db,
mask_secrets=from_model_kwargs['mask_secrets'])
开发者ID:nzlosh,项目名称:st2,代码行数:51,代码来源:actionexecutions.py
示例14: delete
def delete(self, exec_id):
"""
Stops a single execution.
Handles requests:
DELETE /actionexecutions/<id>
"""
execution_api = self._get_one(id=exec_id)
if not execution_api:
abort(http_client.NOT_FOUND, 'Execution with id %s not found.' % exec_id)
return
liveaction_id = execution_api.liveaction['id']
if not liveaction_id:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
try:
liveaction_db = LiveAction.get_by_id(liveaction_id)
except:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
return
if liveaction_db.status == LIVEACTION_STATUS_CANCELED:
abort(http_client.OK,
'Action is already in "canceled" state.')
if liveaction_db.status not in CANCELABLE_STATES:
abort(http_client.OK,
'Action cannot be canceled. State = %s.' % liveaction_db.status)
return
liveaction_db.status = 'canceled'
liveaction_db.end_timestamp = date_utils.get_datetime_utc_now()
liveaction_db.result = {'message': 'Action canceled by user.'}
try:
LiveAction.add_or_update(liveaction_db)
except:
LOG.exception('Failed updating status to canceled for liveaction %s.',
liveaction_db.id)
abort(http_client.INTERNAL_SERVER_ERROR, 'Failed canceling execution.')
return
execution_db = execution_service.update_execution(liveaction_db)
from_model_kwargs = self._get_from_model_kwargs_for_request(request=pecan.request)
return ActionExecutionAPI.from_model(execution_db, from_model_kwargs)
开发者ID:ipv1337,项目名称:st2,代码行数:49,代码来源:actionexecutions.py
示例15: test_datetime_range
def test_datetime_range(self):
base = date_utils.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
for i in range(60):
timestamp = base + datetime.timedelta(seconds=i)
doc = copy.deepcopy(self.fake_history_subtasks[0])
doc['id'] = str(bson.ObjectId())
doc['start_timestamp'] = isotime.format(timestamp)
obj = ActionExecutionAPI(**doc)
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
dt_range = '2014-12-25T00:00:10Z..2014-12-25T00:00:19Z'
objs = ActionExecution.query(start_timestamp=dt_range)
self.assertEqual(len(objs), 10)
dt_range = '2014-12-25T00:00:19Z..2014-12-25T00:00:10Z'
objs = ActionExecution.query(start_timestamp=dt_range)
self.assertEqual(len(objs), 10)
开发者ID:lyandut,项目名称:st2,代码行数:17,代码来源:test_executions.py
示例16: _bootstrap
def _bootstrap(self):
marker = self._get_export_marker_from_db()
LOG.info('Using marker %s...' % marker)
missed_executions = self._get_missed_executions_from_db(export_marker=marker)
LOG.info('Found %d executions not exported yet...', len(missed_executions))
for missed_execution in missed_executions:
if missed_execution.status not in COMPLETION_STATUSES:
continue
execution_api = ActionExecutionAPI.from_model(missed_execution, mask_secrets=True)
try:
LOG.debug('Missed execution %s', execution_api)
self.pending_executions.put_nowait(execution_api)
except:
LOG.exception('Failed adding execution to in-memory queue.')
continue
LOG.info('Bootstrapped executions...')
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:17,代码来源:worker.py
示例17: delete
def delete(self, exec_id):
"""
Stops a single execution.
Handles requests:
DELETE /executions/<id>
"""
execution_api = self._get_one(id=exec_id)
if not execution_api:
abort(http_client.NOT_FOUND, 'Execution with id %s not found.' % exec_id)
liveaction_id = execution_api.liveaction['id']
if not liveaction_id:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
try:
liveaction_db = LiveAction.get_by_id(liveaction_id)
except:
abort(http_client.INTERNAL_SERVER_ERROR,
'Execution object missing link to liveaction %s.' % liveaction_id)
if liveaction_db.status == LIVEACTION_STATUS_CANCELED:
LOG.info(
'Action %s already in "canceled" state; \
returning execution object.' % liveaction_db.id
)
return execution_api
if liveaction_db.status not in LIVEACTION_CANCELABLE_STATES:
abort(http_client.OK, 'Action cannot be canceled. State = %s.' % liveaction_db.status)
try:
(liveaction_db, execution_db) = action_service.request_cancellation(
liveaction_db, get_requester())
except:
LOG.exception('Failed requesting cancellation for liveaction %s.', liveaction_db.id)
abort(http_client.INTERNAL_SERVER_ERROR, 'Failed canceling execution.')
from_model_kwargs = self._get_from_model_kwargs_for_request(request=pecan.request)
return ActionExecutionAPI.from_model(execution_db, from_model_kwargs)
开发者ID:Pulsant,项目名称:st2,代码行数:44,代码来源:actionexecutions.py
示例18: _schedule_execution
def _schedule_execution(self, liveaction, user=None):
# Initialize execution context if it does not exist.
if not hasattr(liveaction, 'context'):
liveaction.context = dict()
liveaction.context['user'] = user
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:
# By this point the execution is already in the DB therefore need to mark it failed.
_, e, tb = sys.exc_info()
action_service.update_status(
liveaction=liveaction_db,
new_status=LIVEACTION_STATUS_FAILED,
result={'error': str(e), 'traceback': ''.join(traceback.format_tb(tb, 20))})
# Might be a good idea to return the actual ActionExecution rather than bubble up
# the execption.
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:Bala96,项目名称:st2,代码行数:42,代码来源:actionexecutions.py
示例19: _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'] = self._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.
liveactiondb = LiveActionAPI.to_model(liveaction)
_, actionexecutiondb = action_service.request(liveactiondb)
from_model_kwargs = self._get_from_model_kwargs_for_request(request=pecan.request)
return ActionExecutionAPI.from_model(actionexecutiondb, from_model_kwargs)
开发者ID:langelee,项目名称:st2,代码行数:20,代码来源:actionexecutions.py
示例20: test_sort_by_start_timestamp
def test_sort_by_start_timestamp(self):
base = isotime.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
for i in range(60):
timestamp = base + datetime.timedelta(seconds=i)
doc = copy.deepcopy(self.fake_history_subtasks[0])
doc['id'] = str(bson.ObjectId())
doc['start_timestamp'] = isotime.format(timestamp)
obj = ActionExecutionAPI(**doc)
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
dt_range = '2014-12-25T00:00:10Z..2014-12-25T00:00:19Z'
objs = ActionExecution.query(start_timestamp=dt_range,
order_by=['start_timestamp'])
self.assertLess(objs[0]['start_timestamp'],
objs[9]['start_timestamp'])
dt_range = '2014-12-25T00:00:19Z..2014-12-25T00:00:10Z'
objs = ActionExecution.query(start_timestamp=dt_range,
order_by=['-start_timestamp'])
self.assertLess(objs[9]['start_timestamp'],
objs[0]['start_timestamp'])
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:21,代码来源:test_executions.py
注:本文中的st2common.models.api.execution.ActionExecutionAPI类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论