Пример #1
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('name', required=True, help='name is empty')
     parser.add_argument('comment')
     parser.add_argument('config',
                         type=dict,
                         required=True,
                         help='config is empty')
     data = parser.parse_args()
     name = data['name']
     comment = data['comment']
     config = data['config']
     if WorkflowTemplate.query.filter_by(name=name).first() is not None:
         raise ResourceConflictException(
             'Workflow template {} already exists'.format(name))
     # form to proto buffer
     template_proto = dict_to_workflow_definition(config)
     group_template = WorkflowTemplate.query.filter_by(
         group_alias=template_proto.group_alias).first()
     if group_template is not None:
         group_proto = group_template.get_config()
         if not (check_group_match(group_proto, template_proto)
                 or check_group_same(group_proto, template_proto)):
             raise InvalidArgumentException(
                 'The group is not matched with existing groups.')
     template = WorkflowTemplate(name=name,
                                 comment=comment,
                                 group_alias=template_proto.group_alias)
     template.set_config(template_proto)
     db.session.add(template)
     db.session.commit()
     logging.info('Inserted a workflow_template to db')
     return {'data': template.to_dict()}, HTTPStatus.CREATED
Пример #2
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('name', required=True, help='name is empty')
        parser.add_argument('comment')
        parser.add_argument('config', type=dict, required=True,
                            help='config is empty')
        data = parser.parse_args()
        name = data['name']
        comment = data['comment']
        config = data['config']

        if 'group_alias' not in config:
            raise InvalidArgumentException(details={
                'config.group_alias': 'config.group_alias is required'})
        if 'is_left' not in config:
            raise InvalidArgumentException(
                details={'config.is_left': 'config.is_left is required'})

        if WorkflowTemplate.query.filter_by(name=name).first() is not None:
            raise ResourceConflictException(
                'Workflow template {} already exists'.format(name))
        # form to proto buffer
        template_proto = dict_to_workflow_definition(config)
        template = WorkflowTemplate(name=name,
                                    comment=comment,
                                    group_alias=template_proto.group_alias,
                                    is_left=template_proto.is_left)
        template.set_config(template_proto)
        db.session.add(template)
        db.session.commit()
        logging.info('Inserted a workflow_template to db')
        return {'data': template.to_dict()}, HTTPStatus.CREATED
Пример #3
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('name', required=True, help='name is empty')
        parser.add_argument('comment')
        parser.add_argument('config',
                            type=dict,
                            required=True,
                            help='config is empty')
        data = parser.parse_args()
        name = data['name']
        comment = data['comment']
        config = data['config']
        # TODO: format check
        if 'group_alias' not in config:
            raise InvalidArgumentException(
                details={
                    'config.group_alias': 'config.group_alias is required'
                })
        if 'is_left' not in config:
            raise InvalidArgumentException(
                details={'config.is_left': 'config.is_left is required'})

        if WorkflowTemplate.query.filter_by(name=name).first() is not None:
            raise ResourceConflictException(
                'Workflow template {} already exists'.format(name))
        # form to proto buffer
        template_proto = dict_to_workflow_definition(config)
        for index, job_def in enumerate(template_proto.job_definitions):
            # pod label name must be no more than 63 characters.
            #  workflow.uuid is 20 characters, pod name suffix such as
            #  '-follower-master-0' is less than 19 characters, so the
            #  job name must be no more than 24
            if len(job_def.name) > 24:
                raise InvalidArgumentException(
                    details={
                        'config.job_definitions':
                        'job_name:{} must be no more than 24 characters'
                    })
            # limit from k8s
            if not re.match('[a-z0-9-]*', job_def.name):
                raise InvalidArgumentException(
                    details={
                        f'config.job_definitions[{index}].job_name':
                        'Only letters(a-z), numbers(0-9) '
                        'and dashes(-) are supported.'
                    })
        template = WorkflowTemplate(name=name,
                                    comment=comment,
                                    group_alias=template_proto.group_alias,
                                    is_left=template_proto.is_left)
        template.set_config(template_proto)
        db.session.add(template)
        db.session.commit()
        logging.info('Inserted a workflow_template to db')
        return {'data': template.to_dict()}, HTTPStatus.CREATED
Пример #4
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('name', required=True, help='name is empty')
     parser.add_argument('comment')
     parser.add_argument('config',
                         type=dict,
                         required=True,
                         help='config is empty')
     parser.add_argument('editor_info', type=dict, default={})
     parser.add_argument('kind', type=int, default=0)
     data = parser.parse_args()
     name = data['name']
     comment = data['comment']
     config = data['config']
     editor_info = data['editor_info']
     kind = data['kind']
     if WorkflowTemplate.query.filter_by(name=name).first() is not None:
         raise ResourceConflictException(
             'Workflow template {} already exists'.format(name))
     template_proto, editor_info_proto = _check_config_and_editor_info(
         config, editor_info)
     template_proto = _format_template_with_yaml_editor(
         template_proto, editor_info_proto)
     template = WorkflowTemplate(name=name,
                                 comment=comment,
                                 group_alias=template_proto.group_alias,
                                 is_left=template_proto.is_left,
                                 kind=kind)
     template.set_config(template_proto)
     template.set_editor_info(editor_info_proto)
     db.session.add(template)
     db.session.commit()
     logging.info('Inserted a workflow_template to db')
     result = template.to_dict()
     return {'data': result}, HTTPStatus.CREATED
Пример #5
0
 def setUp(self):
     super().setUp()
     # Inserts data
     template1 = WorkflowTemplate(name='t1',
                                  comment='comment for t1',
                                  group_alias='g1',
                                  is_left=True)
     template1.set_config(WorkflowDefinition(
         group_alias='g1',
         is_left=True,
     ))
     template2 = WorkflowTemplate(name='t2',
                                  group_alias='g2',
                                  is_left=False)
     template2.set_config(WorkflowDefinition(
         group_alias='g2',
         is_left=False,
     ))
     db.session.add(template1)
     db.session.add(template2)
     db.session.commit()