mirror of https://github.com/status-im/consul.git
parent
c6e441dd60
commit
abd83f2d28
|
@ -18,7 +18,9 @@ import (
|
||||||
"github.com/hashicorp/consul/types"
|
"github.com/hashicorp/consul/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the configuration for the State.
|
// Config is the configuration for the State. It is
|
||||||
|
// populated during NewLocalAgent from the agent configuration to avoid
|
||||||
|
// race conditions with the agent configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AdvertiseAddr string
|
AdvertiseAddr string
|
||||||
CheckUpdateInterval time.Duration
|
CheckUpdateInterval time.Duration
|
||||||
|
@ -108,7 +110,7 @@ type rpc interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// State is used to represent the node's services,
|
// State is used to represent the node's services,
|
||||||
// and checks. We use it to perform anti-entropy with the
|
// and checks. We used it to perform anti-entropy with the
|
||||||
// catalog representation
|
// catalog representation
|
||||||
type State struct {
|
type State struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
@ -152,7 +154,7 @@ type State struct {
|
||||||
tokens *token.Store
|
tokens *token.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLocalState creates a new local state for the agent.
|
// NewLocalState creates a is used to initialize the local state
|
||||||
func NewState(c Config, lg *log.Logger, tokens *token.Store) *State {
|
func NewState(c Config, lg *log.Logger, tokens *token.Store) *State {
|
||||||
l := &State{
|
l := &State{
|
||||||
config: c,
|
config: c,
|
||||||
|
@ -166,8 +168,6 @@ func NewState(c Config, lg *log.Logger, tokens *token.Store) *State {
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDiscardCheckOutput configures whether the check output
|
|
||||||
// is discarded. This can be changed at runtime.
|
|
||||||
func (l *State) SetDiscardCheckOutput(b bool) {
|
func (l *State) SetDiscardCheckOutput(b bool) {
|
||||||
l.discardCheckOutput.Store(b)
|
l.discardCheckOutput.Store(b)
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,6 @@ func (l *State) ServiceToken(id string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// serviceToken returns an ACL token associated with a service.
|
// serviceToken returns an ACL token associated with a service.
|
||||||
// This method is not synchronized and the lock must already be held.
|
|
||||||
func (l *State) serviceToken(id string) string {
|
func (l *State) serviceToken(id string) string {
|
||||||
var token string
|
var token string
|
||||||
if s := l.services[id]; s != nil {
|
if s := l.services[id]; s != nil {
|
||||||
|
@ -311,7 +310,6 @@ func (l *State) CheckToken(checkID types.CheckID) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkToken returns an ACL token associated with a check.
|
// checkToken returns an ACL token associated with a check.
|
||||||
// This method is not synchronized and the lock must already be held.
|
|
||||||
func (l *State) checkToken(id types.CheckID) string {
|
func (l *State) checkToken(id types.CheckID) string {
|
||||||
var token string
|
var token string
|
||||||
c := l.checks[id]
|
c := l.checks[id]
|
||||||
|
@ -502,10 +500,7 @@ func (l *State) CheckStates() map[types.CheckID]*CheckState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CriticalCheckStates returns the locally registered checks that the
|
// CriticalCheckStates returns the locally registered checks that the
|
||||||
// agent is aware of and are being kept in sync with the server.
|
// agent is aware of and are being kept in sync with the server
|
||||||
// The map contains a shallow copy of the current check states but
|
|
||||||
// references to the actual check definition which must not be
|
|
||||||
// modified.
|
|
||||||
func (l *State) CriticalCheckStates() map[types.CheckID]*CheckState {
|
func (l *State) CriticalCheckStates() map[types.CheckID]*CheckState {
|
||||||
l.RLock()
|
l.RLock()
|
||||||
defer l.RUnlock()
|
defer l.RUnlock()
|
||||||
|
|
Loading…
Reference in New Issue