...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/backup/jobcancellations.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/backup

     1  package backup
     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  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // JobCancellationsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type JobCancellationsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewJobCancellationsClient creates an instance of the JobCancellationsClient client.
    23  func NewJobCancellationsClient(subscriptionID string) JobCancellationsClient {
    24  	return NewJobCancellationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewJobCancellationsClientWithBaseURI creates an instance of the JobCancellationsClient client using a custom
    28  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    29  // stack).
    30  func NewJobCancellationsClientWithBaseURI(baseURI string, subscriptionID string) JobCancellationsClient {
    31  	return JobCancellationsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Trigger cancels a job. This is an asynchronous operation. To know the status of the cancellation, call
    35  // GetCancelOperationResult API.
    36  // Parameters:
    37  // vaultName - the name of the recovery services vault.
    38  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    39  // jobName - name of the job to cancel.
    40  func (client JobCancellationsClient) Trigger(ctx context.Context, vaultName string, resourceGroupName string, jobName string) (result autorest.Response, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/JobCancellationsClient.Trigger")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response != nil {
    46  				sc = result.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	req, err := client.TriggerPreparer(ctx, vaultName, resourceGroupName, jobName)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "backup.JobCancellationsClient", "Trigger", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.TriggerSender(req)
    58  	if err != nil {
    59  		result.Response = resp
    60  		err = autorest.NewErrorWithError(err, "backup.JobCancellationsClient", "Trigger", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.TriggerResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "backup.JobCancellationsClient", "Trigger", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // TriggerPreparer prepares the Trigger request.
    74  func (client JobCancellationsClient) TriggerPreparer(ctx context.Context, vaultName string, resourceGroupName string, jobName string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"jobName":           autorest.Encode("path", jobName),
    77  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    78  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    79  		"vaultName":         autorest.Encode("path", vaultName),
    80  	}
    81  
    82  	const APIVersion = "2019-05-13"
    83  	queryParameters := map[string]interface{}{
    84  		"api-version": APIVersion,
    85  	}
    86  
    87  	preparer := autorest.CreatePreparer(
    88  		autorest.AsPost(),
    89  		autorest.WithBaseURL(client.BaseURI),
    90  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupJobs/{jobName}/cancel", pathParameters),
    91  		autorest.WithQueryParameters(queryParameters))
    92  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    93  }
    94  
    95  // TriggerSender sends the Trigger request. The method will close the
    96  // http.Response Body if it receives an error.
    97  func (client JobCancellationsClient) TriggerSender(req *http.Request) (*http.Response, error) {
    98  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    99  }
   100  
   101  // TriggerResponder handles the response to the Trigger request. The method always
   102  // closes the http.Response Body.
   103  func (client JobCancellationsClient) TriggerResponder(resp *http.Response) (result autorest.Response, err error) {
   104  	err = autorest.Respond(
   105  		resp,
   106  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   107  		autorest.ByClosing())
   108  	result.Response = resp
   109  	return
   110  }
   111  

View as plain text