Ejemplo n.º 1
0
    def add_package(self,
                    name,
                    package_source,
                    package_path,
                    description=None):
        #    NO.A317
        #        Add one new package, create a new conda or find an existed conda according to requirement_list.
        #    Args:
        #        package_name - The name of package.
        #        deployment_path - The path to deploy algorithm.
        #        upload_source - The upload source of package.
        #        requirement_list - Dependencies of algorithms in this package.
        #    Returns:
        #        package_id
        #        hyperparameter_config
        #    Exceptions:
        #        ADD_FAILURE

        id = generate_primary_key('PACK')
        create_time = datetime.now()
        package = Package(id=id,
                          subid=id,
                          creator='admin',
                          owner='admin',
                          last_modifier='admin',
                          create_time=create_time,
                          name=name,
                          package_source=package_source,
                          package_path=package_path,
                          description=description)
        self.db_session.add(package)
        self.db_session.commit()
        return id
Ejemplo n.º 2
0
    def add_user(self,
                 name,
                 date=None,
                 creator=None,
                 subid=None,
                 last_modifier=None,
                 last_modify_time=None,
                 comment=None,
                 password=None,
                 display_name=None,
                 email=None,
                 expiredtime=None,
                 isfrozen=False):
        """

        :param name:
        :param date:
        :param creator:
        :param subid:
        :param last_modifier:
        :param last_modify_time:
        :param comment:
        :param password:
        :param display_name:
        :param email:
        :param expiredtime:
        :param isfrozen:
        :return:
        """

        id = generate_primary_key('USER')
        create_time = datetime.now()

        if creator is None:
            creator = 'admin'
        if last_modifier is None:
            last_modifier = 'admin'

        user = User(id=id,
                    date=date,
                    creator=creator,
                    subid=subid,
                    last_modifier=last_modifier,
                    last_modify_time=last_modify_time,
                    comment=comment,
                    name=name,
                    password=password,
                    create_time=create_time,
                    display_name=display_name,
                    email=email,
                    expiredtime=expiredtime,
                    isfrozen=isfrozen)
        self.db_session.add(user)
        self.db_session.commit()

        return id
Ejemplo n.º 3
0
    def add_dataset(self, name, datasource_id, subid=None, creator=None, owner=None, current_process=None,
                    last_modifier=None, data_file_format=None, default_filter_string=None, description=None,
                    filter=None, patterns=None, target_entity_class=None):
        """
        创建数据集元信息

        :param name: 数据集名称
        :param datasource_id: 数据源ID
        :param subid:
        :param creator:
        :param owner:
        :param current_process:
        :param last_modifier:
        :param data_file_format:
        :param default_filter_string:
        :param description:
        :param filter:
        :param patterns:
        :param target_entity_class:
        :return: 数据集ID
        """

        check_name = self.db_session.query(Dataset).filter(Dataset.name == name).all()
        if check_name :
            raise DUPLICATE_NAME

        id = generate_primary_key('DSET')
        create_time = datetime.now()

        if creator is None:
            creator = 'admin'
        if owner is None:
            owner = 'admin'
        if last_modifier is None:
            last_modifier = 'admin'

        try:
            dataset = Dataset(id=id, subid=subid, creator=creator, owner=owner, current_process=current_process,
                              last_modifier=last_modifier, create_time=create_time, name=name,
                              data_file_format=data_file_format, datasource_id=datasource_id,
                              default_filter_string=default_filter_string, description=description, filter=filter,
                              patterns=patterns, target_entity_class=target_entity_class)
            self.db_session.add(dataset)
            self.db_session.commit()
        except Exception as e:
            logger.error(e)
            logger.debug(traceback.format_exc())
            self.db_session.rollback()
            raise ADD_FAILED

        return id
