Added support for Service Metadata
This commit is contained in:
parent
32f89f4306
commit
3acc5b58d4
|
@ -576,6 +576,11 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re
|
||||||
|
|
||||||
// Get the node service.
|
// Get the node service.
|
||||||
ns := args.NodeService()
|
ns := args.NodeService()
|
||||||
|
if err := structs.ValidateMetadata(ns.ServiceMeta, false); err != nil {
|
||||||
|
resp.WriteHeader(http.StatusBadRequest)
|
||||||
|
fmt.Fprint(resp, fmt.Errorf("Invalid Meta: %v", err))
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Verify the check type.
|
// Verify the check type.
|
||||||
chkTypes, err := args.CheckTypes()
|
chkTypes, err := args.CheckTypes()
|
||||||
|
|
|
@ -6,6 +6,7 @@ type ServiceDefinition struct {
|
||||||
Name string
|
Name string
|
||||||
Tags []string
|
Tags []string
|
||||||
Address string
|
Address string
|
||||||
|
ServiceMeta map[string]string
|
||||||
Port int
|
Port int
|
||||||
Check CheckType
|
Check CheckType
|
||||||
Checks CheckTypes
|
Checks CheckTypes
|
||||||
|
@ -19,6 +20,7 @@ func (s *ServiceDefinition) NodeService() *NodeService {
|
||||||
Service: s.Name,
|
Service: s.Name,
|
||||||
Tags: s.Tags,
|
Tags: s.Tags,
|
||||||
Address: s.Address,
|
Address: s.Address,
|
||||||
|
ServiceMeta: s.ServiceMeta,
|
||||||
Port: s.Port,
|
Port: s.Port,
|
||||||
EnableTagOverride: s.EnableTagOverride,
|
EnableTagOverride: s.EnableTagOverride,
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,6 +368,7 @@ type ServiceNode struct {
|
||||||
ServiceName string
|
ServiceName string
|
||||||
ServiceTags []string
|
ServiceTags []string
|
||||||
ServiceAddress string
|
ServiceAddress string
|
||||||
|
ServiceMeta map[string]string
|
||||||
ServicePort int
|
ServicePort int
|
||||||
ServiceEnableTagOverride bool
|
ServiceEnableTagOverride bool
|
||||||
|
|
||||||
|
@ -390,6 +391,7 @@ func (s *ServiceNode) PartialClone() *ServiceNode {
|
||||||
ServiceTags: tags,
|
ServiceTags: tags,
|
||||||
ServiceAddress: s.ServiceAddress,
|
ServiceAddress: s.ServiceAddress,
|
||||||
ServicePort: s.ServicePort,
|
ServicePort: s.ServicePort,
|
||||||
|
ServiceMeta: s.ServiceMeta,
|
||||||
ServiceEnableTagOverride: s.ServiceEnableTagOverride,
|
ServiceEnableTagOverride: s.ServiceEnableTagOverride,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
|
@ -406,6 +408,7 @@ func (s *ServiceNode) ToNodeService() *NodeService {
|
||||||
Tags: s.ServiceTags,
|
Tags: s.ServiceTags,
|
||||||
Address: s.ServiceAddress,
|
Address: s.ServiceAddress,
|
||||||
Port: s.ServicePort,
|
Port: s.ServicePort,
|
||||||
|
ServiceMeta: s.ServiceMeta,
|
||||||
EnableTagOverride: s.ServiceEnableTagOverride,
|
EnableTagOverride: s.ServiceEnableTagOverride,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
|
@ -422,6 +425,7 @@ type NodeService struct {
|
||||||
Service string
|
Service string
|
||||||
Tags []string
|
Tags []string
|
||||||
Address string
|
Address string
|
||||||
|
ServiceMeta map[string]string
|
||||||
Port int
|
Port int
|
||||||
EnableTagOverride bool
|
EnableTagOverride bool
|
||||||
|
|
||||||
|
@ -438,6 +442,7 @@ func (s *NodeService) IsSame(other *NodeService) bool {
|
||||||
!reflect.DeepEqual(s.Tags, other.Tags) ||
|
!reflect.DeepEqual(s.Tags, other.Tags) ||
|
||||||
s.Address != other.Address ||
|
s.Address != other.Address ||
|
||||||
s.Port != other.Port ||
|
s.Port != other.Port ||
|
||||||
|
!reflect.DeepEqual(s.ServiceMeta, other.ServiceMeta) ||
|
||||||
s.EnableTagOverride != other.EnableTagOverride {
|
s.EnableTagOverride != other.EnableTagOverride {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -457,6 +462,7 @@ func (s *NodeService) ToServiceNode(node string) *ServiceNode {
|
||||||
ServiceTags: s.Tags,
|
ServiceTags: s.Tags,
|
||||||
ServiceAddress: s.Address,
|
ServiceAddress: s.Address,
|
||||||
ServicePort: s.Port,
|
ServicePort: s.Port,
|
||||||
|
ServiceMeta: s.ServiceMeta,
|
||||||
ServiceEnableTagOverride: s.EnableTagOverride,
|
ServiceEnableTagOverride: s.EnableTagOverride,
|
||||||
RaftIndex: RaftIndex{
|
RaftIndex: RaftIndex{
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
|
|
13
api/agent.go
13
api/agent.go
|
@ -60,12 +60,13 @@ type MembersOpts struct {
|
||||||
|
|
||||||
// AgentServiceRegistration is used to register a new service
|
// AgentServiceRegistration is used to register a new service
|
||||||
type AgentServiceRegistration struct {
|
type AgentServiceRegistration struct {
|
||||||
ID string `json:",omitempty"`
|
ID string `json:",omitempty"`
|
||||||
Name string `json:",omitempty"`
|
Name string `json:",omitempty"`
|
||||||
Tags []string `json:",omitempty"`
|
Tags []string `json:",omitempty"`
|
||||||
Port int `json:",omitempty"`
|
Port int `json:",omitempty"`
|
||||||
Address string `json:",omitempty"`
|
Address string `json:",omitempty"`
|
||||||
EnableTagOverride bool `json:",omitempty"`
|
EnableTagOverride bool `json:",omitempty"`
|
||||||
|
ServiceMeta map[string]string `json:",omitempty"`
|
||||||
Check *AgentServiceCheck
|
Check *AgentServiceCheck
|
||||||
Checks AgentServiceChecks
|
Checks AgentServiceChecks
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ type CatalogService struct {
|
||||||
ServiceName string
|
ServiceName string
|
||||||
ServiceAddress string
|
ServiceAddress string
|
||||||
ServiceTags []string
|
ServiceTags []string
|
||||||
|
ServiceMeta map[string]string
|
||||||
ServicePort int
|
ServicePort int
|
||||||
ServiceEnableTagOverride bool
|
ServiceEnableTagOverride bool
|
||||||
CreateIndex uint64
|
CreateIndex uint64
|
||||||
|
|
Loading…
Reference in New Issue