Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix agentctl dump command #1460

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions cmd/agentctl/commands/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/spf13/cobra"

"github.com/ligato/vpp-agent/pkg/models"
"github.com/ligato/vpp-agent/plugins/kvscheduler/api"
)

Expand All @@ -50,8 +49,8 @@ func NewDumpCommand(cli *AgentCli) *cobra.Command {
For a list of all supported models that can be dumped run:
$ agentctl model list

To specify the HTTP address of the agent use --httpaddr flag:
$ agentctl --httpaddr 172.17.0.3:9191 dump vpp.interfaces
To specify the HTTP address of the agent use --host flag:
$ agentctl --host 172.17.0.3 dump vpp.interfaces
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -129,9 +128,13 @@ func printDumpTable(dump []api.KVWithMetadata) {
}

func dumpKeyPrefix(cli *AgentCli, keyPrefix string, dumpView string) ([]api.KVWithMetadata, error) {
type ProtoWithName struct {
ProtoMsgName string
ProtoMsgData string
}
type KVWithMetadata struct {
api.KVWithMetadata
Value json.RawMessage
Value ProtoWithName
}
var kvdump []KVWithMetadata

Expand All @@ -152,17 +155,15 @@ func dumpKeyPrefix(cli *AgentCli, keyPrefix string, dumpView string) ([]api.KVWi
var dump []api.KVWithMetadata
for _, kvd := range kvdump {
d := kvd.KVWithMetadata
key := d.Key
model, err := models.GetModelForKey(key)
if err != nil {
return nil, err
if kvd.Value.ProtoMsgName == "" {
return nil, fmt.Errorf("empty proto message name for key %s", d.Key)
}
valueType := proto.MessageType(model.ProtoName())
valueType := proto.MessageType(kvd.Value.ProtoMsgName)
if valueType == nil {
return nil, fmt.Errorf("unknown proto message defined for key %s", key)
return nil, fmt.Errorf("unknown proto message defined for key %s", d.Key)
}
d.Value = reflect.New(valueType.Elem()).Interface().(proto.Message)
if err := jsonpb.Unmarshal(bytes.NewReader(kvd.Value), d.Value); err != nil {
if err = jsonpb.UnmarshalString(kvd.Value.ProtoMsgData, d.Value); err != nil {
return nil, fmt.Errorf("decoding reply failed: %v", err)
}
dump = append(dump, d)
Expand Down