Browse Source

command/keys: list keys working end-to-end

pull/336/head
Ryan Uber 10 years ago
parent
commit
9b4707a329
  1. BIN
      command/.keys.go.swp
  2. 31
      command/agent/rpc.go
  3. 16
      command/agent/rpc_client.go
  4. 24
      command/keys.go

BIN
command/.keys.go.swp

Binary file not shown.

31
command/agent/rpc.go

@ -111,10 +111,11 @@ type joinResponse struct {
Num int32
}
type keysResponse struct {
type keyResponse struct {
Messages map[string]string
NumNodes int
NumResp int
NumErr int
Keys map[string]int
}
@ -625,27 +626,41 @@ func (i *AgentRPC) handleReload(client *rpcClient, seq uint64) error {
}
func (i *AgentRPC) handleListKeysLAN(client *rpcClient, seq uint64) error {
queryResp, err := i.agent.ListKeysLAN()
header := responseHeader{
Seq: seq,
Error: "",
Error: errToString(err),
}
resp, err := i.agent.ListKeysLAN()
if err != nil {
return err
resp := keyResponse{
Messages: queryResp.Messages,
Keys: queryResp.Keys,
NumResp: queryResp.NumResp,
NumErr: queryResp.NumErr,
NumNodes: queryResp.NumNodes,
}
return client.Send(&header, resp)
return client.Send(&header, &resp)
}
func (i *AgentRPC) handleListKeysWAN(client *rpcClient, seq uint64) error {
resp, err := i.agent.ListKeysWAN()
queryResp, err := i.agent.ListKeysWAN()
header := responseHeader{
Seq: seq,
Error: errToString(err),
}
return client.Send(&header, resp)
resp := keyResponse{
Messages: queryResp.Messages,
Keys: queryResp.Keys,
NumResp: queryResp.NumResp,
NumErr: queryResp.NumErr,
NumNodes: queryResp.NumNodes,
}
return client.Send(&header, &resp)
}
// Used to convert an error to a string representation

16
command/agent/rpc_client.go

@ -176,26 +176,26 @@ func (c *RPCClient) WANMembers() ([]Member, error) {
return resp.Members, err
}
func (c *RPCClient) ListKeysLAN() (map[string]int, error) {
func (c *RPCClient) ListKeysLAN() (map[string]int, int, map[string]string, error) {
header := requestHeader{
Command: listKeysLANCommand,
Seq: c.getSeq(),
}
resp := make(map[string]int)
resp := new(keyResponse)
err := c.genericRPC(&header, nil, &resp)
return resp, err
err := c.genericRPC(&header, nil, resp)
return resp.Keys, resp.NumNodes, resp.Messages, err
}
func (c *RPCClient) ListKeysWAN() (map[string]int, error) {
func (c *RPCClient) ListKeysWAN() (map[string]int, int, map[string]string, error) {
header := requestHeader{
Command: listKeysWANCommand,
Seq: c.getSeq(),
}
resp := make(map[string]int)
resp := new(keyResponse)
err := c.genericRPC(&header, nil, &resp)
return resp, err
err := c.genericRPC(&header, nil, resp)
return resp.Keys, resp.NumNodes, resp.Messages, err
}
// Leave is used to trigger a graceful leave and shutdown

24
command/keys.go

@ -6,6 +6,7 @@ import (
"strings"
"github.com/mitchellh/cli"
"github.com/ryanuber/columnize"
)
// KeysCommand is a Command implementation that handles querying, installing,
@ -51,20 +52,35 @@ func (c *KeysCommand) Run(args []string) int {
if listKeys {
var keys map[string]int
var numNodes int
var messages map[string]string
var err error
var out []string
if wan {
keys, err = client.ListKeysWAN()
keys, numNodes, messages, err = client.ListKeysWAN()
} else {
keys, err = client.ListKeysLAN()
keys, numNodes, messages, err = client.ListKeysLAN()
}
if err != nil {
c.Ui.Error(fmt.Sprintf("Error: %s", err))
for node, msg := range messages {
out = append(out, fmt.Sprintf("failed: %s | %s", node, msg))
}
c.Ui.Error(columnize.SimpleFormat(out))
c.Ui.Error("")
c.Ui.Error(fmt.Sprintf("Failed gathering member keys: %s", err))
return 1
}
fmt.Println(keys)
c.Ui.Info("Keys gathered, listing cluster keys...")
c.Ui.Output("")
for key, num := range keys {
out = append(out, fmt.Sprintf("%s | [%d/%d]", key, num, numNodes))
}
c.Ui.Output(columnize.SimpleFormat(out))
return 0
}

Loading…
Cancel
Save