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