Skip to content

Commit

Permalink
neofs-cli/control: support ObjectStatus control command
Browse files Browse the repository at this point in the history
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
carpawell committed Aug 9, 2024
1 parent 5c5c42c commit d1d6303
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog for NeoFS Node
- Indexes inspection command to neofs-lens (#2882)
- Add objects sanity checker to neofs-lens (#2506)
- Support for 0.20.0+ neofs-contract archive format (#2872)
- `neofs-cli control object status` command (#2886)

### Fixed
- Control service's Drop call does not clean metabase (#2822)
Expand Down
92 changes: 92 additions & 0 deletions cmd/neofs-cli/modules/control/objects.go
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()

Check warning on line 31 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L29-L31

Added lines #L29 - L31 were not covered by tests

pk := key.Get(cmd)
addressRaw, err := cmd.Flags().GetString(objectFlag)
if err != nil {
return fmt.Errorf("reading %s flag: %w", objectFlag, err)

Check warning on line 36 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L33-L36

Added lines #L33 - L36 were not covered by tests
}

var sdkAddr oid.Address
err = sdkAddr.DecodeString(addressRaw)
if err != nil {
return fmt.Errorf("validating address (%s): %w", addressRaw, err)

Check warning on line 42 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L39-L42

Added lines #L39 - L42 were not covered by tests
}

var resp *control.ObjectStatusResponse
req := &control.ObjectStatusRequest{
Body: &control.ObjectStatusRequest_Body{
ObjectAddress: addressRaw,
},

Check warning on line 49 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L45-L49

Added lines #L45 - L49 were not covered by tests
}
signRequest(cmd, pk, req)

Check warning on line 51 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L51

Added line #L51 was not covered by tests

cli := getClient(ctx, cmd)

Check warning on line 53 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L53

Added line #L53 was not covered by tests

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)

Check warning on line 60 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L55-L60

Added lines #L55 - L60 were not covered by tests
}

verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

Check warning on line 63 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L63

Added line #L63 was not covered by tests

shards := resp.GetBody().GetShards()
if len(shards) == 0 {
cmd.Println("<emtpy response>")
return nil

Check warning on line 68 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L65-L68

Added lines #L65 - L68 were not covered by tests
}

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

Check warning on line 76 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L71-L76

Added lines #L71 - L76 were not covered by tests
}

for _, storage := range storages {
cmd.Printf("\t%s: %s\n", storage.Type, storage.Status)

Check warning on line 80 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L79-L80

Added lines #L79 - L80 were not covered by tests
}
}

return nil

Check warning on line 84 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L84

Added line #L84 was not covered by tests
}

func initObjectStatusFlags() {
initControlFlags(objectStatusCmd)

Check warning on line 88 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L87-L88

Added lines #L87 - L88 were not covered by tests

flags := objectStatusCmd.Flags()
flags.String(objectFlag, "", "Object address")

Check warning on line 91 in cmd/neofs-cli/modules/control/objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/objects.go#L90-L91

Added lines #L90 - L91 were not covered by tests
}
6 changes: 6 additions & 0 deletions cmd/neofs-cli/modules/control/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ const (
)

func init() {
objectCmd.AddCommand(
objectStatusCmd,
)

Check warning on line 32 in cmd/neofs-cli/modules/control/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/root.go#L30-L32

Added lines #L30 - L32 were not covered by tests

Cmd.AddCommand(
healthCheckCmd,
setNetmapStatusCmd,
dropObjectsCmd,
shardsCmd,
synchronizeTreeCmd,
objectCmd,

Check warning on line 40 in cmd/neofs-cli/modules/control/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/root.go#L40

Added line #L40 was not covered by tests
)

initControlHealthCheckCmd()
initControlSetNetmapStatusCmd()
initControlDropObjectsCmd()
initControlShardsCmd()
initControlSynchronizeTreeCmd()
initObjectStatusFlags()

Check warning on line 48 in cmd/neofs-cli/modules/control/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/root.go#L48

Added line #L48 was not covered by tests
}

0 comments on commit d1d6303

Please sign in to comment.