Skip to content

Commit

Permalink
ns_server handlers now find all nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoch committed Jul 28, 2015
1 parent b23b8d0 commit fa7ce3d
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,53 @@ func NewNsStatusHandler(mgr *cbgt.Manager, server string) (*NsStatusHandler, err
}, nil
}

func HostsForIndex(name string, planPIndexes *cbgt.PlanPIndexes, nodeDefs *cbgt.NodeDefs) []string {
// find the node UUIDs related to this index
nodes := make(map[string]struct{})
for _, planPIndex := range planPIndexes.PlanPIndexes {
if planPIndex.IndexName == name {
for planPIndexNodeUUID := range planPIndex.Nodes {
nodes[planPIndexNodeUUID] = struct{}{}
}
}
}
nodeExtras := make(map[string]string)
// look for all these nodes in the nodes wanted
for _, nodeDef := range nodeDefs.NodeDefs {
_, ok := nodes[nodeDef.UUID]
if ok {
nodeExtras[nodeDef.UUID] = nodeDef.Extras
}
}

// build slide of node extras
nodeStrings := make(sort.StringSlice, 0, len(nodeExtras))
for _, nodeExtra := range nodeExtras {
nodeStrings = append(nodeStrings, nodeExtra)
}

// sort slice for stability
sort.Sort(nodeStrings)

return nodeStrings
}

func (h *NsStatusHandler) ServeHTTP(
w http.ResponseWriter, req *http.Request) {

cfg := h.mgr.Cfg()
planPIndexes, _, err := cbgt.CfgGetPlanPIndexes(cfg)
if err != nil {
rest.ShowError(w, req, "could not retrieve plan pIndexes", 500)
return
}

nodesDefs, _, err := cbgt.CfgGetNodeDefs(cfg, cbgt.NODE_DEFS_WANTED)
if err != nil {
rest.ShowError(w, req, "could not retrieve node defs (wanted)", 500)
return
}

_, indexDefsMap, err := h.mgr.GetIndexDefs(false)
if err != nil {
rest.ShowError(w, req, "could not retrieve index defs", 500)
Expand Down Expand Up @@ -262,7 +306,7 @@ func (h *NsStatusHandler) ServeHTTP(
}{
Bucket: indexDef.SourceName,
Name: indexDefName,
Hosts: []string{h.serverURL.Host},
Hosts: HostsForIndex(indexDefName, planPIndexes, nodesDefs),
// FIXME hard-coded
Completion: 100,
Status: "Ready",
Expand Down

0 comments on commit fa7ce3d

Please sign in to comment.