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