Skip to content

Commit

Permalink
Remove task serialization and use host resource manager for task reso…
Browse files Browse the repository at this point in the history
…urces (#3723)
  • Loading branch information
prateekchaudhry authored Jun 1, 2023
1 parent 3348d1d commit e00484f
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 396 deletions.
1 change: 0 additions & 1 deletion agent/acs/handler/acs_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,6 @@ func validateAddedTask(expectedTask apitask.Task, addedTask apitask.Task) error
Family: addedTask.Family,
Version: addedTask.Version,
DesiredStatusUnsafe: addedTask.GetDesiredStatus(),
StartSequenceNumber: addedTask.StartSequenceNumber,
}

if !reflect.DeepEqual(expectedTask, taskToCompareFromAdded) {
Expand Down
4 changes: 4 additions & 0 deletions agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ func (client *APIECSClient) GetHostResources() (map[string]*ecs.Resource, error)
}
resourceMap := make(map[string]*ecs.Resource)
for _, resource := range resources {
if *resource.Name == "PORTS" {
// Except for RCI, TCP Ports are named as PORTS_TCP in agent for Host Resources purpose
resource.Name = utils.Strptr("PORTS_TCP")
}
resourceMap[*resource.Name] = resource
}
return resourceMap, nil
Expand Down
38 changes: 10 additions & 28 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ type Task struct {
// is handled properly so that the state storage continues to work.
SentStatusUnsafe apitaskstatus.TaskStatus `json:"SentStatus"`

StartSequenceNumber int64
StopSequenceNumber int64

// ExecutionCredentialsID is the ID of credentials that are used by agent to
// perform some action at the task level, such as pulling image from ECR
ExecutionCredentialsID string `json:"executionCredentialsID"`
Expand Down Expand Up @@ -312,11 +309,6 @@ func TaskFromACS(acsTask *ecsacs.Task, envelope *ecsacs.PayloadMessage) (*Task,
if err := json.Unmarshal(data, task); err != nil {
return nil, err
}
if task.GetDesiredStatus() == apitaskstatus.TaskRunning && envelope.SeqNum != nil {
task.StartSequenceNumber = *envelope.SeqNum
} else if task.GetDesiredStatus() == apitaskstatus.TaskStopped && envelope.SeqNum != nil {
task.StopSequenceNumber = *envelope.SeqNum
}

// Overrides the container command if it's set
for _, container := range task.Containers {
Expand Down Expand Up @@ -2831,22 +2823,6 @@ func (task *Task) GetAppMesh() *apiappmesh.AppMesh {
return task.AppMesh
}

// GetStopSequenceNumber returns the stop sequence number of a task
func (task *Task) GetStopSequenceNumber() int64 {
task.lock.RLock()
defer task.lock.RUnlock()

return task.StopSequenceNumber
}

// SetStopSequenceNumber sets the stop seqence number of a task
func (task *Task) SetStopSequenceNumber(seqnum int64) {
task.lock.Lock()
defer task.lock.Unlock()

task.StopSequenceNumber = seqnum
}

// SetPullStartedAt sets the task pullstartedat timestamp and returns whether
// this field was updated or not
func (task *Task) SetPullStartedAt(timestamp time.Time) bool {
Expand Down Expand Up @@ -3522,10 +3498,6 @@ func (task *Task) IsServiceConnectConnectionDraining() bool {
//
// * GPU
// - Return num of gpus requested (len of GPUIDs field)
//
// TODO remove this once ToHostResources is used
//
//lint:file-ignore U1000 Ignore all unused code
func (task *Task) ToHostResources() map[string]*ecs.Resource {
resources := make(map[string]*ecs.Resource)
// CPU
Expand Down Expand Up @@ -3639,3 +3611,13 @@ func (task *Task) ToHostResources() map[string]*ecs.Resource {
})
return resources
}

func (task *Task) HasActiveContainers() bool {
for _, container := range task.Containers {
containerStatus := container.GetKnownStatus()
if containerStatus >= apicontainerstatus.ContainerPulled && containerStatus <= apicontainerstatus.ContainerResourcesProvisioned {
return true
}
}
return false
}
7 changes: 3 additions & 4 deletions agent/api/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1860,10 +1860,9 @@ func TestTaskFromACS(t *testing.T) {
Type: "elastic-inference",
},
},
StartSequenceNumber: 42,
CPU: 2.0,
Memory: 512,
ResourcesMapUnsafe: make(map[string][]taskresource.TaskResource),
CPU: 2.0,
Memory: 512,
ResourcesMapUnsafe: make(map[string][]taskresource.TaskResource),
}

seqNum := int64(42)
Expand Down
4 changes: 0 additions & 4 deletions agent/api/task/taskvolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ func TestMarshalTaskVolumesEFS(t *testing.T) {
"PullStoppedAt": "0001-01-01T00:00:00Z",
"ExecutionStoppedAt": "0001-01-01T00:00:00Z",
"SentStatus": "NONE",
"StartSequenceNumber": 0,
"StopSequenceNumber": 0,
"executionCredentialsID": "",
"ENI": null,
"AppMesh": null,
Expand Down Expand Up @@ -168,8 +166,6 @@ func TestUnmarshalTaskVolumesEFS(t *testing.T) {
"PullStoppedAt": "0001-01-01T00:00:00Z",
"ExecutionStoppedAt": "0001-01-01T00:00:00Z",
"SentStatus": "NONE",
"StartSequenceNumber": 0,
"StopSequenceNumber": 0,
"executionCredentialsID": "",
"ENI": null,
"AppMesh": null,
Expand Down
4 changes: 0 additions & 4 deletions agent/api/task/taskvolume_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ func TestMarshalTaskVolumeFSxWindowsFileServer(t *testing.T) {
"PullStoppedAt": "0001-01-01T00:00:00Z",
"ExecutionStoppedAt": "0001-01-01T00:00:00Z",
"SentStatus": "NONE",
"StartSequenceNumber": 0,
"StopSequenceNumber": 0,
"executionCredentialsID": "",
"ENI": null,
"AppMesh": null,
Expand Down Expand Up @@ -118,8 +116,6 @@ func TestUnmarshalTaskVolumeFSxWindowsFileServer(t *testing.T) {
"PullStoppedAt": "0001-01-01T00:00:00Z",
"ExecutionStoppedAt": "0001-01-01T00:00:00Z",
"SentStatus": "NONE",
"StartSequenceNumber": 0,
"StopSequenceNumber": 0,
"executionCredentialsID": "",
"ENI": null,
"AppMesh": null,
Expand Down
2 changes: 2 additions & 0 deletions agent/app/agent_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ func TestDoStartCgroupInitHappyPath(t *testing.T) {
state.EXPECT().AllImageStates().Return(nil),
state.EXPECT().AllENIAttachments().Return(nil),
state.EXPECT().AllTasks().Return(nil),
state.EXPECT().AllTasks().Return(nil),
client.EXPECT().DiscoverPollEndpoint(gomock.Any()).Do(func(x interface{}) {
// Ensures that the test waits until acs session has bee started
discoverEndpointsInvoked.Done()
Expand Down Expand Up @@ -646,6 +647,7 @@ func TestDoStartGPUManagerHappyPath(t *testing.T) {
state.EXPECT().AllImageStates().Return(nil),
state.EXPECT().AllENIAttachments().Return(nil),
state.EXPECT().AllTasks().Return(nil),
state.EXPECT().AllTasks().Return(nil),
client.EXPECT().DiscoverPollEndpoint(gomock.Any()).Do(func(x interface{}) {
// Ensures that the test waits until acs session has been started
discoverEndpointsInvoked.Done()
Expand Down
4 changes: 3 additions & 1 deletion agent/engine/common_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,16 @@ func skipIntegTestIfApplicable(t *testing.T) {
}
}

// Values in host resources from getTestHostResources() should be looked at and CPU/Memory assigned
// accordingly
func createTestContainerWithImageAndName(image string, name string) *apicontainer.Container {
return &apicontainer.Container{
Name: name,
Image: image,
Command: []string{},
Essential: true,
DesiredStatusUnsafe: apicontainerstatus.ContainerRunning,
CPU: 1024,
CPU: 256,
Memory: 128,
}
}
Expand Down
12 changes: 6 additions & 6 deletions agent/engine/docker_image_manager_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,23 +568,23 @@ func createImageCleanupHappyTestTask(taskName string) *apitask.Task {
Image: test1Image1Name,
Essential: false,
DesiredStatusUnsafe: apicontainerstatus.ContainerRunning,
CPU: 512,
CPU: 256,
Memory: 256,
},
{
Name: "test2",
Image: test1Image2Name,
Essential: false,
DesiredStatusUnsafe: apicontainerstatus.ContainerRunning,
CPU: 512,
CPU: 256,
Memory: 256,
},
{
Name: "test3",
Image: test1Image3Name,
Essential: false,
DesiredStatusUnsafe: apicontainerstatus.ContainerRunning,
CPU: 512,
CPU: 256,
Memory: 256,
},
},
Expand All @@ -603,23 +603,23 @@ func createImageCleanupThresholdTestTask(taskName string) *apitask.Task {
Image: test2Image1Name,
Essential: false,
DesiredStatusUnsafe: apicontainerstatus.ContainerRunning,
CPU: 512,
CPU: 256,
Memory: 256,
},
{
Name: "test2",
Image: test2Image2Name,
Essential: false,
DesiredStatusUnsafe: apicontainerstatus.ContainerRunning,
CPU: 512,
CPU: 256,
Memory: 256,
},
{
Name: "test3",
Image: test2Image3Name,
Essential: false,
DesiredStatusUnsafe: apicontainerstatus.ContainerRunning,
CPU: 512,
CPU: 256,
Memory: 256,
},
},
Expand Down
Loading

0 comments on commit e00484f

Please sign in to comment.