Esempio n. 1
0
def delete_entity(app_name, entity_id):
    try:
        mongo_ins_name = f"{app_name}_entity"
        entity = MongoIns.search_by_id(mongo_ins_name, entity_id)

        if not entity.count():
            raise NotExistError("Entity %s not exist" % entity_id,
                                "NotExistError")
        for item in entity:
            en = new_mapping_ins(item)
            for name, fields in en._docs.items():
                # delete s3 object
                bucket_name = fields.get("url").split("/")[-2]
                object_name = fields.get("url").split("/")[-1]
                S3Ins.del_object(bucket_name, object_name)
                # delete vector from milvus
                vids = fields.get("ids")
                app = application_detail(app_name)
                pipe_name = app.fields[name]["value"]
                pipe = pipeline_detail(pipe_name)
                instance_name = pipe.encoder.get("instance")
                MilvusIns.del_vectors(f"{app_name}_{name}_{instance_name}",
                                      vids)
            # delete from mongodb
            MongoIns.delete_by_id(mongo_ins_name, entity_id)
            logger.info("delete entity %s in application %s", entity_id,
                        app_name)
            return en
    except Exception as e:
        logger.error(e)
        raise e
Esempio n. 2
0
def delete_entity(app_name, entity_name):
    try:
        entity = search_from_mapping(entity_name)
        if not entity:
            raise NotExistError("Entity %s not exist" % entity_name,
                                "NotExistError")
        MilvusIns.del_vectors(app_name, [int(entity_name)])
        bucket_name = entity.image_url.split("/")[-2]
        object_name = entity.image_url.split("/")[-1]
        S3Ins.del_object(bucket_name, object_name)
        del_mapping(entity_name)
        logger.info("delete entity %s in application %s", entity_name,
                    app_name)
        return new_mapping_ins(id=entity.id,
                               app_name=entity.app_name,
                               image_url=entity.image_url,
                               fields=entity.fields)
    except Exception as e:
        logger.error(e)
        return e