alias.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Licensed to the LF AI & Data foundation under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. package client
  17. import (
  18. "context"
  19. "google.golang.org/grpc"
  20. "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
  21. "github.com/milvus-io/milvus/client/v2/entity"
  22. "github.com/milvus-io/milvus/pkg/util/merr"
  23. )
  24. func (c *Client) CreateAlias(ctx context.Context, option CreateAliasOption, callOptions ...grpc.CallOption) error {
  25. req := option.Request()
  26. return c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  27. resp, err := milvusService.CreateAlias(ctx, req, callOptions...)
  28. return merr.CheckRPCCall(resp, err)
  29. })
  30. }
  31. func (c *Client) DescribeAlias(ctx context.Context, option DescribeAliasOption, callOptions ...grpc.CallOption) (*entity.Alias, error) {
  32. req := option.Request()
  33. var alias *entity.Alias
  34. err := c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  35. resp, err := milvusService.DescribeAlias(ctx, req, callOptions...)
  36. if err := merr.CheckRPCCall(resp, err); err != nil {
  37. return err
  38. }
  39. alias = &entity.Alias{
  40. DbName: resp.GetDbName(),
  41. Alias: resp.GetAlias(),
  42. CollectionName: resp.GetCollection(),
  43. }
  44. return nil
  45. })
  46. return alias, err
  47. }
  48. func (c *Client) DropAlias(ctx context.Context, option DropAliasOption, callOptions ...grpc.CallOption) error {
  49. req := option.Request()
  50. return c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  51. resp, err := milvusService.DropAlias(ctx, req, callOptions...)
  52. return merr.CheckRPCCall(resp, err)
  53. })
  54. }
  55. func (c *Client) AlterAlias(ctx context.Context, option AlterAliasOption, callOptions ...grpc.CallOption) error {
  56. req := option.Request()
  57. return c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  58. resp, err := milvusService.AlterAlias(ctx, req, callOptions...)
  59. return merr.CheckRPCCall(resp, err)
  60. })
  61. }
  62. func (c *Client) ListAliases(ctx context.Context, option ListAliasesOption, callOptions ...grpc.CallOption) ([]string, error) {
  63. req := option.Request()
  64. var aliases []string
  65. err := c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  66. resp, err := milvusService.ListAliases(ctx, req, callOptions...)
  67. if err := merr.CheckRPCCall(resp, err); err != nil {
  68. return err
  69. }
  70. aliases = resp.GetAliases()
  71. return nil
  72. })
  73. return aliases, err
  74. }