def test_adhoc_action_definition_with_namespace(self):
        namespace1 = 'ad-hoc_test'
        namespace2 = 'ad-hoc_test2'

        wb_text = """---

        version: '2.0'

        name: my_wb1

        actions:
          test_env:
            base: std.echo
            base-input:
              output: '{{ env().foo }}' # TODO(rakhmerov): It won't work.

        workflows:
          wf:
            input:
              - str1
            output:
                workflow_result: '{{ _.printenv_result }}'

            tasks:
              printenv:
                action: test_env
                publish:
                  printenv_result: '{{ task().result }}'
        """

        wb_service.create_workbook_v2(wb_text, namespace=namespace1)
        wb_service.create_workbook_v2(wb_text, namespace=namespace2)

        with db_api.transaction():
            action_defs = db_api.get_action_definitions(
                name='my_wb1.test_env'
            )

            self.assertEqual(2, len(action_defs))

            action_defs = db_api.get_action_definitions(
                name='my_wb1.test_env',
                namespace=namespace1
            )

            self.assertEqual(1, len(action_defs))

            action_defs = db_api.get_action_definitions(
                name='my_wb1.test_env',
                namespace=namespace2
            )

            self.assertEqual(1, len(action_defs))

            self.assertRaises(
                exc.DBEntityNotFoundError,
                db_api.get_action_definition,
                name='my_wb1.test_env'
            )
Beispiel #2
0
 def find_all(self,
              namespace=None,
              limit=None,
              sort_fields=None,
              sort_dirs=None,
              **filters):
     # TODO(rakhmerov): Apply sort_keys, sort_dirs and filters.
     return [
         AdHocActionDescriptor(a_d)
         for a_d in db_api.get_action_definitions()
     ]
    def test_delete_workbook(self):
        namespace = 'pqr'

        # Create workbook.
        wb_service.create_workbook_v2(WORKBOOK, namespace=namespace)

        db_wfs = db_api.get_workflow_definitions()
        db_actions = db_api.get_action_definitions(name='my_wb.concat')

        self.assertEqual(2, len(db_wfs))
        self.assertEqual(1, len(db_actions))

        db_api.delete_workbook('my_wb', namespace=namespace)

        db_wfs = db_api.get_workflow_definitions()
        db_actions = db_api.get_action_definitions(name='my_wb.concat')

        # Deleting workbook shouldn't delete workflows and actions
        self.assertEqual(2, len(db_wfs))
        self.assertEqual(1, len(db_actions))
    def test_delete_workbook(self):
        namespace = 'pqr'

        # Create workbook.
        wb_service.create_workbook_v2(WORKBOOK, namespace=namespace)

        db_wfs = db_api.get_workflow_definitions()
        db_actions = db_api.get_action_definitions(name='my_wb.concat')

        self.assertEqual(2, len(db_wfs))
        self.assertEqual(1, len(db_actions))

        db_api.delete_workbook('my_wb', namespace=namespace)

        db_wfs = db_api.get_workflow_definitions()
        db_actions = db_api.get_action_definitions(name='my_wb.concat')

        # Deleting workbook shouldn't delete workflows and actions
        self.assertEqual(2, len(db_wfs))
        self.assertEqual(1, len(db_actions))
Beispiel #5
0
    def get_all(self):
        """Return all actions.

        Where project_id is the same as the requester or
        project_id is different but the scope is public.
        """
        LOG.info("Fetch actions.")

        action_list = [Action.from_dict(db_model.to_dict())
                       for db_model in db_api.get_action_definitions()]

        return Actions(actions=action_list)
