open-consul/command/agent/structs.go

80 lines
1.8 KiB
Go
Raw Normal View History

package agent
import (
"github.com/hashicorp/consul/consul/structs"
)
// ServiceDefinition is used to JSON decode the Service definitions
type ServiceDefinition struct {
2015-08-18 17:34:55 +00:00
ID string
Name string
Tags []string
Address string
Port int
Check CheckType
Checks CheckTypes
Token string
EnableTagDrift bool
}
func (s *ServiceDefinition) NodeService() *structs.NodeService {
ns := &structs.NodeService{
2015-08-18 17:34:55 +00:00
ID: s.ID,
Service: s.Name,
Tags: s.Tags,
Address: s.Address,
Port: s.Port,
EnableTagDrift: s.EnableTagDrift,
}
if ns.ID == "" && ns.Service != "" {
ns.ID = ns.Service
}
return ns
}
func (s *ServiceDefinition) CheckTypes() (checks CheckTypes) {
s.Checks = append(s.Checks, &s.Check)
for _, check := range s.Checks {
if check.Valid() {
checks = append(checks, check)
}
}
return
}
// ChecKDefinition is used to JSON decode the Check definitions
type CheckDefinition struct {
ID string
Name string
Notes string
ServiceID string
Token string
Status string
CheckType `mapstructure:",squash"`
}
func (c *CheckDefinition) HealthCheck(node string) *structs.HealthCheck {
health := &structs.HealthCheck{
Node: node,
CheckID: c.ID,
Name: c.Name,
Status: structs.HealthCritical,
Notes: c.Notes,
ServiceID: c.ServiceID,
}
if c.Status != "" {
health.Status = c.Status
}
if health.CheckID == "" && health.Name != "" {
health.CheckID = health.Name
}
return health
}
// persistedService is used to wrap a service definition and bundle it
// with an ACL token so we can restore both at a later agent start.
type persistedService struct {
Token string
Service *structs.NodeService
}