1package batch
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/date"
14	"github.com/Azure/go-autorest/autorest/validation"
15	"github.com/Azure/go-autorest/tracing"
16	"github.com/gofrs/uuid"
17	"net/http"
18)
19
20// AccountClient is the a client for issuing REST requests to the Azure Batch service.
21type AccountClient struct {
22	BaseClient
23}
24
25// NewAccountClient creates an instance of the AccountClient client.
26func NewAccountClient(batchURL string) AccountClient {
27	return AccountClient{New(batchURL)}
28}
29
30// ListPoolNodeCounts gets the number of Compute Nodes in each state, grouped by Pool.
31// Parameters:
32// filter - an OData $filter clause. For more information on constructing this filter, see
33// https://docs.microsoft.com/en-us/rest/api/batchservice/odata-filters-in-batch.
34// maxResults - the maximum number of items to return in the response.
35// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
36// seconds.
37// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
38// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
39// returnClientRequestID - whether the server should return the client-request-id in the response.
40// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
41// time; set it explicitly if you are calling the REST API directly.
42func (client AccountClient) ListPoolNodeCounts(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result PoolNodeCountsListResultPage, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListPoolNodeCounts")
45		defer func() {
46			sc := -1
47			if result.pnclr.Response.Response != nil {
48				sc = result.pnclr.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: maxResults,
55			Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
56				Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: int64(10), Chain: nil},
57					{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
58				}}}}}); err != nil {
59		return result, validation.NewError("batch.AccountClient", "ListPoolNodeCounts", err.Error())
60	}
61
62	result.fn = client.listPoolNodeCountsNextResults
63	req, err := client.ListPoolNodeCountsPreparer(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListPoolNodeCounts", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.ListPoolNodeCountsSender(req)
70	if err != nil {
71		result.pnclr.Response = autorest.Response{Response: resp}
72		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListPoolNodeCounts", resp, "Failure sending request")
73		return
74	}
75
76	result.pnclr, err = client.ListPoolNodeCountsResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListPoolNodeCounts", resp, "Failure responding to request")
79		return
80	}
81	if result.pnclr.hasNextLink() && result.pnclr.IsEmpty() {
82		err = result.NextWithContext(ctx)
83		return
84	}
85
86	return
87}
88
89// ListPoolNodeCountsPreparer prepares the ListPoolNodeCounts request.
90func (client AccountClient) ListPoolNodeCountsPreparer(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
91	urlParameters := map[string]interface{}{
92		"batchUrl": client.BatchURL,
93	}
94
95	const APIVersion = "2019-08-01.10.0"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99	if len(filter) > 0 {
100		queryParameters["$filter"] = autorest.Encode("query", filter)
101	}
102	if maxResults != nil {
103		queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
104	} else {
105		queryParameters["maxresults"] = autorest.Encode("query", 10)
106	}
107	if timeout != nil {
108		queryParameters["timeout"] = autorest.Encode("query", *timeout)
109	} else {
110		queryParameters["timeout"] = autorest.Encode("query", 30)
111	}
112
113	preparer := autorest.CreatePreparer(
114		autorest.AsGet(),
115		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
116		autorest.WithPath("/nodecounts"),
117		autorest.WithQueryParameters(queryParameters))
118	if clientRequestID != nil {
119		preparer = autorest.DecoratePreparer(preparer,
120			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
121	}
122	if returnClientRequestID != nil {
123		preparer = autorest.DecoratePreparer(preparer,
124			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
125	} else {
126		preparer = autorest.DecoratePreparer(preparer,
127			autorest.WithHeader("return-client-request-id", autorest.String(false)))
128	}
129	if ocpDate != nil {
130		preparer = autorest.DecoratePreparer(preparer,
131			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
132	}
133	return preparer.Prepare((&http.Request{}).WithContext(ctx))
134}
135
136// ListPoolNodeCountsSender sends the ListPoolNodeCounts request. The method will close the
137// http.Response Body if it receives an error.
138func (client AccountClient) ListPoolNodeCountsSender(req *http.Request) (*http.Response, error) {
139	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
140}
141
142// ListPoolNodeCountsResponder handles the response to the ListPoolNodeCounts request. The method always
143// closes the http.Response Body.
144func (client AccountClient) ListPoolNodeCountsResponder(resp *http.Response) (result PoolNodeCountsListResult, err error) {
145	err = autorest.Respond(
146		resp,
147		azure.WithErrorUnlessStatusCode(http.StatusOK),
148		autorest.ByUnmarshallingJSON(&result),
149		autorest.ByClosing())
150	result.Response = autorest.Response{Response: resp}
151	return
152}
153
154// listPoolNodeCountsNextResults retrieves the next set of results, if any.
155func (client AccountClient) listPoolNodeCountsNextResults(ctx context.Context, lastResults PoolNodeCountsListResult) (result PoolNodeCountsListResult, err error) {
156	req, err := lastResults.poolNodeCountsListResultPreparer(ctx)
157	if err != nil {
158		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listPoolNodeCountsNextResults", nil, "Failure preparing next results request")
159	}
160	if req == nil {
161		return
162	}
163	resp, err := client.ListPoolNodeCountsSender(req)
164	if err != nil {
165		result.Response = autorest.Response{Response: resp}
166		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listPoolNodeCountsNextResults", resp, "Failure sending next results request")
167	}
168	result, err = client.ListPoolNodeCountsResponder(resp)
169	if err != nil {
170		err = autorest.NewErrorWithError(err, "batch.AccountClient", "listPoolNodeCountsNextResults", resp, "Failure responding to next results request")
171	}
172	return
173}
174
175// ListPoolNodeCountsComplete enumerates all values, automatically crossing page boundaries as required.
176func (client AccountClient) ListPoolNodeCountsComplete(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result PoolNodeCountsListResultIterator, err error) {
177	if tracing.IsEnabled() {
178		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListPoolNodeCounts")
179		defer func() {
180			sc := -1
181			if result.Response().Response.Response != nil {
182				sc = result.page.Response().Response.Response.StatusCode
183			}
184			tracing.EndSpan(ctx, sc, err)
185		}()
186	}
187	result.page, err = client.ListPoolNodeCounts(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
188	return
189}
190
191// ListSupportedImages sends the list supported images request.
192// Parameters:
193// filter - an OData $filter clause. For more information on constructing this filter, see
194// https://docs.microsoft.com/en-us/rest/api/batchservice/odata-filters-in-batch#list-support-images.
195// maxResults - the maximum number of items to return in the response. A maximum of 1000 results will be
196// returned.
197// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
198// seconds.
199// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
200// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
201// returnClientRequestID - whether the server should return the client-request-id in the response.
202// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
203// time; set it explicitly if you are calling the REST API directly.
204func (client AccountClient) ListSupportedImages(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result AccountListSupportedImagesResultPage, err error) {
205	if tracing.IsEnabled() {
206		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListSupportedImages")
207		defer func() {
208			sc := -1
209			if result.alsir.Response.Response != nil {
210				sc = result.alsir.Response.Response.StatusCode
211			}
212			tracing.EndSpan(ctx, sc, err)
213		}()
214	}
215	if err := validation.Validate([]validation.Validation{
216		{TargetValue: maxResults,
217			Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
218				Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
219					{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
220				}}}}}); err != nil {
221		return result, validation.NewError("batch.AccountClient", "ListSupportedImages", err.Error())
222	}
223
224	result.fn = client.listSupportedImagesNextResults
225	req, err := client.ListSupportedImagesPreparer(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
226	if err != nil {
227		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListSupportedImages", nil, "Failure preparing request")
228		return
229	}
230
231	resp, err := client.ListSupportedImagesSender(req)
232	if err != nil {
233		result.alsir.Response = autorest.Response{Response: resp}
234		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListSupportedImages", resp, "Failure sending request")
235		return
236	}
237
238	result.alsir, err = client.ListSupportedImagesResponder(resp)
239	if err != nil {
240		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListSupportedImages", resp, "Failure responding to request")
241		return
242	}
243	if result.alsir.hasNextLink() && result.alsir.IsEmpty() {
244		err = result.NextWithContext(ctx)
245		return
246	}
247
248	return
249}
250
251// ListSupportedImagesPreparer prepares the ListSupportedImages request.
252func (client AccountClient) ListSupportedImagesPreparer(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
253	urlParameters := map[string]interface{}{
254		"batchUrl": client.BatchURL,
255	}
256
257	const APIVersion = "2019-08-01.10.0"
258	queryParameters := map[string]interface{}{
259		"api-version": APIVersion,
260	}
261	if len(filter) > 0 {
262		queryParameters["$filter"] = autorest.Encode("query", filter)
263	}
264	if maxResults != nil {
265		queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
266	} else {
267		queryParameters["maxresults"] = autorest.Encode("query", 1000)
268	}
269	if timeout != nil {
270		queryParameters["timeout"] = autorest.Encode("query", *timeout)
271	} else {
272		queryParameters["timeout"] = autorest.Encode("query", 30)
273	}
274
275	preparer := autorest.CreatePreparer(
276		autorest.AsGet(),
277		autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
278		autorest.WithPath("/supportedimages"),
279		autorest.WithQueryParameters(queryParameters))
280	if clientRequestID != nil {
281		preparer = autorest.DecoratePreparer(preparer,
282			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
283	}
284	if returnClientRequestID != nil {
285		preparer = autorest.DecoratePreparer(preparer,
286			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
287	} else {
288		preparer = autorest.DecoratePreparer(preparer,
289			autorest.WithHeader("return-client-request-id", autorest.String(false)))
290	}
291	if ocpDate != nil {
292		preparer = autorest.DecoratePreparer(preparer,
293			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
294	}
295	return preparer.Prepare((&http.Request{}).WithContext(ctx))
296}
297
298// ListSupportedImagesSender sends the ListSupportedImages request. The method will close the
299// http.Response Body if it receives an error.
300func (client AccountClient) ListSupportedImagesSender(req *http.Request) (*http.Response, error) {
301	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
302}
303
304// ListSupportedImagesResponder handles the response to the ListSupportedImages request. The method always
305// closes the http.Response Body.
306func (client AccountClient) ListSupportedImagesResponder(resp *http.Response) (result AccountListSupportedImagesResult, err error) {
307	err = autorest.Respond(
308		resp,
309		azure.WithErrorUnlessStatusCode(http.StatusOK),
310		autorest.ByUnmarshallingJSON(&result),
311		autorest.ByClosing())
312	result.Response = autorest.Response{Response: resp}
313	return
314}
315
316// listSupportedImagesNextResults retrieves the next set of results, if any.
317func (client AccountClient) listSupportedImagesNextResults(ctx context.Context, lastResults AccountListSupportedImagesResult) (result AccountListSupportedImagesResult, err error) {
318	req, err := lastResults.accountListSupportedImagesResultPreparer(ctx)
319	if err != nil {
320		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listSupportedImagesNextResults", nil, "Failure preparing next results request")
321	}
322	if req == nil {
323		return
324	}
325	resp, err := client.ListSupportedImagesSender(req)
326	if err != nil {
327		result.Response = autorest.Response{Response: resp}
328		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listSupportedImagesNextResults", resp, "Failure sending next results request")
329	}
330	result, err = client.ListSupportedImagesResponder(resp)
331	if err != nil {
332		err = autorest.NewErrorWithError(err, "batch.AccountClient", "listSupportedImagesNextResults", resp, "Failure responding to next results request")
333	}
334	return
335}
336
337// ListSupportedImagesComplete enumerates all values, automatically crossing page boundaries as required.
338func (client AccountClient) ListSupportedImagesComplete(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result AccountListSupportedImagesResultIterator, err error) {
339	if tracing.IsEnabled() {
340		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListSupportedImages")
341		defer func() {
342			sc := -1
343			if result.Response().Response.Response != nil {
344				sc = result.page.Response().Response.Response.StatusCode
345			}
346			tracing.EndSpan(ctx, sc, err)
347		}()
348	}
349	result.page, err = client.ListSupportedImages(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
350	return
351}
352