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