-
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.
- Loading branch information
Showing
7 changed files
with
187 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,36 @@ | ||
package peapod | ||
|
||
import ( | ||
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" | ||
blobstorcommon "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var inspectCMD = &cobra.Command{ | ||
Use: "inspect", | ||
Short: "Object inspection", | ||
Long: `Inspect specific object in a Peapod.`, | ||
Run: inspectFunc, | ||
} | ||
|
||
func init() { | ||
common.AddAddressFlag(inspectCMD, &vAddress) | ||
common.AddComponentPathFlag(inspectCMD, &vPath) | ||
common.AddOutputFileFlag(inspectCMD, &vOut) | ||
} | ||
|
||
func inspectFunc(cmd *cobra.Command, _ []string) { | ||
var getPrm blobstorcommon.GetPrm | ||
|
||
err := getPrm.Address.DecodeString(vAddress) | ||
common.ExitOnErr(cmd, common.Errf("failed to decode object address: %w", err)) | ||
|
||
ppd := openPeapod(cmd) | ||
defer ppd.Close() | ||
|
||
res, err := ppd.Get(getPrm) | ||
common.ExitOnErr(cmd, common.Errf("failed to read object from Peapod: %w", err)) | ||
|
||
common.PrintObjectHeader(cmd, *res.Object) | ||
common.WriteObjectToFile(cmd, vOut, res.RawData) | ||
} |
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,37 @@ | ||
package peapod | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" | ||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var listCMD = &cobra.Command{ | ||
Use: "list", | ||
Short: "Object listing", | ||
Long: `List all objects stored in a Peapod.`, | ||
Run: listFunc, | ||
} | ||
|
||
func init() { | ||
common.AddComponentPathFlag(listCMD, &vPath) | ||
} | ||
|
||
func listFunc(cmd *cobra.Command, _ []string) { | ||
// other targets can be supported | ||
w := cmd.OutOrStderr() | ||
|
||
wAddr := func(addr oid.Address) error { | ||
_, err := io.WriteString(w, fmt.Sprintf("%s\n", addr)) | ||
return err | ||
} | ||
|
||
ppd := openPeapod(cmd) | ||
defer ppd.Close() | ||
|
||
err := ppd.IterateAddresses(wAddr) | ||
common.ExitOnErr(cmd, common.Errf("Peapod iterator failure: %w", err)) | ||
} |
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,41 @@ | ||
package peapod | ||
|
||
import ( | ||
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" | ||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression" | ||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/peapod" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
vAddress string | ||
vPath string | ||
vOut string | ||
) | ||
|
||
// Root defines root command for operations with Peapod. | ||
var Root = &cobra.Command{ | ||
Use: "peapod", | ||
Short: "Operations with a Peapod", | ||
} | ||
|
||
func init() { | ||
Root.AddCommand(listCMD, inspectCMD) | ||
} | ||
|
||
// open and returns read-only peapod.Peapod located in vPath. | ||
func openPeapod(cmd *cobra.Command) *peapod.Peapod { | ||
// interval prm doesn't matter for read-only usage, but must be positive | ||
ppd := peapod.New(vPath, 0400, 1) | ||
var compressCfg compression.Config | ||
|
||
err := compressCfg.Init() | ||
common.ExitOnErr(cmd, common.Errf("failed to init compression config: %w", err)) | ||
|
||
ppd.SetCompressor(&compressCfg) | ||
|
||
err = ppd.Open(true) | ||
common.ExitOnErr(cmd, common.Errf("failed to open Peapod: %w", err)) | ||
|
||
return ppd | ||
} |
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
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