Rename ConsulService back to Service

This commit is contained in:
Alex Dadgar 2016-06-12 16:36:49 -07:00
parent 3bef934580
commit 8e231fa382
15 changed files with 94 additions and 95 deletions

View File

@ -1345,7 +1345,7 @@ func (c *Client) setupConsulSyncer() error {
consulServicesSyncFn := func() error {
const estInitialConsulServices = 8
const serviceGroupName = "executor"
services := make([]*structs.ConsulService, 0, estInitialConsulServices)
services := make([]*structs.Service, 0, estInitialConsulServices)
for allocID, ar := range c.getAllocRunners() {
ar.taskStatusLock.RLock()
taskStates := copyTaskStates(ar.taskStates)
@ -1353,7 +1353,7 @@ func (c *Client) setupConsulSyncer() error {
for taskName, taskState := range taskStates {
if taskState.State == structs.TaskStateRunning {
if tr, ok := ar.tasks[taskName]; ok {
for _, service := range tr.task.ConsulServices {
for _, service := range tr.task.Services {
if service.Name == "" {
service.Name = fmt.Sprintf("%s-%s", tr.task.Name, allocID)
}

View File

@ -365,7 +365,7 @@ func (e *UniversalExecutor) UpdateTask(task *structs.Task) error {
// Re-syncing task with Consul agent
if e.consulSyncer != nil {
e.interpolateServices(e.ctx.Task)
e.consulSyncer.SetServices(e.ctx.AllocID, task.ConsulServices)
e.consulSyncer.SetServices(e.ctx.AllocID, task.Services)
}
return nil
}
@ -496,7 +496,7 @@ func (e *UniversalExecutor) SyncServices(ctx *ConsulContext) error {
if e.ctx != nil {
syncerFn := func() error {
e.interpolateServices(e.ctx.Task)
e.consulSyncer.SetServices(e.ctx.AllocID, e.ctx.Task.ConsulServices)
e.consulSyncer.SetServices(e.ctx.AllocID, e.ctx.Task.Services)
return nil
}
e.consulSyncer.AddPeriodicHandler(e.ctx.AllocID, syncerFn)
@ -700,7 +700,7 @@ func (e *UniversalExecutor) createCheck(check *structs.ServiceCheck, checkID str
// task's environment.
func (e *UniversalExecutor) interpolateServices(task *structs.Task) {
e.ctx.TaskEnv.Build()
for _, service := range task.ConsulServices {
for _, service := range task.Services {
for _, check := range service.Checks {
if check.Type == structs.ServiceCheckScript {
check.Name = e.ctx.TaskEnv.ReplaceEnv(check.Name)

View File

@ -338,18 +338,18 @@ func TestExecutorInterpolateServices(t *testing.T) {
executor.(*UniversalExecutor).ctx = ctx
executor.(*UniversalExecutor).interpolateServices(task)
expectedTags := []string{"pci:true", "datacenter:dc1"}
if !reflect.DeepEqual(task.ConsulServices[0].Tags, expectedTags) {
t.Fatalf("expected: %v, actual: %v", expectedTags, task.ConsulServices[0].Tags)
if !reflect.DeepEqual(task.Services[0].Tags, expectedTags) {
t.Fatalf("expected: %v, actual: %v", expectedTags, task.Services[0].Tags)
}
expectedCheckCmd := "/usr/local/check-table-mysql"
expectedCheckArgs := []string{"5.6"}
if !reflect.DeepEqual(task.ConsulServices[0].Checks[0].Command, expectedCheckCmd) {
t.Fatalf("expected: %v, actual: %v", expectedCheckCmd, task.ConsulServices[0].Checks[0].Command)
if !reflect.DeepEqual(task.Services[0].Checks[0].Command, expectedCheckCmd) {
t.Fatalf("expected: %v, actual: %v", expectedCheckCmd, task.Services[0].Checks[0].Command)
}
if !reflect.DeepEqual(task.ConsulServices[0].Checks[0].Args, expectedCheckArgs) {
t.Fatalf("expected: %v, actual: %v", expectedCheckArgs, task.ConsulServices[0].Checks[0].Args)
if !reflect.DeepEqual(task.Services[0].Checks[0].Args, expectedCheckArgs) {
t.Fatalf("expected: %v, actual: %v", expectedCheckArgs, task.Services[0].Checks[0].Args)
}
}

View File

@ -368,18 +368,18 @@ func (a *Agent) setupServer() error {
// Create the Nomad Server services for Consul
if a.config.Consul.AutoRegister && a.config.Consul.ServerServiceName != "" {
const serviceGroupName = "server"
a.consulSyncer.SetServices(serviceGroupName, []*structs.ConsulService{
&structs.ConsulService{
a.consulSyncer.SetServices(serviceGroupName, []*structs.Service{
&structs.Service{
Name: a.config.Consul.ServerServiceName,
PortLabel: a.serverHTTPAddr,
Tags: []string{consul.ServiceTagHTTP},
},
&structs.ConsulService{
&structs.Service{
Name: a.config.Consul.ServerServiceName,
PortLabel: a.serverRPCAddr,
Tags: []string{consul.ServiceTagRPC},
},
&structs.ConsulService{
&structs.Service{
PortLabel: a.serverSerfAddr,
Name: a.config.Consul.ServerServiceName,
Tags: []string{consul.ServiceTagSerf},
@ -419,13 +419,13 @@ func (a *Agent) setupClient() error {
// Create the Nomad Server services for Consul
if a.config.Consul.AutoRegister && a.config.Consul.ClientServiceName != "" {
const serviceGroupName = "client"
a.consulSyncer.SetServices(serviceGroupName, []*structs.ConsulService{
&structs.ConsulService{
a.consulSyncer.SetServices(serviceGroupName, []*structs.Service{
&structs.Service{
Name: a.config.Consul.ClientServiceName,
PortLabel: a.clientHTTPAddr,
Tags: []string{consul.ServiceTagHTTP},
},
&structs.ConsulService{
&structs.Service{
Name: a.config.Consul.ClientServiceName,
PortLabel: a.clientRPCAddr,
Tags: []string{consul.ServiceTagRPC},

View File

@ -217,8 +217,8 @@ func (c *Syncer) filterPrefix() string {
}
// GenerateServiceID creates a unique Consul ServiceID for a given
// ConsulService.
func (c *Syncer) GenerateServiceID(groupName string, service *structs.ConsulService) string {
// Service.
func (c *Syncer) GenerateServiceID(groupName string, service *structs.Service) string {
numTags := len(service.Tags)
switch numTags {
case 0:
@ -233,7 +233,7 @@ func (c *Syncer) GenerateServiceID(groupName string, service *structs.ConsulServ
// SetServices assigns the slice of Nomad Services to the provided services
// group name.
func (c *Syncer) SetServices(groupName string, services []*structs.ConsulService) error {
func (c *Syncer) SetServices(groupName string, services []*structs.Service) error {
var mErr multierror.Error
registeredServices := make([]*consul.AgentServiceRegistration, 0, len(services))
for _, service := range services {
@ -702,7 +702,7 @@ func (c *Syncer) createDelegatedCheckReg(check *structs.ServiceCheck, service *c
}
// createService creates a Consul AgentService from a Nomad ConsulService.
func (c *Syncer) createService(service *structs.ConsulService) (*consul.AgentServiceRegistration, error) {
func (c *Syncer) createService(service *structs.Service) (*consul.AgentServiceRegistration, error) {
c.registryLock.RLock()
defer c.registryLock.RUnlock()

View File

@ -27,7 +27,7 @@ var (
Interval: 30 * time.Second,
Timeout: 5 * time.Second,
}
service1 = structs.ConsulService{
service1 = structs.Service{
Name: "foo-1",
Tags: []string{"tag1", "tag2"},
PortLabel: "port1",
@ -36,7 +36,7 @@ var (
},
}
service2 = structs.ConsulService{
service2 = structs.Service{
Name: "foo-2",
Tags: []string{"tag1", "tag2"},
PortLabel: "port2",
@ -61,9 +61,9 @@ func TestConsulServiceRegisterServices(t *testing.T) {
}
defer cs.Shutdown()
service1 := &structs.ConsulService{Name: task.Name}
service2 := &structs.ConsulService{Name: task.Name}
services := []*structs.ConsulService{service1, service2}
service1 := &structs.Service{Name: task.Name}
service2 := &structs.Service{Name: task.Name}
services := []*structs.Service{service1, service2}
service1.ServiceID = fmt.Sprintf("%s-%s:%s/%s", cs.GenerateServiceID(serviceGroupName, service1), task.Name, allocID)
service2.ServiceID = fmt.Sprintf("%s-%s:%s/%s", cs.GenerateServiceID(serviceGroupName, service2), task.Name, allocID)
@ -98,14 +98,14 @@ func TestConsulServiceUpdateService(t *testing.T) {
//Update Service defn 1
newTags := []string{"tag3"}
task.ConsulServices[0].Tags = newTags
task.Services[0].Tags = newTags
if err := cs.SyncServices(); err != nil {
t.Fatalf("err: %v", err)
}
// Make sure all the services and checks are still present
service1 := &structs.ConsulService{Name: task.Name}
service2 := &structs.ConsulService{Name: task.Name}
services := []*structs.ConsulService{service1, service2}
service1 := &structs.Service{Name: task.Name}
service2 := &structs.Service{Name: task.Name}
services := []*structs.Service{service1, service2}
service1.ServiceID = fmt.Sprintf("%s-%s:%s/%s", cs.GenerateServiceID(serviceGroupName, service1), task.Name, allocID)
service2.ServiceID = fmt.Sprintf("%s-%s:%s/%s", cs.GenerateServiceID(serviceGroupName, service2), task.Name, allocID)
if err := servicesPresent(t, services, cs); err != nil {
@ -127,7 +127,7 @@ func TestConsulServiceUpdateService(t *testing.T) {
}
}
func servicesPresent(t *testing.T, configuredServices []*structs.ConsulService, syncer *Syncer) error {
func servicesPresent(t *testing.T, configuredServices []*structs.Service, syncer *Syncer) error {
var mErr multierror.Error
services, err := syncer.client.Agent().Services()
if err != nil {
@ -159,8 +159,8 @@ func checksPresent(t *testing.T, checkIDs []string, syncer *Syncer) error {
func mockTask() *structs.Task {
task := structs.Task{
Name: "foo",
ConsulServices: []*structs.ConsulService{&service1, &service2},
Name: "foo",
Services: []*structs.Service{&service1, &service2},
Resources: &structs.Resources{
Networks: []*structs.NetworkResource{
&structs.NetworkResource{

View File

@ -701,7 +701,7 @@ func parseArtifactOption(result map[string]string, list *ast.ObjectList) error {
}
func parseServices(jobName string, taskGroupName string, task *structs.Task, serviceObjs *ast.ObjectList) error {
task.ConsulServices = make([]*structs.ConsulService, len(serviceObjs.Items))
task.Services = make([]*structs.Service, len(serviceObjs.Items))
var defaultServiceName bool
for idx, o := range serviceObjs.Items {
// Check for invalid keys
@ -715,7 +715,7 @@ func parseServices(jobName string, taskGroupName string, task *structs.Task, ser
return multierror.Prefix(err, fmt.Sprintf("service (%d) ->", idx))
}
var service structs.ConsulService
var service structs.Service
var m map[string]interface{}
if err := hcl.DecodeObject(&m, o.Val); err != nil {
return err
@ -750,13 +750,13 @@ func parseServices(jobName string, taskGroupName string, task *structs.Task, ser
}
}
task.ConsulServices[idx] = &service
task.Services[idx] = &service
}
return nil
}
func parseChecks(service *structs.ConsulService, checkObjs *ast.ObjectList) error {
func parseChecks(service *structs.Service, checkObjs *ast.ObjectList) error {
service.Checks = make([]*structs.ServiceCheck, len(checkObjs.Items))
for idx, co := range checkObjs.Items {
// Check for invalid keys

View File

@ -97,7 +97,7 @@ func TestParse(t *testing.T) {
},
},
},
ConsulServices: []*structs.ConsulService{
Services: []*structs.Service{
{
Name: "binstore-storagelocker-binsl-binstore",
Tags: []string{"foo", "bar"},

View File

@ -48,7 +48,7 @@ func TestJobEndpoint_Register(t *testing.T) {
if out.CreateIndex != resp.JobModifyIndex {
t.Fatalf("index mis-match")
}
serviceName := out.TaskGroups[0].Tasks[0].ConsulServices[0].Name
serviceName := out.TaskGroups[0].Tasks[0].Services[0].Name
expectedServiceName := "web-frontend"
if serviceName != expectedServiceName {
t.Fatalf("Expected Service Name: %s, Actual: %s", expectedServiceName, serviceName)
@ -237,7 +237,7 @@ func TestJobEndpoint_Register_Periodic(t *testing.T) {
if out.CreateIndex != resp.JobModifyIndex {
t.Fatalf("index mis-match")
}
serviceName := out.TaskGroups[0].Tasks[0].ConsulServices[0].Name
serviceName := out.TaskGroups[0].Tasks[0].Services[0].Name
expectedServiceName := "web-frontend"
if serviceName != expectedServiceName {
t.Fatalf("Expected Service Name: %s, Actual: %s", expectedServiceName, serviceName)
@ -685,12 +685,12 @@ func TestJobEndpoint_GetJob(t *testing.T) {
// Make a copy of the origin job and change the service name so that we can
// do a deep equal with the response from the GET JOB Api
j := job
j.TaskGroups[0].Tasks[0].ConsulServices[0].Name = "web-frontend"
j.TaskGroups[0].Tasks[0].Services[0].Name = "web-frontend"
for tgix, tg := range j.TaskGroups {
for tidx, t := range tg.Tasks {
for sidx, service := range t.ConsulServices {
for sidx, service := range t.Services {
for cidx, check := range service.Checks {
check.Name = resp2.Job.TaskGroups[tgix].Tasks[tidx].ConsulServices[sidx].Checks[cidx].Name
check.Name = resp2.Job.TaskGroups[tgix].Tasks[tidx].Services[sidx].Checks[cidx].Name
}
}
}

View File

@ -94,7 +94,7 @@ func Job() *structs.Job {
Env: map[string]string{
"FOO": "bar",
},
ConsulServices: []*structs.ConsulService{
Services: []*structs.Service{
{
Name: "${TASK}-frontend",
PortLabel: "http",

View File

@ -386,7 +386,7 @@ func (t *Task) Diff(other *Task, contextual bool) (*TaskDiff, error) {
}
// Services diff
if sDiffs := serviceDiffs(t.ConsulServices, other.ConsulServices, contextual); sDiffs != nil {
if sDiffs := serviceDiffs(t.Services, other.Services, contextual); sDiffs != nil {
diff.Objects = append(diff.Objects, sDiffs...)
}
@ -458,18 +458,18 @@ func (t TaskDiffs) Less(i, j int) bool { return t[i].Name < t[j].Name }
// serviceDiff returns the diff of two service objects. If contextual diff is
// enabled, all fields will be returned, even if no diff occurred.
func serviceDiff(old, new *ConsulService, contextual bool) *ObjectDiff {
func serviceDiff(old, new *Service, contextual bool) *ObjectDiff {
diff := &ObjectDiff{Type: DiffTypeNone, Name: "Service"}
var oldPrimitiveFlat, newPrimitiveFlat map[string]string
if reflect.DeepEqual(old, new) {
return nil
} else if old == nil {
old = &ConsulService{}
old = &Service{}
diff.Type = DiffTypeAdded
newPrimitiveFlat = flatmap.Flatten(new, nil, true)
} else if new == nil {
new = &ConsulService{}
new = &Service{}
diff.Type = DiffTypeDeleted
oldPrimitiveFlat = flatmap.Flatten(old, nil, true)
} else {
@ -491,9 +491,9 @@ func serviceDiff(old, new *ConsulService, contextual bool) *ObjectDiff {
// serviceDiffs diffs a set of services. If contextual diff is enabled, unchanged
// fields within objects nested in the tasks will be returned.
func serviceDiffs(old, new []*ConsulService, contextual bool) []*ObjectDiff {
oldMap := make(map[string]*ConsulService, len(old))
newMap := make(map[string]*ConsulService, len(new))
func serviceDiffs(old, new []*Service, contextual bool) []*ObjectDiff {
oldMap := make(map[string]*Service, len(old))
newMap := make(map[string]*Service, len(new))
for _, o := range old {
oldMap[o.Name] = o
}

View File

@ -2363,7 +2363,7 @@ func TestTaskDiff(t *testing.T) {
{
// Services edited (no checks)
Old: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "foo",
PortLabel: "foo",
@ -2379,7 +2379,7 @@ func TestTaskDiff(t *testing.T) {
},
},
New: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "bar",
PortLabel: "bar",
@ -2452,7 +2452,7 @@ func TestTaskDiff(t *testing.T) {
// Services edited (no checks) with context
Contextual: true,
Old: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "foo",
PortLabel: "foo",
@ -2460,7 +2460,7 @@ func TestTaskDiff(t *testing.T) {
},
},
New: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "foo",
PortLabel: "bar",
@ -2500,7 +2500,7 @@ func TestTaskDiff(t *testing.T) {
{
// Service Checks edited
Old: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "foo",
Checks: []*ServiceCheck{
@ -2539,7 +2539,7 @@ func TestTaskDiff(t *testing.T) {
},
},
New: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "foo",
Checks: []*ServiceCheck{
@ -2701,7 +2701,7 @@ func TestTaskDiff(t *testing.T) {
// Service Checks edited with context
Contextual: true,
Old: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "foo",
Checks: []*ServiceCheck{
@ -2720,7 +2720,7 @@ func TestTaskDiff(t *testing.T) {
},
},
New: &Task{
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "foo",
Checks: []*ServiceCheck{

View File

@ -1553,9 +1553,8 @@ func (sc *ServiceCheck) Hash(serviceID string) string {
return fmt.Sprintf("%x", h.Sum(nil))
}
// The ConsulService model represents a Consul service definition in Nomad
// Agent's Config.
type ConsulService struct {
// Service represents a Consul service definition in Nomad
type Service struct {
// ServiceID is the calculated Consul ServiceID used for a service.
// This value is not available to be set via configuration.
ServiceID string `mapstructure:"-"`
@ -1573,11 +1572,11 @@ type ConsulService struct {
Checks []*ServiceCheck // List of checks associated with the service
}
func (s *ConsulService) Copy() *ConsulService {
func (s *Service) Copy() *Service {
if s == nil {
return nil
}
ns := new(ConsulService)
ns := new(Service)
*ns = *s
ns.Tags = CopySliceString(ns.Tags)
@ -1594,7 +1593,7 @@ func (s *ConsulService) Copy() *ConsulService {
// InitFields interpolates values of Job, Task Group and Task in the Service
// Name. This also generates check names, service id and check ids.
func (s *ConsulService) InitFields(job string, taskGroup string, task string) {
func (s *Service) InitFields(job string, taskGroup string, task string) {
s.Name = args.ReplaceEnv(s.Name, map[string]string{
"JOB": job,
"TASKGROUP": taskGroup,
@ -1611,7 +1610,7 @@ func (s *ConsulService) InitFields(job string, taskGroup string, task string) {
}
// Validate checks if the Check definition is valid
func (s *ConsulService) Validate() error {
func (s *Service) Validate() error {
var mErr multierror.Error
// Ensure the service name is valid per RFC-952 §1
@ -1637,7 +1636,7 @@ func (s *ConsulService) Validate() error {
// Hash calculates the hash of the check based on it's content and the service
// which owns it
func (s *ConsulService) Hash() string {
func (s *Service) Hash() string {
h := sha1.New()
io.WriteString(h, s.Name)
io.WriteString(h, strings.Join(s.Tags, ""))
@ -1696,7 +1695,7 @@ type Task struct {
Env map[string]string
// List of service definitions exposed by the Task
ConsulServices []*ConsulService
Services []*Service
// Constraints can be specified at a task level and apply only to
// the particular task.
@ -1729,12 +1728,12 @@ func (t *Task) Copy() *Task {
*nt = *t
nt.Env = CopyMapStringString(nt.Env)
if t.ConsulServices != nil {
services := make([]*ConsulService, len(nt.ConsulServices))
for i, s := range nt.ConsulServices {
if t.Services != nil {
services := make([]*Service, len(nt.Services))
for i, s := range nt.Services {
services[i] = s.Copy()
}
nt.ConsulServices = services
nt.Services = services
}
nt.Constraints = CopySliceConstraints(nt.Constraints)
@ -1771,7 +1770,7 @@ func (t *Task) InitFields(job *Job, tg *TaskGroup) {
// and Tasks in all the service Names of a Task. This also generates the service
// id, check id and check names.
func (t *Task) InitServiceFields(job string, taskGroup string) {
for _, service := range t.ConsulServices {
for _, service := range t.Services {
service.InitFields(job, taskGroup, t.Name)
}
}
@ -1861,7 +1860,7 @@ func validateServices(t *Task) error {
// unique.
servicePorts := make(map[string][]string)
knownServices := make(map[string]struct{})
for i, service := range t.ConsulServices {
for i, service := range t.Services {
if err := service.Validate(); err != nil {
outer := fmt.Errorf("service %d validation failed: %s", i, err)
mErr.Errors = append(mErr.Errors, outer)

View File

@ -136,7 +136,7 @@ func testJob() *Job {
GetterSource: "http://foo.com",
},
},
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "${TASK}-frontend",
PortLabel: "http",
@ -283,7 +283,7 @@ func TestTask_Validate(t *testing.T) {
}
func TestTask_Validate_Services(t *testing.T) {
s1 := &ConsulService{
s1 := &Service{
Name: "service-name",
PortLabel: "bar",
Checks: []*ServiceCheck{
@ -298,7 +298,7 @@ func TestTask_Validate_Services(t *testing.T) {
},
}
s2 := &ConsulService{
s2 := &Service{
Name: "service-name",
}
@ -311,7 +311,7 @@ func TestTask_Validate_Services(t *testing.T) {
MemoryMB: 100,
IOPS: 10,
},
ConsulServices: []*ConsulService{s1, s2},
Services: []*Service{s1, s2},
}
err := task.Validate()
if err == nil {
@ -568,7 +568,7 @@ func BenchmarkEncodeDecode(b *testing.B) {
}
func TestInvalidServiceCheck(t *testing.T) {
s := ConsulService{
s := Service{
Name: "service-name",
PortLabel: "bar",
Checks: []*ServiceCheck{
@ -582,7 +582,7 @@ func TestInvalidServiceCheck(t *testing.T) {
t.Fatalf("Service should be invalid (invalid type)")
}
s = ConsulService{
s = Service{
Name: "service.name",
PortLabel: "bar",
}
@ -590,7 +590,7 @@ func TestInvalidServiceCheck(t *testing.T) {
t.Fatalf("Service should be invalid (contains a dot): %v", err)
}
s = ConsulService{
s = Service{
Name: "-my-service",
PortLabel: "bar",
}
@ -598,7 +598,7 @@ func TestInvalidServiceCheck(t *testing.T) {
t.Fatalf("Service should be invalid (begins with a hyphen): %v", err)
}
s = ConsulService{
s = Service{
Name: "abcdef0123456789-abcdef0123456789-abcdef0123456789-abcdef0123456",
PortLabel: "bar",
}
@ -606,7 +606,7 @@ func TestInvalidServiceCheck(t *testing.T) {
t.Fatalf("Service should be invalid (too long): %v", err)
}
s = ConsulService{
s = Service{
Name: "service-name",
Checks: []*ServiceCheck{
{
@ -628,7 +628,7 @@ func TestInvalidServiceCheck(t *testing.T) {
t.Fatalf("service should be invalid (tcp/http checks with no port): %v", err)
}
s = ConsulService{
s = Service{
Name: "service-name",
Checks: []*ServiceCheck{
{
@ -684,7 +684,7 @@ func TestService_InitFields(t *testing.T) {
taskGroup := "cache"
task := "redis"
s := ConsulService{
s := Service{
Name: "${TASK}-db",
}
@ -722,7 +722,7 @@ func TestJob_ExpandServiceNames(t *testing.T) {
Tasks: []*Task{
{
Name: "frontend",
ConsulServices: []*ConsulService{
Services: []*Service{
{
Name: "${BASE}-default",
},
@ -746,12 +746,12 @@ func TestJob_ExpandServiceNames(t *testing.T) {
j.InitFields()
service1Name := j.TaskGroups[0].Tasks[0].ConsulServices[0].Name
service1Name := j.TaskGroups[0].Tasks[0].Services[0].Name
if service1Name != "my-job-web-frontend-default" {
t.Fatalf("Expected Service Name: %s, Actual: %s", "my-job-web-frontend-default", service1Name)
}
service2Name := j.TaskGroups[0].Tasks[0].ConsulServices[1].Name
service2Name := j.TaskGroups[0].Tasks[0].Services[1].Name
if service2Name != "jmx" {
t.Fatalf("Expected Service Name: %s, Actual: %s", "jmx", service2Name)
}

View File

@ -671,7 +671,7 @@ func TestInplaceUpdate_Success(t *testing.T) {
*tg = *job.TaskGroups[0]
resource := &structs.Resources{CPU: 737}
tg.Tasks[0].Resources = resource
newServices := []*structs.ConsulService{
newServices := []*structs.Service{
{
Name: "dummy-service",
PortLabel: "http",
@ -683,10 +683,10 @@ func TestInplaceUpdate_Success(t *testing.T) {
}
// Delete service 2
tg.Tasks[0].ConsulServices = tg.Tasks[0].ConsulServices[:1]
tg.Tasks[0].Services = tg.Tasks[0].Services[:1]
// Add the new services
tg.Tasks[0].ConsulServices = append(tg.Tasks[0].ConsulServices, newServices...)
tg.Tasks[0].Services = append(tg.Tasks[0].Services, newServices...)
updates := []allocTuple{{Alloc: alloc, TaskGroup: tg}}
stack := NewGenericStack(false, ctx)
@ -721,12 +721,12 @@ func TestInplaceUpdate_Success(t *testing.T) {
t.Fatalf("bad")
}
if len(a.Job.TaskGroups[0].Tasks[0].ConsulServices) != 3 {
t.Fatalf("Expected number of services: %v, Actual: %v", 3, len(a.Job.TaskGroups[0].Tasks[0].ConsulServices))
if len(a.Job.TaskGroups[0].Tasks[0].Services) != 3 {
t.Fatalf("Expected number of services: %v, Actual: %v", 3, len(a.Job.TaskGroups[0].Tasks[0].Services))
}
serviceNames := make(map[string]struct{}, 3)
for _, consulService := range a.Job.TaskGroups[0].Tasks[0].ConsulServices {
for _, consulService := range a.Job.TaskGroups[0].Tasks[0].Services {
serviceNames[consulService.Name] = struct{}{}
}
if len(serviceNames) != 3 {