Ejemplo n.º 4
0
    def update_package(self,
                       package_id,
                       name=None,
                       package_source=None,
                       package_path=None,
                       description=None):
        #    NO.A321
        #        Update one package.
        #    Args:
        #        package_name - The name of package.
        #        deployment_path - The path to deploy algorithm.
        #        upload_source - The upload source of package.
        #        requirement_list - Dependencies of algorithms in this package.
        #    Returns:
        #        package_id - The id of package.
        #        conda_id - The id of conda.
        #    Exceptions:
        #        UPDATE_FAILURE - Fail to add this package.
        pending = self.db_session.query(Package).get(package_id)
        if package_id is None:
            logger.error('package_id is needed')
            raise PARAM_LACK

        if name is not None:
            pending.name = name
        if package_source is not None:
            pending.package_source = package_source
        if package_path is not None:
            pending.package_path = package_path
        if description is not None:
            pending.description = description

        pending.last_modifier = 'admin'
        pending.update_time = datetime.now()
        self.db_session.commit()
        return pending
Ejemplo n.º 5
0
    def update_dataset(self, dataset_id, subid=None, creator=None, owner=None, current_process=None, last_modifier=None,
                       name=None, datasource_id=None, data_file_format=None, default_filter_string=None,
                       description=None, filter=None, patterns=None, target_entity_class=None):
        """
        更新数据集元信息

        :param dataset_id: 数据集ID
        :param subid:
        :param creator:
        :param owner:
        :param current_process:
        :param last_modifier:
        :param name: 数据集名称
        :param datasource_id: 数据源ID
        :param data_file_format:
        :param default_filter_string:
        :param description:
        :param filter:
        :param patterns:
        :param target_entity_class:
        :return: 无
        """

        if dataset_id is None:
            logger.error('缺少数据集ID')
            raise PARAM_LACK

        check_name = self.db_session.query(Dataset).filter(Dataset.name == name).all()
        if check_name :
            raise DUPLICATE_NAME

        pending = self.db_session.query(Dataset).get(dataset_id)

        try:
            if subid is not None:
                pending.subid = subid
            if creator is not None:
                pending.creator = creator
            if owner is not None:
                pending.owner = owner
            if current_process is not None:
                pending.current_process = current_process
            if last_modifier is not None:
                pending.last_modifier = last_modifier
            if name is not None:
                pending.name = name
            if datasource_id is not None:
                pending.datasource_id = datasource_id
            if data_file_format is not None:
                pending.data_file_format = data_file_format
            if default_filter_string is not None:
                pending.default_filter_string = default_filter_string
            if description is not None:
                pending.description = description
            if filter is not None:
                pending.filter = filter
            if patterns is not None:
                pending.patterns = patterns
            if target_entity_class is not None:
                pending.target_entity_class = target_entity_class

            pending.update_time = datetime.now()
            self.db_session.commit()
        except Exception as e:
            logger.error(e)
            logger.debug(traceback.format_exc())
            self.db_session.rollback()
            raise UPDATE_FAILED
Ejemplo n.º 6
0
    def add_datasource(self,
                       name,
                       subid=None,
                       creator=None,
                       owner=None,
                       current_process=None,
                       last_modifier=None,
                       data_file_format=None,
                       database_name=None,
                       datasource_type='LOCAL_FS',
                       description=None,
                       folder_depth=None,
                       paramone=None,
                       password=None,
                       server_ip=None,
                       server_port=None,
                       username=None,
                       workbench_url=None):
        """
        创建数据源元信息

        :param name: 数据源名称
        :param subid:
        :param creator:
        :param owner:
        :param current_process:
        :param last_modifier:
        :param data_file_format:
        :param database_name:
        :param datasource_type:
        :param description:
        :param folder_depth:
        :param paramone:
        :param password:
        :param server_ip:
        :param server_port:
        :param username:
        :param workbench_url:
        :return: 数据源ID
        """

        id = generate_primary_key('DSOU')
        create_time = datetime.now()

        if creator is None:
            creator = 'admin'
        if owner is None:
            owner = 'admin'
        if last_modifier is None:
            last_modifier = 'admin'
        if database_name is None:
            database_name = '/'
        if folder_depth is None:
            folder_depth = -1

        new_datasource = Datasource(id=id,
                                    subid=subid,
                                    creator=creator,
                                    owner=owner,
                                    current_process=current_process,
                                    last_modifier=last_modifier,
                                    create_time=create_time,
                                    name=name,
                                    database_name=database_name,
                                    data_file_format=data_file_format,
                                    datasource_type=datasource_type,
                                    description=description,
                                    folder_depth=folder_depth,
                                    paramone=paramone,
                                    password=password,
                                    server_ip=server_ip,
                                    server_port=server_port,
                                    username=username,
                                    workbench_url=workbench_url)
        self.db_session.add(new_datasource)
        self.db_session.commit()

        return id
