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