Sync some bits over

This commit is contained in:
Jeff Mitchell 2018-01-22 21:44:38 -05:00
parent 7be7bc1754
commit 8e8675053b
14 changed files with 121 additions and 86 deletions

View File

@ -21,13 +21,13 @@ func (c *Sys) Health() (*HealthResponse, error) {
}
type HealthResponse struct {
Initialized bool `json:"initialized"`
Sealed bool `json:"sealed"`
Standby bool `json:"standby"`
ReplicationPerfMode string `json:"replication_perf_mode"`
ReplicationDRMode string `json:"replication_dr_mode"`
ServerTimeUTC int64 `json:"server_time_utc"`
Version string `json:"version"`
ClusterName string `json:"cluster_name,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
Initialized bool `json:"initialized"`
Sealed bool `json:"sealed"`
Standby bool `json:"standby"`
ReplicationPerformanceMode string `json:"replication_performance_mode"`
ReplicationDRMode string `json:"replication_dr_mode"`
ServerTimeUTC int64 `json:"server_time_utc"`
Version string `json:"version"`
ClusterName string `json:"cluster_name,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
}

View File

@ -8,50 +8,68 @@ const (
OldReplicationSecondary
OldReplicationBootstrapping
ReplicationDisabled ReplicationState = 0
ReplicationUnknown ReplicationState = 0
ReplicationPerformancePrimary ReplicationState = 1 << iota
ReplicationPerformanceSecondary
ReplicationBootstrapping
OldSplitReplicationBootstrapping
ReplicationDRPrimary
ReplicationDRSecondary
ReplicationPerformanceBootstrapping
ReplicationDRBootstrapping
ReplicationPerformanceDisabled
ReplicationDRDisabled
)
func (r ReplicationState) String() string {
func (r ReplicationState) string() string {
switch r {
case ReplicationPerformanceSecondary:
return "perf-secondary"
return "secondary"
case ReplicationPerformancePrimary:
return "perf-primary"
case ReplicationBootstrapping:
return "primary"
case ReplicationPerformanceBootstrapping:
return "bootstrapping"
case ReplicationPerformanceDisabled:
return "disabled"
case ReplicationDRPrimary:
return "dr-primary"
return "primary"
case ReplicationDRSecondary:
return "dr-secondary"
return "secondary"
case ReplicationDRBootstrapping:
return "bootstrapping"
case ReplicationDRDisabled:
return "disabled"
}
return "disabled"
return "unknown"
}
func (r ReplicationState) GetDRString() string {
switch {
case r.HasState(ReplicationDRBootstrapping):
return ReplicationDRBootstrapping.string()
case r.HasState(ReplicationDRPrimary):
return ReplicationDRPrimary.String()
return ReplicationDRPrimary.string()
case r.HasState(ReplicationDRSecondary):
return ReplicationDRSecondary.String()
return ReplicationDRSecondary.string()
case r.HasState(ReplicationDRDisabled):
return ReplicationDRDisabled.string()
default:
return ReplicationDisabled.String()
return "unknown"
}
}
func (r ReplicationState) GetPerformanceString() string {
switch {
case r.HasState(ReplicationPerformanceBootstrapping):
return ReplicationPerformanceBootstrapping.string()
case r.HasState(ReplicationPerformancePrimary):
return ReplicationPerformancePrimary.String()
return ReplicationPerformancePrimary.string()
case r.HasState(ReplicationPerformanceSecondary):
return ReplicationPerformanceSecondary.String()
return ReplicationPerformanceSecondary.string()
case r.HasState(ReplicationPerformanceDisabled):
return ReplicationPerformanceDisabled.string()
default:
return ReplicationDisabled.String()
return "unknown"
}
}

View File

@ -157,27 +157,27 @@ func getSysHealth(core *vault.Core, r *http.Request) (int, *HealthResponse, erro
// Format the body
body := &HealthResponse{
Initialized: init,
Sealed: sealed,
Standby: standby,
ReplicationPerfMode: replicationState.GetPerformanceString(),
ReplicationDRMode: replicationState.GetDRString(),
ServerTimeUTC: time.Now().UTC().Unix(),
Version: version.GetVersion().VersionNumber(),
ClusterName: clusterName,
ClusterID: clusterID,
Initialized: init,
Sealed: sealed,
Standby: standby,
ReplicationPerformanceMode: replicationState.GetPerformanceString(),
ReplicationDRMode: replicationState.GetDRString(),
ServerTimeUTC: time.Now().UTC().Unix(),
Version: version.GetVersion().VersionNumber(),
ClusterName: clusterName,
ClusterID: clusterID,
}
return code, body, nil
}
type HealthResponse struct {
Initialized bool `json:"initialized"`
Sealed bool `json:"sealed"`
Standby bool `json:"standby"`
ReplicationPerfMode string `json:"replication_perf_mode"`
ReplicationDRMode string `json:"replication_dr_mode"`
ServerTimeUTC int64 `json:"server_time_utc"`
Version string `json:"version"`
ClusterName string `json:"cluster_name,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
Initialized bool `json:"initialized"`
Sealed bool `json:"sealed"`
Standby bool `json:"standby"`
ReplicationPerformanceMode string `json:"replication_performance_mode"`
ReplicationDRMode string `json:"replication_dr_mode"`
ServerTimeUTC int64 `json:"server_time_utc"`
Version string `json:"version"`
ClusterName string `json:"cluster_name,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
}

View File

@ -24,11 +24,11 @@ func TestSysHealth_get(t *testing.T) {
var actual map[string]interface{}
expected := map[string]interface{}{
"replication_perf_mode": consts.ReplicationDisabled.String(),
"replication_dr_mode": consts.ReplicationDisabled.String(),
"initialized": false,
"sealed": true,
"standby": true,
"replication_performance_mode": consts.ReplicationUnknown.GetPerformanceString(),
"replication_dr_mode": consts.ReplicationUnknown.GetDRString(),
"initialized": false,
"sealed": true,
"standby": true,
}
testResponseStatus(t, resp, 501)
testResponseBody(t, resp, &actual)
@ -56,11 +56,11 @@ func TestSysHealth_get(t *testing.T) {
actual = map[string]interface{}{}
expected = map[string]interface{}{
"replication_perf_mode": consts.ReplicationDisabled.String(),
"replication_dr_mode": consts.ReplicationDisabled.String(),
"initialized": true,
"sealed": true,
"standby": true,
"replication_performance_mode": consts.ReplicationUnknown.GetPerformanceString(),
"replication_dr_mode": consts.ReplicationUnknown.GetDRString(),
"initialized": true,
"sealed": true,
"standby": true,
}
testResponseStatus(t, resp, 503)
testResponseBody(t, resp, &actual)
@ -92,11 +92,11 @@ func TestSysHealth_get(t *testing.T) {
actual = map[string]interface{}{}
expected = map[string]interface{}{
"replication_perf_mode": consts.ReplicationDisabled.String(),
"replication_dr_mode": consts.ReplicationDisabled.String(),
"initialized": true,
"sealed": false,
"standby": false,
"replication_performance_mode": consts.ReplicationPerformanceDisabled.GetPerformanceString(),
"replication_dr_mode": consts.ReplicationDRDisabled.GetDRString(),
"initialized": true,
"sealed": false,
"standby": false,
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
@ -134,11 +134,11 @@ func TestSysHealth_customcodes(t *testing.T) {
var actual map[string]interface{}
expected := map[string]interface{}{
"replication_perf_mode": consts.ReplicationDisabled.String(),
"replication_dr_mode": consts.ReplicationDisabled.String(),
"initialized": false,
"sealed": true,
"standby": true,
"replication_performance_mode": consts.ReplicationUnknown.GetPerformanceString(),
"replication_dr_mode": consts.ReplicationUnknown.GetDRString(),
"initialized": false,
"sealed": true,
"standby": true,
}
testResponseStatus(t, resp, 581)
testResponseBody(t, resp, &actual)
@ -167,11 +167,11 @@ func TestSysHealth_customcodes(t *testing.T) {
actual = map[string]interface{}{}
expected = map[string]interface{}{
"replication_perf_mode": consts.ReplicationDisabled.String(),
"replication_dr_mode": consts.ReplicationDisabled.String(),
"initialized": true,
"sealed": true,
"standby": true,
"replication_performance_mode": consts.ReplicationUnknown.GetPerformanceString(),
"replication_dr_mode": consts.ReplicationUnknown.GetDRString(),
"initialized": true,
"sealed": true,
"standby": true,
}
testResponseStatus(t, resp, 523)
testResponseBody(t, resp, &actual)
@ -204,11 +204,11 @@ func TestSysHealth_customcodes(t *testing.T) {
actual = map[string]interface{}{}
expected = map[string]interface{}{
"replication_perf_mode": consts.ReplicationDisabled.String(),
"replication_dr_mode": consts.ReplicationDisabled.String(),
"initialized": true,
"sealed": false,
"standby": false,
"replication_performance_mode": consts.ReplicationPerformanceDisabled.GetPerformanceString(),
"replication_dr_mode": consts.ReplicationDRDisabled.GetDRString(),
"initialized": true,
"sealed": false,
"standby": false,
}
testResponseStatus(t, resp, 202)
testResponseBody(t, resp, &actual)

View File

@ -78,7 +78,7 @@ func (s *gRPCSystemViewClient) CachingDisabled() bool {
func (s *gRPCSystemViewClient) ReplicationState() consts.ReplicationState {
reply, err := s.client.ReplicationState(context.Background(), &pb.Empty{})
if err != nil {
return consts.ReplicationDisabled
return consts.ReplicationUnknown
}
return consts.ReplicationState(reply.State)

View File

@ -79,7 +79,7 @@ func (s *SystemViewClient) ReplicationState() consts.ReplicationState {
err := s.client.Call("Plugin.ReplicationState", new(interface{}), &reply)
if err != nil {
return consts.ReplicationDisabled
return consts.ReplicationUnknown
}
return reply.ReplicationState

View File

@ -493,6 +493,8 @@ func NewCore(conf *CoreConfig) (*Core, error) {
activeNodeReplicationState: new(uint32),
}
atomic.StoreUint32(c.replicationState, uint32(consts.ReplicationDRDisabled|consts.ReplicationPerformanceDisabled))
if conf.ClusterCipherSuites != "" {
suites, err := tlsutil.ParseCiphers(conf.ClusterCipherSuites)
if err != nil {

View File

@ -43,7 +43,7 @@ var (
var state consts.ReplicationState
resp := &logical.Response{
Data: map[string]interface{}{
"mode": state.String(),
"mode": "disabled",
},
}
return resp, nil

View File

@ -480,7 +480,7 @@ func (c *forwardingClient) startHeartbeat() {
case <-c.echoContext.Done():
c.echoTicker.Stop()
c.core.logger.Trace("forwarding: stopping heartbeating")
atomic.StoreUint32(c.core.activeNodeReplicationState, uint32(consts.ReplicationDisabled))
atomic.StoreUint32(c.core.activeNodeReplicationState, uint32(consts.ReplicationUnknown))
return
case <-c.echoTicker.C:
tick()

View File

@ -59,14 +59,20 @@ $ curl \
This response is only returned for a `GET` request.
Note: `replication_perf_mode` and `replication_dr_mode` reflect the state of
the active node in the cluster; if you are querying it for a standby that has
just come up, it can take a small time for the active node to inform the
standby of its status.
```json
{
"cluster_id": "c9abceea-4f46-4dab-a688-5ce55f89e228",
"cluster_name": "vault-cluster-5515c810",
"version": "0.6.2",
"server_time_utc": 1469555798,
"standby": false,
"initialized": true,
"sealed": false,
"initialized": true
"standby": false,
"replication_perf_mode": "disabled",
"replication_dr_mode": "disabled",
"server_time_utc": 1516639589,
"version": "0.9.1",
"cluster_name": "vault-cluster-3bd69ca2",
"cluster_id": "00af5aa8-c87d-b5fc-e82e-97cd8dfaf731"
}
```

View File

@ -59,6 +59,15 @@ This endpoint is used to install a license into Vault.
| :------- | :--------------------------- | :--------------------- |
| `PUT` | `/sys/license` | `204 (empty body)` |
### Parameters
- `text` `(string: <required>)`  The text of the license.
*DR Secondary Specific Parameters*
- `dr_operation_token` `(string: <required>)` - DR operation token used to authorize this request.
### Sample Payload
```json

View File

@ -35,7 +35,7 @@ primary, it will look something like:
```json
{
"mode": "dr-primary",
"mode": "primary",
"cluster_id": "d4095d41-3aee-8791-c421-9bc7f88f7c3e",
"known_secondaries": [],
"last_wal": 0,

View File

@ -35,7 +35,7 @@ primary, it will look something like:
```json
{
"mode": "perf-primary",
"mode": "primary",
"cluster_id": "d4095d41-3aee-8791-c421-9bc7f88f7c3e",
"known_secondaries": [],
"last_wal": 0,

View File

@ -99,7 +99,7 @@ primary, it will look something like:
],
"last_wal": 43,
"merkle_root": "86d67839f47045f7d24beb4f39b14504d15a146c",
"mode": "dr-primary",
"mode": "primary",
"primary_cluster_addr": ""
},
"performance": {
@ -109,7 +109,7 @@ primary, it will look something like:
],
"last_wal": 43,
"merkle_root": "e0531d566b23403101b0868e85b63d6774ba0ef2",
"mode": "perf-primary",
"mode": "primary",
"primary_cluster_addr": ""
}
},