...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-03-15/documentdb/collectionpartition.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-03-15/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  // CollectionPartitionClient is the azure Cosmos DB Database Service Resource Provider REST API
    19  type CollectionPartitionClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewCollectionPartitionClient creates an instance of the CollectionPartitionClient client.
    24  func NewCollectionPartitionClient(subscriptionID string) CollectionPartitionClient {
    25  	return NewCollectionPartitionClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewCollectionPartitionClientWithBaseURI creates an instance of the CollectionPartitionClient 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 NewCollectionPartitionClientWithBaseURI(baseURI string, subscriptionID string) CollectionPartitionClient {
    32  	return CollectionPartitionClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // ListMetrics retrieves the metrics determined by the given filter for the given collection, split by partition.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // accountName - cosmos DB database account name.
    39  // databaseRid - cosmos DB database rid.
    40  // collectionRid - cosmos DB collection rid.
    41  // filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be
    42  // filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and
    43  // timeGrain. The supported operator is eq.
    44  func (client CollectionPartitionClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (result PartitionMetricListResult, err error) {
    45  	if tracing.IsEnabled() {
    46  		ctx = tracing.StartSpan(ctx, fqdn+"/CollectionPartitionClient.ListMetrics")
    47  		defer func() {
    48  			sc := -1
    49  			if result.Response.Response != nil {
    50  				sc = result.Response.Response.StatusCode
    51  			}
    52  			tracing.EndSpan(ctx, sc, err)
    53  		}()
    54  	}
    55  	if err := validation.Validate([]validation.Validation{
    56  		{TargetValue: client.SubscriptionID,
    57  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    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.CollectionPartitionClient", "ListMetrics", err.Error())
    67  	}
    68  
    69  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid, filter)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "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.CollectionPartitionClient", "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.CollectionPartitionClient", "ListMetrics", resp, "Failure responding to request")
    85  		return
    86  	}
    87  
    88  	return
    89  }
    90  
    91  // ListMetricsPreparer prepares the ListMetrics request.
    92  func (client CollectionPartitionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid 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  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    98  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    99  	}
   100  
   101  	const APIVersion = "2021-03-15"
   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}/partitions/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 CollectionPartitionClient) 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 CollectionPartitionClient) 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  
   133  // ListUsages retrieves the usages (most recent storage data) for the given collection, split by partition.
   134  // Parameters:
   135  // resourceGroupName - the name of the resource group. The name is case insensitive.
   136  // accountName - cosmos DB database account name.
   137  // databaseRid - cosmos DB database rid.
   138  // collectionRid - cosmos DB collection rid.
   139  // filter - an OData filter expression that describes a subset of usages to return. The supported parameter is
   140  // name.value (name of the metric, can have an or of multiple names).
   141  func (client CollectionPartitionClient) ListUsages(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (result PartitionUsagesResult, err error) {
   142  	if tracing.IsEnabled() {
   143  		ctx = tracing.StartSpan(ctx, fqdn+"/CollectionPartitionClient.ListUsages")
   144  		defer func() {
   145  			sc := -1
   146  			if result.Response.Response != nil {
   147  				sc = result.Response.Response.StatusCode
   148  			}
   149  			tracing.EndSpan(ctx, sc, err)
   150  		}()
   151  	}
   152  	if err := validation.Validate([]validation.Validation{
   153  		{TargetValue: client.SubscriptionID,
   154  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   155  		{TargetValue: resourceGroupName,
   156  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   157  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   158  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   159  		{TargetValue: accountName,
   160  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   161  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   162  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   163  		return result, validation.NewError("documentdb.CollectionPartitionClient", "ListUsages", err.Error())
   164  	}
   165  
   166  	req, err := client.ListUsagesPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid, filter)
   167  	if err != nil {
   168  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "ListUsages", nil, "Failure preparing request")
   169  		return
   170  	}
   171  
   172  	resp, err := client.ListUsagesSender(req)
   173  	if err != nil {
   174  		result.Response = autorest.Response{Response: resp}
   175  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "ListUsages", resp, "Failure sending request")
   176  		return
   177  	}
   178  
   179  	result, err = client.ListUsagesResponder(resp)
   180  	if err != nil {
   181  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "ListUsages", resp, "Failure responding to request")
   182  		return
   183  	}
   184  
   185  	return
   186  }
   187  
   188  // ListUsagesPreparer prepares the ListUsages request.
   189  func (client CollectionPartitionClient) ListUsagesPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (*http.Request, error) {
   190  	pathParameters := map[string]interface{}{
   191  		"accountName":       autorest.Encode("path", accountName),
   192  		"collectionRid":     autorest.Encode("path", collectionRid),
   193  		"databaseRid":       autorest.Encode("path", databaseRid),
   194  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   195  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   196  	}
   197  
   198  	const APIVersion = "2021-03-15"
   199  	queryParameters := map[string]interface{}{
   200  		"api-version": APIVersion,
   201  	}
   202  	if len(filter) > 0 {
   203  		queryParameters["$filter"] = autorest.Encode("query", filter)
   204  	}
   205  
   206  	preparer := autorest.CreatePreparer(
   207  		autorest.AsGet(),
   208  		autorest.WithBaseURL(client.BaseURI),
   209  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/databases/{databaseRid}/collections/{collectionRid}/partitions/usages", pathParameters),
   210  		autorest.WithQueryParameters(queryParameters))
   211  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   212  }
   213  
   214  // ListUsagesSender sends the ListUsages request. The method will close the
   215  // http.Response Body if it receives an error.
   216  func (client CollectionPartitionClient) ListUsagesSender(req *http.Request) (*http.Response, error) {
   217  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   218  }
   219  
   220  // ListUsagesResponder handles the response to the ListUsages request. The method always
   221  // closes the http.Response Body.
   222  func (client CollectionPartitionClient) ListUsagesResponder(resp *http.Response) (result PartitionUsagesResult, err error) {
   223  	err = autorest.Respond(
   224  		resp,
   225  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   226  		autorest.ByUnmarshallingJSON(&result),
   227  		autorest.ByClosing())
   228  	result.Response = autorest.Response{Response: resp}
   229  	return
   230  }
   231  

View as plain text