...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-11-15-preview/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 client for the CollectionPartition methods of the Documentdb service.
    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  		{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.CollectionPartitionClient", "ListMetrics", err.Error())
    66  	}
    67  
    68  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid, filter)
    69  	if err != nil {
    70  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "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.CollectionPartitionClient", "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.CollectionPartitionClient", "ListMetrics", resp, "Failure responding to request")
    84  		return
    85  	}
    86  
    87  	return
    88  }
    89  
    90  // ListMetricsPreparer prepares the ListMetrics request.
    91  func (client CollectionPartitionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid 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  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    97  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    98  	}
    99  
   100  	const APIVersion = "2021-11-15-preview"
   101  	queryParameters := map[string]interface{}{
   102  		"$filter":     autorest.Encode("query", filter),
   103  		"api-version": APIVersion,
   104  	}
   105  
   106  	preparer := autorest.CreatePreparer(
   107  		autorest.AsGet(),
   108  		autorest.WithBaseURL(client.BaseURI),
   109  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/databases/{databaseRid}/collections/{collectionRid}/partitions/metrics", pathParameters),
   110  		autorest.WithQueryParameters(queryParameters))
   111  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   112  }
   113  
   114  // ListMetricsSender sends the ListMetrics request. The method will close the
   115  // http.Response Body if it receives an error.
   116  func (client CollectionPartitionClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   117  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   118  }
   119  
   120  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   121  // closes the http.Response Body.
   122  func (client CollectionPartitionClient) ListMetricsResponder(resp *http.Response) (result PartitionMetricListResult, err error) {
   123  	err = autorest.Respond(
   124  		resp,
   125  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   126  		autorest.ByUnmarshallingJSON(&result),
   127  		autorest.ByClosing())
   128  	result.Response = autorest.Response{Response: resp}
   129  	return
   130  }
   131  
   132  // ListUsages retrieves the usages (most recent storage data) for the given collection, split by partition.
   133  // Parameters:
   134  // resourceGroupName - the name of the resource group. The name is case insensitive.
   135  // accountName - cosmos DB database account name.
   136  // databaseRid - cosmos DB database rid.
   137  // collectionRid - cosmos DB collection rid.
   138  // filter - an OData filter expression that describes a subset of usages to return. The supported parameter is
   139  // name.value (name of the metric, can have an or of multiple names).
   140  func (client CollectionPartitionClient) ListUsages(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (result PartitionUsagesResult, err error) {
   141  	if tracing.IsEnabled() {
   142  		ctx = tracing.StartSpan(ctx, fqdn+"/CollectionPartitionClient.ListUsages")
   143  		defer func() {
   144  			sc := -1
   145  			if result.Response.Response != nil {
   146  				sc = result.Response.Response.StatusCode
   147  			}
   148  			tracing.EndSpan(ctx, sc, err)
   149  		}()
   150  	}
   151  	if err := validation.Validate([]validation.Validation{
   152  		{TargetValue: client.SubscriptionID,
   153  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   154  		{TargetValue: resourceGroupName,
   155  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   156  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   157  		{TargetValue: accountName,
   158  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   159  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   160  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   161  		return result, validation.NewError("documentdb.CollectionPartitionClient", "ListUsages", err.Error())
   162  	}
   163  
   164  	req, err := client.ListUsagesPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid, filter)
   165  	if err != nil {
   166  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "ListUsages", nil, "Failure preparing request")
   167  		return
   168  	}
   169  
   170  	resp, err := client.ListUsagesSender(req)
   171  	if err != nil {
   172  		result.Response = autorest.Response{Response: resp}
   173  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "ListUsages", resp, "Failure sending request")
   174  		return
   175  	}
   176  
   177  	result, err = client.ListUsagesResponder(resp)
   178  	if err != nil {
   179  		err = autorest.NewErrorWithError(err, "documentdb.CollectionPartitionClient", "ListUsages", resp, "Failure responding to request")
   180  		return
   181  	}
   182  
   183  	return
   184  }
   185  
   186  // ListUsagesPreparer prepares the ListUsages request.
   187  func (client CollectionPartitionClient) ListUsagesPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (*http.Request, error) {
   188  	pathParameters := map[string]interface{}{
   189  		"accountName":       autorest.Encode("path", accountName),
   190  		"collectionRid":     autorest.Encode("path", collectionRid),
   191  		"databaseRid":       autorest.Encode("path", databaseRid),
   192  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   193  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   194  	}
   195  
   196  	const APIVersion = "2021-11-15-preview"
   197  	queryParameters := map[string]interface{}{
   198  		"api-version": APIVersion,
   199  	}
   200  	if len(filter) > 0 {
   201  		queryParameters["$filter"] = autorest.Encode("query", filter)
   202  	}
   203  
   204  	preparer := autorest.CreatePreparer(
   205  		autorest.AsGet(),
   206  		autorest.WithBaseURL(client.BaseURI),
   207  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/databases/{databaseRid}/collections/{collectionRid}/partitions/usages", pathParameters),
   208  		autorest.WithQueryParameters(queryParameters))
   209  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   210  }
   211  
   212  // ListUsagesSender sends the ListUsages request. The method will close the
   213  // http.Response Body if it receives an error.
   214  func (client CollectionPartitionClient) ListUsagesSender(req *http.Request) (*http.Response, error) {
   215  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   216  }
   217  
   218  // ListUsagesResponder handles the response to the ListUsages request. The method always
   219  // closes the http.Response Body.
   220  func (client CollectionPartitionClient) ListUsagesResponder(resp *http.Response) (result PartitionUsagesResult, err error) {
   221  	err = autorest.Respond(
   222  		resp,
   223  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   224  		autorest.ByUnmarshallingJSON(&result),
   225  		autorest.ByClosing())
   226  	result.Response = autorest.Response{Response: resp}
   227  	return
   228  }
   229  

View as plain text