...

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

View as plain text