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
def save(self): fields = json.dumps(self._fields) app = DB(name=self._application_name, fields=fields, s3_buckets=self._buckets) try: S3Ins.new_s3_buckets(self.buckets.split(",")) insert_application(app) logger.info("create new application %s", self.name) except Exception as e: logger.error(e) raise e return self
def save(self): fields = json.dumps(self._fields) app = DB(name=self._application_name, fields=fields, s3_buckets=self._buckets) try: # Record created resource # TODO create s3 bucket if bucket not exist S3Ins.new_s3_buckets(self.buckets.split(",")) # TODO create milvus collections insert_application(app) logger.info("create new application %s", self.name) except Exception as e: logger.error(e) # TODO collection created resource raise e return self