...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb/databaseaccountregion.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb

     1  package documentdb
     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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // DatabaseAccountRegionClient is the azure Cosmos DB Database Service Resource Provider REST API
    19  type DatabaseAccountRegionClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDatabaseAccountRegionClient creates an instance of the DatabaseAccountRegionClient client.
    24  func NewDatabaseAccountRegionClient(subscriptionID string) DatabaseAccountRegionClient {
    25  	return NewDatabaseAccountRegionClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewDatabaseAccountRegionClientWithBaseURI creates an instance of the DatabaseAccountRegionClient client using a
    29  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    30  // Azure stack).
    31  func NewDatabaseAccountRegionClientWithBaseURI(baseURI string, subscriptionID string) DatabaseAccountRegionClient {
    32  	return DatabaseAccountRegionClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // ListMetrics retrieves the metrics determined by the given filter for the given database account and region.
    36  // Parameters:
    37  // resourceGroupName - name of an Azure resource group.
    38  // accountName - cosmos DB database account name.
    39  // region - cosmos DB region, with spaces between words and each word capitalized.
    40  // filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be
    41  // filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and
    42  // timeGrain. The supported operator is eq.
    43  func (client DatabaseAccountRegionClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, region string, filter string) (result MetricListResult, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseAccountRegionClient.ListMetrics")
    46  		defer func() {
    47  			sc := -1
    48  			if result.Response.Response != nil {
    49  				sc = result.Response.Response.StatusCode
    50  			}
    51  			tracing.EndSpan(ctx, sc, err)
    52  		}()
    53  	}
    54  	if err := validation.Validate([]validation.Validation{
    55  		{TargetValue: resourceGroupName,
    56  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    57  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    58  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    59  		{TargetValue: accountName,
    60  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    61  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
    62  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
    63  		return result, validation.NewError("documentdb.DatabaseAccountRegionClient", "ListMetrics", err.Error())
    64  	}
    65  
    66  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, region, filter)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseAccountRegionClient", "ListMetrics", nil, "Failure preparing request")
    69  		return
    70  	}
    71  
    72  	resp, err := client.ListMetricsSender(req)
    73  	if err != nil {
    74  		result.Response = autorest.Response{Response: resp}
    75  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseAccountRegionClient", "ListMetrics", resp, "Failure sending request")
    76  		return
    77  	}
    78  
    79  	result, err = client.ListMetricsResponder(resp)
    80  	if err != nil {
    81  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseAccountRegionClient", "ListMetrics", resp, "Failure responding to request")
    82  		return
    83  	}
    84  
    85  	return
    86  }
    87  
    88  // ListMetricsPreparer prepares the ListMetrics request.
    89  func (client DatabaseAccountRegionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, region string, filter string) (*http.Request, error) {
    90  	pathParameters := map[string]interface{}{
    91  		"accountName":       autorest.Encode("path", accountName),
    92  		"region":            autorest.Encode("path", region),
    93  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    94  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    95  	}
    96  
    97  	const APIVersion = "2015-04-08"
    98  	queryParameters := map[string]interface{}{
    99  		"$filter":     autorest.Encode("query", filter),
   100  		"api-version": APIVersion,
   101  	}
   102  
   103  	preparer := autorest.CreatePreparer(
   104  		autorest.AsGet(),
   105  		autorest.WithBaseURL(client.BaseURI),
   106  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/region/{region}/metrics", pathParameters),
   107  		autorest.WithQueryParameters(queryParameters))
   108  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   109  }
   110  
   111  // ListMetricsSender sends the ListMetrics request. The method will close the
   112  // http.Response Body if it receives an error.
   113  func (client DatabaseAccountRegionClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   114  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   115  }
   116  
   117  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   118  // closes the http.Response Body.
   119  func (client DatabaseAccountRegionClient) ListMetricsResponder(resp *http.Response) (result MetricListResult, err error) {
   120  	err = autorest.Respond(
   121  		resp,
   122  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   123  		autorest.ByUnmarshallingJSON(&result),
   124  		autorest.ByClosing())
   125  	result.Response = autorest.Response{Response: resp}
   126  	return
   127  }
   128  

View as plain text