...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2022-05-15/documentdb/collection.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2022-05-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  // CollectionClient is the client for the Collection methods of the Documentdb service.
    19  type CollectionClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewCollectionClient creates an instance of the CollectionClient client.
    24  func NewCollectionClient(subscriptionID string) CollectionClient {
    25  	return NewCollectionClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewCollectionClientWithBaseURI creates an instance of the CollectionClient client using a custom endpoint.  Use this
    29  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewCollectionClientWithBaseURI(baseURI string, subscriptionID string) CollectionClient {
    31  	return CollectionClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // ListMetricDefinitions retrieves metric definitions for the given collection.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group. The name is case insensitive.
    37  // accountName - cosmos DB database account name.
    38  // databaseRid - cosmos DB database rid.
    39  // collectionRid - cosmos DB collection rid.
    40  func (client CollectionClient) ListMetricDefinitions(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string) (result MetricDefinitionsListResult, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/CollectionClient.ListMetricDefinitions")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: client.SubscriptionID,
    53  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    54  		{TargetValue: resourceGroupName,
    55  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    57  		{TargetValue: accountName,
    58  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    59  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
    60  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
    61  		return result, validation.NewError("documentdb.CollectionClient", "ListMetricDefinitions", err.Error())
    62  	}
    63  
    64  	req, err := client.ListMetricDefinitionsPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListMetricDefinitions", nil, "Failure preparing request")
    67  		return
    68  	}
    69  
    70  	resp, err := client.ListMetricDefinitionsSender(req)
    71  	if err != nil {
    72  		result.Response = autorest.Response{Response: resp}
    73  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListMetricDefinitions", resp, "Failure sending request")
    74  		return
    75  	}
    76  
    77  	result, err = client.ListMetricDefinitionsResponder(resp)
    78  	if err != nil {
    79  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListMetricDefinitions", resp, "Failure responding to request")
    80  		return
    81  	}
    82  
    83  	return
    84  }
    85  
    86  // ListMetricDefinitionsPreparer prepares the ListMetricDefinitions request.
    87  func (client CollectionClient) ListMetricDefinitionsPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string) (*http.Request, error) {
    88  	pathParameters := map[string]interface{}{
    89  		"accountName":       autorest.Encode("path", accountName),
    90  		"collectionRid":     autorest.Encode("path", collectionRid),
    91  		"databaseRid":       autorest.Encode("path", databaseRid),
    92  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    93  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    94  	}
    95  
    96  	const APIVersion = "2022-05-15"
    97  	queryParameters := map[string]interface{}{
    98  		"api-version": APIVersion,
    99  	}
   100  
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsGet(),
   103  		autorest.WithBaseURL(client.BaseURI),
   104  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/databases/{databaseRid}/collections/{collectionRid}/metricDefinitions", pathParameters),
   105  		autorest.WithQueryParameters(queryParameters))
   106  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   107  }
   108  
   109  // ListMetricDefinitionsSender sends the ListMetricDefinitions request. The method will close the
   110  // http.Response Body if it receives an error.
   111  func (client CollectionClient) ListMetricDefinitionsSender(req *http.Request) (*http.Response, error) {
   112  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   113  }
   114  
   115  // ListMetricDefinitionsResponder handles the response to the ListMetricDefinitions request. The method always
   116  // closes the http.Response Body.
   117  func (client CollectionClient) ListMetricDefinitionsResponder(resp *http.Response) (result MetricDefinitionsListResult, err error) {
   118  	err = autorest.Respond(
   119  		resp,
   120  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   121  		autorest.ByUnmarshallingJSON(&result),
   122  		autorest.ByClosing())
   123  	result.Response = autorest.Response{Response: resp}
   124  	return
   125  }
   126  
   127  // ListMetrics retrieves the metrics determined by the given filter for the given database account and collection.
   128  // Parameters:
   129  // resourceGroupName - the name of the resource group. The name is case insensitive.
   130  // accountName - cosmos DB database account name.
   131  // databaseRid - cosmos DB database rid.
   132  // collectionRid - cosmos DB collection rid.
   133  // filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be
   134  // filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and
   135  // timeGrain. The supported operator is eq.
   136  func (client CollectionClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (result MetricListResult, err error) {
   137  	if tracing.IsEnabled() {
   138  		ctx = tracing.StartSpan(ctx, fqdn+"/CollectionClient.ListMetrics")
   139  		defer func() {
   140  			sc := -1
   141  			if result.Response.Response != nil {
   142  				sc = result.Response.Response.StatusCode
   143  			}
   144  			tracing.EndSpan(ctx, sc, err)
   145  		}()
   146  	}
   147  	if err := validation.Validate([]validation.Validation{
   148  		{TargetValue: client.SubscriptionID,
   149  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   150  		{TargetValue: resourceGroupName,
   151  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   152  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   153  		{TargetValue: accountName,
   154  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   155  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   156  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   157  		return result, validation.NewError("documentdb.CollectionClient", "ListMetrics", err.Error())
   158  	}
   159  
   160  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid, filter)
   161  	if err != nil {
   162  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListMetrics", nil, "Failure preparing request")
   163  		return
   164  	}
   165  
   166  	resp, err := client.ListMetricsSender(req)
   167  	if err != nil {
   168  		result.Response = autorest.Response{Response: resp}
   169  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListMetrics", resp, "Failure sending request")
   170  		return
   171  	}
   172  
   173  	result, err = client.ListMetricsResponder(resp)
   174  	if err != nil {
   175  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListMetrics", resp, "Failure responding to request")
   176  		return
   177  	}
   178  
   179  	return
   180  }
   181  
   182  // ListMetricsPreparer prepares the ListMetrics request.
   183  func (client CollectionClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (*http.Request, error) {
   184  	pathParameters := map[string]interface{}{
   185  		"accountName":       autorest.Encode("path", accountName),
   186  		"collectionRid":     autorest.Encode("path", collectionRid),
   187  		"databaseRid":       autorest.Encode("path", databaseRid),
   188  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   189  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   190  	}
   191  
   192  	const APIVersion = "2022-05-15"
   193  	queryParameters := map[string]interface{}{
   194  		"$filter":     autorest.Encode("query", filter),
   195  		"api-version": APIVersion,
   196  	}
   197  
   198  	preparer := autorest.CreatePreparer(
   199  		autorest.AsGet(),
   200  		autorest.WithBaseURL(client.BaseURI),
   201  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/databases/{databaseRid}/collections/{collectionRid}/metrics", pathParameters),
   202  		autorest.WithQueryParameters(queryParameters))
   203  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   204  }
   205  
   206  // ListMetricsSender sends the ListMetrics request. The method will close the
   207  // http.Response Body if it receives an error.
   208  func (client CollectionClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
   209  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   210  }
   211  
   212  // ListMetricsResponder handles the response to the ListMetrics request. The method always
   213  // closes the http.Response Body.
   214  func (client CollectionClient) ListMetricsResponder(resp *http.Response) (result MetricListResult, err error) {
   215  	err = autorest.Respond(
   216  		resp,
   217  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   218  		autorest.ByUnmarshallingJSON(&result),
   219  		autorest.ByClosing())
   220  	result.Response = autorest.Response{Response: resp}
   221  	return
   222  }
   223  
   224  // ListUsages retrieves the usages (most recent storage data) for the given collection.
   225  // Parameters:
   226  // resourceGroupName - the name of the resource group. The name is case insensitive.
   227  // accountName - cosmos DB database account name.
   228  // databaseRid - cosmos DB database rid.
   229  // collectionRid - cosmos DB collection rid.
   230  // filter - an OData filter expression that describes a subset of usages to return. The supported parameter is
   231  // name.value (name of the metric, can have an or of multiple names).
   232  func (client CollectionClient) ListUsages(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (result UsagesResult, err error) {
   233  	if tracing.IsEnabled() {
   234  		ctx = tracing.StartSpan(ctx, fqdn+"/CollectionClient.ListUsages")
   235  		defer func() {
   236  			sc := -1
   237  			if result.Response.Response != nil {
   238  				sc = result.Response.Response.StatusCode
   239  			}
   240  			tracing.EndSpan(ctx, sc, err)
   241  		}()
   242  	}
   243  	if err := validation.Validate([]validation.Validation{
   244  		{TargetValue: client.SubscriptionID,
   245  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   246  		{TargetValue: resourceGroupName,
   247  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   248  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   249  		{TargetValue: accountName,
   250  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   251  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   252  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   253  		return result, validation.NewError("documentdb.CollectionClient", "ListUsages", err.Error())
   254  	}
   255  
   256  	req, err := client.ListUsagesPreparer(ctx, resourceGroupName, accountName, databaseRid, collectionRid, filter)
   257  	if err != nil {
   258  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListUsages", nil, "Failure preparing request")
   259  		return
   260  	}
   261  
   262  	resp, err := client.ListUsagesSender(req)
   263  	if err != nil {
   264  		result.Response = autorest.Response{Response: resp}
   265  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListUsages", resp, "Failure sending request")
   266  		return
   267  	}
   268  
   269  	result, err = client.ListUsagesResponder(resp)
   270  	if err != nil {
   271  		err = autorest.NewErrorWithError(err, "documentdb.CollectionClient", "ListUsages", resp, "Failure responding to request")
   272  		return
   273  	}
   274  
   275  	return
   276  }
   277  
   278  // ListUsagesPreparer prepares the ListUsages request.
   279  func (client CollectionClient) ListUsagesPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, collectionRid string, filter string) (*http.Request, error) {
   280  	pathParameters := map[string]interface{}{
   281  		"accountName":       autorest.Encode("path", accountName),
   282  		"collectionRid":     autorest.Encode("path", collectionRid),
   283  		"databaseRid":       autorest.Encode("path", databaseRid),
   284  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   285  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   286  	}
   287  
   288  	const APIVersion = "2022-05-15"
   289  	queryParameters := map[string]interface{}{
   290  		"api-version": APIVersion,
   291  	}
   292  	if len(filter) > 0 {
   293  		queryParameters["$filter"] = autorest.Encode("query", filter)
   294  	}
   295  
   296  	preparer := autorest.CreatePreparer(
   297  		autorest.AsGet(),
   298  		autorest.WithBaseURL(client.BaseURI),
   299  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/databases/{databaseRid}/collections/{collectionRid}/usages", pathParameters),
   300  		autorest.WithQueryParameters(queryParameters))
   301  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   302  }
   303  
   304  // ListUsagesSender sends the ListUsages request. The method will close the
   305  // http.Response Body if it receives an error.
   306  func (client CollectionClient) ListUsagesSender(req *http.Request) (*http.Response, error) {
   307  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   308  }
   309  
   310  // ListUsagesResponder handles the response to the ListUsages request. The method always
   311  // closes the http.Response Body.
   312  func (client CollectionClient) ListUsagesResponder(resp *http.Response) (result UsagesResult, err error) {
   313  	err = autorest.Respond(
   314  		resp,
   315  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   316  		autorest.ByUnmarshallingJSON(&result),
   317  		autorest.ByClosing())
   318  	result.Response = autorest.Response{Response: resp}
   319  	return
   320  }
   321  

View as plain text