Beispiel #6
0
    def test_create_workbook(self):
        namespace = 'test_workbook_service_0123_namespace'

        wb_db = wb_service.create_workbook_v2(WORKBOOK, namespace=namespace)

        self.assertIsNotNone(wb_db)
        self.assertEqual('my_wb', wb_db.name)
        self.assertEqual(namespace, wb_db.namespace)
        self.assertEqual(WORKBOOK, wb_db.definition)
        self.assertIsNotNone(wb_db.spec)
        self.assertListEqual(['test'], wb_db.tags)

        db_actions = db_api.get_action_definitions(name='my_wb.concat',
                                                   namespace=namespace)

        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())
        self.assertEqual(ACTION_DEFINITION, action_db.definition)

        db_wfs = db_api.get_workflow_definitions()

        self.assertEqual(2, len(db_wfs))

        # Workflow 1.
        wf1_db = self._assert_single_item(db_wfs, name='my_wb.wf1')
        wf1_spec = spec_parser.get_workflow_spec(wf1_db.spec)

        self.assertEqual('wf1', wf1_spec.get_name())
        self.assertEqual('reverse', wf1_spec.get_type())
        self.assertListEqual(['wf_test'], wf1_spec.get_tags())
        self.assertListEqual(['wf_test'], wf1_db.tags)
        self.assertEqual(namespace, wf1_db.namespace)
        self.assertEqual(WORKBOOK_WF1_DEFINITION, wf1_db.definition)

        # Workflow 2.
        wf2_db = self._assert_single_item(db_wfs, name='my_wb.wf2')
        wf2_spec = spec_parser.get_workflow_spec(wf2_db.spec)

        self.assertEqual('wf2', wf2_spec.get_name())
        self.assertEqual('direct', wf2_spec.get_type())
        self.assertEqual(namespace, wf2_db.namespace)
        self.assertEqual(WORKBOOK_WF2_DEFINITION, wf2_db.definition)
    def test_create_workbook(self):
        namespace = 'test_workbook_service_0123_namespace'

        wb_db = wb_service.create_workbook_v2(WORKBOOK, namespace=namespace)

        self.assertIsNotNone(wb_db)
        self.assertEqual('my_wb', wb_db.name)
        self.assertEqual(namespace, wb_db.namespace)
        self.assertEqual(WORKBOOK, wb_db.definition)
        self.assertIsNotNone(wb_db.spec)
        self.assertListEqual(['test'], wb_db.tags)

        db_actions = db_api.get_action_definitions(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())
        self.assertEqual(ACTION_DEFINITION, action_db.definition)

        db_wfs = db_api.get_workflow_definitions()

        self.assertEqual(2, len(db_wfs))

        # Workflow 1.
        wf1_db = self._assert_single_item(db_wfs, name='my_wb.wf1')
        wf1_spec = spec_parser.get_workflow_spec(wf1_db.spec)

        self.assertEqual('wf1', wf1_spec.get_name())
        self.assertEqual('reverse', wf1_spec.get_type())
        self.assertListEqual(['wf_test'], wf1_spec.get_tags())
        self.assertListEqual(['wf_test'], wf1_db.tags)
        self.assertEqual(namespace, wf1_db.namespace)
        self.assertEqual(WORKBOOK_WF1_DEFINITION, wf1_db.definition)

        # Workflow 2.
        wf2_db = self._assert_single_item(db_wfs, name='my_wb.wf2')
        wf2_spec = spec_parser.get_workflow_spec(wf2_db.spec)

        self.assertEqual('wf2', wf2_spec.get_name())
        self.assertEqual('direct', wf2_spec.get_type())
        self.assertEqual(namespace, wf2_db.namespace)
        self.assertEqual(WORKBOOK_WF2_DEFINITION, wf2_db.definition)
Beispiel #8
0
    def get_all(self):
        """Return all actions.

        Where project_id is the same as the requester or
        project_id is different but the scope is public.
        """
        LOG.info("Fetch actions.")

        action_list = [
            Action.from_dict(db_model.to_dict())
            for db_model in db_api.get_action_definitions()
        ]

        return Actions(actions=action_list)
Beispiel #9
0
    def get_all(self,
                marker=None,
                limit=None,
                sort_keys='name',
                sort_dirs='asc'):
        """Return all actions.

        :param marker: Optional. Pagination marker for large data sets.
        :param limit: Optional. Maximum number of resources to return in a
                      single result. Default value is None for backward
                      compatibility.
        :param sort_keys: Optional. Columns to sort results by.
                          Default: name.
        :param sort_dirs: Optional. Directions to sort corresponding to
                          sort_keys, "asc" or "desc" can be choosed.
                          Default: asc.

        Where project_id is the same as the requester or
        project_id is different but the scope is public.
        """
        LOG.info(
            "Fetch actions. marker=%s, limit=%s, sort_keys=%s, "
            "sort_dirs=%s", marker, limit, sort_keys, sort_dirs)

        rest_utils.validate_query_params(limit, sort_keys, sort_dirs)

        marker_obj = None

        if marker:
            marker_obj = db_api.get_action_definition_by_id(marker)

        db_action_defs = db_api.get_action_definitions(limit=limit,
                                                       marker=marker_obj,
                                                       sort_keys=sort_keys,
                                                       sort_dirs=sort_dirs)

        actions_list = [
            Action.from_dict(db_model.to_dict()) for db_model in db_action_defs
        ]

        return Actions.convert_with_links(actions_list,
                                          limit,
                                          pecan.request.host_url,
                                          sort_keys=','.join(sort_keys),
                                          sort_dirs=','.join(sort_dirs))
Beispiel #10
0
    def get_all(self, marker=None, limit=None, sort_keys='name',
                sort_dirs='asc'):
        """Return all actions.

        :param marker: Optional. Pagination marker for large data sets.
        :param limit: Optional. Maximum number of resources to return in a
                      single result. Default value is None for backward
                      compatibility.
        :param sort_keys: Optional. Columns to sort results by.
                          Default: name.
        :param sort_dirs: Optional. Directions to sort corresponding to
                          sort_keys, "asc" or "desc" can be choosed.
                          Default: asc.

        Where project_id is the same as the requester or
        project_id is different but the scope is public.
        """
        LOG.info("Fetch actions. marker=%s, limit=%s, sort_keys=%s, "
                 "sort_dirs=%s", marker, limit, sort_keys, sort_dirs)

        rest_utils.validate_query_params(limit, sort_keys, sort_dirs)

        marker_obj = None

        if marker:
            marker_obj = db_api.get_action_definition_by_id(marker)

        db_action_defs = db_api.get_action_definitions(
            limit=limit,
            marker=marker_obj,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs
        )

        actions_list = [Action.from_dict(db_model.to_dict())
                        for db_model in db_action_defs]

        return Actions.convert_with_links(
            actions_list,
            limit,
            pecan.request.host_url,
            sort_keys=','.join(sort_keys),
            sort_dirs=','.join(sort_dirs)
        )
Beispiel #11
0
def get_registered_actions(**kwargs):
    return db_api.get_action_definitions(**kwargs)
Beispiel #12
0
def get_registered_actions(**kwargs):
    return db_api.get_action_definitions(**kwargs)