Skip to content

Commit

Permalink
statemanager: add container start/stop statemanger
Browse files Browse the repository at this point in the history
  • Loading branch information
adnxn committed Feb 18, 2019
1 parent 79bd517 commit 3265bf9
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 2 deletions.
2 changes: 1 addition & 1 deletion agent/api/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,7 @@ func TestInitializeContainerOrderingWithError(t *testing.T) {
assert.Error(t, errLink2)
}

func TestPostUnmarshalPerContainerTimeouts(t *testing.T) {
func TestTaskFromACSPerContainerTimeouts(t *testing.T) {
modelTimeout := int64(10)
expectedTimeout := uint(modelTimeout)

Expand Down
5 changes: 4 additions & 1 deletion agent/statemanager/state_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ const (
// a) Add 'Associations' field to 'api.task.task'
// b) Add 'GPUIDs' field to 'apicontainer.Container'
// c) Add 'NvidiaRuntime' field to 'api.task.task'
// 20) Add 'DependsOn' field to 'apicontainer.Container'
// 20)
// a) Add 'DependsOn' field to 'apicontainer.Container'
// b) Add 'StartTime' field to 'api.container.Container'
// c) Add 'StopTime' field to 'api.container.Container'
ECSDataVersion = 20

// ecsDataFile specifies the filename in the ECS_DATADIR
Expand Down
35 changes: 35 additions & 0 deletions agent/statemanager/state_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,38 @@ func TestLoadsDataForContainerOrdering(t *testing.T) {
assert.Equal(t, "container_1", dependsOn[0].Container)
assert.Equal(t, "START", dependsOn[0].Condition)
}

func TestLoadsDataForPerContainerTimeouts(t *testing.T) {
cleanup, err := setupWindowsTest(filepath.Join(".", "testdata", "v20", "perContainerTimeouts", "ecs_agent_data.json"))
require.Nil(t, err, "Failed to set up test")
defer cleanup()
cfg := &config.Config{DataDir: filepath.Join(".", "testdata", "v20", "perContainerTimeouts")}
taskEngine := engine.NewTaskEngine(&config.Config{}, nil, nil, nil, nil, dockerstate.NewTaskEngineState(), nil, nil)
var containerInstanceArn, cluster, savedInstanceID string
var sequenceNumber int64
stateManager, err := statemanager.NewStateManager(cfg,
statemanager.AddSaveable("TaskEngine", taskEngine),
statemanager.AddSaveable("ContainerInstanceArn", &containerInstanceArn),
statemanager.AddSaveable("Cluster", &cluster),
statemanager.AddSaveable("EC2InstanceID", &savedInstanceID),
statemanager.AddSaveable("SeqNum", &sequenceNumber),
)
assert.NoError(t, err)
err = stateManager.Load()
assert.NoError(t, err)
assert.Equal(t, "state-file", cluster)
assert.EqualValues(t, 0, sequenceNumber)

tasks, err := taskEngine.ListTasks()
assert.NoError(t, err)
assert.Equal(t, 1, len(tasks))

task := tasks[0]
assert.Equal(t, "arn:aws:ecs:us-west-2:1234567890:task/33425c99-5db7-45fb-8244-bc94d00661e4", task.Arn)
assert.Equal(t, "per-container-timeouts", task.Family)
assert.Equal(t, 1, len(task.Containers))

c1 := task.Containers[0]
assert.Equal(t, uint(10), c1.StartTimeout)
assert.Equal(t, uint(10), c1.StopTimeout)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"Data": {
"Cluster": "state-file",
"ContainerInstanceArn": "arn:aws:ecs:us-west-2:1234567890:container-instance/46efd519-df3f-4096-8f34-faebb1747752",
"EC2InstanceID": "i-0da29eb1a8a98768b",
"TaskEngine": {
"Tasks": [
{
"Arn": "arn:aws:ecs:us-west-2:1234567890:task/33425c99-5db7-45fb-8244-bc94d00661e4",
"Family": "per-container-timeouts",
"Version": "1",
"Containers": [
{
"Name": "container_1",
"Image": "amazonlinux:1",
"ImageID": "sha256:7f929d2604c7e504a568eac9a2523c1b9e9b15e1fcee4076e1411a552913d08e",
"Command": [
"sleep",
"3600"
],
"Cpu": 0,
"GPUIDs": ["0", "1"],
"Memory": 512,
"Links": null,
"volumesFrom": [],
"mountPoints": [],
"portMappings": [],
"Essential": true,
"StartTimeout":10,
"StopTimeout":10,
"EntryPoint": null,
"environment": {
"NVIDIA_VISIBLE_DEVICES": "0,1"
},
"overrides": {
"command": null
},
"dockerConfig": {
"config": "{}",
"hostConfig": "{\"CapAdd\":[],\"CapDrop\":[]}",
"version": "1.17"
},
"registryAuthentication": null,
"secrets": [],
"LogsAuthStrategy": "",
"desiredStatus": "RUNNING",
"KnownStatus": "RUNNING",
"TransitionDependencySet": {
"1": {
"ContainerDependencies": null,
"ResourceDependencies": [
{
"Name": "cgroup",
"RequiredStatus": 1
}
]
}
},
"RunDependencies": null,
"IsInternal": "NORMAL",
"ApplyingError": {
"error": "API error (500): Get https://registry-1.docker.io/v2/library/amazonlinux/manifests/1: toomanyrequests: too many failed login attempts for username or IP address\n",
"name": "CannotPullContainerError"
},
"SentStatus": "RUNNING",
"metadataFileUpdated": false,
"KnownExitCode": null,
"KnownPortBindings": null
}
],
"Associations": [
{
"Containers": ["container_1"],
"Content": {
"Encoding": "base64",
"Value": "val"
},
"Name": "0",
"Type": "gpu"
},
{
"Containers": ["container_1"],
"Content": {
"Encoding": "base64",
"Value": "val"
},
"Name": "1",
"Type": "gpu"
}
],
"resources": {
"cgroup": [
{
"cgroupRoot": "/ecs/33425c99-5db7-45fb-8244-bc94d00661e4",
"cgroupMountPath": "/sys/fs/cgroup",
"createdAt": "0001-01-01T00:00:00Z",
"desiredStatus": "CREATED",
"knownStatus": "CREATED",
"resourceSpec": {
"cpu": {
"shares": 2
}
}
}
]
},
"volumes": [],
"DesiredStatus": "RUNNING",
"KnownStatus": "RUNNING",
"KnownTime": "2018-10-04T18:05:49.121835686Z",
"PullStartedAt": "2018-10-04T18:05:34.359798761Z",
"PullStoppedAt": "2018-10-04T18:05:48.445985904Z",
"ExecutionStoppedAt": "0001-01-01T00:00:00Z",
"SentStatus": "RUNNING",
"StartSequenceNumber": 2,
"StopSequenceNumber": 0,
"executionCredentialsID": "b1a6ede6-1a9f-4ab3-a02e-bd3e51b11244",
"ENI": null,
"MemoryCPULimitsEnabled": true,
"PlatformFields": {}
}
],
"IdToContainer": {
"8f5e6e3091f221c876103289ddabcbcdeb64acd7ac7e2d0cf4da2be2be9d8956": {
"DockerId": "8f5e6e3091f221c876103289ddabcbcdeb64acd7ac7e2d0cf4da2be2be9d8956",
"DockerName": "ecs-private-registry-state-1-container1-a68ef4b6e0fba38d3500",
"Container": {
"Name": "container_1",
"Image": "amazonlinux:1",
"ImageID": "sha256:7f929d2604c7e504a568eac9a2523c1b9e9b15e1fcee4076e1411a552913d08e",
"Command": [
"sleep",
"3600"
],
"Cpu": 0,
"Memory": 512,
"Links": null,
"volumesFrom": [],
"mountPoints": [],
"portMappings": [],
"Essential": true,
"EntryPoint": null,
"environment": {},
"overrides": {
"command": null
},
"dockerConfig": {
"config": "{}",
"hostConfig": "{\"CapAdd\":[],\"CapDrop\":[]}",
"version": "1.17"
},
"registryAuthentication": null,
"LogsAuthStrategy": "",
"desiredStatus": "RUNNING",
"KnownStatus": "RUNNING",
"TransitionDependencySet": {
"1": {
"ContainerDependencies": null,
"ResourceDependencies": [
{
"Name": "cgroup",
"RequiredStatus": 1
}
]
}
},
"RunDependencies": null,
"IsInternal": "NORMAL",
"ApplyingError": {
"error": "API error (500): Get https://registry-1.docker.io/v2/library/amazonlinux/manifests/1: toomanyrequests: too many failed login attempts for username or IP address\n",
"name": "CannotPullContainerError"
},
"SentStatus": "RUNNING",
"metadataFileUpdated": false,
"KnownExitCode": null,
"KnownPortBindings": null
}
}
},
"IdToTask": {
"8f5e6e3091f221c876103289ddabcbcdeb64acd7ac7e2d0cf4da2be2be9d8956": "arn:aws:ecs:us-west-2:1234567890:task/33425c99-5db7-45fb-8244-bc94d00661e4"
},
"ImageStates": [
{
"Image": {
"ImageID": "sha256:7f929d2604c7e504a568eac9a2523c1b9e9b15e1fcee4076e1411a552913d08e",
"Names": [
"amazonlinux:1"
],
"Size": 165452304
},
"PulledAt": "2018-10-04T18:05:48.445644088Z",
"LastUsedAt": "2018-10-04T18:05:48.445645342Z",
"PullSucceeded": false
}
],
"ENIAttachments": null,
"IPToTask": {}
}
},
"Version": 20
}

0 comments on commit 3265bf9

Please sign in to comment.