2014-01-30 23:35:38 +00:00
|
|
|
package agent
|
|
|
|
|
2014-02-03 23:15:35 +00:00
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/consul/structs"
|
|
|
|
)
|
|
|
|
|
2014-01-30 23:35:38 +00:00
|
|
|
// ServiceDefinition is used to JSON decode the Service definitions
|
|
|
|
type ServiceDefinition struct {
|
2015-01-02 21:10:05 +00:00
|
|
|
ID string
|
|
|
|
Name string
|
|
|
|
Tags []string
|
|
|
|
Address string
|
|
|
|
Port int
|
|
|
|
Check CheckType
|
2014-02-03 23:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ServiceDefinition) NodeService() *structs.NodeService {
|
|
|
|
ns := &structs.NodeService{
|
|
|
|
ID: s.ID,
|
|
|
|
Service: s.Name,
|
2014-04-03 19:12:23 +00:00
|
|
|
Tags: s.Tags,
|
2015-01-02 21:10:05 +00:00
|
|
|
Address: s.Address,
|
2014-02-03 23:15:35 +00:00
|
|
|
Port: s.Port,
|
|
|
|
}
|
|
|
|
if ns.ID == "" && ns.Service != "" {
|
|
|
|
ns.ID = ns.Service
|
|
|
|
}
|
|
|
|
return ns
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ServiceDefinition) CheckType() *CheckType {
|
|
|
|
if s.Check.Script == "" && s.Check.Interval == 0 && s.Check.TTL == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &s.Check
|
2014-01-30 23:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ChecKDefinition is used to JSON decode the Check definitions
|
|
|
|
type CheckDefinition struct {
|
2014-02-03 23:15:35 +00:00
|
|
|
ID string
|
|
|
|
Name string
|
|
|
|
Notes string
|
|
|
|
CheckType `mapstructure:",squash"`
|
2014-01-30 23:35:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:15:35 +00:00
|
|
|
func (c *CheckDefinition) HealthCheck(node string) *structs.HealthCheck {
|
|
|
|
health := &structs.HealthCheck{
|
|
|
|
Node: node,
|
|
|
|
CheckID: c.ID,
|
|
|
|
Name: c.Name,
|
2014-10-15 17:08:13 +00:00
|
|
|
Status: structs.HealthCritical,
|
2014-02-03 23:15:35 +00:00
|
|
|
Notes: c.Notes,
|
|
|
|
}
|
|
|
|
if health.CheckID == "" && health.Name != "" {
|
|
|
|
health.CheckID = health.Name
|
|
|
|
}
|
|
|
|
return health
|
2014-01-30 23:35:38 +00:00
|
|
|
}
|