1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package emr
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/emr/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13	"time"
14)
15
16// Provides the status of all clusters visible to this AWS account. Allows you to
17// filter the list of clusters based on certain criteria; for example, filtering by
18// cluster creation date and time or by status. This call returns a maximum of 50
19// clusters per call, but returns a marker to track the paging of the cluster list
20// across multiple ListClusters calls.
21func (c *Client) ListClusters(ctx context.Context, params *ListClustersInput, optFns ...func(*Options)) (*ListClustersOutput, error) {
22	if params == nil {
23		params = &ListClustersInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "ListClusters", params, optFns, addOperationListClustersMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*ListClustersOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36// This input determines how the ListClusters action filters the list of clusters
37// that it returns.
38type ListClustersInput struct {
39
40	// The cluster state filters to apply when listing clusters.
41	ClusterStates []types.ClusterState
42
43	// The creation date and time beginning value filter for listing clusters.
44	CreatedAfter *time.Time
45
46	// The creation date and time end value filter for listing clusters.
47	CreatedBefore *time.Time
48
49	// The pagination token that indicates the next set of results to retrieve.
50	Marker *string
51}
52
53// This contains a ClusterSummaryList with the cluster details; for example, the
54// cluster IDs, names, and status.
55type ListClustersOutput struct {
56
57	// The list of clusters for the account based on the given filters.
58	Clusters []types.ClusterSummary
59
60	// The pagination token that indicates the next set of results to retrieve.
61	Marker *string
62
63	// Metadata pertaining to the operation's result.
64	ResultMetadata middleware.Metadata
65}
66
67func addOperationListClustersMiddlewares(stack *middleware.Stack, options Options) (err error) {
68	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListClusters{}, middleware.After)
69	if err != nil {
70		return err
71	}
72	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListClusters{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	if err = addSetLoggerMiddleware(stack, options); err != nil {
77		return err
78	}
79	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
80		return err
81	}
82	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
83		return err
84	}
85	if err = addResolveEndpointMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
89		return err
90	}
91	if err = addRetryMiddlewares(stack, options); err != nil {
92		return err
93	}
94	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
95		return err
96	}
97	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
101		return err
102	}
103	if err = addClientUserAgent(stack); err != nil {
104		return err
105	}
106	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
107		return err
108	}
109	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
110		return err
111	}
112	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListClusters(options.Region), middleware.Before); err != nil {
113		return err
114	}
115	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
116		return err
117	}
118	if err = addResponseErrorMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addRequestResponseLogging(stack, options); err != nil {
122		return err
123	}
124	return nil
125}
126
127// ListClustersAPIClient is a client that implements the ListClusters operation.
128type ListClustersAPIClient interface {
129	ListClusters(context.Context, *ListClustersInput, ...func(*Options)) (*ListClustersOutput, error)
130}
131
132var _ ListClustersAPIClient = (*Client)(nil)
133
134// ListClustersPaginatorOptions is the paginator options for ListClusters
135type ListClustersPaginatorOptions struct {
136	// Set to true if pagination should stop if the service returns a pagination token
137	// that matches the most recent token provided to the service.
138	StopOnDuplicateToken bool
139}
140
141// ListClustersPaginator is a paginator for ListClusters
142type ListClustersPaginator struct {
143	options   ListClustersPaginatorOptions
144	client    ListClustersAPIClient
145	params    *ListClustersInput
146	nextToken *string
147	firstPage bool
148}
149
150// NewListClustersPaginator returns a new ListClustersPaginator
151func NewListClustersPaginator(client ListClustersAPIClient, params *ListClustersInput, optFns ...func(*ListClustersPaginatorOptions)) *ListClustersPaginator {
152	if params == nil {
153		params = &ListClustersInput{}
154	}
155
156	options := ListClustersPaginatorOptions{}
157
158	for _, fn := range optFns {
159		fn(&options)
160	}
161
162	return &ListClustersPaginator{
163		options:   options,
164		client:    client,
165		params:    params,
166		firstPage: true,
167	}
168}
169
170// HasMorePages returns a boolean indicating whether more pages are available
171func (p *ListClustersPaginator) HasMorePages() bool {
172	return p.firstPage || p.nextToken != nil
173}
174
175// NextPage retrieves the next ListClusters page.
176func (p *ListClustersPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListClustersOutput, error) {
177	if !p.HasMorePages() {
178		return nil, fmt.Errorf("no more pages available")
179	}
180
181	params := *p.params
182	params.Marker = p.nextToken
183
184	result, err := p.client.ListClusters(ctx, &params, optFns...)
185	if err != nil {
186		return nil, err
187	}
188	p.firstPage = false
189
190	prevToken := p.nextToken
191	p.nextToken = result.Marker
192
193	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
194		p.nextToken = nil
195	}
196
197	return result, nil
198}
199
200func newServiceMetadataMiddleware_opListClusters(region string) *awsmiddleware.RegisterServiceMetadata {
201	return &awsmiddleware.RegisterServiceMetadata{
202		Region:        region,
203		ServiceID:     ServiceID,
204		SigningName:   "elasticmapreduce",
205		OperationName: "ListClusters",
206	}
207}
208