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