Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure task status is reported before cleanup #705

Merged
merged 9 commits into from
Feb 14, 2017
2 changes: 1 addition & 1 deletion agent/acs/handler/acs_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ func validateAddedContainer(expectedContainer *api.Container, addedContainer *ap
// fields that we are intrested in for comparison
containerToCompareFromAdded := &api.Container{
Name: addedContainer.Name,
Cpu: addedContainer.Cpu,
CPU: addedContainer.CPU,
Essential: addedContainer.Essential,
Memory: addedContainer.Memory,
Image: addedContainer.Image,
Expand Down
2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func _main() int {
// the credentials handler
credentialsManager := credentials.NewManager()
// Create image manager. This will be used by the task engine for saving image states
state := dockerstate.NewDockerTaskEngineState()
state := dockerstate.NewTaskEngineState()
imageManager := engine.NewImageManager(cfg, dockerClient, state)
if *versionFlag {
versionableEngine := engine.NewTaskEngine(cfg, dockerClient, credentialsManager, containerChangeEventStream, imageManager, state)
Expand Down
18 changes: 17 additions & 1 deletion agent/api/container.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -62,3 +62,19 @@ func (c *Container) SetDesiredStatus(status ContainerStatus) {

c.DesiredStatus = status
}

// GetSentStatus safely returns the SentStatus of the container
func (c *Container) GetSentStatus() ContainerStatus {
c.sentStatusLock.RLock()
defer c.sentStatusLock.RUnlock()

return c.SentStatus
}

// SetSentStatus safely sets the SentStatus of the container
func (c *Container) SetSentStatus(status ContainerStatus) {
c.sentStatusLock.Lock()
defer c.sentStatusLock.Unlock()

c.SentStatus = status
}
6 changes: 3 additions & 3 deletions agent/api/container_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -26,7 +26,7 @@ func TestOverridden(t *testing.T) {
Name: "name",
Image: "image",
Command: []string{"foo", "bar"},
Cpu: 1,
CPU: 1,
Memory: 1,
Links: []string{},
Ports: []PortBinding{PortBinding{10, 10, "", TransportProtocolTCP}},
Expand Down Expand Up @@ -63,7 +63,7 @@ func (pair configPair) Equal() bool {
if (conf.Memory / 1024 / 1024) != int64(cont.Memory) {
return false
}
if conf.CPUShares != int64(cont.Cpu) {
if conf.CPUShares != int64(cont.CPU) {
return false
}
if conf.Image != cont.Image {
Expand Down
2 changes: 1 addition & 1 deletion agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (client *APIECSClient) SubmitContainerStateChange(change api.ContainerState
for i, binding := range change.PortBindings {
hostPort := int64(binding.HostPort)
containerPort := int64(binding.ContainerPort)
bindIP := binding.BindIp
bindIP := binding.BindIP
protocol := binding.Protocol.String()
networkBindings[i] = &ecs.NetworkBinding{
BindIP: &bindIP,
Expand Down
6 changes: 3 additions & 3 deletions agent/api/ecsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ func TestSubmitContainerStateChange(t *testing.T) {
Status: api.ContainerRunning,
PortBindings: []api.PortBinding{
api.PortBinding{
BindIp: "1.2.3.4",
BindIP: "1.2.3.4",
ContainerPort: 1,
HostPort: 2,
},
api.PortBinding{
BindIp: "2.2.3.4",
BindIP: "2.2.3.4",
ContainerPort: 3,
HostPort: 4,
Protocol: api.TransportProtocolUDP,
Expand Down Expand Up @@ -247,7 +247,7 @@ func buildAttributeList(capabilities []string, attributes map[string]string) []*

func TestReRegisterContainerInstance(t *testing.T) {
additionalAttributes := map[string]string{"my_custom_attribute": "Custom_Value1",
"my_other_custom_attribute": "Custom_Value2",
"my_other_custom_attribute": "Custom_Value2",
"attribute_name_with_no_value": "",
}

Expand Down
4 changes: 2 additions & 2 deletions agent/api/port_binding.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -47,7 +47,7 @@ func PortBindingFromDockerPortBinding(dockerPortBindings map[docker.Port][]docke
portBindings = append(portBindings, PortBinding{
ContainerPort: uint16(containerPort),
HostPort: uint16(hostPort),
BindIp: binding.HostIP,
BindIP: binding.HostIP,
Protocol: protocol,
})
}
Expand Down
8 changes: 4 additions & 4 deletions agent/api/port_binding_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -31,7 +31,7 @@ func TestPortBindingFromDockerPortBinding(t *testing.T) {
},
[]PortBinding{
PortBinding{
BindIp: "1.2.3.4",
BindIP: "1.2.3.4",
HostPort: 55,
ContainerPort: 53,
Protocol: TransportProtocolUDP,
Expand All @@ -47,13 +47,13 @@ func TestPortBindingFromDockerPortBinding(t *testing.T) {
},
[]PortBinding{
PortBinding{
BindIp: "2.3.4.5",
BindIP: "2.3.4.5",
HostPort: 8080,
ContainerPort: 80,
Protocol: TransportProtocolTCP,
},
PortBinding{
BindIp: "5.6.7.8",
BindIP: "5.6.7.8",
HostPort: 80,
ContainerPort: 80,
Protocol: TransportProtocolTCP,
Expand Down
32 changes: 24 additions & 8 deletions agent/api/task.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -265,7 +265,7 @@ func (task *Task) dockerConfig(container *Container) (*docker.Config, *DockerCli
Volumes: dockerVolumes,
Env: dockerEnv,
Memory: dockerMem,
CPUShares: task.dockerCpuShares(container.Cpu),
CPUShares: task.dockerCpuShares(container.CPU),
}

if container.DockerConfig.Config != nil {
Expand Down Expand Up @@ -545,17 +545,17 @@ func (task *Task) updateKnownStatusTime() {
}

func (task *Task) SetCredentialsId(id string) {
task.credentialsIdLock.Lock()
defer task.credentialsIdLock.Unlock()
task.credentialsIDLock.Lock()
defer task.credentialsIDLock.Unlock()

task.credentialsId = id
task.credentialsID = id
}

func (task *Task) GetCredentialsId() string {
task.credentialsIdLock.RLock()
defer task.credentialsIdLock.RUnlock()
task.credentialsIDLock.RLock()
defer task.credentialsIDLock.RUnlock()

return task.credentialsId
return task.credentialsID
}

func (task *Task) GetDesiredStatus() TaskStatus {
Expand All @@ -571,3 +571,19 @@ func (task *Task) SetDesiredStatus(status TaskStatus) {

task.DesiredStatus = status
}

// GetSentStatus safely returns the SentStatus of the task
func (task *Task) GetSentStatus() TaskStatus {
task.sentStatusLock.RLock()
defer task.sentStatusLock.RUnlock()

return task.SentStatus
}

// SetSentStatus safely sets the SentStatus of the task
func (task *Task) SetSentStatus(status TaskStatus) {
task.sentStatusLock.Lock()
defer task.sentStatusLock.Unlock()

task.SentStatus = status
}
18 changes: 9 additions & 9 deletions agent/api/task_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -33,7 +33,7 @@ func strptr(s string) *string { return &s }
func dockerMap(task *Task) map[string]*DockerContainer {
m := make(map[string]*DockerContainer)
for _, c := range task.Containers {
m[c.Name] = &DockerContainer{DockerId: "dockerid-" + c.Name, DockerName: "dockername-" + c.Name, Container: c}
m[c.Name] = &DockerContainer{DockerID: "dockerid-" + c.Name, DockerName: "dockername-" + c.Name, Container: c}
}
return m
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestDockerConfigCPUShareZero(t *testing.T) {
Containers: []*Container{
&Container{
Name: "c1",
Cpu: 0,
CPU: 0,
},
},
}
Expand All @@ -104,7 +104,7 @@ func TestDockerConfigCPUShareMinimum(t *testing.T) {
Containers: []*Container{
&Container{
Name: "c1",
Cpu: 1,
CPU: 1,
},
},
}
Expand All @@ -124,7 +124,7 @@ func TestDockerConfigCPUShareUnchanged(t *testing.T) {
Containers: []*Container{
&Container{
Name: "c1",
Cpu: 100,
CPU: 100,
},
},
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestDockerHostConfigRawConfigMerging(t *testing.T) {
&Container{
Name: "c1",
Image: "image",
Cpu: 50,
CPU: 50,
Memory: 100,
VolumesFrom: []VolumeFrom{VolumeFrom{SourceContainer: "c2"}},
DockerConfig: DockerConfig{
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestDockerConfigRawConfigMerging(t *testing.T) {
&Container{
Name: "c1",
Image: "image",
Cpu: 50,
CPU: 50,
Memory: 100,
DockerConfig: DockerConfig{
Config: strptr(string(rawConfig)),
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestGetCredentialsEndpointWhenCredentialsAreSet(t *testing.T) {
Name: "c2",
Environment: make(map[string]string),
}},
credentialsId: credentialsIDInTask,
credentialsID: credentialsIDInTask,
}

taskCredentials := &credentials.TaskIAMRoleCredentials{
Expand Down Expand Up @@ -652,7 +652,7 @@ func TestTaskFromACS(t *testing.T) {
EntryPoint: &[]string{"sh", "-c"},
Essential: true,
Environment: map[string]string{"key": "value"},
Cpu: 10,
CPU: 10,
Memory: 100,
MountPoints: []MountPoint{
MountPoint{
Expand Down
4 changes: 2 additions & 2 deletions agent/api/testutils/container_equal.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -38,7 +38,7 @@ func ContainersEqual(lhs, rhs *api.Container) bool {
if !utils.StrSliceEqual(lhs.Command, rhs.Command) {
return false
}
if lhs.Cpu != rhs.Cpu || lhs.Memory != rhs.Memory {
if lhs.CPU != rhs.CPU || lhs.Memory != rhs.Memory {
return false
}
// Order doesn't matter
Expand Down
6 changes: 3 additions & 3 deletions agent/api/testutils/container_equal_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -30,7 +30,7 @@ func TestContainerEqual(t *testing.T) {
Container{Name: "name"}, Container{Name: "name"},
Container{Image: "nginx"}, Container{Image: "nginx"},
Container{Command: []string{"c"}}, Container{Command: []string{"c"}},
Container{Cpu: 1}, Container{Cpu: 1},
Container{CPU: 1}, Container{CPU: 1},
Container{Memory: 1}, Container{Memory: 1},
Container{Links: []string{"1", "2"}}, Container{Links: []string{"1", "2"}},
Container{Links: []string{"1", "2"}}, Container{Links: []string{"2", "1"}},
Expand All @@ -53,7 +53,7 @@ func TestContainerEqual(t *testing.T) {
Container{Image: "nginx"}, Container{Image: "えんじんえっくす"},
Container{Command: []string{"c"}}, Container{Command: []string{"し"}},
Container{Command: []string{"c", "b"}}, Container{Command: []string{"b", "c"}},
Container{Cpu: 1}, Container{Cpu: 2e2},
Container{CPU: 1}, Container{CPU: 2e2},
Container{Memory: 1}, Container{Memory: 2e2},
Container{Links: []string{"1", "2"}}, Container{Links: []string{"1", "二"}},
Container{VolumesFrom: []VolumeFrom{VolumeFrom{"1", false}, VolumeFrom{"2", true}}}, Container{VolumesFrom: []VolumeFrom{VolumeFrom{"1", false}, VolumeFrom{"二", false}}},
Expand Down
Loading