Ejemplo n.º 7
0
    def update_datasource(self,
                          datasource_id,
                          name=None,
                          subid=None,
                          creator=None,
                          owner=None,
                          current_process=None,
                          last_modifier=None,
                          data_file_format=None,
                          database_name=None,
                          datasource_type=None,
                          description=None,
                          folder_depth=None,
                          paramone=None,
                          password=None,
                          server_ip=None,
                          server_port=None,
                          username=None,
                          workbench_url=None):
        """
        更新数据源元信息

        :param datasource_id: 数据源ID
        :param name: 数据源名称
        :param subid:
        :param creator:
        :param owner:
        :param current_process:
        :param last_modifier:
        :param data_file_format:
        :param database_name:
        :param datasource_type:
        :param description:
        :param folder_depth:
        :param paramone:
        :param password:
        :param server_ip:
        :param server_port:
        :param username:
        :param workbench_url:
        :return: 无
        """

        if datasource_id is None:
            logger.error('缺少数据源ID')
            raise PARAM_LACK

        pending = self.db_session.query(Datasource).get(datasource_id)

        if subid is not None:
            pending.subid = subid
        if creator is not None:
            pending.creator = creator
        if owner is not None:
            pending.owner = owner
        if current_process is not None:
            pending.current_process = current_process
        if last_modifier is not None:
            pending.last_modifier = last_modifier
        if name is not None:
            pending.name = name
        if database_name is not None:
            pending.database_name = database_name
        if server_ip is not None:
            pending.server_ip = server_ip
        if server_port is not None:
            pending.server_port = server_port
        if workbench_url is not None:
            pending.workbench_url = workbench_url
        if data_file_format is not None:
            pending.data_file_format = data_file_format
        if datasource_type is not None:
            pending.datasource_type = datasource_type
        if folder_depth is not None:
            pending.folder_depth = folder_depth
        if paramone is not None:
            pending.paramone = paramone
        if password is not None:
            pending.password = password
        if username is not None:
            pending.username = username
        if description is not None:
            pending.description = description

        pending.update_time = datetime.now()
        self.db_session.commit()
Ejemplo n.º 8
0
    def update_user(self,
                    user_id,
                    name=None,
                    date=None,
                    creator=None,
                    subid=None,
                    last_modifier=None,
                    comment=None,
                    password=None,
                    display_name=None,
                    email=None,
                    expiredtime=None,
                    isfrozen=False):
        """

        :param user_id:
        :param name:
        :param date:
        :param creator:
        :param subid:
        :param last_modifier:
        :param comment:
        :param password:
        :param display_name:
        :param email:
        :param expiredtime:
        :param isfrozen:
        :return:
        """

        if user_id is None:
            logger.error('缺少用户ID')
            raise PARAM_LACK

        user = self.db_session.query(User).get(user_id)

        if name is not None:
            user.name = name
        if date is not None:
            user.date = date
        if creator is not None:
            user.creator = creator
        if subid is not None:
            user.subid = subid
        if last_modifier is not None:
            user.last_modifier = last_modifier
        if comment is not None:
            user.comment = comment
        if password is not None:
            user.password = password
        if display_name is not None:
            user.display_name = display_name
        if email is not None:
            user.email = email
        if expiredtime is not None:
            user.expiredtime = expiredtime
        if isfrozen is not None:
            user.isfrozen = isfrozen

        user.last_modify_time = datetime.now()
        self.db_session.commit()
