Browse Source

Added support for Service Metadata

pull/3881/head
Pierre Souchay 7 years ago
parent
commit
80dde5465b
  1. 5
      agent/agent_endpoint.go
  2. 2
      agent/structs/service_definition.go
  3. 6
      agent/structs/structs.go
  4. 13
      api/agent.go
  5. 1
      api/catalog.go

5
agent/agent_endpoint.go

@ -576,6 +576,11 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re
// Get the node service.
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.
chkTypes, err := args.CheckTypes()

2
agent/structs/service_definition.go

@ -6,6 +6,7 @@ type ServiceDefinition struct {
Name string
Tags []string
Address string
ServiceMeta map[string]string
Port int
Check CheckType
Checks CheckTypes
@ -19,6 +20,7 @@ func (s *ServiceDefinition) NodeService() *NodeService {
Service: s.Name,
Tags: s.Tags,
Address: s.Address,
ServiceMeta: s.ServiceMeta,
Port: s.Port,
EnableTagOverride: s.EnableTagOverride,
}

6
agent/structs/structs.go

@ -368,6 +368,7 @@ type ServiceNode struct {
ServiceName string
ServiceTags []string
ServiceAddress string
ServiceMeta map[string]string
ServicePort int
ServiceEnableTagOverride bool
@ -390,6 +391,7 @@ func (s *ServiceNode) PartialClone() *ServiceNode {
ServiceTags: tags,
ServiceAddress: s.ServiceAddress,
ServicePort: s.ServicePort,
ServiceMeta: s.ServiceMeta,
ServiceEnableTagOverride: s.ServiceEnableTagOverride,
RaftIndex: RaftIndex{
CreateIndex: s.CreateIndex,
@ -406,6 +408,7 @@ func (s *ServiceNode) ToNodeService() *NodeService {
Tags: s.ServiceTags,
Address: s.ServiceAddress,
Port: s.ServicePort,
ServiceMeta: s.ServiceMeta,
EnableTagOverride: s.ServiceEnableTagOverride,
RaftIndex: RaftIndex{
CreateIndex: s.CreateIndex,
@ -422,6 +425,7 @@ type NodeService struct {
Service string
Tags []string
Address string
ServiceMeta map[string]string
Port int
EnableTagOverride bool
@ -438,6 +442,7 @@ func (s *NodeService) IsSame(other *NodeService) bool {
!reflect.DeepEqual(s.Tags, other.Tags) ||
s.Address != other.Address ||
s.Port != other.Port ||
!reflect.DeepEqual(s.ServiceMeta, other.ServiceMeta) ||
s.EnableTagOverride != other.EnableTagOverride {
return false
}
@ -457,6 +462,7 @@ func (s *NodeService) ToServiceNode(node string) *ServiceNode {
ServiceTags: s.Tags,
ServiceAddress: s.Address,
ServicePort: s.Port,
ServiceMeta: s.ServiceMeta,
ServiceEnableTagOverride: s.EnableTagOverride,
RaftIndex: RaftIndex{
CreateIndex: s.CreateIndex,

13
api/agent.go

@ -60,12 +60,13 @@ type MembersOpts struct {
// AgentServiceRegistration is used to register a new service
type AgentServiceRegistration struct {
ID string `json:",omitempty"`
Name string `json:",omitempty"`
Tags []string `json:",omitempty"`
Port int `json:",omitempty"`
Address string `json:",omitempty"`
EnableTagOverride bool `json:",omitempty"`
ID string `json:",omitempty"`
Name string `json:",omitempty"`
Tags []string `json:",omitempty"`
Port int `json:",omitempty"`
Address string `json:",omitempty"`
EnableTagOverride bool `json:",omitempty"`
ServiceMeta map[string]string `json:",omitempty"`
Check *AgentServiceCheck
Checks AgentServiceChecks
}

1
api/catalog.go

@ -22,6 +22,7 @@ type CatalogService struct {
ServiceName string
ServiceAddress string
ServiceTags []string
ServiceMeta map[string]string
ServicePort int
ServiceEnableTagOverride bool
CreateIndex uint64

Loading…
Cancel
Save