Exemplo n.º 1
0
    def test_update_workbook(self):
        # Create workbook.
        wb_db = wb_service.create_workbook_v2(WORKBOOK)

        self.assertIsNotNone(wb_db)
        self.assertEqual(2, len(db_api.get_workflow_definitions()))

        # Update workbook.
        wb_db = wb_service.update_workbook_v2(UPDATED_WORKBOOK)

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

        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('direct', wf1_spec.get_type())

        # 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('reverse', wf2_spec.get_type())
Exemplo n.º 2
0
    def get_all(self, marker=None, limit=None, sort_keys='created_at',
                sort_dirs='asc', fields=''):
        """Return a list of workflows.

        :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: created_at.
        :param sort_dirs: Optional. Directions to sort corresponding to
                          sort_keys, "asc" or "desc" can be choosed.
                          Default: asc.
        :param fields: Optional. A specified list of fields of the resource to
                       be returned. 'id' will be included automatically in
                       fields if it's provided, since it will be used when
                       constructing 'next' link.

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

        if fields and 'id' not in fields:
            fields.insert(0, 'id')

        rest_utils.validate_query_params(limit, sort_keys, sort_dirs)
        rest_utils.validate_fields(fields, Workflow.get_fields())

        marker_obj = None

        if marker:
            marker_obj = db_api.get_workflow_definition_by_id(marker)

        db_workflows = db_api.get_workflow_definitions(
            limit=limit,
            marker=marker_obj,
            sort_keys=sort_keys,
            sort_dirs=sort_dirs,
            fields=fields
        )

        workflows_list = []

        for data in db_workflows:
            workflow_dict = (dict(zip(fields, data)) if fields else
                             data.to_dict())
            workflows_list.append(Workflow.from_dict(workflow_dict))

        return Workflows.convert_with_links(
            workflows_list,
            limit,
            pecan.request.host_url,
            sort_keys=','.join(sort_keys),
            sort_dirs=','.join(sort_dirs),
            fields=','.join(fields) if fields else ''
        )
Exemplo n.º 3
0
    def _create_workflow_execution(self, params):
        wf_def = db_api.get_workflow_definitions()[0]

        self.wf_ex = db_api.create_workflow_execution({
            'id': '1-2-3-4',
            'spec': self.wb_spec.get_workflows().get('wf').to_dict(),
            'state': states.RUNNING,
            'params': params,
            'workflow_id': wf_def.id
        })
    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))
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    def get_all(self):
        """Return all workflows.

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

        workflows_list = [Workflow.from_dict(db_model.to_dict())
                          for db_model in db_api.get_workflow_definitions()]

        return Workflows(workflows=workflows_list)
Exemplo n.º 7
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)
Exemplo n.º 8
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')

        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)
Exemplo n.º 9
0
    def setUp(self):
        super(ReverseWorkflowControllerTest, self).setUp()

        wb_service.create_workbook_v2(WB)

        wf_def = db_api.get_workflow_definitions()[0]

        wb_spec = spec_parser.get_workbook_spec_from_yaml(WB)

        wf_ex = models.WorkflowExecution(
            id='1-2-3-4',
            spec=wb_spec.get_workflows().get('wf').to_dict(),
            state=states.RUNNING,
            params={},
            workflow_id=wf_def.id)

        self.wf_ex = wf_ex
        self.wb_spec = wb_spec
    def setUp(self):
        super(ReverseWorkflowControllerTest, self).setUp()

        wb_service.create_workbook_v2(WB)

        wf_def = db_api.get_workflow_definitions()[0]

        wb_spec = spec_parser.get_workbook_spec_from_yaml(WB)

        wf_ex = models.WorkflowExecution(
            id='1-2-3-4',
            spec=wb_spec.get_workflows().get('wf').to_dict(),
            state=states.RUNNING,
            params={},
            workflow_id=wf_def.id
        )

        self.wf_ex = wf_ex
        self.wb_spec = wb_spec
        self.wf_ctrl = reverse_wf.ReverseWorkflowController(wf_ex)
Exemplo n.º 11
0
    def get_all(self,
                marker=None,
                limit=None,
                sort_keys='created_at',
                sort_dirs='asc',
                fields=''):
        """Return a list of workflows.

        :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: created_at.
        :param sort_dirs: Optional. Directions to sort corresponding to
                          sort_keys, "asc" or "desc" can be choosed.
                          Default: asc.
        :param fields: Optional. A specified list of fields of the resource to
                       be returned. 'id' will be included automatically in
                       fields if it's provided, since it will be used when
                       constructing 'next' link.

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

        if fields and 'id' not in fields:
            fields.insert(0, 'id')

        rest_utils.validate_query_params(limit, sort_keys, sort_dirs)
        rest_utils.validate_fields(fields, Workflow.get_fields())

        marker_obj = None

        if marker:
            marker_obj = db_api.get_workflow_definition_by_id(marker)

        db_workflows = db_api.get_workflow_definitions(limit=limit,
                                                       marker=marker_obj,
                                                       sort_keys=sort_keys,
                                                       sort_dirs=sort_dirs,
                                                       fields=fields)

        workflows_list = []

        for data in db_workflows:
            workflow_dict = (dict(zip(fields, data))
                             if fields else data.to_dict())
            workflows_list.append(Workflow.from_dict(workflow_dict))

        return Workflows.convert_with_links(
            workflows_list,
            limit,
            pecan.request.host_url,
            sort_keys=','.join(sort_keys),
            sort_dirs=','.join(sort_dirs),
            fields=','.join(fields) if fields else '')