From cddc6845590d1de2c53f34915db3dffe0f4ae232 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Fri, 3 Mar 2017 11:53:48 +0100 Subject: [PATCH] admin: Set Config returns errSet and errMsg (#3822) There is no way to see if a node encountered an error when trying to set a new config set, this commit adds a bool errSet field. --- cmd/admin-handlers.go | 11 +++++++---- cmd/admin-handlers_test.go | 10 +++++++--- pkg/madmin/API.md | 3 ++- pkg/madmin/config-commands.go | 5 +++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 4a21d2cee..98ede6b53 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -718,9 +718,11 @@ func toAdminAPIErrCode(err error) APIErrorCode { // SetConfigResult - represents detailed results of a set-config // operation. type nodeSummary struct { - Name string `json:"name"` - Err string `json:"err"` + Name string `json:"name"` + ErrSet bool `json:"errSet"` + ErrMsg string `json:"errMsg"` } + type setConfigResult struct { NodeResults []nodeSummary `json:"nodeResults"` Status bool `json:"status"` @@ -733,8 +735,9 @@ func writeSetConfigResponse(w http.ResponseWriter, peers adminPeers, errs []erro // set-config operation. for i := range errs { nodeResults = append(nodeResults, nodeSummary{ - Name: peers[i].addr, - Err: fmt.Sprintf("%v", errs[i]), + Name: peers[i].addr, + ErrSet: errs[i] != nil, + ErrMsg: fmt.Sprintf("%v", errs[i]), }) } diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index 931c0c208..a1018d7d0 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -1279,9 +1279,13 @@ func TestWriteSetConfigResponse(t *testing.T) { if res.Name != testPeers[p].addr { t.Errorf("Test %d: Expected node name %s but received %s", i+1, testPeers[p].addr, res.Name) } - expectedErrStr := fmt.Sprintf("%v", test.errs[p]) - if res.Err != expectedErrStr { - t.Errorf("Test %d: Expected error %s but received %s", i+1, expectedErrStr, res.Err) + expectedErrMsg := fmt.Sprintf("%v", test.errs[p]) + if res.ErrMsg != expectedErrMsg { + t.Errorf("Test %d: Expected error %s but received %s", i+1, expectedErrMsg, res.ErrMsg) + } + expectedErrSet := test.errs[p] != nil + if res.ErrSet != expectedErrSet { + t.Errorf("Test %d: Expected ErrSet %v but received %v", i+1, expectedErrSet, res.ErrSet) } } } diff --git a/pkg/madmin/API.md b/pkg/madmin/API.md index 033bb0816..8a6222bce 100644 --- a/pkg/madmin/API.md +++ b/pkg/madmin/API.md @@ -330,7 +330,8 @@ change to take effect. |---|---|---| |`st.Status` | _bool_ | true if set-config succeeded, false otherwise. | |`st.NodeSummary.Name` | _string_ | Network address of the node. | -|`st.NodeSummary.Err` | _string_ | String representation of the error (if any) on the node.| +|`st.NodeSummary.ErrSet` | _bool_ | Bool representation indicating if an error is encountered with the node.| +|`st.NodeSummary.ErrMsg` | _string_ | String representation of the error (if any) on the node.| __Example__ diff --git a/pkg/madmin/config-commands.go b/pkg/madmin/config-commands.go index d63aece4a..e4f8afb53 100644 --- a/pkg/madmin/config-commands.go +++ b/pkg/madmin/config-commands.go @@ -33,8 +33,9 @@ const ( // NodeSummary - represents the result of an operation part of // set-config on a node. type NodeSummary struct { - Name string `json:"name"` - Err string `json:"err"` + Name string `json:"name"` + ErrSet bool `json:"errSet"` + ErrMsg string `json:"errMsg"` } // SetConfigResult - represents detailed results of a set-config