2021-11-06 00:39:41 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2021-11-08 08:09:11 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
2022-05-29 23:37:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2021-11-06 00:39:41 +00:00
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Commands = append(Commands, &commandClusterPs{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type commandClusterPs struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandClusterPs) Name() string {
|
|
|
|
return "cluster.ps"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandClusterPs) Help() string {
|
|
|
|
return `check current cluster process status
|
|
|
|
|
|
|
|
cluster.ps
|
|
|
|
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
|
|
|
|
clusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
|
|
if err = clusterPsCommand.Parse(args); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-29 23:37:14 +00:00
|
|
|
var filerNodes []*master_pb.ListClusterNodesResponse_ClusterNode
|
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
|
2021-11-06 00:39:41 +00:00
|
|
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
2021-11-08 08:09:11 +00:00
|
|
|
ClientType: cluster.FilerType,
|
2022-05-02 04:59:16 +00:00
|
|
|
FilerGroup: *commandEnv.option.FilerGroup,
|
2021-11-06 00:39:41 +00:00
|
|
|
})
|
2022-05-29 23:37:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-11-06 00:39:41 +00:00
|
|
|
}
|
2022-05-29 23:37:14 +00:00
|
|
|
|
|
|
|
filerNodes = resp.ClusterNodes
|
2021-11-06 00:39:41 +00:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-29 23:37:14 +00:00
|
|
|
fmt.Fprintf(writer, "the cluster has %d filers\n", len(filerNodes))
|
|
|
|
for _, node := range filerNodes {
|
|
|
|
fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
|
|
|
|
pb.WithFilerClient(false, pb.ServerAddress(node.Address), commandEnv.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{})
|
|
|
|
if err == nil {
|
|
|
|
if resp.FilerGroup != "" {
|
|
|
|
fmt.Fprintf(writer, " filer group: %s\n", resp.FilerGroup)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(writer, " signature: %d\n", resp.Signature)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(writer, " failed to connect: %v\n", err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-11-06 00:39:41 +00:00
|
|
|
return nil
|
|
|
|
}
|