Beispiel #1
0
func (r *ConsulAdapter) Register(service *bridge.Service) error {
	agentService := new(consulapi.AgentService)
	agentService.ID = service.ID
	agentService.Service = service.Name
	agentService.Port = service.Port
	agentService.Tags = service.Tags
	agentService.Address = service.IP

	registration := new(consulapi.CatalogRegistration)
	registration.Node = Hostname
	registration.Address = service.Origin.HostIP
	registration.Datacenter = service.Attrs["region"]
	registration.Service = agentService
	registration.Check = nil

	writeOptions := new(consulapi.WriteOptions)
	writeOptions.Datacenter = service.Attrs["region"]

	out, _ := json.Marshal(registration)

	log.Println("REGISTERING :", string(out))
	_, res := r.client.Catalog().Register(registration, writeOptions)

	return res
}
Beispiel #2
0
// createService creates a Consul AgentService from a Nomad Service
func (c *ConsulService) createService(service *structs.Service) (*consul.AgentService, error) {
	srv := consul.AgentService{
		ID:      service.ID(c.allocID, c.task.Name),
		Service: service.Name,
		Tags:    service.Tags,
	}
	host, port := c.task.FindHostAndPortFor(service.PortLabel)
	if host != "" {
		srv.Address = host
	}

	if port != 0 {
		srv.Port = port
	}

	return &srv, nil
}
Beispiel #3
0
// createService creates a Consul AgentService from a Nomad Service
func (c *ConsulService) createService(service *structs.Service) (*consul.AgentService, error) {
	srv := consul.AgentService{
		ID:      service.ID(c.serviceIdentifier),
		Service: service.Name,
		Tags:    service.Tags,
	}
	host, port := c.addrFinder(service.PortLabel)
	if host != "" {
		srv.Address = host
	}

	if port != 0 {
		srv.Port = port
	}

	return &srv, nil
}