func (s *HTTPServer) HealthNodeChecks(resp http.ResponseWriter, req *http.Request) (interface{}, error) { // Set default DC args := structs.NodeSpecificRequest{} if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done { return nil, nil } // Pull out the service name args.Node = strings.TrimPrefix(req.URL.Path, "/v1/health/node/") if args.Node == "" { resp.WriteHeader(400) resp.Write([]byte("Missing node name")) return nil, nil } // Make the RPC request var out structs.IndexedHealthChecks defer setMeta(resp, &out.QueryMeta) if err := s.agent.RPC("Health.NodeChecks", &args, &out); err != nil { return nil, err } // Use empty list instead of nil if out.HealthChecks == nil { out.HealthChecks = make(structs.HealthChecks, 0) } return out.HealthChecks, nil }
// SessionsForNode returns all the nodes belonging to a node func (s *HTTPServer) SessionsForNode(resp http.ResponseWriter, req *http.Request) (interface{}, error) { args := structs.NodeSpecificRequest{} if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done { return nil, nil } // Pull out the node name args.Node = strings.TrimPrefix(req.URL.Path, "/v1/session/node/") if args.Node == "" { resp.WriteHeader(400) resp.Write([]byte("Missing node name")) return nil, nil } var out structs.IndexedSessions defer setMeta(resp, &out.QueryMeta) if err := s.agent.RPC("Session.NodeSessions", &args, &out); err != nil { return nil, err } // Use empty list instead of nil if out.Sessions == nil { out.Sessions = make(structs.Sessions, 0) } return out.Sessions, nil }
// nodeLookup is used to handle a node query func (d *DNSServer) nodeLookup(network, datacenter, node string, req, resp *dns.Msg) { // Only handle ANY, A and AAAA type requests qType := req.Question[0].Qtype if qType != dns.TypeANY && qType != dns.TypeA && qType != dns.TypeAAAA { return } // Make an RPC request args := structs.NodeSpecificRequest{ Datacenter: datacenter, Node: node, QueryOptions: structs.QueryOptions{ Token: d.agent.config.ACLToken, AllowStale: d.config.AllowStale, }, } var out structs.IndexedNodeServices RPC: if err := d.agent.RPC("Catalog.NodeServices", &args, &out); err != nil { d.logger.Printf("[ERR] dns: rpc error: %v", err) resp.SetRcode(req, dns.RcodeServerFailure) return } // Verify that request is not too stale, redo the request if args.AllowStale && out.LastContact > d.config.MaxStale { args.AllowStale = false d.logger.Printf("[WARN] dns: Query results too stale, re-requesting") goto RPC } // If we have no address, return not found! if out.NodeServices == nil { d.addSOA(d.domain, resp) resp.SetRcode(req, dns.RcodeNameError) return } // Add the node record records := d.formatNodeRecord(out.NodeServices.Node, out.NodeServices.Node.Address, req.Question[0].Name, qType, d.config.NodeTTL) if records != nil { resp.Answer = append(resp.Answer, records...) } }
// UINodeInfo is used to get info on a single node in a given datacenter. We return a // NodeInfo which provides overview information for the node func (s *HTTPServer) UINodeInfo(resp http.ResponseWriter, req *http.Request) (interface{}, error) { // Parse arguments args := structs.NodeSpecificRequest{} if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done { return nil, nil } // Verify we have some DC, or use the default args.Node = strings.TrimPrefix(req.URL.Path, "/v1/internal/ui/node/") if args.Node == "" { resp.WriteHeader(400) resp.Write([]byte("Missing node name")) return nil, nil } // Make the RPC request var out structs.IndexedNodeDump defer setMeta(resp, &out.QueryMeta) RPC: if err := s.agent.RPC("Internal.NodeInfo", &args, &out); err != nil { // Retry the request allowing stale data if no leader if strings.Contains(err.Error(), structs.ErrNoLeader.Error()) && !args.AllowStale { args.AllowStale = true goto RPC } return nil, err } // Return only the first entry if len(out.Dump) > 0 { info := out.Dump[0] if info.Services == nil { info.Services = make([]*structs.NodeService, 0) } if info.Checks == nil { info.Checks = make([]*structs.HealthCheck, 0) } return info, nil } return nil, nil }
func (s *HTTPServer) CatalogNodeServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) { // Set default Datacenter args := structs.NodeSpecificRequest{} if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done { return nil, nil } // Pull out the node name args.Node = strings.TrimPrefix(req.URL.Path, "/v1/catalog/node/") if args.Node == "" { resp.WriteHeader(400) resp.Write([]byte("Missing node name")) return nil, nil } // Make the RPC request var out structs.IndexedNodeServices defer setMeta(resp, &out.QueryMeta) if err := s.agent.RPC("Catalog.NodeServices", &args, &out); err != nil { return nil, err } return out.NodeServices, nil }