...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2019-08-01/documentdb/collection.go

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

View as plain text