GetZeroState queries the /state endpoint on the specified Zero and returns the parsed membership snapshot.
(id int)
| 45 | // GetZeroState queries the /state endpoint on the specified Zero and returns |
| 46 | // the parsed membership snapshot. |
| 47 | func (c *LocalCluster) GetZeroState(id int) (*ZeroState, error) { |
| 48 | stateURL, err := c.GetZeroStateURL(id) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | |
| 53 | resp, err := http.Get(stateURL) |
| 54 | if err != nil { |
| 55 | return nil, errors.Wrapf(err, "GET %s", stateURL) |
| 56 | } |
| 57 | defer func() { _ = resp.Body.Close() }() |
| 58 | |
| 59 | body, err := io.ReadAll(resp.Body) |
| 60 | if err != nil { |
| 61 | return nil, errors.Wrap(err, "reading /state body") |
| 62 | } |
| 63 | if resp.StatusCode != http.StatusOK { |
| 64 | return nil, fmt.Errorf("/state HTTP %d: %s", resp.StatusCode, body) |
| 65 | } |
| 66 | |
| 67 | var state ZeroState |
| 68 | if err := json.Unmarshal(body, &state); err != nil { |
| 69 | return nil, errors.Wrapf(err, "unmarshal /state (body: %s)", string(body)) |
| 70 | } |
| 71 | return &state, nil |
| 72 | } |
| 73 | |
| 74 | // ZeroLocator identifies a Zero by its container index and Raft ID. |
| 75 | type ZeroLocator struct { |
no test coverage detected