diff --git a/mistral/db/v2/sqlalchemy/models.py b/mistral/db/v2/sqlalchemy/models.py index 45aa2265..afa0d752 100644 --- a/mistral/db/v2/sqlalchemy/models.py +++ b/mistral/db/v2/sqlalchemy/models.py @@ -36,6 +36,8 @@ class Workbook(mb.MistralModelBase): definition = sa.Column(sa.Text(), nullable=True) spec = sa.Column(st.JsonDictType()) tags = sa.Column(st.JsonListType()) + + # Security properties. scope = sa.Column(sa.String(80)) project_id = sa.Column(sa.String(80)) trust_id = sa.Column(sa.String(80)) @@ -55,6 +57,8 @@ class Workflow(mb.MistralModelBase): definition = sa.Column(sa.Text(), nullable=True) spec = sa.Column(st.JsonDictType()) tags = sa.Column(st.JsonListType()) + + # Security properties. scope = sa.Column(sa.String(80)) project_id = sa.Column(sa.String(80)) trust_id = sa.Column(sa.String(80)) @@ -145,7 +149,16 @@ class Action(mb.MistralModelBase): name = sa.Column(sa.String(200)) description = sa.Column(sa.Text()) + # Ad-hoc action properties. + definition = sa.Column(sa.Text(), nullable=True) + spec = sa.Column(st.JsonDictType()) + # Service properties. action_class = sa.Column(sa.String(200)) attributes = sa.Column(st.JsonDictType()) is_system = sa.Column(sa.Boolean()) + + # Security properties. + scope = sa.Column(sa.String(80)) + project_id = sa.Column(sa.String(80)) + trust_id = sa.Column(sa.String(80)) diff --git a/mistral/services/workbooks.py b/mistral/services/workbooks.py index 94d2c427..9c960f88 100644 --- a/mistral/services/workbooks.py +++ b/mistral/services/workbooks.py @@ -74,8 +74,19 @@ def _check_workbook_definition_update(wb_db, values): def _create_or_update_actions(wb_db, actions_spec): if actions_spec: - # TODO(rakhmerov): Complete when action DB model is added. - pass + for action_spec in actions_spec: + action_name = '%s.%s' % (wb_db.name, action_spec.get_name()) + + values = { + 'name': action_name, + 'spec': action_spec.to_dict(), + 'is_system': False, + 'scope': wb_db.scope, + 'trust_id': wb_db.trust_id, + 'project_id': wb_db.project_id + } + + db_api_v2.create_or_update_action(action_name, values) def _create_or_update_workflows(wb_db, workflows_spec): diff --git a/mistral/tests/unit/services/test_workbook_service.py b/mistral/tests/unit/services/test_workbook_service.py index 2f636c51..392b067c 100644 --- a/mistral/tests/unit/services/test_workbook_service.py +++ b/mistral/tests/unit/services/test_workbook_service.py @@ -31,6 +31,12 @@ WORKBOOK = """ --- Version: '2.0' +Actions: + concat: + base: std.echo + base-parameters: + output: "{$.str1}{$.str2}" + Workflows: wf1: type: reverse @@ -62,6 +68,12 @@ UPDATED_WORKBOOK = """ --- Version: '2.0' +Actions: + concat: + base: std.echo + base-parameters: + output: "{$.str1}{$.str2}" + Workflows: wf1: type: direct @@ -104,6 +116,20 @@ class WorkbookServiceTest(base.EngineTestCase): self.assertIsNotNone(wb_db.spec) self.assertListEqual(['test'], wb_db.tags) + db_actions = db_api.get_actions(name='my_wb.concat') + + self.assertEqual(1, len(db_actions)) + + # Action. + action_db = self._assert_single_item(db_actions, name='my_wb.concat') + + self.assertFalse(action_db.is_system) + + action_spec = spec_parser.get_action_spec(action_db.spec) + + self.assertEqual('concat', action_spec.get_name()) + self.assertEqual('std.echo', action_spec.get_base()) + db_wfs = db_api.get_workflows() self.assertEqual(2, len(db_wfs))