Ejemplo n.º 9
0
    def add_model(self,
                  name,
                  algorithm_id,
                  input_data_patterns,
                  output_data_patterns,
                  subid=None,
                  creator=None,
                  owner=None,
                  current_process=None,
                  last_modifier=None,
                  description=None,
                  model_path=None,
                  model_resource=None,
                  usage=None):
        """
        创建模型元信息

        :param name: 模型名称
        :param algorithm_id: 算法ID
        :param input_data_patterns:
        :param output_data_patterns:
        :param subid:
        :param creator:
        :param owner:
        :param current_process:
        :param last_modifier:
        :param description:
        :param model_path:
        :param model_resource:
        :param usage:
        :return: 模型ID
        """

        check_name = self.db_session.query(Model).filter(
            Model.name == name).all()
        if check_name:
            raise DUPLICATE_NAME

        id = generate_primary_key('MODE')
        create_time = datetime.now()

        if creator is None:
            creator = 'admin'
        if owner is None:
            owner = 'admin'
        if last_modifier is None:
            last_modifier = 'admin'

        try:
            model = Model(id=id,
                          subid=subid,
                          creator=creator,
                          owner=owner,
                          current_process=current_process,
                          last_modifier=last_modifier,
                          create_time=create_time,
                          name=name,
                          algorithm_id=algorithm_id,
                          description=description,
                          input_data_patterns=input_data_patterns,
                          output_data_patterns=output_data_patterns,
                          model_path=model_path,
                          model_resource=model_resource,
                          usage=usage)

            self.db_session.add(model)
            self.db_session.commit()
        except Exception as e:
            logger.error(e)
            logger.debug(traceback.format_exc())
            self.db_session.rollback()
            raise ADD_FAILED

        return id
Ejemplo n.º 10
0
    def update_model(self,
                     model_id,
                     subid=None,
                     creator=None,
                     owner=None,
                     current_process=None,
                     last_modifier=None,
                     name=None,
                     algorithm_id=None,
                     description=None,
                     input_data_patterns=None,
                     output_data_patterns=None,
                     model_path=None,
                     model_resource=None,
                     usage=None):
        """
        更新模型元信息

        :param model_id: 模型ID
        :param subid:
        :param creator:
        :param owner:
        :param current_process:
        :param last_modifier:
        :param name:
        :param algorithm_id:
        :param description:
        :param input_data_patterns:
        :param output_data_patterns:
        :param model_path:
        :param model_resource:
        :param usage:
        :return: 无
        """

        if model_id is None:
            logger.error('缺少模型ID')
            raise PARAM_LACK

        check_name = self.db_session.query(Model).filter(
            Model.name == name).all()
        if check_name:
            raise DUPLICATE_NAME

        pending = self.db_session.query(Model).get(model_id)

        try:
            if subid is not None:
                pending.subid = subid
            if creator is not None:
                pending.creator = creator
            if owner is not None:
                pending.owner = owner
            if current_process is not None:
                pending.current_process = current_process
            if last_modifier is not None:
                pending.last_modifier = last_modifier
            if name is not None:
                pending.name = name
            if algorithm_id is not None:
                pending.algorithm_id = algorithm_id
            if description is not None:
                pending.description = description
            if input_data_patterns is not None:
                pending.input_data_patterns = input_data_patterns
            if output_data_patterns is not None:
                pending.output_data_patterns = output_data_patterns
            if model_path is not None:
                pending.model_path = model_path
            if model_resource is not None:
                pending.model_resource = model_resource
            if usage is not None:
                pending.usage = usage

            pending.update_time = datetime.now()
            self.db_session.commit()
        except Exception as e:
            logger.error(e)
            logger.debug(traceback.format_exc())
            self.db_session.rollback()
            raise UPDATE_FAILED