1package batch
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/date"
25	"github.com/Azure/go-autorest/autorest/validation"
26	"github.com/satori/go.uuid"
27	"net/http"
28)
29
30// ApplicationClient is the a client for issuing REST requests to the Azure Batch service.
31type ApplicationClient struct {
32	BaseClient
33}
34
35// NewApplicationClient creates an instance of the ApplicationClient client.
36func NewApplicationClient() ApplicationClient {
37	return NewApplicationClientWithBaseURI(DefaultBaseURI)
38}
39
40// NewApplicationClientWithBaseURI creates an instance of the ApplicationClient client.
41func NewApplicationClientWithBaseURI(baseURI string) ApplicationClient {
42	return ApplicationClient{NewWithBaseURI(baseURI)}
43}
44
45// Get this operation returns only applications and versions that are available for use on compute nodes; that is, that
46// can be used in an application package reference. For administrator information about applications and versions that
47// are not yet available to compute nodes, use the Azure portal or the Azure Resource Manager API.
48//
49// applicationID is the ID of the application. timeout is the maximum time that the server can spend processing the
50// request, in seconds. The default is 30 seconds. clientRequestID is the caller-generated request identity, in the
51// form of a GUID with no decoration such as curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
52// returnClientRequestID is whether the server should return the client-request-id in the response. ocpDate is the
53// time the request was issued. Client libraries typically set this to the current system clock time; set it
54// explicitly if you are calling the REST API directly.
55func (client ApplicationClient) Get(ctx context.Context, applicationID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result ApplicationSummary, err error) {
56	req, err := client.GetPreparer(ctx, applicationID, timeout, clientRequestID, returnClientRequestID, ocpDate)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "Get", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.GetSender(req)
63	if err != nil {
64		result.Response = autorest.Response{Response: resp}
65		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "Get", resp, "Failure sending request")
66		return
67	}
68
69	result, err = client.GetResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "Get", resp, "Failure responding to request")
72	}
73
74	return
75}
76
77// GetPreparer prepares the Get request.
78func (client ApplicationClient) GetPreparer(ctx context.Context, applicationID string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"applicationId": autorest.Encode("path", applicationID),
81	}
82
83	const APIVersion = "2017-09-01.6.0"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87	if timeout != nil {
88		queryParameters["timeout"] = autorest.Encode("query", *timeout)
89	} else {
90		queryParameters["timeout"] = autorest.Encode("query", 30)
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsGet(),
95		autorest.WithBaseURL(client.BaseURI),
96		autorest.WithPathParameters("/applications/{applicationId}", pathParameters),
97		autorest.WithQueryParameters(queryParameters))
98	if clientRequestID != nil {
99		preparer = autorest.DecoratePreparer(preparer,
100			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
101	}
102	if returnClientRequestID != nil {
103		preparer = autorest.DecoratePreparer(preparer,
104			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
105	} else {
106		preparer = autorest.DecoratePreparer(preparer,
107			autorest.WithHeader("return-client-request-id", autorest.String(false)))
108	}
109	if ocpDate != nil {
110		preparer = autorest.DecoratePreparer(preparer,
111			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
112	}
113	return preparer.Prepare((&http.Request{}).WithContext(ctx))
114}
115
116// GetSender sends the Get request. The method will close the
117// http.Response Body if it receives an error.
118func (client ApplicationClient) GetSender(req *http.Request) (*http.Response, error) {
119	return autorest.SendWithSender(client, req,
120		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
121}
122
123// GetResponder handles the response to the Get request. The method always
124// closes the http.Response Body.
125func (client ApplicationClient) GetResponder(resp *http.Response) (result ApplicationSummary, err error) {
126	err = autorest.Respond(
127		resp,
128		client.ByInspecting(),
129		azure.WithErrorUnlessStatusCode(http.StatusOK),
130		autorest.ByUnmarshallingJSON(&result),
131		autorest.ByClosing())
132	result.Response = autorest.Response{Response: resp}
133	return
134}
135
136// List this operation returns only applications and versions that are available for use on compute nodes; that is,
137// that can be used in an application package reference. For administrator information about applications and versions
138// that are not yet available to compute nodes, use the Azure portal or the Azure Resource Manager API.
139//
140// maxResults is the maximum number of items to return in the response. A maximum of 1000 applications can be
141// returned. timeout is the maximum time that the server can spend processing the request, in seconds. The default
142// is 30 seconds. clientRequestID is the caller-generated request identity, in the form of a GUID with no
143// decoration such as curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0. returnClientRequestID is whether the
144// server should return the client-request-id in the response. ocpDate is the time the request was issued. Client
145// libraries typically set this to the current system clock time; set it explicitly if you are calling the REST API
146// directly.
147func (client ApplicationClient) List(ctx context.Context, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result ApplicationListResultPage, err error) {
148	if err := validation.Validate([]validation.Validation{
149		{TargetValue: maxResults,
150			Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
151				Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil},
152					{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil},
153				}}}}}); err != nil {
154		return result, validation.NewError("batch.ApplicationClient", "List", err.Error())
155	}
156
157	result.fn = client.listNextResults
158	req, err := client.ListPreparer(ctx, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
159	if err != nil {
160		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "List", nil, "Failure preparing request")
161		return
162	}
163
164	resp, err := client.ListSender(req)
165	if err != nil {
166		result.alr.Response = autorest.Response{Response: resp}
167		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "List", resp, "Failure sending request")
168		return
169	}
170
171	result.alr, err = client.ListResponder(resp)
172	if err != nil {
173		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "List", resp, "Failure responding to request")
174	}
175
176	return
177}
178
179// ListPreparer prepares the List request.
180func (client ApplicationClient) ListPreparer(ctx context.Context, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
181	const APIVersion = "2017-09-01.6.0"
182	queryParameters := map[string]interface{}{
183		"api-version": APIVersion,
184	}
185	if maxResults != nil {
186		queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
187	} else {
188		queryParameters["maxresults"] = autorest.Encode("query", 1000)
189	}
190	if timeout != nil {
191		queryParameters["timeout"] = autorest.Encode("query", *timeout)
192	} else {
193		queryParameters["timeout"] = autorest.Encode("query", 30)
194	}
195
196	preparer := autorest.CreatePreparer(
197		autorest.AsGet(),
198		autorest.WithBaseURL(client.BaseURI),
199		autorest.WithPath("/applications"),
200		autorest.WithQueryParameters(queryParameters))
201	if clientRequestID != nil {
202		preparer = autorest.DecoratePreparer(preparer,
203			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
204	}
205	if returnClientRequestID != nil {
206		preparer = autorest.DecoratePreparer(preparer,
207			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
208	} else {
209		preparer = autorest.DecoratePreparer(preparer,
210			autorest.WithHeader("return-client-request-id", autorest.String(false)))
211	}
212	if ocpDate != nil {
213		preparer = autorest.DecoratePreparer(preparer,
214			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
215	}
216	return preparer.Prepare((&http.Request{}).WithContext(ctx))
217}
218
219// ListSender sends the List request. The method will close the
220// http.Response Body if it receives an error.
221func (client ApplicationClient) ListSender(req *http.Request) (*http.Response, error) {
222	return autorest.SendWithSender(client, req,
223		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
224}
225
226// ListResponder handles the response to the List request. The method always
227// closes the http.Response Body.
228func (client ApplicationClient) ListResponder(resp *http.Response) (result ApplicationListResult, err error) {
229	err = autorest.Respond(
230		resp,
231		client.ByInspecting(),
232		azure.WithErrorUnlessStatusCode(http.StatusOK),
233		autorest.ByUnmarshallingJSON(&result),
234		autorest.ByClosing())
235	result.Response = autorest.Response{Response: resp}
236	return
237}
238
239// listNextResults retrieves the next set of results, if any.
240func (client ApplicationClient) listNextResults(lastResults ApplicationListResult) (result ApplicationListResult, err error) {
241	req, err := lastResults.applicationListResultPreparer()
242	if err != nil {
243		return result, autorest.NewErrorWithError(err, "batch.ApplicationClient", "listNextResults", nil, "Failure preparing next results request")
244	}
245	if req == nil {
246		return
247	}
248	resp, err := client.ListSender(req)
249	if err != nil {
250		result.Response = autorest.Response{Response: resp}
251		return result, autorest.NewErrorWithError(err, "batch.ApplicationClient", "listNextResults", resp, "Failure sending next results request")
252	}
253	result, err = client.ListResponder(resp)
254	if err != nil {
255		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "listNextResults", resp, "Failure responding to next results request")
256	}
257	return
258}
259
260// ListComplete enumerates all values, automatically crossing page boundaries as required.
261func (client ApplicationClient) ListComplete(ctx context.Context, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result ApplicationListResultIterator, err error) {
262	result.page, err = client.List(ctx, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
263	return
264}
265