func newTaskResponse(task *api.Task, containerMap map[string]*api.DockerContainer) *TaskResponse {
	containers := []ContainerResponse{}
	for containerName, container := range containerMap {
		if container.Container.IsInternal {
			continue
		}
		containers = append(containers, ContainerResponse{container.DockerId, container.DockerName, containerName})
	}

	knownStatus := task.GetKnownStatus()
	knownBackendStatus := knownStatus.BackendStatus()
	desiredStatusInAgent := task.GetDesiredStatus()
	desiredStatus := desiredStatusInAgent.BackendStatus()

	if (knownBackendStatus == "STOPPED" && desiredStatus != "STOPPED") || (knownBackendStatus == "RUNNING" && desiredStatus == "PENDING") {
		desiredStatus = ""
	}

	return &TaskResponse{
		Arn:           task.Arn,
		DesiredStatus: desiredStatus,
		KnownStatus:   knownBackendStatus,
		Family:        task.Family,
		Version:       task.Version,
		Containers:    containers,
	}
}
示例#2
0
// TasksEqual determines if the lhs and rhs tasks are equal for the definition
// of having the same family, version, statuses, and equal containers.
func TasksEqual(lhs, rhs *api.Task) bool {
	if lhs == rhs {
		return true
	}
	if lhs.Arn != rhs.Arn {
		return false
	}

	if lhs.Family != rhs.Family || lhs.Version != rhs.Version {
		return false
	}

	for _, left := range lhs.Containers {
		right, ok := rhs.ContainerByName(left.Name)
		if !ok {
			return false
		}
		if !ContainersEqual(left, right) {
			return false
		}
	}

	if lhs.DesiredStatus != rhs.DesiredStatus {
		return false
	}
	if lhs.GetKnownStatus() != rhs.GetKnownStatus() {
		return false
	}
	return true
}
func (engine *DockerTaskEngine) emitTaskEvent(task *api.Task, reason string) {
	taskKnownStatus := task.GetKnownStatus()
	if !taskKnownStatus.BackendRecognized() {
		return
	}
	if task.SentStatus >= taskKnownStatus {
		log.Debug("Already sent task event; no need to re-send", "task", task.Arn, "event", taskKnownStatus.String())
		return
	}
	event := api.TaskStateChange{
		TaskArn:    task.Arn,
		Status:     taskKnownStatus,
		Reason:     reason,
		SentStatus: &task.SentStatus,
	}
	log.Info("Task change event", "event", event)
	engine.taskEvents <- event
}