...

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

View as plain text