Renamed serviceId to serviceID

This commit is contained in:
Diptanu Choudhury
2015-12-14 15:57:56 -08:00
parent ed04b11862
commit f089e249c8
6 changed files with 42 additions and 42 deletions

View File

@@ -47,8 +47,8 @@ func (a *consulApiClient) ServiceRegister(service *consul.AgentServiceRegistrati
return a.client.Agent().ServiceRegister(service)
}
func (a *consulApiClient) ServiceDeregister(serviceId string) error {
return a.client.Agent().ServiceDeregister(serviceId)
func (a *consulApiClient) ServiceDeregister(serviceID string) error {
return a.client.Agent().ServiceDeregister(serviceID)
}
func (a *consulApiClient) Services() (map[string]*consul.AgentService, error) {
@@ -168,12 +168,12 @@ func (c *ConsulService) Deregister(task *structs.Task, alloc *structs.Allocation
delete(c.trackedTasks, fmt.Sprintf("%s-%s", alloc.ID, task.Name))
c.trackedTskLock.Unlock()
for _, service := range task.Services {
serviceId := alloc.Services[service.Name]
if serviceId == "" {
serviceID := alloc.Services[service.Name]
if serviceID == "" {
continue
}
c.logger.Printf("[INFO] consul: deregistering service %v with consul", service.Name)
if err := c.deregisterService(serviceId); err != nil {
if err := c.deregisterService(serviceID); err != nil {
c.printLogMessage("[DEBUG] consul: error in deregistering service %v from consul", service.Name)
mErr.Errors = append(mErr.Errors, err)
}
@@ -225,18 +225,18 @@ func (c *ConsulService) performSync() {
// Add services and checks which Consul doesn't know about
for _, trackedTask := range c.trackedTasks {
for _, service := range trackedTask.task.Services {
serviceId := trackedTask.alloc.Services[service.Name]
serviceID := trackedTask.alloc.Services[service.Name]
// Add new services which Consul agent isn't aware of
knownServices[serviceId] = struct{}{}
if _, ok := consulServices[serviceId]; !ok {
knownServices[serviceID] = struct{}{}
if _, ok := consulServices[serviceID]; !ok {
c.printLogMessage("[INFO] consul: registering service %s with consul.", service.Name)
c.registerService(service, trackedTask.task, trackedTask.alloc)
continue
}
// If a service has changed, re-register it with Consul agent
if service.Hash() != c.serviceStates[serviceId] {
if service.Hash() != c.serviceStates[serviceID] {
c.printLogMessage("[INFO] consul: reregistering service %s with consul.", service.Name)
c.registerService(service, trackedTask.task, trackedTask.alloc)
continue
@@ -244,11 +244,11 @@ func (c *ConsulService) performSync() {
// Add new checks that Consul isn't aware of
for _, check := range service.Checks {
checkId := check.Hash(serviceId)
knownChecks[checkId] = struct{}{}
if _, ok := consulChecks[checkId]; !ok {
checkID := check.Hash(serviceID)
knownChecks[checkID] = struct{}{}
if _, ok := consulChecks[checkID]; !ok {
host, port := trackedTask.task.FindHostAndPortFor(service.PortLabel)
cr := c.makeCheck(serviceId, check, host, port)
cr := c.makeCheck(serviceID, check, host, port)
c.registerCheck(cr)
}
}
@@ -256,9 +256,9 @@ func (c *ConsulService) performSync() {
}
// Remove services from the service tracker which no longer exists
for serviceId := range c.serviceStates {
if _, ok := knownServices[serviceId]; !ok {
delete(c.serviceStates, serviceId)
for serviceID := range c.serviceStates {
if _, ok := knownServices[serviceID]; !ok {
delete(c.serviceStates, serviceID)
}
}
@@ -286,11 +286,11 @@ func (c *ConsulService) registerService(service *structs.Service, task *structs.
if host == "" || port == 0 {
return fmt.Errorf("consul: the port:%q marked for registration of service: %q couldn't be found", service.PortLabel, service.Name)
}
serviceId := alloc.Services[service.Name]
c.serviceStates[serviceId] = service.Hash()
serviceID := alloc.Services[service.Name]
c.serviceStates[serviceID] = service.Hash()
asr := &consul.AgentServiceRegistration{
ID: serviceId,
ID: serviceID,
Name: service.Name,
Tags: service.Tags,
Port: port,
@@ -302,7 +302,7 @@ func (c *ConsulService) registerService(service *structs.Service, task *structs.
mErr.Errors = append(mErr.Errors, err)
}
for _, check := range service.Checks {
cr := c.makeCheck(serviceId, check, host, port)
cr := c.makeCheck(serviceID, check, host, port)
if err := c.registerCheck(cr); err != nil {
c.printLogMessage("[DEBUG] consul: error while registerting check %v with consul: %v", check.Name, err)
mErr.Errors = append(mErr.Errors, err)
@@ -325,21 +325,21 @@ func (c *ConsulService) deregisterCheck(checkID string) error {
}
// deregisterService de-registers a Service with a specific id from Consul
func (c *ConsulService) deregisterService(serviceId string) error {
delete(c.serviceStates, serviceId)
if err := c.client.ServiceDeregister(serviceId); err != nil {
func (c *ConsulService) deregisterService(serviceID string) error {
delete(c.serviceStates, serviceID)
if err := c.client.ServiceDeregister(serviceID); err != nil {
return err
}
return nil
}
// makeCheck creates a Consul Check Registration struct
func (c *ConsulService) makeCheck(serviceId string, check *structs.ServiceCheck, ip string, port int) *consul.AgentCheckRegistration {
checkId := check.Hash(serviceId)
func (c *ConsulService) makeCheck(serviceID string, check *structs.ServiceCheck, ip string, port int) *consul.AgentCheckRegistration {
checkID := check.Hash(serviceID)
cr := &consul.AgentCheckRegistration{
ID: checkId,
ID: checkID,
Name: check.Name,
ServiceID: serviceId,
ServiceID: serviceID,
}
cr.Interval = check.Interval.String()
cr.Timeout = check.Timeout.String()

View File

@@ -34,7 +34,7 @@ func (a *mockConsulApiClient) ServiceRegister(service *consul.AgentServiceRegist
return nil
}
func (a *mockConsulApiClient) ServiceDeregister(serviceId string) error {
func (a *mockConsulApiClient) ServiceDeregister(serviceID string) error {
a.serviceDeregisterCallCount += 1
return nil
}
@@ -96,11 +96,11 @@ func TestConsul_MakeChecks(t *testing.T) {
}
c := newConsulService()
serviceId := fmt.Sprintf("%s-1234", structs.NomadConsulPrefix)
serviceID := fmt.Sprintf("%s-1234", structs.NomadConsulPrefix)
check1 := c.makeCheck(serviceId, service.Checks[0], "10.10.0.1", 8090)
check2 := c.makeCheck(serviceId, service.Checks[1], "10.10.0.1", 8090)
check3 := c.makeCheck(serviceId, service.Checks[2], "10.10.0.1", 8090)
check1 := c.makeCheck(serviceID, service.Checks[0], "10.10.0.1", 8090)
check2 := c.makeCheck(serviceID, service.Checks[1], "10.10.0.1", 8090)
check3 := c.makeCheck(serviceID, service.Checks[2], "10.10.0.1", 8090)
if check1.HTTP != "http://10.10.0.1:8090/foo/bar" {
t.Fatalf("Invalid http url for check: %v", check1.HTTP)

View File

@@ -1130,9 +1130,9 @@ func (sc *ServiceCheck) Validate() error {
return nil
}
func (sc *ServiceCheck) Hash(serviceId string) string {
func (sc *ServiceCheck) Hash(serviceID string) string {
h := sha1.New()
io.WriteString(h, serviceId)
io.WriteString(h, serviceID)
io.WriteString(h, sc.Name)
io.WriteString(h, sc.Type)
io.WriteString(h, sc.Script)
@@ -1500,7 +1500,7 @@ func (a *Allocation) Stub() *AllocListStub {
}
}
func (a *Allocation) PopulateServiceIds() {
func (a *Allocation) PopulateServiceIDs() {
a.Services = make(map[string]string)
tg := a.Job.LookupTaskGroup(a.TaskGroup)
for _, task := range tg.Tasks {

View File

@@ -406,7 +406,7 @@ func TestInvalidServiceCheck(t *testing.T) {
}
}
func TestDistinctCheckId(t *testing.T) {
func TestDistinctCheckID(t *testing.T) {
c1 := ServiceCheck{
Name: "web-health",
Type: "http",
@@ -429,10 +429,10 @@ func TestDistinctCheckId(t *testing.T) {
Interval: 4 * time.Second,
Timeout: 3 * time.Second,
}
serviceId := "123"
c1Hash := c1.Hash(serviceId)
c2Hash := c2.Hash(serviceId)
c3Hash := c3.Hash(serviceId)
serviceID := "123"
c1Hash := c1.Hash(serviceID)
c2Hash := c2.Hash(serviceID)
c3Hash := c3.Hash(serviceID)
if c1Hash == c2Hash || c1Hash == c3Hash || c3Hash == c2Hash {
t.Fatalf("Checks need to be uniq c1: %s, c2: %s, c3: %s", c1Hash, c2Hash, c3Hash)

View File

@@ -281,7 +281,7 @@ func (s *GenericScheduler) computePlacements(place []allocTuple) error {
// Generate the service ids for the tasks which this allocation is going
// to run
alloc.PopulateServiceIds()
alloc.PopulateServiceIDs()
// Set fields based on if we found an allocation option
if option != nil {

View File

@@ -248,7 +248,7 @@ func (s *SystemScheduler) computePlacements(place []allocTuple) error {
// Generate the service ids for the tasks that this allocation is going
// to run
alloc.PopulateServiceIds()
alloc.PopulateServiceIDs()
// Set fields based on if we found an allocation option
if option != nil {