Beispiel #1
0
def new_application(app_name, fields, s3_buckets):
    ok, message = fields_check(fields)
    if not ok:
        raise ArgsCheckError(message, "")
    try:
        # check application exist
        if search_application(app_name):
            raise ExistError(f"application <{app_name}> had exist", "")
        # insert fields to metadata
        fieldsdb = []
        for name, field in fields.items():
            fieldsdb.append(
                FieldsDB(name=name,
                         type=field.get('type'),
                         value=field.get('value'),
                         app=app_name))
        ids = insert_fields(fieldsdb)
        # create a application entity collection
        MongoIns.new_mongo_collection(f"{app_name}_entity")
        app = Application(name=app_name, fields=ids, buckets=s3_buckets)
        # create milvus collections
        create_milvus_collections_by_fields(app)
        # insert application to metadata
        app.save()
        app.fields = fields2dict(search_fields(ids))
        return app
    except Exception as e:
        logger.error("error happen during create app: %s",
                     str(e),
                     exc_info=True)
        raise e
Beispiel #2
0
def application_detail(name):
    try:
        x = search_application(name)
        if not x:
            raise NotExistError(f"application {name} not exist", "")
        fields = json.loads(x.fields)
        app = Application(name=x.name, fields=fields, buckets=x.s3_buckets)
        return app
    except Exception as e:
        logger.error(e)
        raise e
Beispiel #3
0
def all_applications():
    res = []
    try:
        apps = search_application()
        for x in apps:
            fields = json.loads(x.Application.fields)
            app = Application(name=x.Application.name,
                              fields=fields,
                              buckets=x.Application.s3_buckets)
            res.append(app)
        logger.info("get all application")
        return res
    except Exception as e:
        logger.error(e)
        return e