def clean_db_model_manager():
    labels = {'labels': {}}
    models = {'models': {}}
    versions = {'versions': {}}
    # 暂未清理
    edge_nodes = {'versions': {}}
    delete_from_mongodb('model-manager', [labels, models, versions])
def clean_db_resource_manager():
    resource_configs = {'resource_configs': {}}
    # 无法区分新添加的内容,暂时不清理
    resource_templates = {'resource_templates': {}}
    delete_from_mongodb('resource-manager', [resource_configs])

    default_config = """{
        "_id" : "efc3afdc-8570-4d32-9b4c-ba3674116ffb",
        "created_at" : "2019-09-11T04:34:14.956Z",
        "updated_at" : "2019-09-11T04:34:14.956Z",
        "user_id" : null,
        "max_concurrent_tasks" : 10,
        "max_concurrent_heavy_tasks" : 3,
        "max_cpu_time" : 259200,
        "max_gpu_time" : 5184000,
        "max_gpus" : 3,
        "heavy_task_threshold" : {
            "cpu" : 16000,
            "memory" : 34359738368
        },
        "parameter_type" : "GLOBAL",
        "_cls" : "apis.v1.config.models.ResourceConfig"
    } """
    default_config = json.loads(default_config)
    resource_configs_recover = {'resource_configs': default_config}
    insert_to_mongodb('resource-manager', resource_configs_recover)
def clean_db_project_manager():
    project = {'project': {}}
    tasks = {'tasks': {}}
    delete_from_mongodb('project-manager', [project, tasks])
def clean_db_image_manager():
    base_image = {'baseImage': {"build_type": {"$nin": ['BASIC']}}}
    image_builder = {'imageBuilder': {}}
    # 暂未清理
    image_package_op = {}
    delete_from_mongodb('image-manager', [base_image, image_builder])
def clean_db_file_manager():
    user_uuids = get_auto_test_user_uuid()
    file_shares = {'file_shares': {"owner_id": {"$in": user_uuids}}}
    delete_from_mongodb('file-manager', [file_shares])
def clean_db_data_manager():
    data_source = {'data_source': {"name": {"$regex": "^autoT.*"}}}
    data_set = {'data_set': {"name": {"$regex": "^autoT.*"}}}
    data_set_tag = {'data_set_tag': {"label": {"$regex": "^autoT.*"}}}  # 需要关联表
    delete_from_mongodb('data-manager', [data_source, data_set, data_set_tag])
def clean_db_user_manager():
    # 用户清理需放在数据库清理的最后一步调用
    user = {'users': {"username": {"$regex": "^autoT.*"}}}
    group = {'groups': {"name": {"$regex": "^autoT.*"}}}
    delete_from_mongodb('user-manager', [user, group])
def clean_db_workflow_engine():
    workflow_engine = {'workflow-engine': {}}
    delete_from_mongodb('workflow-engine', [workflow_engine])
def clean_db_skyflow_manager():
    skyflow = {'skyflow': {}}
    skyflow_component = {'skyflow_component': {'is_custom': True}}
    skyflow_execute = {'skyflow_execute': {}}
    delete_from_mongodb('skyflow-manager',
                        [skyflow, skyflow_component, skyflow_execute])