예제 #1
0
def save_deployment(task, namespace, is_public):
    save_task_step_progress(task.uuid, '模型部署', '执行', 92, '开始保存模型部署对象...')
    try:
        k8s_status = g.k8s_client.core_api.read_namespaced_service_status(
            "service-" + task.uuid, namespace)
    except:
        save_task_step_progress(task.uuid, '模型部署', '失败', 100,
                                '获取Kubernetes服务访问端口失败。')
        return False

    res = umm_client.get_solutions(task.targetUuid)
    if res['status'] != 'ok':
        save_task_step_progress(task.uuid, '模型部署', '失败', 100, '从umm获取模型对象失败。')
        return False
    solution = Solution()
    solution.__dict__ = res['value']['results'][0]
    deployment = Deployment()
    deployment.uuid = task.uuid
    deployment.deployer = task.userLogin
    deployment.solutionUuid = task.targetUuid
    deployment.solutionName = task.taskName
    deployment.solutionAuthor = solution.authorLogin
    deployment.pictureUrl = solution.pictureUrl
    deployment.k8sPort = k8s_status.spec.ports[0].node_port
    deployment.isPublic = is_public
    deployment.status = '运行'

    res = umm_client.create_deployment(deployment,
                                       jwt=g.oauth_client.get_jwt())
    if res['status'] != 'ok':
        save_task_step_progress(task.uuid, '模型部署', '失败', 100, '保存模型部署对象失败。')

    save_task_step_progress(task.uuid, '模型部署', '执行', 98, '保存模型部署对象完成。')
    save_task_step_progress(task.uuid, '模型部署', '成功', 100, '模型部署成功。')
    return True
예제 #2
0
def update_solution_comment_count(**args):
    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))
    solution.commentCount = comment_db.get_comment_count(solution.uuid)

    solution_db.update_solution_comment_count(solution)
    return 0
예제 #3
0
def update_solution_active(**args):
    token = token_service.get_token(args.get('http_request'))
    user_login = token.username
    has_role = token.has_role('ROLE_MANAGER')

    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))

    if user_login != solution.authorLogin and not has_role:
        raise Exception('403 Forbidden')

    if solution.active and not args.get('active'):
        credit = Credit()
        credit.__dict__ = credit_service.find_user_credit(user_login)
        if credit.credit < 20:
            raise Exception('400 Bad request')
        else:
            solution.active = args.get('active')
            solution_db.update_solution_active(solution)
            credit_service.do_update_credit(
                credit, -20, '将AI模型<{}>设为私有'.format(solution.name))
            return 0
    else:
        solution.active = args.get('active')
        solution_db.update_solution_active(solution)
        return 0
예제 #4
0
def update_solution_star_count(**args):
    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))
    solution.starCount = star_db.get_stared_count(solution.uuid)

    solution_db.update_solution_star_count(solution)
    return 0
예제 #5
0
def update_solution_baseinfo(**args):
    token = token_service.get_token(args.get('http_request'))
    user_login = token.username
    has_role = token.has_role('ROLE_MANAGER')

    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))

    if user_login != solution.authorLogin and not has_role:
        raise Exception('403 Forbidden')

    solution.name = args.get('name') if args.get('name') else ''
    solution.company = args.get('company') if args.get('company') else ''
    solution.version = args.get('version') if args.get('version') else ''
    solution.summary = args.get('summary') if args.get('summary') else ''
    solution.tag1 = args.get('tag1') if args.get('tag1') else ''
    solution.tag2 = args.get('tag2') if args.get('tag2') else ''
    solution.tag3 = args.get('tag3') if args.get('tag3') else ''
    solution.modelType = args.get('modelType') if args.get('modelType') else ''
    solution.toolkitType = args.get('toolkitType') if args.get(
        'toolkitType') else ''
    solution.modifiedDate = mytime.now()

    solution_db.update_solution_baseinfo(solution)
    return 0
예제 #6
0
def upload_document(**args):
    http_request = args.get('http_request')
    token = token_service.get_token(http_request)
    if not token.is_valid:
        raise Exception('403 Forbidden')
    user_login = token.username

    file_body = args.get('stream')
    solution_uuid = args.get('path_arg')
    res = umm_client.get_solutions(solution_uuid, token.jwt)
    if res['status'] != 'ok' or res['value']['total'] < 1:
        raise Exception('文档模型不存在')

    solution = Solution()
    solution.__dict__ = res['value']['results'][0]

    if solution.authorLogin != user_login:
        raise Exception('403 Forbidden')

    filename = http_request.files.get('upload_document')[0].filename
    short_url = solution.authorLogin + '/' + solution_uuid + '/document/' + filename
    long_url = nexus_client.upload_artifact_data(short_url, file_body)

    if long_url is None:
        raise Exception('向Nexus上传文件出错!')

    document = Document()
    document.solutionUuid = solution.uuid
    document.name = filename
    document.url = long_url
    document.fileSize = len(file_body)
    umm_client.create_document(document, token.jwt)

    return 0
