2023-07-11 09:43:48 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2023-08-01 10:03:34 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
2023-07-11 09:43:48 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var getOpLogCmd = &cobra.Command{
|
|
|
|
Use: "get-op-log",
|
|
|
|
Short: "Get logged operations starting with some height",
|
|
|
|
Run: getOpLog,
|
|
|
|
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
|
|
|
|
commonflags.Bind(cmd)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initGetOpLogCmd() {
|
|
|
|
commonflags.Init(getOpLogCmd)
|
|
|
|
initCTID(getOpLogCmd)
|
|
|
|
|
|
|
|
ff := getOpLogCmd.Flags()
|
|
|
|
ff.Uint64(heightFlagKey, 0, "Height to start with")
|
|
|
|
ff.Uint64(countFlagKey, 10, "Logged operations count")
|
|
|
|
}
|
|
|
|
|
|
|
|
func getOpLog(cmd *cobra.Command, _ []string) {
|
|
|
|
pk := key.GetOrGenerate(cmd)
|
|
|
|
|
|
|
|
cidRaw, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
|
|
|
|
|
|
|
var cnr cid.ID
|
|
|
|
err := cnr.DecodeString(cidRaw)
|
|
|
|
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
|
|
|
|
|
|
|
tid, _ := cmd.Flags().GetString(treeIDFlagKey)
|
2024-09-13 08:32:03 +00:00
|
|
|
ctx, cancel := contextWithTimeout(cmd)
|
|
|
|
defer cancel()
|
2023-07-11 09:43:48 +00:00
|
|
|
|
2024-09-13 08:32:03 +00:00
|
|
|
cli, err := _client()
|
2023-07-11 09:43:48 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
|
|
|
|
|
|
|
rawCID := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(rawCID)
|
|
|
|
|
|
|
|
height, _ := cmd.Flags().GetUint64(heightFlagKey)
|
|
|
|
count, _ := cmd.Flags().GetUint64(countFlagKey)
|
|
|
|
|
|
|
|
req := &tree.GetOpLogRequest{
|
|
|
|
Body: &tree.GetOpLogRequest_Body{
|
|
|
|
ContainerId: rawCID,
|
|
|
|
TreeId: tid,
|
|
|
|
Height: height,
|
|
|
|
Count: count,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk))
|
|
|
|
|
|
|
|
resp, err := cli.GetOpLog(ctx, req)
|
|
|
|
commonCmd.ExitOnErr(cmd, "get op log: %w", err)
|
|
|
|
|
|
|
|
opLogResp, err := resp.Recv()
|
|
|
|
for ; err == nil; opLogResp, err = resp.Recv() {
|
|
|
|
o := opLogResp.GetBody().GetOperation()
|
|
|
|
|
|
|
|
cmd.Println("Parent ID: ", o.GetParentId())
|
|
|
|
|
|
|
|
cmd.Println("\tChild ID: ", o.GetChildId())
|
2023-08-01 10:03:34 +00:00
|
|
|
|
|
|
|
m := &pilorama.Meta{}
|
|
|
|
err = m.FromBytes(o.GetMeta())
|
|
|
|
commonCmd.ExitOnErr(cmd, "could not unmarshal meta: %w", err)
|
|
|
|
cmd.Printf("\tMeta:\n")
|
|
|
|
cmd.Printf("\t\tTime: %d\n", m.Time)
|
|
|
|
for _, item := range m.Items {
|
|
|
|
cmd.Printf("\t\t%s: %s\n", item.Key, item.Value)
|
|
|
|
}
|
2023-07-11 09:43:48 +00:00
|
|
|
}
|
|
|
|
if !errors.Is(err, io.EOF) {
|
|
|
|
commonCmd.ExitOnErr(cmd, "get op log response stream: %w", err)
|
|
|
|
}
|
|
|
|
}
|