From dc450e8b65cfa91fc58582b843c1163c0030c4fc Mon Sep 17 00:00:00 2001 From: Amogh Rathore Date: Tue, 16 Aug 2022 14:31:17 -0700 Subject: [PATCH] Add ServiceName to task (#3342) * Add ServiceName to task * Update windows unit tests Co-authored-by: Amogh Rathore --- agent/acs/model/api/api-2.json | 3 ++- agent/acs/model/ecsacs/api.go | 2 ++ agent/api/task/task.go | 3 +++ agent/api/task/task_test.go | 12 ++++++++++++ agent/api/task/taskvolume_test.go | 1 + agent/api/task/taskvolume_windows_test.go | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/agent/acs/model/api/api-2.json b/agent/acs/model/api/api-2.json index 3f873aafe71..c97ab2bb848 100644 --- a/agent/acs/model/api/api-2.json +++ b/agent/acs/model/api/api-2.json @@ -723,7 +723,8 @@ "pidMode":{"shape":"String"}, "ipcMode":{"shape":"String"}, "proxyConfiguration":{"shape":"ProxyConfiguration"}, - "launchType":{"shape":"String"} + "launchType":{"shape":"String"}, + "serviceName":{"shape":"String"} } }, "TaskList":{ diff --git a/agent/acs/model/ecsacs/api.go b/agent/acs/model/ecsacs/api.go index 622d197b96b..b71dcd4f84b 100644 --- a/agent/acs/model/ecsacs/api.go +++ b/agent/acs/model/ecsacs/api.go @@ -1631,6 +1631,8 @@ type Task struct { RoleCredentials *IAMRoleCredentials `locationName:"roleCredentials" type:"structure"` + ServiceName *string `locationName:"serviceName" type:"string"` + TaskDefinitionAccountId *string `locationName:"taskDefinitionAccountId" type:"string"` Version *string `locationName:"version" type:"string"` diff --git a/agent/api/task/task.go b/agent/api/task/task.go index 7e2b2a62554..2eb859fef11 100644 --- a/agent/api/task/task.go +++ b/agent/api/task/task.go @@ -161,6 +161,9 @@ type Task struct { Family string // Version is the version of the task definition Version string + // ServiceName is the name of the service to which the task belongs. + // It is empty if the task does not belong to any service. + ServiceName string // Containers are the containers for the task Containers []*apicontainer.Container // Associations are the available associations for the task. diff --git a/agent/api/task/task_test.go b/agent/api/task/task_test.go index 2e557d868ef..eeae30b5505 100644 --- a/agent/api/task/task_test.go +++ b/agent/api/task/task_test.go @@ -1178,6 +1178,7 @@ func TestTaskFromACS(t *testing.T) { DesiredStatus: strptr("RUNNING"), Family: strptr("myFamily"), Version: strptr("1"), + ServiceName: strptr("myService"), Containers: []*ecsacs.Container{ { Name: strptr("myName"), @@ -1273,6 +1274,7 @@ func TestTaskFromACS(t *testing.T) { DesiredStatusUnsafe: apitaskstatus.TaskRunning, Family: "myFamily", Version: "1", + ServiceName: "myService", Containers: []*apicontainer.Container{ { Name: "myName", @@ -3281,6 +3283,16 @@ func TestTaskFromACSPerContainerTimeouts(t *testing.T) { assert.Equal(t, task.Containers[0].StopTimeout, expectedTimeout) } +// Tests that ACS Task to Task translation does not fail when ServiceName is missing. +// Asserts that Task.ServiceName is empty in such a case. +func TestTaskFromACSServiceNameMissing(t *testing.T) { + taskFromACS := ecsacs.Task{} // No service name + seqNum := int64(42) + task, err := TaskFromACS(&taskFromACS, &ecsacs.PayloadMessage{SeqNum: &seqNum}) + assert.Nil(t, err, "Should be able to handle acs task") + assert.Equal(t, task.ServiceName, "") +} + func TestGetContainerIndex(t *testing.T) { task := &Task{ Containers: []*apicontainer.Container{ diff --git a/agent/api/task/taskvolume_test.go b/agent/api/task/taskvolume_test.go index 737dd8e1342..ed0f8ad9a91 100644 --- a/agent/api/task/taskvolume_test.go +++ b/agent/api/task/taskvolume_test.go @@ -91,6 +91,7 @@ func TestMarshalTaskVolumesEFS(t *testing.T) { "Arn": "test", "Family": "", "Version": "", + "ServiceName": "", "Containers": null, "associations": null, "resources": null, diff --git a/agent/api/task/taskvolume_windows_test.go b/agent/api/task/taskvolume_windows_test.go index 2d02669b15d..98070de3f3f 100644 --- a/agent/api/task/taskvolume_windows_test.go +++ b/agent/api/task/taskvolume_windows_test.go @@ -51,6 +51,7 @@ func TestMarshalTaskVolumeFSxWindowsFileServer(t *testing.T) { "Arn": "test", "Family": "", "Version": "", + "ServiceName": "", "Containers": null, "associations": null, "resources": null,