Add API for setting node status, respect it in leader tasks

This commit is contained in:
Ingo Oppermann
2024-06-24 16:50:15 +02:00
parent 166e313642
commit c032cdf5c7
19 changed files with 1219 additions and 126 deletions

View File

@@ -70,6 +70,10 @@ type GetKVResponse struct {
UpdatedAt time.Time `json:"updated_at"`
}
type SetNodeStateRequest struct {
State string `json:"state"`
}
type APIClient struct {
Address string
Client *http.Client
@@ -333,6 +337,17 @@ func (c *APIClient) GetKV(origin string, key string) (string, time.Time, error)
return res.Value, res.UpdatedAt, nil
}
func (c *APIClient) SetNodeState(origin string, nodeid string, r SetNodeStateRequest) error {
data, err := json.Marshal(r)
if err != nil {
return err
}
_, err = c.call(http.MethodPut, "/v1/node/"+url.PathEscape(nodeid)+"/state", "application/json", bytes.NewReader(data), origin)
return err
}
func (c *APIClient) Snapshot(origin string) (io.ReadCloser, error) {
return c.stream(http.MethodGet, "/v1/snapshot", "", nil, origin)
}