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