Example #1
0
def fetch_operators(url, overwrite=True):
    """fetch operators from origin market

    url -- origin url
    overwrite -- Whether to overwrite local information if the same name exists

    """
    origin = []
    try:
        r = requests.get(url)
        if r.headers.get(MARKET_IDENTITY_HEADER) != "0.1.0":
            raise RequestError("Uncertified market", "")
        if r.status_code != 200:
            raise RequestError(r.text, r.status_code)
    except Exception as e:
        raise RequestError(e.args[0], e)
    for op in r.json():
        origin.append(Operator(op['name'], op['addr'], op['author'],
                               op['version'], op['type'], op['description']))
    local_operators = all_operators()
    local_operator_names = [x.name for x in local_operators]
    for x in origin:
        if x.name not in local_operator_names:
            local_operators.append(x)
        else:
            if overwrite:
                for lop in local_operators:
                    if lop.name == x.name:
                        local_operators.remove(lop)
                        local_operators.append(x)
    MongoIns.delete_mongo_collection(OPERATOR_COLLECTION_NAME)
    for x in local_operators:
        MongoIns.insert_documents(OPERATOR_COLLECTION_NAME, x.to_dict())
    return local_operators
Example #2
0
def delete_application(name, force=False):
    try:
        if not force:
            if not entities_list(name, 100, 0):
                raise RequestError(
                    "Prevent to delete application with entity not deleted",
                    "")
        app = MongoIns.search_by_name(APPLICATION_COLLECTION_NAME, name)
        if not app:
            raise NotExistError(f"application {name} not exist", "")
        app = app[0]
        delete_milvus_collections_by_fields(app)
        S3Ins.del_s3_buckets(app['bucket'])
        MongoIns.delete_mongo_collection(f"{name}_entity")
        MongoIns.delete_by_name(APPLICATION_COLLECTION_NAME, name)
        logger.info("delete application %s", name)
        application = Application(app["name"], app["fields"], app["bucket"])
        application.metadata = app["metadata"]
        return application
    except Exception as e:
        logger.error(e)
        raise e
Example #3
0
def delete_application(name):
    try:
        if len(entities_list(name, 100, 0)):
            raise RequestError(
                "Prevent to delete application with entity not deleted", "")
        # TODO rewrite clean all resource before change metadata
        x = del_application(name)
        if not x:
            raise NotExistError(f"application {name} not exist", "")
        x = x[0]
        fields = search_fields(json.loads(x.fields))
        app = Application(name=x.name,
                          fields=fields2dict(fields),
                          buckets=x.s3_buckets)
        delete_milvus_collections_by_fields(app)
        delete_fields(json.loads(x.fields))
        S3Ins.del_s3_buckets(x.s3_buckets.split(","))
        MongoIns.delete_mongo_collection(f"{name}_entity")
        logger.info("delete application %s", name)
        return app
    except Exception as e:
        logger.error(e)
        raise e