Exemplo n.º 1
0
def new_application(app_name, fields, s3_bucket):
    ok, message = fields_check(fields)
    if not ok:
        raise ArgsCheckError(message, "")
    try:
        # check application exist
        if MongoIns.search_by_name(APPLICATION_COLLECTION_NAME, app_name):
            raise ExistError(f"application <{app_name}> had exist", "")
    except ExistError:
        raise
    try:
        for _, value in fields.items():
            if value.get("type") == "pipeline":
                pipe = MongoIns.search_by_name(PIPELINE_COLLECTION_NAME,
                                               value.get("value"))[0]
                ei = identity(
                    pipe.get("encoder").get("instance").get("endpoint"))
                name = f"{app_name}_{pipe.get('encoder').get('instance').get('name').replace('phantoscope_', '')}"
                MilvusIns.new_milvus_collection(name, int(ei["dimension"]),
                                                1024, "l2")
        # create a application entity collection
        MongoIns.new_mongo_collection(f"{app_name}_entity")
        S3Ins.new_s3_buckets(s3_bucket)
        # create milvus collections
        app = Application(name=app_name, fields=fields, bucket=s3_bucket)
        app.metadata = app._metadata()
        MongoIns.insert_documents(APPLICATION_COLLECTION_NAME, app.to_dict())
        return app
    except Exception as e:
        logger.error("error happen during create app: %s",
                     str(e),
                     exc_info=True)
        raise e
Exemplo n.º 2
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