github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/resource_group.go (about) 1 // Copyright (C) 2019-2021 Zilliz. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance 4 // with the License. You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software distributed under the License 9 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 10 // or implied. See the License for the specific language governing permissions and limitations under the License. 11 12 package client 13 14 import ( 15 "context" 16 17 "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" 18 "github.com/milvus-io/milvus-sdk-go/v2/entity" 19 ) 20 21 // ListResourceGroups returns list of resource group names in current Milvus instance. 22 func (c *GrpcClient) ListResourceGroups(ctx context.Context) ([]string, error) { 23 if c.Service == nil { 24 return nil, ErrClientNotReady 25 } 26 27 req := &milvuspb.ListResourceGroupsRequest{} 28 29 resp, err := c.Service.ListResourceGroups(ctx, req) 30 if err != nil { 31 return nil, err 32 } 33 if err = handleRespStatus(resp.GetStatus()); err != nil { 34 return nil, err 35 } 36 37 return resp.GetResourceGroups(), nil 38 } 39 40 // CreateResourceGroup creates a resource group with provided name. 41 func (c *GrpcClient) CreateResourceGroup(ctx context.Context, rgName string) error { 42 if c.Service == nil { 43 return ErrClientNotReady 44 } 45 46 req := &milvuspb.CreateResourceGroupRequest{ 47 ResourceGroup: rgName, 48 } 49 50 resp, err := c.Service.CreateResourceGroup(ctx, req) 51 if err != nil { 52 return err 53 } 54 return handleRespStatus(resp) 55 } 56 57 // DescribeResourceGroup returns resource groups information. 58 func (c *GrpcClient) DescribeResourceGroup(ctx context.Context, rgName string) (*entity.ResourceGroup, error) { 59 if c.Service == nil { 60 return nil, ErrClientNotReady 61 } 62 63 req := &milvuspb.DescribeResourceGroupRequest{ 64 ResourceGroup: rgName, 65 } 66 67 resp, err := c.Service.DescribeResourceGroup(ctx, req) 68 if err != nil { 69 return nil, err 70 } 71 if err = handleRespStatus(resp.GetStatus()); err != nil { 72 return nil, err 73 } 74 75 rg := resp.GetResourceGroup() 76 result := &entity.ResourceGroup{ 77 Name: rg.GetName(), 78 Capacity: rg.GetCapacity(), 79 AvailableNodesNumber: rg.GetNumAvailableNode(), 80 LoadedReplica: rg.GetNumLoadedReplica(), 81 OutgoingNodeNum: rg.GetNumOutgoingNode(), 82 IncomingNodeNum: rg.GetNumIncomingNode(), 83 } 84 85 return result, nil 86 } 87 88 // DropResourceGroup drops the resource group with provided name. 89 func (c *GrpcClient) DropResourceGroup(ctx context.Context, rgName string) error { 90 if c.Service == nil { 91 return ErrClientNotReady 92 } 93 94 req := &milvuspb.DropResourceGroupRequest{ 95 ResourceGroup: rgName, 96 } 97 98 resp, err := c.Service.DropResourceGroup(ctx, req) 99 if err != nil { 100 return err 101 } 102 return handleRespStatus(resp) 103 } 104 105 // TransferNode transfers querynodes between resource groups. 106 func (c *GrpcClient) TransferNode(ctx context.Context, sourceRg, targetRg string, nodesNum int32) error { 107 if c.Service == nil { 108 return ErrClientNotReady 109 } 110 111 req := &milvuspb.TransferNodeRequest{ 112 SourceResourceGroup: sourceRg, 113 TargetResourceGroup: targetRg, 114 NumNode: nodesNum, 115 } 116 117 resp, err := c.Service.TransferNode(ctx, req) 118 if err != nil { 119 return err 120 } 121 return handleRespStatus(resp) 122 } 123 124 // TransferReplica transfer collection replicas between source,target resource group. 125 func (c *GrpcClient) TransferReplica(ctx context.Context, sourceRg, targetRg string, collectionName string, replicaNum int64) error { 126 if c.Service == nil { 127 return ErrClientNotReady 128 } 129 130 req := &milvuspb.TransferReplicaRequest{ 131 SourceResourceGroup: sourceRg, 132 TargetResourceGroup: targetRg, 133 CollectionName: collectionName, 134 NumReplica: replicaNum, 135 } 136 137 resp, err := c.Service.TransferReplica(ctx, req) 138 if err != nil { 139 return err 140 } 141 return handleRespStatus(resp) 142 }