...

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

View as plain text