diff --git a/examples/resource_group.py b/examples/resource_group.py index 6407e7902..cdfc46914 100644 --- a/examples/resource_group.py +++ b/examples/resource_group.py @@ -1,6 +1,5 @@ -from pymilvus import utility, connections +from pymilvus import utility, connections, DEFAULT_RESOURCE_GROUP from example import * -from role_and_privilege import * _HOST = '127.0.0.1' _PORT = '19530' @@ -11,10 +10,6 @@ _ID_FIELD_NAME = 'id_field' _VECTOR_FIELD_NAME = 'float_vector_field' -_USER = "user" -_PASSWD = "123456" -_ROLE = "role" - # Vector parameters _DIM = 128 @@ -25,37 +20,6 @@ def create_connection(user, passwd): connections.connect(alias=_CONNECTION_NAME,host=_HOST, port=_PORT, user=user, password=passwd) print(f"\nList connections:") print(connections.list_connections()) - -def create_rbac_user(): - create_credential(_USER, _PASSWD, _CONNECTION_NAME) - role = Role(_ROLE, using=_CONNECTION_NAME) - print(f"create role, role_name: {_ROLE}") - role.create() - print(f"add user") - role.add_user(_USER) - print(f"grant privilege") - role.grant("Global", "*", "CreateResourceGroup") - role.grant("Global", "*", "DropResourceGroup") - role.grant("Global", "*", "DescribeResourceGroup") - role.grant("Global", "*", "ListResourceGroups") - role.grant("Global", "*", "TransferNode") - role.grant("Global", "*", "TransferReplica") - print(f"list grants") - print(role.list_grants()) - -def remove_rbac_user(): - create_connection("root", "123456") - role = Role(_ROLE, using=_CONNECTION_NAME) - print(f"remove user") - role.remove_user(_USER) - role.revoke("Global", "*", "CreateResourceGroup") - role.revoke("Global", "*", "DropResourceGroup") - role.revoke("Global", "*", "DescribeResourceGroup") - role.revoke("Global", "*", "ListResourceGroups") - role.revoke("Global", "*", "TransferNode") - role.revoke("Global", "*", "TransferReplica") - role.drop() - drop_credential(_USER, _CONNECTION_NAME) def create_resource_group(name): @@ -89,42 +53,36 @@ def transfer_replica(source, target, collection_name, num_replica): utility.transfer_replica( source, target, collection_name, num_replica, using=_CONNECTION_NAME) -def load_collection_for_transfer(): +def run(): + create_connection("root", "123456") coll = create_collection(_COLLECTION_NAME, _ID_FIELD_NAME, _VECTOR_FIELD_NAME) vectors = insert(coll, 10000, _DIM) coll.flush() create_index(coll, _VECTOR_FIELD_NAME) - load_collection(coll) - -def run(): - create_connection("root", "123456") - # create_rbac_user() - # create_connection(_USER, _PASSWD) - # load_collection_for_transfer() create_resource_group("rg") list_resource_groups() describe_resource_group("rg") - transfer_node("__default_resource_group", "rg", 1) - describe_resource_group("__default_resource_group") + transfer_node(DEFAULT_RESOURCE_GROUP, "rg", 1) + describe_resource_group(DEFAULT_RESOURCE_GROUP) describe_resource_group("rg") + release_collection(coll) + coll.load(_resource_groups=["rg"]) + print("load finish") - transfer_node("rg", "__default_resource_group", 1) - describe_resource_group("__default_resource_group") + transfer_node("rg", DEFAULT_RESOURCE_GROUP, 1) + describe_resource_group(DEFAULT_RESOURCE_GROUP) describe_resource_group("rg") - - describe_resource_group("__default_resource_group") + describe_resource_group(DEFAULT_RESOURCE_GROUP) describe_resource_group("rg") - # transfer_replica("__default_resource_group", "rg", _COLLECTION_NAME, 1) - describe_resource_group("__default_resource_group") + transfer_replica("rg", DEFAULT_RESOURCE_GROUP, _COLLECTION_NAME, 1) + describe_resource_group(DEFAULT_RESOURCE_GROUP) describe_resource_group("rg") drop_resource_group("rg") - - # release_collection(coll) - # drop_collection(_COLLECTION_NAME) - # remove_rbac_user() + release_collection(coll) + drop_collection(_COLLECTION_NAME) if __name__ == "__main__": run() diff --git a/pymilvus/__init__.py b/pymilvus/__init__.py index 8704bdef8..72e94648a 100644 --- a/pymilvus/__init__.py +++ b/pymilvus/__init__.py @@ -58,7 +58,7 @@ ) from .orm import utility -from .orm.default_config import DefaultConfig, ENV_CONNECTION_CONF +from .orm.default_config import DefaultConfig, ENV_CONNECTION_CONF, DEFAULT_RESOURCE_GROUP from .orm.search import SearchResult, Hits, Hit from .orm.schema import FieldSchema, CollectionSchema diff --git a/pymilvus/client/grpc_handler.py b/pymilvus/client/grpc_handler.py index 8d8b21ff8..12845b326 100644 --- a/pymilvus/client/grpc_handler.py +++ b/pymilvus/client/grpc_handler.py @@ -291,7 +291,7 @@ def drop_partition(self, collection_name, partition_name, timeout=None): raise MilvusException(response.error_code, response.reason) @retry_on_rpc_failure() - def has_partition(self, collection_name, partition_name, timeout=None): + def has_partition(self, collection_name, partition_name, timeout=None, **kwargs): check_pass_param(collection_name=collection_name, partition_name=partition_name) request = Prepare.has_partition_request(collection_name, partition_name) rf = self._stub.HasPartition.future(request, timeout=timeout)