2023-03-15 19:00:52 +03:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-04-20 22:04:13 +03:00
|
|
|
package api
|
|
|
|
|
2020-12-12 03:50:19 +03:00
|
|
|
import (
|
|
|
|
"context"
|
2022-03-24 20:58:03 +03:00
|
|
|
"net/http"
|
2020-12-12 03:50:19 +03:00
|
|
|
"time"
|
|
|
|
)
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2015-04-20 22:04:13 +03:00
|
|
|
func (c *Sys) Leader() (*LeaderResponse, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.LeaderWithContext(context.Background())
|
|
|
|
}
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
func (c *Sys) LeaderWithContext(ctx context.Context) (*LeaderResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2018-07-25 01:49:55 +03:00
|
|
|
defer cancelFunc()
|
2022-03-24 00:47:43 +03:00
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/leader")
|
2022-03-24 00:47:43 +03:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2015-04-20 22:04:13 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result LeaderResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type LeaderResponse struct {
|
2020-12-12 03:50:19 +03:00
|
|
|
HAEnabled bool `json:"ha_enabled"`
|
|
|
|
IsSelf bool `json:"is_self"`
|
|
|
|
ActiveTime time.Time `json:"active_time"`
|
|
|
|
LeaderAddress string `json:"leader_address"`
|
|
|
|
LeaderClusterAddress string `json:"leader_cluster_address"`
|
|
|
|
PerfStandby bool `json:"performance_standby"`
|
|
|
|
PerfStandbyLastRemoteWAL uint64 `json:"performance_standby_last_remote_wal"`
|
|
|
|
LastWAL uint64 `json:"last_wal"`
|
|
|
|
RaftCommittedIndex uint64 `json:"raft_committed_index,omitempty"`
|
|
|
|
RaftAppliedIndex uint64 `json:"raft_applied_index,omitempty"`
|
2015-04-20 22:04:13 +03:00
|
|
|
}
|