-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
neofs-cli/control: support
ObjectStatus
control command
It is the second command related to object operations, so additional `object` subcommand seems reasonable, in the future, the others can be placed (move to) here too. Example: ``` ▶ neofs-cli control object status --endpoint s01.neofs.devenv:8081 -w services/storage/wallet01.json --object EnCqHUUwS6vd2MENDe1MvjiXv9jADF8iA1vZimpjJpYt/AWUFtrRLU8NkPVyF3b5WjMXUe8awxPdHtNvSRpKqEaFq Enter password > Shard ID: 66cJzDxA4hqqF3YKFiqFyc metabase: AVAILABLE peapod: Path: "/storage/peapod1.db" ``` Closes #2886. Signed-off-by: Pavel Karpy <[email protected]>
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package control | ||
|
||
import ( | ||
"fmt" | ||
|
||
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" | ||
"github.com/nspcc-dev/neofs-node/pkg/services/control" | ||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const objectFlag = "object" | ||
|
||
var objectCmd = &cobra.Command{ | ||
Use: "object", | ||
Short: "Direct object operations with storage engine", | ||
} | ||
|
||
var objectStatusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "Check current object status", | ||
Args: cobra.NoArgs, | ||
SilenceUsage: true, | ||
RunE: objectStatus, | ||
} | ||
|
||
func objectStatus(cmd *cobra.Command, _ []string) error { | ||
ctx, cancel := commonflags.GetCommandContext(cmd) | ||
defer cancel() | ||
|
||
pk := key.Get(cmd) | ||
addressRaw, err := cmd.Flags().GetString(objectFlag) | ||
if err != nil { | ||
return fmt.Errorf("reading %s flag: %w", objectFlag, err) | ||
} | ||
|
||
var sdkAddr oid.Address | ||
err = sdkAddr.DecodeString(addressRaw) | ||
if err != nil { | ||
return fmt.Errorf("validating address (%s): %w", addressRaw, err) | ||
} | ||
|
||
var resp *control.ObjectStatusResponse | ||
req := &control.ObjectStatusRequest{ | ||
Body: &control.ObjectStatusRequest_Body{ | ||
ObjectAddress: addressRaw, | ||
}, | ||
} | ||
signRequest(cmd, pk, req) | ||
|
||
cli := getClient(ctx, cmd) | ||
|
||
err = cli.ExecRaw(func(client *rawclient.Client) error { | ||
resp, err = control.ObjectStatus(client, req) | ||
return err | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("rpc error: %w", err) | ||
} | ||
|
||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) | ||
|
||
shards := resp.GetBody().GetShards() | ||
if len(shards) == 0 { | ||
cmd.Println("<emtpy response>") | ||
return nil | ||
} | ||
|
||
for _, shard := range shards { | ||
cmd.Printf("Shard ID: %s\n", shard.ShardId) | ||
storages := shard.GetStorages() | ||
if len(storages) == 0 { | ||
cmd.Println("\t<emtpy response>") | ||
continue | ||
} | ||
|
||
for _, storage := range storages { | ||
cmd.Printf("\t%s: %s\n", storage.Type, storage.Status) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func initObjectStatusFlags() { | ||
initControlFlags(objectStatusCmd) | ||
|
||
flags := objectStatusCmd.Flags() | ||
flags.String(objectFlag, "", "Object address") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters