From 9b4707a3297fd1edebfdc2bb42732aa1018daaca Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 8 Sep 2014 20:09:35 -0700 Subject: [PATCH] command/keys: list keys working end-to-end --- command/.keys.go.swp | Bin 12288 -> 0 bytes command/agent/rpc.go | 31 +++++++++++++++++++++++-------- command/agent/rpc_client.go | 16 ++++++++-------- command/keys.go | 24 ++++++++++++++++++++---- 4 files changed, 51 insertions(+), 20 deletions(-) delete mode 100644 command/.keys.go.swp diff --git a/command/.keys.go.swp b/command/.keys.go.swp deleted file mode 100644 index 370906d22e6ad9df77d1abb6dd771a7f967c2a1b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeHNO^g&p6fRKEQIWqGPwJzM>kOHlS-^-{T@u{*L-<)_S&bnmHQhBc9lE>P>h4`f zL@#>Oc+o^jJfYDQ-+bvHY+?5^QR(nG$T{;Busy|2D{ zRTHW+@#MaPw7a!S;Im1HLHE|9FRa}n*4`n68OSK>D8sK-`;_g*!%jTDvlVDp2Fta7 zschKp>2_k=cF#}yS*PXdu-%tQ-*>f%+pdn1EWlS7%E)VdG~3|tKZ z8^o@iJ0{rTZf6^9-7 zzx@6G*G3`!1bziB0vCYqf$xA%fRBNXfMz4qODz1D^rsfDeFIfB`TEJOLaA_5hoKb-)@x0Ke6Q_!+ne{0Mvld<}dBdZxG@=;4E+kcn3HDtOGt@ z4<3Lq;Nm(V-T>x+^}y%XW88oTfct?hz$RcL@C(NE3xLP>9FKAJx#k%-Eow%knTg0b zC?nZZ3H5Z6_%Q`?pbV+VHG??ybwqr6#u42ta;fgp_Wih>&JWf!Xm$|kIPsHugOb$v zQIAduvFJO0mb8u|r@RdObO251dEY}};8wEZ+lL6h5R1*m z=v3MwQRsGj0TxYkW<@lbT$3lX4V_=&F7hZ>7U_VM#{>6NA1cDRy^bF#FQ01grfnKB zDBi0`b})v;Oe{|MSwR<*5d%W%c^Se9Nu)HdhUkL7vgD0&SPUklSk{U~K|Pii#~}kq zTFkNBCJ`?mH_UTBmdBbL7qzn1(c~1JSfPMEj(WI4@!TP5ZfnkO&17kurFFNJw`~Yf zLxnBN_k^hV-GaycQ2e$javZM0S2luF|EEPEz13RPx?$Qnj8dNlQJn{p%zW&12182C11x%~i)FDGoasO(ig_NACyT+V_>mQ~z>_CZn4?^d^vEJV zDwCxuspY-q0zur^F-%*L)VE_-u@`%XB{Kz~6h6?}4ZTOPf+wxR(jaK0lr$b3m0_)L z!=%7Ddt{S(Y0B=)>(;|s2Tw{%NGLOPk6iLAhQOn72163K*j zFgW@1;jqiBFEdwcVOOZsM>0FZ6DlWF1B-Xc6#?aTWi_M1JVUd@ZCH7!D`C%L=o{IS*oc3i(*t>WER_*69 zWd`ujM3{Ed!`DJUch1n6`Or^YtW!b1jrbj~=j0UwJN}x3%5A?uv?I`$HYwHdn^d|d MvF`CQ&ByD-f6l=}_5c6? diff --git a/command/agent/rpc.go b/command/agent/rpc.go index 09bf68fb87..e1007cb1d3 100644 --- a/command/agent/rpc.go +++ b/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 diff --git a/command/agent/rpc_client.go b/command/agent/rpc_client.go index d5ff5894e6..daa72e1c05 100644 --- a/command/agent/rpc_client.go +++ b/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 diff --git a/command/keys.go b/command/keys.go index 49bac18315..069af85661 100644 --- a/command/keys.go +++ b/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 }