2021-05-11 17:59:29 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append("..")
|
|
|
|
from check.param_check import *
|
|
|
|
from check.func_check import *
|
2021-06-07 12:15:35 +08:00
|
|
|
from utils.api_request import api_request
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
2021-07-26 15:51:20 +08:00
|
|
|
TIMEOUT = 5
|
|
|
|
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
class ApiPartitionWrapper:
|
2021-05-11 17:59:29 +08:00
|
|
|
partition = None
|
|
|
|
|
2021-06-07 12:15:35 +08:00
|
|
|
def init_partition(self, collection, name, description="",
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
""" In order to distinguish the same name of partition """
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
response, is_succ = api_request([Partition, collection, name, description], **kwargs)
|
|
|
|
self.partition = response if is_succ is True else None
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(response, func_name, check_task, check_items, is_succ,
|
2021-06-05 10:25:34 +08:00
|
|
|
**kwargs).run()
|
2021-06-07 12:15:35 +08:00
|
|
|
return response, check_result
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def description(self):
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.description if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def name(self):
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.name if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def is_empty(self):
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.is_empty if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def num_entities(self):
|
2021-06-07 12:15:35 +08:00
|
|
|
return self.partition.num_entities if self.partition else None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def drop(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.drop], **kwargs)
|
2021-06-17 11:49:57 +08:00
|
|
|
check_result = ResponseChecker(res, func_name,
|
|
|
|
check_task, check_items, succ, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def load(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, succ = api_request([self.partition.load], **kwargs)
|
2021-06-07 12:15:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_items, is_succ=succ,
|
2021-06-05 10:25:34 +08:00
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def release(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.release], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_items, is_succ=succ,
|
2021-06-07 12:15:35 +08:00
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def insert(self, data, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.insert, data], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_items, is_succ=succ, data=data,
|
2021-06-07 12:15:35 +08:00
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 12:15:35 +08:00
|
|
|
def search(self, data, anns_field, params, limit, expr=None, output_fields=None,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.partition.search, data, anns_field, params,
|
|
|
|
limit, expr, output_fields], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items,
|
2021-06-07 12:15:35 +08:00
|
|
|
is_succ=succ, data=data, anns_field=anns_field,
|
|
|
|
params=params, limit=limit, expr=expr,
|
|
|
|
output_fields=output_fields, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|