예제 #7
0
def update_solution_download_count(**args):
    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))

    solution.downloadCount += 1

    solution_db.update_solution_download_count(solution)
    return 0
예제 #8
0
def update_solution_name(**args):
    token = token_service.get_token(args.get('http_request'))
    user_login = token.username

    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))

    if user_login != solution.authorLogin:
        raise Exception('403 Forbidden')

    solution.name = args.get('name')
    solution.modifiedDate = mytime.now()

    solution_db.update_solution_name(solution)
    return 0
예제 #9
0
def update_solution_picture_url(**args):
    token = token_service.get_token(args.get('http_request'))
    user_login = token.username
    has_role = token.has_role('ROLE_MANAGER')

    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))

    if user_login != solution.authorLogin and not has_role:
        raise Exception('403 Forbidden')

    solution.pictureUrl = args.get('pictureUrl')
    solution.modifiedDate = mytime.now()

    solution_db.update_solution_picture_url(solution)
    return 0
예제 #10
0
def update_solution_admininfo(**args):
    token = token_service.get_token(args.get('http_request'))
    has_role = token.has_role('ROLE_MANAGER')

    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))

    if not has_role:
        raise Exception('403 Forbidden')

    solution.subject1 = args.get('subject1') if args.get('subject1') else ''
    solution.subject2 = args.get('subject2') if args.get('subject2') else ''
    solution.subject3 = args.get('subject3') if args.get('subject3') else ''
    solution.displayOrder = args.get('displayOrder') if args.get(
        'displayOrder') else 0
    solution.modifiedDate = mytime.now()

    solution_db.update_solution_admininfo(solution)
    return 0
예제 #11
0
def create_solution(**args):
    token = token_service.get_token(args.get('http_request'))
    if not token.is_valid:
        raise Exception('403 Forbidden')
    user_login = token.username

    solution = Solution()
    solution.__dict__ = args.get('solution')
    if user_login != solution.authorLogin and user_login != 'internal':
        raise Exception('403 Forbidden')

    solution.active = True
    solution.company = ''
    solution.starCount = 0
    solution.viewCount = 0
    solution.downloadCount = 0
    solution.commentCount = 0
    solution.displayOrder = 0
    solution.createdDate = mytime.now()
    solution.modifiedDate = mytime.now()

    solution_id = solution_db.create_solution(solution)

    # 为solution创建描述,其uuid设为与solution的uuid一致。 ----huolongshe
    # description表只能在这里创建
    description = Description()
    description.solutionUuid = solution.uuid
    description.authorLogin = solution.authorLogin
    description.content = r'<p>无内容</p>'
    description_db.create_description(description)

    credit = Credit()
    credit.__dict__ = credit_service.find_user_credit(solution.authorLogin)
    credit_service.do_update_credit(credit, 3,
                                    '创建新模型<{}>'.format(solution.name))

    return solution_id
예제 #12
0
def delete_solution(**args):
    token = token_service.get_token(args.get('http_request'))
    user_login = token.username
    has_role = token.has_role('ROLE_MANAGER')

    solution = Solution()
    solution.__dict__ = solution_db.get_solution_by_id(args.get('solutionId'))

    if user_login != solution.authorLogin and user_login != 'internal' and not has_role:
        raise Exception('403 Forbidden')

    where = 'WHERE solution_uuid = "{}"'.format(solution.uuid)
    document_list = document_db.get_documents(where)
    for document in document_list:
        nexus_client.delete_artifact(document.get('url'))
        document_db.delete_document(document.get('id'))

    artifact_list = artifact_db.get_artifacts(where)
    for artifact in artifact_list:
        if artifact.get('type') == 'DOCKER镜像':
            nexus_client.delete_docker_image(artifact.get('url'))
        else:
            nexus_client.delete_artifact(artifact.get('url'))

        artifact_db.delete_artifact(artifact.get('id'))

    description = description_db.get_descriptions(solution.uuid)[0]
    description_db.delete_description(description.get('id'))

    where = 'WHERE target_uuid = "{}"'.format(solution.uuid)
    _, star_list = star_db.get_stars(where, None)
    for star in star_list:
        star_db.delete_star(star.get('id'))

    solution_db.delete_solution(solution.id)
    return 0