MCPcopy Create free account
hub / github.com/couchbase/cbft / fetchServerGroupDetails

Function fetchServerGroupDetails

server_groups.go:242–291  ·  view source on GitHub ↗

fetchServerGroupDetails retrives the server group node hierarchy for all the given node UUIDs.

(mgr *cbgt.Manager, uuids []string)

Source from the content-addressed store, hash-verified

240// fetchServerGroupDetails retrives the server group node hierarchy
241// for all the given node UUIDs.
242func fetchServerGroupDetails(mgr *cbgt.Manager, uuids []string) (
243 map[string]string, error) {
244 if len(uuids) == 0 {
245 return nil, fmt.Errorf("empty UUID list")
246 }
247
248 url := mgr.Server() + "/pools/default/serverGroups"
249 u, err := cbgt.CBAuthURL(url)
250 if err != nil {
251 return nil, fmt.Errorf("server_groups: auth for ns_server,"+
252 " url: %s, authType: %s, err: %v",
253 url, "cbauth", err)
254 }
255
256 req, err := http.NewRequest("GET", u, nil)
257 if err != nil {
258 return nil, err
259 }
260
261 resp, err := cbgt.HttpClient().Do(req)
262 if err != nil {
263 return nil, err
264 }
265 defer resp.Body.Close()
266
267 respBuf, err := ioutil.ReadAll(resp.Body)
268 if err != nil || len(respBuf) == 0 {
269 return nil, fmt.Errorf("server_groups: error reading resp.Body,"+
270 " url: %s, resp: %#v, err: %v", url, resp, err)
271 }
272
273 var sg serverGroups
274 err = json.Unmarshal(respBuf, &sg)
275 if err != nil {
276 return nil, fmt.Errorf("server_groups: error parsing respBuf: %s,"+
277 " url: %s, err: %v", respBuf, url, err)
278 }
279
280 uuidMap := cbgt.StringsToMap(uuids)
281 nodeHierarchy := make(map[string]string, len(uuids))
282 for _, g := range sg.ServerGroups {
283 for _, nd := range g.NodeDetails {
284 if _, found := uuidMap[nd.NodeUUID]; found {
285 nodeHierarchy[nd.NodeUUID] = "datacenter/" + g.Name
286 }
287 }
288 }
289
290 return nodeHierarchy, nil
291}
292
293// listenStreamingEndpoint is a generic stream endpoint listen
294// utility function which accepts callback methods for decoding the

Callers 1

Calls 2

UnmarshalMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected