1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ecs
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/ecs/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Modifies the status of an Amazon ECS container instance. Once a container
15// instance has reached an ACTIVE state, you can change the status of a container
16// instance to DRAINING to manually remove an instance from a cluster, for example
17// to perform system updates, update the Docker daemon, or scale down the cluster
18// size. A container instance cannot be changed to DRAINING until it has reached an
19// ACTIVE status. If the instance is in any other status, an error will be
20// received. When you set a container instance to DRAINING, Amazon ECS prevents new
21// tasks from being scheduled for placement on the container instance and
22// replacement service tasks are started on other container instances in the
23// cluster if the resources are available. Service tasks on the container instance
24// that are in the PENDING state are stopped immediately. Service tasks on the
25// container instance that are in the RUNNING state are stopped and replaced
26// according to the service's deployment configuration parameters,
27// minimumHealthyPercent and maximumPercent. You can change the deployment
28// configuration of your service using UpdateService.
29//
30// * If minimumHealthyPercent
31// is below 100%, the scheduler can ignore desiredCount temporarily during task
32// replacement. For example, desiredCount is four tasks, a minimum of 50% allows
33// the scheduler to stop two existing tasks before starting two new tasks. If the
34// minimum is 100%, the service scheduler can't remove existing tasks until the
35// replacement tasks are considered healthy. Tasks for services that do not use a
36// load balancer are considered healthy if they are in the RUNNING state. Tasks for
37// services that use a load balancer are considered healthy if they are in the
38// RUNNING state and the container instance they are hosted on is reported as
39// healthy by the load balancer.
40//
41// * The maximumPercent parameter represents an
42// upper limit on the number of running tasks during task replacement, which
43// enables you to define the replacement batch size. For example, if desiredCount
44// is four tasks, a maximum of 200% starts four new tasks before stopping the four
45// tasks to be drained, provided that the cluster resources required to do this are
46// available. If the maximum is 100%, then replacement tasks can't start until the
47// draining tasks have stopped.
48//
49// Any PENDING or RUNNING tasks that do not belong to
50// a service are not affected. You must wait for them to finish or stop them
51// manually. A container instance has completed draining when it has no more
52// RUNNING tasks. You can verify this using ListTasks. When a container instance
53// has been drained, you can set a container instance to ACTIVE status and once it
54// has reached that status the Amazon ECS scheduler can begin scheduling tasks on
55// the instance again.
56func (c *Client) UpdateContainerInstancesState(ctx context.Context, params *UpdateContainerInstancesStateInput, optFns ...func(*Options)) (*UpdateContainerInstancesStateOutput, error) {
57	if params == nil {
58		params = &UpdateContainerInstancesStateInput{}
59	}
60
61	result, metadata, err := c.invokeOperation(ctx, "UpdateContainerInstancesState", params, optFns, addOperationUpdateContainerInstancesStateMiddlewares)
62	if err != nil {
63		return nil, err
64	}
65
66	out := result.(*UpdateContainerInstancesStateOutput)
67	out.ResultMetadata = metadata
68	return out, nil
69}
70
71type UpdateContainerInstancesStateInput struct {
72
73	// A list of container instance IDs or full ARN entries.
74	//
75	// This member is required.
76	ContainerInstances []string
77
78	// The container instance state with which to update the container instance. The
79	// only valid values for this action are ACTIVE and DRAINING. A container instance
80	// can only be updated to DRAINING status once it has reached an ACTIVE state. If a
81	// container instance is in REGISTERING, DEREGISTERING, or REGISTRATION_FAILED
82	// state you can describe the container instance but will be unable to update the
83	// container instance state.
84	//
85	// This member is required.
86	Status types.ContainerInstanceStatus
87
88	// The short name or full Amazon Resource Name (ARN) of the cluster that hosts the
89	// container instance to update. If you do not specify a cluster, the default
90	// cluster is assumed.
91	Cluster *string
92}
93
94type UpdateContainerInstancesStateOutput struct {
95
96	// The list of container instances.
97	ContainerInstances []types.ContainerInstance
98
99	// Any failures associated with the call.
100	Failures []types.Failure
101
102	// Metadata pertaining to the operation's result.
103	ResultMetadata middleware.Metadata
104}
105
106func addOperationUpdateContainerInstancesStateMiddlewares(stack *middleware.Stack, options Options) (err error) {
107	err = stack.Serialize.Add(&awsAwsjson11_serializeOpUpdateContainerInstancesState{}, middleware.After)
108	if err != nil {
109		return err
110	}
111	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpUpdateContainerInstancesState{}, middleware.After)
112	if err != nil {
113		return err
114	}
115	if err = addSetLoggerMiddleware(stack, options); err != nil {
116		return err
117	}
118	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
119		return err
120	}
121	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addResolveEndpointMiddleware(stack, options); err != nil {
125		return err
126	}
127	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
128		return err
129	}
130	if err = addRetryMiddlewares(stack, options); err != nil {
131		return err
132	}
133	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
134		return err
135	}
136	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
137		return err
138	}
139	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
140		return err
141	}
142	if err = addClientUserAgent(stack); err != nil {
143		return err
144	}
145	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
146		return err
147	}
148	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addOpUpdateContainerInstancesStateValidationMiddleware(stack); err != nil {
152		return err
153	}
154	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opUpdateContainerInstancesState(options.Region), middleware.Before); err != nil {
155		return err
156	}
157	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
158		return err
159	}
160	if err = addResponseErrorMiddleware(stack); err != nil {
161		return err
162	}
163	if err = addRequestResponseLogging(stack, options); err != nil {
164		return err
165	}
166	return nil
167}
168
169func newServiceMetadataMiddleware_opUpdateContainerInstancesState(region string) *awsmiddleware.RegisterServiceMetadata {
170	return &awsmiddleware.RegisterServiceMetadata{
171		Region:        region,
172		ServiceID:     ServiceID,
173		SigningName:   "ecs",
174		OperationName: "UpdateContainerInstancesState",
175	}
176}
177