Add stdout and stderr execution API models.
@@ -21,11 +21,19 @@ from st2common.constants.action import LIVEACTION_STATUSES
from st2common.util import isotime
from st2common.models.api.base import BaseAPI
from st2common.models.db.execution import ActionExecutionDB
+from st2common.models.db.execution import ActionExecutionStdoutOutputDB
+from st2common.models.db.execution import ActionExecutionStderrOutputDB
from st2common.models.api.trigger import TriggerTypeAPI, TriggerAPI, TriggerInstanceAPI
from st2common.models.api.rule import RuleAPI
from st2common.models.api.action import RunnerTypeAPI, ActionAPI, LiveActionAPI
from st2common import log as logging
+__all__ = [
+ 'ActionExecutionAPI',
+ 'ActionExecutionStdoutAPI',
+ 'ActionExecutionStderrAPI'
+]
+
LOG = logging.getLogger(__name__)
@@ -181,3 +189,71 @@ class ActionExecutionAPI(BaseAPI):
model = cls.model(**values)
return model
+
+
+class ActionExecutionStdoutAPI(BaseAPI):
+ model = ActionExecutionStdoutOutputDB
+ schema = {
+ 'type': 'object',
+ 'properties': {
+ 'id': {
+ 'type': 'string'
+ },
+ 'exection_id': {
+ 'type': 'string'
+ },
+ 'timestamp': {
+ 'type': 'string',
+ 'pattern': isotime.ISO8601_UTC_REGEX
+ },
+ 'action_ref': {
+ 'type': 'string'
+ },
+ 'line': {
+ 'type': 'string'
+ }
+ },
+ 'additionalProperties': False
+ }
+
+ @classmethod
+ def from_model(cls, model, mask_secrets=True):
+ doc = cls._from_model(model, mask_secrets=mask_secrets)
+ doc['timestamp'] = isotime.format(model.timestamp, offset=False)
+
+ attrs = {attr: value for attr, value in six.iteritems(doc) if value is not None}
+ return cls(**attrs)
+
+
+class ActionExecutionStderrAPI(BaseAPI):
+ model = ActionExecutionStderrOutputDB
+ schema = {
+ 'type': 'object',
+ 'properties': {
+ 'id': {
+ 'type': 'string'
+ },
+ 'exection_id': {
+ 'type': 'string'
+ },
+ 'timestamp': {
+ 'type': 'string',
+ 'pattern': isotime.ISO8601_UTC_REGEX
+ },
+ 'action_ref': {
+ 'type': 'string'
+ },
+ 'line': {
+ 'type': 'string'
+ }
+ },
+ 'additionalProperties': False
+ }
+
+ @classmethod
+ def from_model(cls, model, mask_secrets=True):
+ doc = cls._from_model(model, mask_secrets=mask_secrets)
+ doc['timestamp'] = isotime.format(model.timestamp, offset=False)
+
+ attrs = {attr: value for attr, value in six.iteritems(doc) if value is not None}
+ return cls(**attrs)
