aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_remote_mount.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-07-31 22:39:38 -0700
committerChris Lu <chris.lu@gmail.com>2021-07-31 22:39:38 -0700
commit9df7d16791351f85ecb364b4b11caca1ee9bcd59 (patch)
tree05e0569a43d1fb36676e4d6c456c9312f97eaa33 /weed/shell/command_remote_mount.go
parentf5a69a0e4423db70cffb3501c05bf5d4ed593370 (diff)
downloadseaweedfs-9df7d16791351f85ecb364b4b11caca1ee9bcd59.tar.xz
seaweedfs-9df7d16791351f85ecb364b4b11caca1ee9bcd59.zip
read <- remote_storage
Diffstat (limited to 'weed/shell/command_remote_mount.go')
-rw-r--r--weed/shell/command_remote_mount.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/weed/shell/command_remote_mount.go b/weed/shell/command_remote_mount.go
index 8f16d27c8..bd6b49050 100644
--- a/weed/shell/command_remote_mount.go
+++ b/weed/shell/command_remote_mount.go
@@ -8,6 +8,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/remote_storage"
"github.com/chrislusf/seaweedfs/weed/util"
+ "github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"io"
)
@@ -49,6 +50,10 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io
return nil
}
+ if *dir == "" {
+ return c.listExistingRemoteStorageMounts(commandEnv, writer)
+ }
+
remoteStorageLocation := remote_storage.ParseLocation(*remote)
// find configuration for remote storage
@@ -71,6 +76,34 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io
return nil
}
+func (c *commandRemoteMount) listExistingRemoteStorageMounts(commandEnv *CommandEnv, writer io.Writer) (err error) {
+
+ // read current mapping
+ var oldContent []byte
+ err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
+ oldContent, err = filer.ReadInsideFiler(client, filer.DirectoryEtcRemote, filer.REMOTE_STORAGE_MOUNT_FILE)
+ 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{
+ EmitDefaults: false,
+ Indent: " ",
+ }
+
+ return m.Marshal(writer, mappings)
+
+}
+
func (c *commandRemoteMount) findRemoteStorageConfiguration(commandEnv *CommandEnv, writer io.Writer, remote *filer_pb.RemoteStorageLocation) (conf *filer_pb.RemoteConf, err error) {
// read storage configuration data
@@ -178,7 +211,7 @@ func (c *commandRemoteMount) pullMetadata(commandEnv *CommandEnv, writer io.Writ
existingEntry.Attributes.Mtime = remoteEntry.LastModifiedAt
_, updateErr := client.UpdateEntry(ctx, &filer_pb.UpdateEntryRequest{
Directory: localDir,
- Entry: existingEntry,
+ Entry: existingEntry,
})
return updateErr
}
@@ -210,7 +243,7 @@ func (c *commandRemoteMount) saveMountMapping(commandEnv *CommandEnv, writer io.
}
// add new mapping
- newContent, err = filer.AddMapping(oldContent, dir, remoteStorageLocation)
+ newContent, err = filer.AddRemoteStorageMapping(oldContent, dir, remoteStorageLocation)
if err != nil {
return fmt.Errorf("add mapping %s~%s: %v", dir, remoteStorageLocation, err)
}