agent/handlers/v2/response.go
func NewTaskResponse(taskARN string,
	state dockerstate.TaskEngineState,
	ecsClient api.ECSClient,
	cluster string,
	az string,
	containerInstanceArn string,
	propagateTags bool) (*TaskResponse, error) {
	task, ok := state.TaskByArn(taskARN)
	if !ok {
		return nil, errors.Errorf("v2 task response: unable to find task '%s'", taskARN)
	}

	resp := &TaskResponse{
		Cluster:          cluster,
		TaskARN:          task.Arn,
		Family:           task.Family,
		Revision:         task.Version,
		DesiredStatus:    task.GetDesiredStatus().String(),
		KnownStatus:      task.GetKnownStatus().String(),
		AvailabilityZone: az,
	}

	taskCPU := task.CPU
	taskMemory := task.Memory
	if taskCPU != 0 || taskMemory != 0 {
		taskLimits := &LimitsResponse{}
		if taskCPU != 0 {
			taskLimits.CPU = &taskCPU
		}
		if taskMemory != 0 {
			taskLimits.Memory = &taskMemory
		}
		resp.Limits = taskLimits
	}

	if timestamp := task.GetPullStartedAt(); !timestamp.IsZero() {
		resp.PullStartedAt = aws.Time(timestamp.UTC())
	}
	if timestamp := task.GetPullStoppedAt(); !timestamp.IsZero() {
		resp.PullStoppedAt = aws.Time(timestamp.UTC())
	}
	if timestamp := task.GetExecutionStoppedAt(); !timestamp.IsZero() {
		resp.ExecutionStoppedAt = aws.Time(timestamp.UTC())
	}
	containerNameToDockerContainer, ok := state.ContainerMapByArn(task.Arn)
	if !ok {
		seelog.Warnf("V2 task response: unable to get container name mapping for task '%s'",
			task.Arn)
		return resp, nil
	}

	eni := task.GetTaskENI()
	for _, dockerContainer := range containerNameToDockerContainer {
		containerResponse := newContainerResponse(dockerContainer, eni, state)
		resp.Containers = append(resp.Containers, containerResponse)
	}

	if propagateTags {
		propagateTagsToMetadata(state, ecsClient, containerInstanceArn, taskARN, resp)
	}

	return resp, nil
}
func NewTaskResponse(taskARN string,
	state dockerstate.TaskEngineState,
	ecsClient api.ECSClient,
	cluster string,
	az string,
	containerInstanceArn string,
	propagateTags bool) (*TaskResponse, error) {
	task, ok := state.TaskByArn(taskARN)
	if !ok {
		return nil, errors.Errorf("v2 task response: unable to find task '%s'", taskARN)
	}

	resp := &TaskResponse{
		Cluster:          cluster,
		TaskARN:          task.Arn,
		Family:           task.Family,
		Revision:         task.Version,
		DesiredStatus:    task.GetDesiredStatus().String(),
		KnownStatus:      task.GetKnownStatus().String(),
		AvailabilityZone: az,
	}

	taskCPU := task.CPU
	taskMemory := task.Memory
	if taskCPU != 0 || taskMemory != 0 {
		taskLimits := &LimitsResponse{}
		if taskCPU != 0 {
			taskLimits.CPU = &taskCPU
		}
		if taskMemory != 0 {
			taskLimits.Memory = &taskMemory
		}
		resp.Limits = taskLimits
	}

	if timestamp := task.GetPullStartedAt(); !timestamp.IsZero() {
		resp.PullStartedAt = aws.Time(timestamp.UTC())
	}
	if timestamp := task.GetPullStoppedAt(); !timestamp.IsZero() {
		resp.PullStoppedAt = aws.Time(timestamp.UTC())
	}
	if timestamp := task.GetExecutionStoppedAt(); !timestamp.IsZero() {
		resp.ExecutionStoppedAt = aws.Time(timestamp.UTC())
	}
	containerNameToDockerContainer, ok := state.ContainerMapByArn(task.Arn)
	if !ok {
		seelog.Warnf("V2 task response: unable to get container name mapping for task '%s'",
			task.Arn)
		return resp, nil
	}

	eni := task.GetTaskENI()
	for _, dockerContainer := range containerNameToDockerContainer {
		containerResponse := newContainerResponse(dockerContainer, eni, state)
		resp.Containers = append(resp.Containers, containerResponse)
	}

	if propagateTags {
		propagateTagsToMetadata(state, ecsClient, containerInstanceArn, taskARN, resp)
	}

	return resp, nil
}
func NewTaskResponse ( taskARN string , state dockerstate . TaskEngineState , ecsClient api . ECSClient , cluster string , az string , containerInstanceArn string , propagateTags bool ) ( * TaskResponse , error ) { task , ok := state . TaskByArn ( taskARN ) if ! ok { return nil , errors . Errorf ( " " , taskARN ) } resp := & TaskResponse { Cluster : cluster , TaskARN : task . Arn , Family : task . Family , Revision : task . Version , DesiredStatus : task . GetDesiredStatus ( ) . String ( ) , KnownStatus : task . GetKnownStatus ( ) . String ( ) , AvailabilityZone : az , } taskCPU := task . CPU taskMemory := task . Memory if taskCPU != 0 || taskMemory != 0 { taskLimits := & LimitsResponse { } if taskCPU != 0 { taskLimits . CPU = & taskCPU } if taskMemory != 0 { taskLimits . Memory = & taskMemory } resp . Limits = taskLimits } if timestamp := task . GetPullStartedAt ( ) ; ! timestamp . IsZero ( ) { resp . PullStartedAt = aws . Time ( timestamp . UTC ( ) ) } if timestamp := task . GetPullStoppedAt ( ) ; ! timestamp . IsZero ( ) { resp . PullStoppedAt = aws . Time ( timestamp . UTC ( ) ) } if timestamp := task . GetExecutionStoppedAt ( ) ; ! timestamp . IsZero ( ) { resp . ExecutionStoppedAt = aws . Time ( timestamp . UTC ( ) ) } containerNameToDockerContainer , ok := state . ContainerMapByArn ( task . Arn ) if ! ok { seelog . Warnf ( " " , task . Arn ) return resp , nil } eni := task . GetTaskENI ( ) for _ , dockerContainer := range containerNameToDockerContainer { containerResponse := newContainerResponse ( dockerContainer , eni , state ) resp . Containers = append ( resp . Containers , containerResponse ) } if propagateTags { propagateTagsToMetadata ( state , ecsClient , containerInstanceArn , taskARN , resp ) } return resp , nil }
// NewTaskResponse creates a new response object for the task
NewTaskResponse creates a new response object for the task