diff --git a/go/cmd/vtctldclient/commands.go b/go/cmd/vtctldclient/commands.go index 951b04f8679..8603489c6a2 100644 --- a/go/cmd/vtctldclient/commands.go +++ b/go/cmd/vtctldclient/commands.go @@ -17,8 +17,8 @@ limitations under the License. package main import ( - "encoding/json" "fmt" + "strings" "github.com/spf13/cobra" @@ -32,6 +32,21 @@ var ( Args: cobra.ExactArgs(1), RunE: commandFindAllShardsInKeyspace, } + getCellInfoNamesCmd = &cobra.Command{ + Use: "GetCellInfoNames", + Args: cobra.NoArgs, + RunE: commandGetCellInfoNames, + } + getCellInfoCmd = &cobra.Command{ + Use: "GetCellInfo cell", + Args: cobra.ExactArgs(1), + RunE: commandGetCellInfo, + } + getCellsAliasesCmd = &cobra.Command{ + Use: "GetCellsAliases", + Args: cobra.NoArgs, + RunE: commandGetCellsAliases, + } getKeyspaceCmd = &cobra.Command{ Use: "GetKeyspace keyspace", Aliases: []string{"getkeyspace"}, @@ -56,7 +71,7 @@ func commandFindAllShardsInKeyspace(cmd *cobra.Command, args []string) error { return err } - data, err := json.Marshal(&resp) + data, err := MarshalJSON(resp) if err != nil { return err } @@ -65,6 +80,51 @@ func commandFindAllShardsInKeyspace(cmd *cobra.Command, args []string) error { return nil } +func commandGetCellInfoNames(cmd *cobra.Command, args []string) error { + resp, err := client.GetCellInfoNames(commandCtx, &vtctldatapb.GetCellInfoNamesRequest{}) + if err != nil { + return err + } + + fmt.Printf("%s\n", strings.Join(resp.Names, "\n")) + + return nil +} + +func commandGetCellInfo(cmd *cobra.Command, args []string) error { + cell := cmd.Flags().Arg(0) + resp, err := client.GetCellInfo(commandCtx, &vtctldatapb.GetCellInfoRequest{Cell: cell}) + + if err != nil { + return err + } + + data, err := MarshalJSON(resp.CellInfo) + if err != nil { + return err + } + + fmt.Printf("%s\n", data) + + return nil +} + +func commandGetCellsAliases(cmd *cobra.Command, args []string) error { + resp, err := client.GetCellsAliases(commandCtx, &vtctldatapb.GetCellsAliasesRequest{}) + if err != nil { + return err + } + + data, err := MarshalJSON(resp.Aliases) + if err != nil { + return err + } + + fmt.Printf("%s\n", data) + + return nil +} + func commandGetKeyspace(cmd *cobra.Command, args []string) error { ks := cmd.Flags().Arg(0) resp, err := client.GetKeyspace(commandCtx, &vtctldatapb.GetKeyspaceRequest{ @@ -86,13 +146,21 @@ func commandGetKeyspaces(cmd *cobra.Command, args []string) error { return err } - fmt.Printf("%+v\n", resp.Keyspaces) + data, err := MarshalJSON(resp.Keyspaces) + if err != nil { + return err + } + + fmt.Printf("%s\n", data) return nil } func init() { rootCmd.AddCommand(findAllShardsInKeyspaceCmd) + rootCmd.AddCommand(getCellInfoNamesCmd) + rootCmd.AddCommand(getCellInfoCmd) + rootCmd.AddCommand(getCellsAliasesCmd) rootCmd.AddCommand(getKeyspaceCmd) rootCmd.AddCommand(getKeyspacesCmd) } diff --git a/go/cmd/vtctldclient/json.go b/go/cmd/vtctldclient/json.go new file mode 100644 index 00000000000..b7cb3eeff0e --- /dev/null +++ b/go/cmd/vtctldclient/json.go @@ -0,0 +1,61 @@ +/* +Copyright 2021 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "bytes" + "encoding/json" + "fmt" + + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" +) + +// MarshalJSON marshals obj to a JSON string. It uses the jsonpb marshaler for +// proto.Message types, with some sensible defaults, and falls back to the +// standard Go marshaler otherwise. In both cases, the marshaled JSON is +// indented with two spaces for readability. +// +// Unfortunately jsonpb only works for types that implement proto.Message, +// either by being a proto message type or by anonymously embedding one, so for +// other types that may have nested struct fields, we still use the standard Go +// marshaler, which will result in different formattings. +func MarshalJSON(obj interface{}) ([]byte, error) { + switch obj := obj.(type) { + case proto.Message: + b := bytes.NewBuffer(nil) + m := jsonpb.Marshaler{ + EnumsAsInts: false, + EmitDefaults: true, + Indent: " ", + OrigName: true, + } + + if err := m.Marshal(b, obj); err != nil { + return nil, fmt.Errorf("jsonpb.Marshal = %v", err) + } + + return b.Bytes(), nil + default: + data, err := json.MarshalIndent(obj, "", " ") + if err != nil { + return nil, fmt.Errorf("json.Marshal = %v", err) + } + + return data, nil + } +} diff --git a/go/vt/proto/vtctldata/vtctldata.pb.go b/go/vt/proto/vtctldata/vtctldata.pb.go index aba0d093fd3..90d7811045a 100644 --- a/go/vt/proto/vtctldata/vtctldata.pb.go +++ b/go/vt/proto/vtctldata/vtctldata.pb.go @@ -112,6 +112,224 @@ func (m *ExecuteVtctlCommandResponse) GetEvent() *logutil.Event { return nil } +type GetCellInfoNamesRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCellInfoNamesRequest) Reset() { *m = GetCellInfoNamesRequest{} } +func (m *GetCellInfoNamesRequest) String() string { return proto.CompactTextString(m) } +func (*GetCellInfoNamesRequest) ProtoMessage() {} +func (*GetCellInfoNamesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{2} +} + +func (m *GetCellInfoNamesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCellInfoNamesRequest.Unmarshal(m, b) +} +func (m *GetCellInfoNamesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCellInfoNamesRequest.Marshal(b, m, deterministic) +} +func (m *GetCellInfoNamesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCellInfoNamesRequest.Merge(m, src) +} +func (m *GetCellInfoNamesRequest) XXX_Size() int { + return xxx_messageInfo_GetCellInfoNamesRequest.Size(m) +} +func (m *GetCellInfoNamesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetCellInfoNamesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCellInfoNamesRequest proto.InternalMessageInfo + +type GetCellInfoNamesResponse struct { + Names []string `protobuf:"bytes,1,rep,name=names,proto3" json:"names,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCellInfoNamesResponse) Reset() { *m = GetCellInfoNamesResponse{} } +func (m *GetCellInfoNamesResponse) String() string { return proto.CompactTextString(m) } +func (*GetCellInfoNamesResponse) ProtoMessage() {} +func (*GetCellInfoNamesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{3} +} + +func (m *GetCellInfoNamesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCellInfoNamesResponse.Unmarshal(m, b) +} +func (m *GetCellInfoNamesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCellInfoNamesResponse.Marshal(b, m, deterministic) +} +func (m *GetCellInfoNamesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCellInfoNamesResponse.Merge(m, src) +} +func (m *GetCellInfoNamesResponse) XXX_Size() int { + return xxx_messageInfo_GetCellInfoNamesResponse.Size(m) +} +func (m *GetCellInfoNamesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetCellInfoNamesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCellInfoNamesResponse proto.InternalMessageInfo + +func (m *GetCellInfoNamesResponse) GetNames() []string { + if m != nil { + return m.Names + } + return nil +} + +type GetCellInfoRequest struct { + Cell string `protobuf:"bytes,1,opt,name=cell,proto3" json:"cell,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCellInfoRequest) Reset() { *m = GetCellInfoRequest{} } +func (m *GetCellInfoRequest) String() string { return proto.CompactTextString(m) } +func (*GetCellInfoRequest) ProtoMessage() {} +func (*GetCellInfoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{4} +} + +func (m *GetCellInfoRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCellInfoRequest.Unmarshal(m, b) +} +func (m *GetCellInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCellInfoRequest.Marshal(b, m, deterministic) +} +func (m *GetCellInfoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCellInfoRequest.Merge(m, src) +} +func (m *GetCellInfoRequest) XXX_Size() int { + return xxx_messageInfo_GetCellInfoRequest.Size(m) +} +func (m *GetCellInfoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetCellInfoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCellInfoRequest proto.InternalMessageInfo + +func (m *GetCellInfoRequest) GetCell() string { + if m != nil { + return m.Cell + } + return "" +} + +type GetCellInfoResponse struct { + CellInfo *topodata.CellInfo `protobuf:"bytes,1,opt,name=cell_info,json=cellInfo,proto3" json:"cell_info,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCellInfoResponse) Reset() { *m = GetCellInfoResponse{} } +func (m *GetCellInfoResponse) String() string { return proto.CompactTextString(m) } +func (*GetCellInfoResponse) ProtoMessage() {} +func (*GetCellInfoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{5} +} + +func (m *GetCellInfoResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCellInfoResponse.Unmarshal(m, b) +} +func (m *GetCellInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCellInfoResponse.Marshal(b, m, deterministic) +} +func (m *GetCellInfoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCellInfoResponse.Merge(m, src) +} +func (m *GetCellInfoResponse) XXX_Size() int { + return xxx_messageInfo_GetCellInfoResponse.Size(m) +} +func (m *GetCellInfoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetCellInfoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCellInfoResponse proto.InternalMessageInfo + +func (m *GetCellInfoResponse) GetCellInfo() *topodata.CellInfo { + if m != nil { + return m.CellInfo + } + return nil +} + +type GetCellsAliasesRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCellsAliasesRequest) Reset() { *m = GetCellsAliasesRequest{} } +func (m *GetCellsAliasesRequest) String() string { return proto.CompactTextString(m) } +func (*GetCellsAliasesRequest) ProtoMessage() {} +func (*GetCellsAliasesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{6} +} + +func (m *GetCellsAliasesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCellsAliasesRequest.Unmarshal(m, b) +} +func (m *GetCellsAliasesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCellsAliasesRequest.Marshal(b, m, deterministic) +} +func (m *GetCellsAliasesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCellsAliasesRequest.Merge(m, src) +} +func (m *GetCellsAliasesRequest) XXX_Size() int { + return xxx_messageInfo_GetCellsAliasesRequest.Size(m) +} +func (m *GetCellsAliasesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetCellsAliasesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCellsAliasesRequest proto.InternalMessageInfo + +type GetCellsAliasesResponse struct { + Aliases map[string]*topodata.CellsAlias `protobuf:"bytes,1,rep,name=aliases,proto3" json:"aliases,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCellsAliasesResponse) Reset() { *m = GetCellsAliasesResponse{} } +func (m *GetCellsAliasesResponse) String() string { return proto.CompactTextString(m) } +func (*GetCellsAliasesResponse) ProtoMessage() {} +func (*GetCellsAliasesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{7} +} + +func (m *GetCellsAliasesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCellsAliasesResponse.Unmarshal(m, b) +} +func (m *GetCellsAliasesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCellsAliasesResponse.Marshal(b, m, deterministic) +} +func (m *GetCellsAliasesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCellsAliasesResponse.Merge(m, src) +} +func (m *GetCellsAliasesResponse) XXX_Size() int { + return xxx_messageInfo_GetCellsAliasesResponse.Size(m) +} +func (m *GetCellsAliasesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetCellsAliasesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCellsAliasesResponse proto.InternalMessageInfo + +func (m *GetCellsAliasesResponse) GetAliases() map[string]*topodata.CellsAlias { + if m != nil { + return m.Aliases + } + return nil +} + type GetKeyspacesRequest struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -122,7 +340,7 @@ func (m *GetKeyspacesRequest) Reset() { *m = GetKeyspacesRequest{} } func (m *GetKeyspacesRequest) String() string { return proto.CompactTextString(m) } func (*GetKeyspacesRequest) ProtoMessage() {} func (*GetKeyspacesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f41247b323a1ab2e, []int{2} + return fileDescriptor_f41247b323a1ab2e, []int{8} } func (m *GetKeyspacesRequest) XXX_Unmarshal(b []byte) error { @@ -154,7 +372,7 @@ func (m *GetKeyspacesResponse) Reset() { *m = GetKeyspacesResponse{} } func (m *GetKeyspacesResponse) String() string { return proto.CompactTextString(m) } func (*GetKeyspacesResponse) ProtoMessage() {} func (*GetKeyspacesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f41247b323a1ab2e, []int{3} + return fileDescriptor_f41247b323a1ab2e, []int{9} } func (m *GetKeyspacesResponse) XXX_Unmarshal(b []byte) error { @@ -193,7 +411,7 @@ func (m *GetKeyspaceRequest) Reset() { *m = GetKeyspaceRequest{} } func (m *GetKeyspaceRequest) String() string { return proto.CompactTextString(m) } func (*GetKeyspaceRequest) ProtoMessage() {} func (*GetKeyspaceRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f41247b323a1ab2e, []int{4} + return fileDescriptor_f41247b323a1ab2e, []int{10} } func (m *GetKeyspaceRequest) XXX_Unmarshal(b []byte) error { @@ -232,7 +450,7 @@ func (m *GetKeyspaceResponse) Reset() { *m = GetKeyspaceResponse{} } func (m *GetKeyspaceResponse) String() string { return proto.CompactTextString(m) } func (*GetKeyspaceResponse) ProtoMessage() {} func (*GetKeyspaceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f41247b323a1ab2e, []int{5} + return fileDescriptor_f41247b323a1ab2e, []int{11} } func (m *GetKeyspaceResponse) XXX_Unmarshal(b []byte) error { @@ -594,6 +812,13 @@ func (m *MaterializeSettings) GetTabletTypes() string { func init() { proto.RegisterType((*ExecuteVtctlCommandRequest)(nil), "vtctldata.ExecuteVtctlCommandRequest") proto.RegisterType((*ExecuteVtctlCommandResponse)(nil), "vtctldata.ExecuteVtctlCommandResponse") + proto.RegisterType((*GetCellInfoNamesRequest)(nil), "vtctldata.GetCellInfoNamesRequest") + proto.RegisterType((*GetCellInfoNamesResponse)(nil), "vtctldata.GetCellInfoNamesResponse") + proto.RegisterType((*GetCellInfoRequest)(nil), "vtctldata.GetCellInfoRequest") + proto.RegisterType((*GetCellInfoResponse)(nil), "vtctldata.GetCellInfoResponse") + proto.RegisterType((*GetCellsAliasesRequest)(nil), "vtctldata.GetCellsAliasesRequest") + proto.RegisterType((*GetCellsAliasesResponse)(nil), "vtctldata.GetCellsAliasesResponse") + proto.RegisterMapType((map[string]*topodata.CellsAlias)(nil), "vtctldata.GetCellsAliasesResponse.AliasesEntry") proto.RegisterType((*GetKeyspacesRequest)(nil), "vtctldata.GetKeyspacesRequest") proto.RegisterType((*GetKeyspacesResponse)(nil), "vtctldata.GetKeyspacesResponse") proto.RegisterType((*GetKeyspaceRequest)(nil), "vtctldata.GetKeyspaceRequest") diff --git a/go/vt/proto/vtctlservice/vtctlservice.pb.go b/go/vt/proto/vtctlservice/vtctlservice.pb.go index b22a1288dec..35d17c1efea 100644 --- a/go/vt/proto/vtctlservice/vtctlservice.pb.go +++ b/go/vt/proto/vtctlservice/vtctlservice.pb.go @@ -158,8 +158,17 @@ var _Vtctl_serviceDesc = grpc.ServiceDesc{ // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type VtctldClient interface { - // FindAllShardsInKeyspace returns a map of shard names to shard references for a given keyspace. + // FindAllShardsInKeyspace returns a map of shard names to shard references + // for a given keyspace. FindAllShardsInKeyspace(ctx context.Context, in *vtctldata.FindAllShardsInKeyspaceRequest, opts ...grpc.CallOption) (*vtctldata.FindAllShardsInKeyspaceResponse, error) + // GetCellInfoNames returns all the cells for which we have a CellInfo object, + // meaning we have a topology service registered. + GetCellInfoNames(ctx context.Context, in *vtctldata.GetCellInfoNamesRequest, opts ...grpc.CallOption) (*vtctldata.GetCellInfoNamesResponse, error) + // GetCellInfo returns the information for a cell. + GetCellInfo(ctx context.Context, in *vtctldata.GetCellInfoRequest, opts ...grpc.CallOption) (*vtctldata.GetCellInfoResponse, error) + // GetCellsAliases returns a mapping of cell alias to cells identified by that + // alias. + GetCellsAliases(ctx context.Context, in *vtctldata.GetCellsAliasesRequest, opts ...grpc.CallOption) (*vtctldata.GetCellsAliasesResponse, error) // GetKeyspace reads the given keyspace from the topo and returns it. GetKeyspace(ctx context.Context, in *vtctldata.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldata.GetKeyspaceResponse, error) // GetKeyspaces returns the keyspace struct of all keyspaces in the topo. @@ -183,6 +192,33 @@ func (c *vtctldClient) FindAllShardsInKeyspace(ctx context.Context, in *vtctldat return out, nil } +func (c *vtctldClient) GetCellInfoNames(ctx context.Context, in *vtctldata.GetCellInfoNamesRequest, opts ...grpc.CallOption) (*vtctldata.GetCellInfoNamesResponse, error) { + out := new(vtctldata.GetCellInfoNamesResponse) + err := c.cc.Invoke(ctx, "/vtctlservice.Vtctld/GetCellInfoNames", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vtctldClient) GetCellInfo(ctx context.Context, in *vtctldata.GetCellInfoRequest, opts ...grpc.CallOption) (*vtctldata.GetCellInfoResponse, error) { + out := new(vtctldata.GetCellInfoResponse) + err := c.cc.Invoke(ctx, "/vtctlservice.Vtctld/GetCellInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vtctldClient) GetCellsAliases(ctx context.Context, in *vtctldata.GetCellsAliasesRequest, opts ...grpc.CallOption) (*vtctldata.GetCellsAliasesResponse, error) { + out := new(vtctldata.GetCellsAliasesResponse) + err := c.cc.Invoke(ctx, "/vtctlservice.Vtctld/GetCellsAliases", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *vtctldClient) GetKeyspace(ctx context.Context, in *vtctldata.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldata.GetKeyspaceResponse, error) { out := new(vtctldata.GetKeyspaceResponse) err := c.cc.Invoke(ctx, "/vtctlservice.Vtctld/GetKeyspace", in, out, opts...) @@ -203,8 +239,17 @@ func (c *vtctldClient) GetKeyspaces(ctx context.Context, in *vtctldata.GetKeyspa // VtctldServer is the server API for Vtctld service. type VtctldServer interface { - // FindAllShardsInKeyspace returns a map of shard names to shard references for a given keyspace. + // FindAllShardsInKeyspace returns a map of shard names to shard references + // for a given keyspace. FindAllShardsInKeyspace(context.Context, *vtctldata.FindAllShardsInKeyspaceRequest) (*vtctldata.FindAllShardsInKeyspaceResponse, error) + // GetCellInfoNames returns all the cells for which we have a CellInfo object, + // meaning we have a topology service registered. + GetCellInfoNames(context.Context, *vtctldata.GetCellInfoNamesRequest) (*vtctldata.GetCellInfoNamesResponse, error) + // GetCellInfo returns the information for a cell. + GetCellInfo(context.Context, *vtctldata.GetCellInfoRequest) (*vtctldata.GetCellInfoResponse, error) + // GetCellsAliases returns a mapping of cell alias to cells identified by that + // alias. + GetCellsAliases(context.Context, *vtctldata.GetCellsAliasesRequest) (*vtctldata.GetCellsAliasesResponse, error) // GetKeyspace reads the given keyspace from the topo and returns it. GetKeyspace(context.Context, *vtctldata.GetKeyspaceRequest) (*vtctldata.GetKeyspaceResponse, error) // GetKeyspaces returns the keyspace struct of all keyspaces in the topo. @@ -218,6 +263,15 @@ type UnimplementedVtctldServer struct { func (*UnimplementedVtctldServer) FindAllShardsInKeyspace(ctx context.Context, req *vtctldata.FindAllShardsInKeyspaceRequest) (*vtctldata.FindAllShardsInKeyspaceResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method FindAllShardsInKeyspace not implemented") } +func (*UnimplementedVtctldServer) GetCellInfoNames(ctx context.Context, req *vtctldata.GetCellInfoNamesRequest) (*vtctldata.GetCellInfoNamesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCellInfoNames not implemented") +} +func (*UnimplementedVtctldServer) GetCellInfo(ctx context.Context, req *vtctldata.GetCellInfoRequest) (*vtctldata.GetCellInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCellInfo not implemented") +} +func (*UnimplementedVtctldServer) GetCellsAliases(ctx context.Context, req *vtctldata.GetCellsAliasesRequest) (*vtctldata.GetCellsAliasesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCellsAliases not implemented") +} func (*UnimplementedVtctldServer) GetKeyspace(ctx context.Context, req *vtctldata.GetKeyspaceRequest) (*vtctldata.GetKeyspaceResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetKeyspace not implemented") } @@ -247,6 +301,60 @@ func _Vtctld_FindAllShardsInKeyspace_Handler(srv interface{}, ctx context.Contex return interceptor(ctx, in, info, handler) } +func _Vtctld_GetCellInfoNames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(vtctldata.GetCellInfoNamesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VtctldServer).GetCellInfoNames(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/vtctlservice.Vtctld/GetCellInfoNames", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VtctldServer).GetCellInfoNames(ctx, req.(*vtctldata.GetCellInfoNamesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Vtctld_GetCellInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(vtctldata.GetCellInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VtctldServer).GetCellInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/vtctlservice.Vtctld/GetCellInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VtctldServer).GetCellInfo(ctx, req.(*vtctldata.GetCellInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Vtctld_GetCellsAliases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(vtctldata.GetCellsAliasesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VtctldServer).GetCellsAliases(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/vtctlservice.Vtctld/GetCellsAliases", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VtctldServer).GetCellsAliases(ctx, req.(*vtctldata.GetCellsAliasesRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Vtctld_GetKeyspace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(vtctldata.GetKeyspaceRequest) if err := dec(in); err != nil { @@ -291,6 +399,18 @@ var _Vtctld_serviceDesc = grpc.ServiceDesc{ MethodName: "FindAllShardsInKeyspace", Handler: _Vtctld_FindAllShardsInKeyspace_Handler, }, + { + MethodName: "GetCellInfoNames", + Handler: _Vtctld_GetCellInfoNames_Handler, + }, + { + MethodName: "GetCellInfo", + Handler: _Vtctld_GetCellInfo_Handler, + }, + { + MethodName: "GetCellsAliases", + Handler: _Vtctld_GetCellsAliases_Handler, + }, { MethodName: "GetKeyspace", Handler: _Vtctld_GetKeyspace_Handler, diff --git a/go/vt/vtctl/grpcvtctldclient/client_gen.go b/go/vt/vtctl/grpcvtctldclient/client_gen.go index cbe87b15d87..0c600794202 100644 --- a/go/vt/vtctl/grpcvtctldclient/client_gen.go +++ b/go/vt/vtctl/grpcvtctldclient/client_gen.go @@ -37,6 +37,33 @@ func (client *gRPCVtctldClient) FindAllShardsInKeyspace(ctx context.Context, in return client.c.FindAllShardsInKeyspace(ctx, in, opts...) } +// GetCellInfo is part of the vtctlservicepb.VtctldClient interface. +func (client *gRPCVtctldClient) GetCellInfo(ctx context.Context, in *vtctldatapb.GetCellInfoRequest, opts ...grpc.CallOption) (*vtctldatapb.GetCellInfoResponse, error) { + if client.c == nil { + return nil, status.Error(codes.Unavailable, connClosedMsg) + } + + return client.c.GetCellInfo(ctx, in, opts...) +} + +// GetCellInfoNames is part of the vtctlservicepb.VtctldClient interface. +func (client *gRPCVtctldClient) GetCellInfoNames(ctx context.Context, in *vtctldatapb.GetCellInfoNamesRequest, opts ...grpc.CallOption) (*vtctldatapb.GetCellInfoNamesResponse, error) { + if client.c == nil { + return nil, status.Error(codes.Unavailable, connClosedMsg) + } + + return client.c.GetCellInfoNames(ctx, in, opts...) +} + +// GetCellsAliases is part of the vtctlservicepb.VtctldClient interface. +func (client *gRPCVtctldClient) GetCellsAliases(ctx context.Context, in *vtctldatapb.GetCellsAliasesRequest, opts ...grpc.CallOption) (*vtctldatapb.GetCellsAliasesResponse, error) { + if client.c == nil { + return nil, status.Error(codes.Unavailable, connClosedMsg) + } + + return client.c.GetCellsAliases(ctx, in, opts...) +} + // GetKeyspace is part of the vtctlservicepb.VtctldClient interface. func (client *gRPCVtctldClient) GetKeyspace(ctx context.Context, in *vtctldatapb.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.GetKeyspaceResponse, error) { if client.c == nil { diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index 3814bc62165..04b4f0a1cc1 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -21,9 +21,11 @@ import ( "google.golang.org/grpc" "vitess.io/vitess/go/vt/topo" + "vitess.io/vitess/go/vt/vterrors" vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" vtctlservicepb "vitess.io/vitess/go/vt/proto/vtctlservice" + "vitess.io/vitess/go/vt/proto/vtrpc" ) // VtctldServer implements the Vtctld RPC service protocol. @@ -57,6 +59,44 @@ func (s *VtctldServer) FindAllShardsInKeyspace(ctx context.Context, req *vtctlda }, nil } +// GetCellInfoNames is part of the vtctlservicepb.VtctldServer interface. +func (s *VtctldServer) GetCellInfoNames(ctx context.Context, req *vtctldatapb.GetCellInfoNamesRequest) (*vtctldatapb.GetCellInfoNamesResponse, error) { + names, err := s.ts.GetCellInfoNames(ctx) + if err != nil { + return nil, err + } + + return &vtctldatapb.GetCellInfoNamesResponse{Names: names}, nil +} + +// GetCellInfo is part of the vtctlservicepb.VtctldServer interface. +func (s *VtctldServer) GetCellInfo(ctx context.Context, req *vtctldatapb.GetCellInfoRequest) (*vtctldatapb.GetCellInfoResponse, error) { + if req.Cell == "" { + return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "cell field is required") + } + + // We use a strong read, because users using this command want the latest + // data, and this is user-generated, not used in any automated process. + strongRead := true + ci, err := s.ts.GetCellInfo(ctx, req.Cell, strongRead) + if err != nil { + return nil, err + } + + return &vtctldatapb.GetCellInfoResponse{CellInfo: ci}, nil +} + +// GetCellsAliases is part of the vtctlservicepb.VtctldServer interface. +func (s *VtctldServer) GetCellsAliases(ctx context.Context, req *vtctldatapb.GetCellsAliasesRequest) (*vtctldatapb.GetCellsAliasesResponse, error) { + strongRead := true + aliases, err := s.ts.GetCellsAliases(ctx, strongRead) + if err != nil { + return nil, err + } + + return &vtctldatapb.GetCellsAliasesResponse{Aliases: aliases}, nil +} + // GetKeyspace is part of the vtctlservicepb.VtctldServer interface. func (s *VtctldServer) GetKeyspace(ctx context.Context, req *vtctldatapb.GetKeyspaceRequest) (*vtctldatapb.GetKeyspaceResponse, error) { keyspace, err := s.ts.GetKeyspace(ctx, req.Keyspace) diff --git a/proto/vtctldata.proto b/proto/vtctldata.proto index 1a7142ea09e..cd553e53c0d 100644 --- a/proto/vtctldata.proto +++ b/proto/vtctldata.proto @@ -37,6 +37,28 @@ message ExecuteVtctlCommandResponse { logutil.Event event = 1; } +message GetCellInfoNamesRequest { +} + +message GetCellInfoNamesResponse { + repeated string names = 1; +} + +message GetCellInfoRequest { + string cell = 1; +} + +message GetCellInfoResponse { + topodata.CellInfo cell_info = 1; +} + +message GetCellsAliasesRequest { +} + +message GetCellsAliasesResponse { + map aliases = 1; +} + message GetKeyspacesRequest { } diff --git a/proto/vtctlservice.proto b/proto/vtctlservice.proto index ebd82714774..4007550f587 100644 --- a/proto/vtctlservice.proto +++ b/proto/vtctlservice.proto @@ -31,8 +31,17 @@ service Vtctl { // Service Vtctld exposes gRPC endpoints for each vt command. service Vtctld { - // FindAllShardsInKeyspace returns a map of shard names to shard references for a given keyspace. + // FindAllShardsInKeyspace returns a map of shard names to shard references + // for a given keyspace. rpc FindAllShardsInKeyspace(vtctldata.FindAllShardsInKeyspaceRequest) returns (vtctldata.FindAllShardsInKeyspaceResponse) {}; + // GetCellInfoNames returns all the cells for which we have a CellInfo object, + // meaning we have a topology service registered. + rpc GetCellInfoNames(vtctldata.GetCellInfoNamesRequest) returns (vtctldata.GetCellInfoNamesResponse) {}; + // GetCellInfo returns the information for a cell. + rpc GetCellInfo(vtctldata.GetCellInfoRequest) returns (vtctldata.GetCellInfoResponse) {}; + // GetCellsAliases returns a mapping of cell alias to cells identified by that + // alias. + rpc GetCellsAliases(vtctldata.GetCellsAliasesRequest) returns (vtctldata.GetCellsAliasesResponse) {}; // GetKeyspace reads the given keyspace from the topo and returns it. rpc GetKeyspace(vtctldata.GetKeyspaceRequest) returns (vtctldata.GetKeyspaceResponse) {}; // GetKeyspaces returns the keyspace struct of all keyspaces in the topo.