func (h *CfgGetHandler) ServeHTTP( w http.ResponseWriter, req *http.Request) { // TODO: Might need to scrub auth passwords from this output. cfg := h.mgr.Cfg() indexDefs, indexDefsCAS, indexDefsErr := cbgt.CfgGetIndexDefs(cfg) nodeDefsWanted, nodeDefsWantedCAS, nodeDefsWantedErr := cbgt.CfgGetNodeDefs(cfg, cbgt.NODE_DEFS_WANTED) nodeDefsKnown, nodeDefsKnownCAS, nodeDefsKnownErr := cbgt.CfgGetNodeDefs(cfg, cbgt.NODE_DEFS_KNOWN) planPIndexes, planPIndexesCAS, planPIndexesErr := cbgt.CfgGetPlanPIndexes(cfg) MustEncode(w, RESTCfg{ Status: "ok", IndexDefs: indexDefs, IndexDefsCAS: indexDefsCAS, IndexDefsErr: indexDefsErr, NodeDefsWanted: nodeDefsWanted, NodeDefsWantedCAS: nodeDefsWantedCAS, NodeDefsWantedErr: nodeDefsWantedErr, NodeDefsKnown: nodeDefsKnown, NodeDefsKnownCAS: nodeDefsKnownCAS, NodeDefsKnownErr: nodeDefsKnownErr, PlanPIndexes: planPIndexes, PlanPIndexesCAS: planPIndexesCAS, PlanPIndexesErr: planPIndexesErr, }) }
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) return } w.Write(cbgt.JsonOpenBrace) w.Write(statsNamePrefix) w.Write([]byte("status")) w.Write(statsNameSuffix) w.Write([]byte("[")) indexDefNames := make(sort.StringSlice, 0, len(indexDefsMap)) for indexDefName := range indexDefsMap { indexDefNames = append(indexDefNames, indexDefName) } sort.Sort(indexDefNames) for i, indexDefName := range indexDefNames { indexDef := indexDefsMap[indexDefName] if i > 0 { w.Write(cbgt.JsonComma) } rest.MustEncode(w, struct { Completion int `json:"completion"` Hosts []string `json:"hosts"` Status string `json:"status"` Bucket string `json:"bucket"` Name string `json:"name"` }{ Bucket: indexDef.SourceName, Name: indexDefName, Hosts: HostsForIndex(indexDefName, planPIndexes, nodesDefs), // FIXME hard-coded Completion: 100, Status: "Ready", }) } w.Write([]byte("],")) w.Write(statsNamePrefix) w.Write([]byte("code")) w.Write(statsNameSuffix) w.Write([]byte("\"success\"")) w.Write(cbgt.JsonCloseBrace) }
func RunRecentInfoCache(mgr *cbgt.Manager) { cfg := mgr.Cfg() cfgChangedCh := make(chan struct{}, 10) go func() { // Debounce cfg events to feed into the cfgChangedCh. ech := make(chan cbgt.CfgEvent) cfg.Subscribe(cbgt.PLAN_PINDEXES_KEY, ech) for { <-ech // First, wait for a cfg event. debounceTimeCh := time.After(500 * time.Millisecond) DEBOUNCE_LOOP: for { select { case <-ech: // NO-OP when there are more, spammy cfg events. case <-debounceTimeCh: break DEBOUNCE_LOOP } } cfgChangedCh <- struct{}{} } }() tickCh := time.Tick(1 * time.Minute) for { var nodeDefs *cbgt.NodeDefs var planPIndexes *cbgt.PlanPIndexes indexDefs, indexDefsMap, err := mgr.GetIndexDefs(false) if err == nil { nodeDefs, _, err = cbgt.CfgGetNodeDefs(cfg, cbgt.NODE_DEFS_WANTED) if err == nil { planPIndexes, _, err = cbgt.CfgGetPlanPIndexes(cfg) } } rd := &recentInfo{ indexDefs: indexDefs, indexDefsMap: indexDefsMap, nodeDefs: nodeDefs, planPIndexes: planPIndexes, err: err, } runtime.ReadMemStats(&rd.memStats) REUSE_CACHE: for { select { case <-cfgChangedCh: break REUSE_CACHE case <-tickCh: break REUSE_CACHE case recentInfoCh <- rd: if rd.err != nil { break REUSE_CACHE } } } } }