use constants

This commit is contained in:
chrislu 2022-04-01 16:55:26 -07:00
parent bbbbbd70a4
commit 6d55716fc3
4 changed files with 16 additions and 12 deletions

View file

@ -9,9 +9,10 @@ import (
) )
const ( const (
MasterType = "master" MasterType = "master"
FilerType = "filer" VolumeServerType = "volumeServer"
BrokerType = "broker" FilerType = "filer"
BrokerType = "broker"
) )
type ClusterNode struct { type ClusterNode struct {

View file

@ -3,6 +3,7 @@ package weed_server
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/cluster"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
@ -43,19 +44,19 @@ func (fs *FilerServer) Statistics(ctx context.Context, req *filer_pb.StatisticsR
func (fs *FilerServer) Ping(ctx context.Context, req *filer_pb.PingRequest) (resp *filer_pb.PingResponse, pingErr error) { func (fs *FilerServer) Ping(ctx context.Context, req *filer_pb.PingRequest) (resp *filer_pb.PingResponse, pingErr error) {
resp = &filer_pb.PingResponse{} resp = &filer_pb.PingResponse{}
if req.TargetType == "Filer" { if req.TargetType == cluster.FilerType {
pingErr = pb.WithFilerClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { pingErr = pb.WithFilerClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
_, err := client.Ping(ctx, &filer_pb.PingRequest{}) _, err := client.Ping(ctx, &filer_pb.PingRequest{})
return err return err
}) })
} }
if req.TargetType == "VolumeServer" { if req.TargetType == cluster.VolumeServerType {
pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error { pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
_, err := client.Ping(ctx, &volume_server_pb.PingRequest{}) _, err := client.Ping(ctx, &volume_server_pb.PingRequest{})
return err return err
}) })
} }
if req.TargetType == "Master" { if req.TargetType == cluster.MasterType {
pingErr = pb.WithMasterClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client master_pb.SeaweedClient) error { pingErr = pb.WithMasterClient(false, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client master_pb.SeaweedClient) error {
_, err := client.Ping(ctx, &master_pb.PingRequest{}) _, err := client.Ping(ctx, &master_pb.PingRequest{})
return err return err

View file

@ -3,6 +3,7 @@ package weed_server
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/cluster"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
@ -148,19 +149,19 @@ func (ms *MasterServer) ReleaseAdminToken(ctx context.Context, req *master_pb.Re
func (ms *MasterServer) Ping(ctx context.Context, req *master_pb.PingRequest) (resp *master_pb.PingResponse, pingErr error) { func (ms *MasterServer) Ping(ctx context.Context, req *master_pb.PingRequest) (resp *master_pb.PingResponse, pingErr error) {
resp = &master_pb.PingResponse{} resp = &master_pb.PingResponse{}
if req.TargetType == "Filer" { if req.TargetType == cluster.FilerType {
pingErr = pb.WithFilerClient(false, pb.ServerAddress(req.Target), ms.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { pingErr = pb.WithFilerClient(false, pb.ServerAddress(req.Target), ms.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
_, err := client.Ping(ctx, &filer_pb.PingRequest{}) _, err := client.Ping(ctx, &filer_pb.PingRequest{})
return err return err
}) })
} }
if req.TargetType == "VolumeServer" { if req.TargetType == cluster.VolumeServerType {
pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), ms.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error { pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), ms.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
_, err := client.Ping(ctx, &volume_server_pb.PingRequest{}) _, err := client.Ping(ctx, &volume_server_pb.PingRequest{})
return err return err
}) })
} }
if req.TargetType == "Master" { if req.TargetType == cluster.MasterType {
pingErr = pb.WithMasterClient(false, pb.ServerAddress(req.Target), ms.grpcDialOption, func(client master_pb.SeaweedClient) error { pingErr = pb.WithMasterClient(false, pb.ServerAddress(req.Target), ms.grpcDialOption, func(client master_pb.SeaweedClient) error {
_, err := client.Ping(ctx, &master_pb.PingRequest{}) _, err := client.Ping(ctx, &master_pb.PingRequest{})
return err return err

View file

@ -3,6 +3,7 @@ package weed_server
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/cluster"
"github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
@ -253,19 +254,19 @@ func (vs *VolumeServer) VolumeNeedleStatus(ctx context.Context, req *volume_serv
func (vs *VolumeServer) Ping(ctx context.Context, req *volume_server_pb.PingRequest) (resp *volume_server_pb.PingResponse, pingErr error) { func (vs *VolumeServer) Ping(ctx context.Context, req *volume_server_pb.PingRequest) (resp *volume_server_pb.PingResponse, pingErr error) {
resp = &volume_server_pb.PingResponse{} resp = &volume_server_pb.PingResponse{}
if req.TargetType == "Filer" { if req.TargetType == cluster.FilerType {
pingErr = pb.WithFilerClient(false, pb.ServerAddress(req.Target), vs.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { pingErr = pb.WithFilerClient(false, pb.ServerAddress(req.Target), vs.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
_, err := client.Ping(ctx, &filer_pb.PingRequest{}) _, err := client.Ping(ctx, &filer_pb.PingRequest{})
return err return err
}) })
} }
if req.TargetType == "VolumeServer" { if req.TargetType == cluster.VolumeServerType {
pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), vs.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error { pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), vs.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
_, err := client.Ping(ctx, &volume_server_pb.PingRequest{}) _, err := client.Ping(ctx, &volume_server_pb.PingRequest{})
return err return err
}) })
} }
if req.TargetType == "Master" { if req.TargetType == cluster.MasterType {
pingErr = pb.WithMasterClient(false, pb.ServerAddress(req.Target), vs.grpcDialOption, func(client master_pb.SeaweedClient) error { pingErr = pb.WithMasterClient(false, pb.ServerAddress(req.Target), vs.grpcDialOption, func(client master_pb.SeaweedClient) error {
_, err := client.Ping(ctx, &master_pb.PingRequest{}) _, err := client.Ping(ctx, &master_pb.PingRequest{})
return err return err