Exemplo n.º 1
0
// ListAppTasks lists all the tasks for the app.
func (c *Client) ListAppTasks(ctx context.Context, appID string, input *ecs.ListTasksInput) (*ecs.ListTasksOutput, error) {
	var arns []*string

	resp, err := c.ListAppServices(ctx, appID, &ecs.ListServicesInput{
		Cluster: input.Cluster,
	})
	if err != nil {
		return nil, err
	}

	for _, s := range resp.ServiceARNs {
		id, err := arn.ResourceID(*s)
		if err != nil {
			return nil, err
		}

		t, err := c.ListTasks(ctx, &ecs.ListTasksInput{
			Cluster:     input.Cluster,
			ServiceName: aws.String(id),
		})
		if err != nil {
			return nil, err
		}

		if len(t.TaskARNs) == 0 {
			continue
		}

		arns = append(arns, t.TaskARNs...)
	}

	return &ecs.ListTasksOutput{
		TaskARNs: arns,
	}, nil
}
Exemplo n.º 2
0
// ListAppServices lists all services for the app.
func (c *Client) ListAppServices(ctx context.Context, appID string, input *ecs.ListServicesInput) (*ecs.ListServicesOutput, error) {
	resp, err := c.ListServices(ctx, input)
	if err != nil {
		return resp, err
	}

	var arns []*string
	for _, a := range resp.ServiceARNs {
		if a == nil {
			continue
		}

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

		appName, _ := c.split(&id)

		if appName == appID {
			arns = append(arns, a)
		}
	}

	return &ecs.ListServicesOutput{
		ServiceARNs: arns,
	}, nil
}
Exemplo n.º 3
0
// Instances returns all instances that are currently running, pending or
// draining.
func (m *ECSManager) Instances(ctx context.Context, appID string) ([]*Instance, error) {
	var instances []*Instance

	tasks, err := m.describeAppTasks(ctx, appID)
	if err != nil {
		return instances, err
	}

	for _, t := range tasks {
		resp, err := m.ecs.DescribeTaskDefinition(ctx, &ecs.DescribeTaskDefinitionInput{
			TaskDefinition: t.TaskDefinitionARN,
		})
		if err != nil {
			return instances, err
		}

		id, err := arn.ResourceID(*t.TaskARN)
		if err != nil {
			return instances, err
		}

		p, err := taskDefinitionToProcess(resp.TaskDefinition)
		if err != nil {
			return instances, err
		}

		instances = append(instances, &Instance{
			Process:   p,
			State:     safeString(t.LastStatus),
			ID:        id,
			UpdatedAt: timex.Now(),
		})
	}

	return instances, nil
}