mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-08-24 07:49:15 +08:00
refactoring
This commit is contained in:
parent
f6a9ad8001
commit
d84c311699
@ -55,6 +55,7 @@ func runShell(command *Command, args []string) bool {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(*shellInitialFiler)
|
shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(*shellInitialFiler)
|
||||||
|
shellOptions.FilerAddress = *shellInitialFiler
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("failed to parse filer %s: %v\n", *shellInitialFiler, err)
|
fmt.Printf("failed to parse filer %s: %v\n", *shellInitialFiler, err)
|
||||||
return false
|
return false
|
||||||
|
26
weed/remote_storage/mount_mapping.go
Normal file
26
weed/remote_storage/mount_mapping.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package remote_storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ReadMountMappings(grpcDialOption grpc.DialOption, filerAddress string) (mappings *filer_pb.RemoteStorageMapping, readErr error) {
|
||||||
|
var oldContent []byte
|
||||||
|
if readErr = pb.WithFilerClient(filerAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
oldContent, readErr = filer.ReadInsideFiler(client, filer.DirectoryEtcRemote, filer.REMOTE_STORAGE_MOUNT_FILE)
|
||||||
|
return readErr
|
||||||
|
}); readErr != nil {
|
||||||
|
return nil, readErr
|
||||||
|
}
|
||||||
|
|
||||||
|
mappings, readErr = filer.UnmarshalRemoteStorageMappings(oldContent)
|
||||||
|
if readErr != nil {
|
||||||
|
return nil, fmt.Errorf("unmarshal mappings: %v", readErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
@ -228,6 +228,7 @@ func (ms *MasterServer) startAdminScripts() {
|
|||||||
shellOptions.Masters = &masterAddress
|
shellOptions.Masters = &masterAddress
|
||||||
|
|
||||||
shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(filerHostPort)
|
shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(filerHostPort)
|
||||||
|
shellOptions.FilerAddress = filerHostPort
|
||||||
shellOptions.Directory = "/"
|
shellOptions.Directory = "/"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("failed to parse master.filer.default = %s : %v\n", filerHostPort, err)
|
glog.V(0).Infof("failed to parse master.filer.default = %s : %v\n", filerHostPort, err)
|
||||||
|
@ -79,20 +79,9 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io
|
|||||||
func (c *commandRemoteMount) listExistingRemoteStorageMounts(commandEnv *CommandEnv, writer io.Writer) (err error) {
|
func (c *commandRemoteMount) listExistingRemoteStorageMounts(commandEnv *CommandEnv, writer io.Writer) (err error) {
|
||||||
|
|
||||||
// read current mapping
|
// read current mapping
|
||||||
var oldContent []byte
|
mappings, readErr := remote_storage.ReadMountMappings(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress)
|
||||||
err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
if readErr != nil {
|
||||||
oldContent, err = filer.ReadInsideFiler(client, filer.DirectoryEtcRemote, filer.REMOTE_STORAGE_MOUNT_FILE)
|
return readErr
|
||||||
return err
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
if err != filer_pb.ErrNotFound {
|
|
||||||
return fmt.Errorf("read existing mapping: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mappings, unmarshalErr := filer.UnmarshalRemoteStorageMappings(oldContent)
|
|
||||||
if unmarshalErr != nil {
|
|
||||||
return unmarshalErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m := jsonpb.Marshaler{
|
m := jsonpb.Marshaler{
|
||||||
|
@ -20,9 +20,10 @@ type ShellOptions struct {
|
|||||||
Masters *string
|
Masters *string
|
||||||
GrpcDialOption grpc.DialOption
|
GrpcDialOption grpc.DialOption
|
||||||
// shell transient context
|
// shell transient context
|
||||||
FilerHost string
|
FilerHost string
|
||||||
FilerPort int64
|
FilerPort int64
|
||||||
Directory string
|
FilerAddress string
|
||||||
|
Directory string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandEnv struct {
|
type CommandEnv struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user