github.com/weaviate/weaviate@v1.24.6/adapters/clients/cluster_node.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package clients 13 14 import ( 15 "context" 16 "encoding/json" 17 "io" 18 "net/http" 19 "net/url" 20 "path" 21 22 enterrors "github.com/weaviate/weaviate/entities/errors" 23 "github.com/weaviate/weaviate/entities/models" 24 ) 25 26 type RemoteNode struct { 27 client *http.Client 28 } 29 30 func NewRemoteNode(httpClient *http.Client) *RemoteNode { 31 return &RemoteNode{client: httpClient} 32 } 33 34 func (c *RemoteNode) GetNodeStatus(ctx context.Context, hostName, className, output string) (*models.NodeStatus, error) { 35 p := "/nodes/status" 36 if className != "" { 37 p = path.Join(p, className) 38 } 39 method := http.MethodGet 40 params := url.Values{"output": []string{output}} 41 url := url.URL{Scheme: "http", Host: hostName, Path: p, RawQuery: params.Encode()} 42 43 req, err := http.NewRequestWithContext(ctx, method, url.String(), nil) 44 if err != nil { 45 return nil, enterrors.NewErrOpenHttpRequest(err) 46 } 47 48 res, err := c.client.Do(req) 49 if err != nil { 50 return nil, enterrors.NewErrSendHttpRequest(err) 51 } 52 53 defer res.Body.Close() 54 body, _ := io.ReadAll(res.Body) 55 if res.StatusCode != http.StatusOK { 56 return nil, enterrors.NewErrUnexpectedStatusCode(res.StatusCode, body) 57 } 58 59 var nodeStatus models.NodeStatus 60 err = json.Unmarshal(body, &nodeStatus) 61 if err != nil { 62 return nil, enterrors.NewErrUnmarshalBody(err) 63 } 64 65 return &nodeStatus, nil 66 }