1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
from __future__ import absolute_import |
17
|
|
|
|
18
|
|
|
import mongoengine as me |
19
|
|
|
|
20
|
|
|
from st2common.constants import types |
21
|
|
|
from st2common import fields as db_field_types |
22
|
|
|
from st2common import log as logging |
23
|
|
|
from st2common.models.db import stormbase |
24
|
|
|
from st2common.util import date as date_utils |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
__all__ = [ |
28
|
|
|
'WorkflowExecutionDB', |
29
|
|
|
'TaskExecutionDB' |
30
|
|
|
] |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
LOG = logging.getLogger(__name__) |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
class WorkflowExecutionDB(stormbase.StormFoundationDB, stormbase.ChangeRevisionFieldMixin): |
37
|
|
|
RESOURCE_TYPE = types.ResourceType.EXECUTION |
38
|
|
|
|
39
|
|
|
action_execution = me.StringField(required=True) |
40
|
|
|
spec = stormbase.EscapedDictField() |
41
|
|
|
graph = stormbase.EscapedDictField() |
42
|
|
|
flow = stormbase.EscapedDictField() |
43
|
|
|
input = stormbase.EscapedDictField() |
44
|
|
|
output = stormbase.EscapedDictField() |
45
|
|
|
status = me.StringField(required=True) |
46
|
|
|
errors = stormbase.EscapedDynamicField() |
47
|
|
|
start_timestamp = db_field_types.ComplexDateTimeField(default=date_utils.get_datetime_utc_now) |
48
|
|
|
end_timestamp = db_field_types.ComplexDateTimeField() |
49
|
|
|
|
50
|
|
|
meta = { |
51
|
|
|
'indexes': [ |
52
|
|
|
{'fields': ['action_execution']} |
53
|
|
|
] |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
class TaskExecutionDB(stormbase.StormFoundationDB, stormbase.ChangeRevisionFieldMixin): |
58
|
|
|
RESOURCE_TYPE = types.ResourceType.EXECUTION |
59
|
|
|
|
60
|
|
|
workflow_execution = me.StringField(required=True) |
61
|
|
|
task_name = me.StringField(required=True) |
62
|
|
|
task_id = me.StringField(required=True) |
63
|
|
|
task_spec = stormbase.EscapedDictField() |
64
|
|
|
status = me.StringField(required=True) |
65
|
|
|
start_timestamp = db_field_types.ComplexDateTimeField(default=date_utils.get_datetime_utc_now) |
66
|
|
|
end_timestamp = db_field_types.ComplexDateTimeField() |
67
|
|
|
initial_context = stormbase.EscapedDictField() |
68
|
|
|
result = stormbase.EscapedDictField() |
69
|
|
|
|
70
|
|
|
meta = { |
71
|
|
|
'indexes': [ |
72
|
|
|
{'fields': ['workflow_execution']}, |
73
|
|
|
{'fields': ['workflow_execution', 'task_id']} |
74
|
|
|
] |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
MODELS = [ |
79
|
|
|
WorkflowExecutionDB, |
80
|
|
|
TaskExecutionDB |
81
|
|
|
] |
82
|
|
|
|