2021-05-11 17:59:29 +08:00
|
|
|
import sys
|
2021-08-20 11:00:56 +08:00
|
|
|
from pymilvus import Index
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
sys.path.append("..")
|
2021-10-03 20:33:56 +08:00
|
|
|
from check.func_check import ResponseChecker
|
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
|
|
|
|
2022-05-11 21:55:53 +08:00
|
|
|
TIMEOUT = 20
|
|
|
|
INDEX_NAME = "_default_idx"
|
2021-07-26 15:51:20 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
class ApiIndexWrapper:
|
2021-05-11 17:59:29 +08:00
|
|
|
index = None
|
|
|
|
|
2022-05-11 21:55:53 +08:00
|
|
|
def init_index(self, collection, field_name, index_params, index_name=None, check_task=None, check_items=None, **kwargs):
|
2021-12-03 18:31:34 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT * 2)
|
2022-05-11 21:55:53 +08:00
|
|
|
index_name = INDEX_NAME if index_name is None else index_name
|
|
|
|
index_name = kwargs.get("index_name", index_name)
|
|
|
|
kwargs.update({"timeout": timeout, "index_name": index_name})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
""" In order to distinguish the same name of index """
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, is_succ = api_request([Index, collection, field_name, index_params], **kwargs)
|
2021-06-09 14:23:48 +08:00
|
|
|
self.index = res if is_succ is True else None
|
2021-06-16 11:29:55 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, is_succ,
|
|
|
|
collection=collection, field_name=field_name,
|
|
|
|
index_params=index_params, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2022-05-11 21:55:53 +08:00
|
|
|
def drop(self, index_name=None ,check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
2022-05-11 21:55:53 +08:00
|
|
|
index_name = INDEX_NAME if index_name is None else index_name
|
|
|
|
index_name = kwargs.get("index_name", index_name)
|
|
|
|
kwargs.update({"timeout": timeout, "index_name": index_name})
|
2021-07-26 15:51:20 +08:00
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-09 14:23:48 +08:00
|
|
|
res, is_succ = api_request([self.index.drop], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, is_succ, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-09 14:23:48 +08:00
|
|
|
@property
|
|
|
|
def params(self):
|
|
|
|
return self.index.params
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-09 14:23:48 +08:00
|
|
|
@property
|
|
|
|
def collection_name(self):
|
|
|
|
return self.index.collection_name
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-09 14:23:48 +08:00
|
|
|
@property
|
|
|
|
def field_name(self):
|
|
|
|
return self.index.field_name
|