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/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// ApplicationPackageClient is the client for the ApplicationPackage methods of the Batch service. 30type ApplicationPackageClient struct { 31 BaseClient 32} 33 34// NewApplicationPackageClient creates an instance of the ApplicationPackageClient client. 35func NewApplicationPackageClient(subscriptionID string) ApplicationPackageClient { 36 return NewApplicationPackageClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewApplicationPackageClientWithBaseURI creates an instance of the ApplicationPackageClient client using a custom 40// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 41// stack). 42func NewApplicationPackageClientWithBaseURI(baseURI string, subscriptionID string) ApplicationPackageClient { 43 return ApplicationPackageClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// Activate activates the specified application package. 47// Parameters: 48// resourceGroupName - the name of the resource group that contains the Batch account. 49// accountName - the name of the Batch account. 50// applicationID - the ID of the application. 51// version - the version of the application to activate. 52// parameters - the parameters for the request. 53func (client ApplicationPackageClient) Activate(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string, parameters ActivateApplicationPackageParameters) (result autorest.Response, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/ApplicationPackageClient.Activate") 56 defer func() { 57 sc := -1 58 if result.Response != nil { 59 sc = result.Response.StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 if err := validation.Validate([]validation.Validation{ 65 {TargetValue: resourceGroupName, 66 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 67 {TargetValue: accountName, 68 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 69 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 70 {Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 71 {TargetValue: parameters, 72 Constraints: []validation.Constraint{{Target: "parameters.Format", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 73 return result, validation.NewError("batch.ApplicationPackageClient", "Activate", err.Error()) 74 } 75 76 req, err := client.ActivatePreparer(ctx, resourceGroupName, accountName, applicationID, version, parameters) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Activate", nil, "Failure preparing request") 79 return 80 } 81 82 resp, err := client.ActivateSender(req) 83 if err != nil { 84 result.Response = resp 85 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Activate", resp, "Failure sending request") 86 return 87 } 88 89 result, err = client.ActivateResponder(resp) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Activate", resp, "Failure responding to request") 92 return 93 } 94 95 return 96} 97 98// ActivatePreparer prepares the Activate request. 99func (client ApplicationPackageClient) ActivatePreparer(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string, parameters ActivateApplicationPackageParameters) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "accountName": autorest.Encode("path", accountName), 102 "applicationId": autorest.Encode("path", applicationID), 103 "resourceGroupName": autorest.Encode("path", resourceGroupName), 104 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 105 "version": autorest.Encode("path", version), 106 } 107 108 const APIVersion = "2017-01-01" 109 queryParameters := map[string]interface{}{ 110 "api-version": APIVersion, 111 } 112 113 preparer := autorest.CreatePreparer( 114 autorest.AsContentType("application/json; charset=utf-8"), 115 autorest.AsPost(), 116 autorest.WithBaseURL(client.BaseURI), 117 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/applications/{applicationId}/versions/{version}/activate", pathParameters), 118 autorest.WithJSON(parameters), 119 autorest.WithQueryParameters(queryParameters)) 120 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 121} 122 123// ActivateSender sends the Activate request. The method will close the 124// http.Response Body if it receives an error. 125func (client ApplicationPackageClient) ActivateSender(req *http.Request) (*http.Response, error) { 126 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 127} 128 129// ActivateResponder handles the response to the Activate request. The method always 130// closes the http.Response Body. 131func (client ApplicationPackageClient) ActivateResponder(resp *http.Response) (result autorest.Response, err error) { 132 err = autorest.Respond( 133 resp, 134 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 135 autorest.ByClosing()) 136 result.Response = resp 137 return 138} 139 140// Create creates an application package record. 141// Parameters: 142// resourceGroupName - the name of the resource group that contains the Batch account. 143// accountName - the name of the Batch account. 144// applicationID - the ID of the application. 145// version - the version of the application. 146func (client ApplicationPackageClient) Create(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string) (result ApplicationPackage, err error) { 147 if tracing.IsEnabled() { 148 ctx = tracing.StartSpan(ctx, fqdn+"/ApplicationPackageClient.Create") 149 defer func() { 150 sc := -1 151 if result.Response.Response != nil { 152 sc = result.Response.Response.StatusCode 153 } 154 tracing.EndSpan(ctx, sc, err) 155 }() 156 } 157 if err := validation.Validate([]validation.Validation{ 158 {TargetValue: resourceGroupName, 159 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 160 {TargetValue: accountName, 161 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 162 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 163 {Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 164 return result, validation.NewError("batch.ApplicationPackageClient", "Create", err.Error()) 165 } 166 167 req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, applicationID, version) 168 if err != nil { 169 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Create", nil, "Failure preparing request") 170 return 171 } 172 173 resp, err := client.CreateSender(req) 174 if err != nil { 175 result.Response = autorest.Response{Response: resp} 176 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Create", resp, "Failure sending request") 177 return 178 } 179 180 result, err = client.CreateResponder(resp) 181 if err != nil { 182 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Create", resp, "Failure responding to request") 183 return 184 } 185 186 return 187} 188 189// CreatePreparer prepares the Create request. 190func (client ApplicationPackageClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string) (*http.Request, error) { 191 pathParameters := map[string]interface{}{ 192 "accountName": autorest.Encode("path", accountName), 193 "applicationId": autorest.Encode("path", applicationID), 194 "resourceGroupName": autorest.Encode("path", resourceGroupName), 195 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 196 "version": autorest.Encode("path", version), 197 } 198 199 const APIVersion = "2017-01-01" 200 queryParameters := map[string]interface{}{ 201 "api-version": APIVersion, 202 } 203 204 preparer := autorest.CreatePreparer( 205 autorest.AsPut(), 206 autorest.WithBaseURL(client.BaseURI), 207 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/applications/{applicationId}/versions/{version}", pathParameters), 208 autorest.WithQueryParameters(queryParameters)) 209 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 210} 211 212// CreateSender sends the Create request. The method will close the 213// http.Response Body if it receives an error. 214func (client ApplicationPackageClient) CreateSender(req *http.Request) (*http.Response, error) { 215 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 216} 217 218// CreateResponder handles the response to the Create request. The method always 219// closes the http.Response Body. 220func (client ApplicationPackageClient) CreateResponder(resp *http.Response) (result ApplicationPackage, err error) { 221 err = autorest.Respond( 222 resp, 223 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 224 autorest.ByUnmarshallingJSON(&result), 225 autorest.ByClosing()) 226 result.Response = autorest.Response{Response: resp} 227 return 228} 229 230// Delete deletes an application package record and its associated binary file. 231// Parameters: 232// resourceGroupName - the name of the resource group that contains the Batch account. 233// accountName - the name of the Batch account. 234// applicationID - the ID of the application. 235// version - the version of the application to delete. 236func (client ApplicationPackageClient) Delete(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string) (result autorest.Response, err error) { 237 if tracing.IsEnabled() { 238 ctx = tracing.StartSpan(ctx, fqdn+"/ApplicationPackageClient.Delete") 239 defer func() { 240 sc := -1 241 if result.Response != nil { 242 sc = result.Response.StatusCode 243 } 244 tracing.EndSpan(ctx, sc, err) 245 }() 246 } 247 if err := validation.Validate([]validation.Validation{ 248 {TargetValue: resourceGroupName, 249 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 250 {TargetValue: accountName, 251 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 252 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 253 {Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 254 return result, validation.NewError("batch.ApplicationPackageClient", "Delete", err.Error()) 255 } 256 257 req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, applicationID, version) 258 if err != nil { 259 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Delete", nil, "Failure preparing request") 260 return 261 } 262 263 resp, err := client.DeleteSender(req) 264 if err != nil { 265 result.Response = resp 266 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Delete", resp, "Failure sending request") 267 return 268 } 269 270 result, err = client.DeleteResponder(resp) 271 if err != nil { 272 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Delete", resp, "Failure responding to request") 273 return 274 } 275 276 return 277} 278 279// DeletePreparer prepares the Delete request. 280func (client ApplicationPackageClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string) (*http.Request, error) { 281 pathParameters := map[string]interface{}{ 282 "accountName": autorest.Encode("path", accountName), 283 "applicationId": autorest.Encode("path", applicationID), 284 "resourceGroupName": autorest.Encode("path", resourceGroupName), 285 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 286 "version": autorest.Encode("path", version), 287 } 288 289 const APIVersion = "2017-01-01" 290 queryParameters := map[string]interface{}{ 291 "api-version": APIVersion, 292 } 293 294 preparer := autorest.CreatePreparer( 295 autorest.AsDelete(), 296 autorest.WithBaseURL(client.BaseURI), 297 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/applications/{applicationId}/versions/{version}", pathParameters), 298 autorest.WithQueryParameters(queryParameters)) 299 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 300} 301 302// DeleteSender sends the Delete request. The method will close the 303// http.Response Body if it receives an error. 304func (client ApplicationPackageClient) DeleteSender(req *http.Request) (*http.Response, error) { 305 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 306} 307 308// DeleteResponder handles the response to the Delete request. The method always 309// closes the http.Response Body. 310func (client ApplicationPackageClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 311 err = autorest.Respond( 312 resp, 313 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 314 autorest.ByClosing()) 315 result.Response = resp 316 return 317} 318 319// Get gets information about the specified application package. 320// Parameters: 321// resourceGroupName - the name of the resource group that contains the Batch account. 322// accountName - the name of the Batch account. 323// applicationID - the ID of the application. 324// version - the version of the application. 325func (client ApplicationPackageClient) Get(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string) (result ApplicationPackage, err error) { 326 if tracing.IsEnabled() { 327 ctx = tracing.StartSpan(ctx, fqdn+"/ApplicationPackageClient.Get") 328 defer func() { 329 sc := -1 330 if result.Response.Response != nil { 331 sc = result.Response.Response.StatusCode 332 } 333 tracing.EndSpan(ctx, sc, err) 334 }() 335 } 336 if err := validation.Validate([]validation.Validation{ 337 {TargetValue: resourceGroupName, 338 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 339 {TargetValue: accountName, 340 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 341 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 342 {Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 343 return result, validation.NewError("batch.ApplicationPackageClient", "Get", err.Error()) 344 } 345 346 req, err := client.GetPreparer(ctx, resourceGroupName, accountName, applicationID, version) 347 if err != nil { 348 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Get", nil, "Failure preparing request") 349 return 350 } 351 352 resp, err := client.GetSender(req) 353 if err != nil { 354 result.Response = autorest.Response{Response: resp} 355 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Get", resp, "Failure sending request") 356 return 357 } 358 359 result, err = client.GetResponder(resp) 360 if err != nil { 361 err = autorest.NewErrorWithError(err, "batch.ApplicationPackageClient", "Get", resp, "Failure responding to request") 362 return 363 } 364 365 return 366} 367 368// GetPreparer prepares the Get request. 369func (client ApplicationPackageClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, applicationID string, version string) (*http.Request, error) { 370 pathParameters := map[string]interface{}{ 371 "accountName": autorest.Encode("path", accountName), 372 "applicationId": autorest.Encode("path", applicationID), 373 "resourceGroupName": autorest.Encode("path", resourceGroupName), 374 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 375 "version": autorest.Encode("path", version), 376 } 377 378 const APIVersion = "2017-01-01" 379 queryParameters := map[string]interface{}{ 380 "api-version": APIVersion, 381 } 382 383 preparer := autorest.CreatePreparer( 384 autorest.AsGet(), 385 autorest.WithBaseURL(client.BaseURI), 386 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/applications/{applicationId}/versions/{version}", pathParameters), 387 autorest.WithQueryParameters(queryParameters)) 388 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 389} 390 391// GetSender sends the Get request. The method will close the 392// http.Response Body if it receives an error. 393func (client ApplicationPackageClient) GetSender(req *http.Request) (*http.Response, error) { 394 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 395} 396 397// GetResponder handles the response to the Get request. The method always 398// closes the http.Response Body. 399func (client ApplicationPackageClient) GetResponder(resp *http.Response) (result ApplicationPackage, err error) { 400 err = autorest.Respond( 401 resp, 402 azure.WithErrorUnlessStatusCode(http.StatusOK), 403 autorest.ByUnmarshallingJSON(&result), 404 autorest.ByClosing()) 405 result.Response = autorest.Response{Response: resp} 406 return 407} 408