Beispiel #1
0
// Services iterates through all of the ECS services in this cluster, and
// returns the services that are members of the given app.
func (b *StackBuilder) Services(app string) (map[string]string, error) {
	services := make(map[string]string)

	if err := b.ecs.ListServicesPages(&ecs.ListServicesInput{
		Cluster: aws.String(b.Cluster),
	}, func(resp *ecs.ListServicesOutput, lastPage bool) bool {
		for _, serviceArn := range resp.ServiceArns {
			if serviceArn == nil {
				continue
			}

			id, err := arn.ResourceID(*serviceArn)
			if err != nil {
				return false
			}

			appName, process, ok := b.split(id)
			if !ok {
				continue
			}

			if appName == app {
				services[process] = id
			}
		}

		return true
	}); err != nil {
		return nil, err
	}

	return services, nil
}
Beispiel #2
0
// ServiceTasks returns the Tasks running for the given ECS service.
func (s *Scheduler) ServiceTasks(service string) ([]twelvefactor.Task, error) {
	listResp, err := s.ecs.ListTasks(&ecs.ListTasksInput{
		Cluster:     aws.String(s.Cluster),
		ServiceName: aws.String(service),
	})
	if err != nil {
		return nil, err
	}

	// No tasks.
	if len(listResp.TaskArns) == 0 {
		return nil, nil
	}

	describeResp, err := s.ecs.DescribeTasks(&ecs.DescribeTasksInput{
		Cluster: aws.String(s.Cluster),
		Tasks:   listResp.TaskArns,
	})
	if err != nil {
		return nil, err
	}

	var tasks []twelvefactor.Task
	for _, task := range describeResp.Tasks {
		id, err := arn.ResourceID(*task.TaskArn)
		if err != nil {
			return nil, err
		}

		tasks = append(tasks, twelvefactor.Task{
			ID:    id,
			State: *task.LastStatus,
		})
	}

	return tasks, nil
}