...

Source file src/github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-03-15/documentdb/database.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  // DatabaseClient is the azure Cosmos DB Database Service Resource Provider REST API
    19  type DatabaseClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDatabaseClient creates an instance of the DatabaseClient client.
    24  func NewDatabaseClient(subscriptionID string) DatabaseClient {
    25  	return NewDatabaseClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewDatabaseClientWithBaseURI creates an instance of the DatabaseClient 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 NewDatabaseClientWithBaseURI(baseURI string, subscriptionID string) DatabaseClient {
    31  	return DatabaseClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // ListMetricDefinitions retrieves metric definitions for the given database.
    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  func (client DatabaseClient) ListMetricDefinitions(ctx context.Context, resourceGroupName string, accountName string, databaseRid string) (result MetricDefinitionsListResult, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseClient.ListMetricDefinitions")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: client.SubscriptionID,
    52  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    53  		{TargetValue: resourceGroupName,
    54  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    55  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, 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.DatabaseClient", "ListMetricDefinitions", err.Error())
    62  	}
    63  
    64  	req, err := client.ListMetricDefinitionsPreparer(ctx, resourceGroupName, accountName, databaseRid)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseClient", "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.DatabaseClient", "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.DatabaseClient", "ListMetricDefinitions", resp, "Failure responding to request")
    80  		return
    81  	}
    82  
    83  	return
    84  }
    85  
    86  // ListMetricDefinitionsPreparer prepares the ListMetricDefinitions request.
    87  func (client DatabaseClient) ListMetricDefinitionsPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string) (*http.Request, error) {
    88  	pathParameters := map[string]interface{}{
    89  		"accountName":       autorest.Encode("path", accountName),
    90  		"databaseRid":       autorest.Encode("path", databaseRid),
    91  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    92  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    93  	}
    94  
    95  	const APIVersion = "2021-03-15"
    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}/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 DatabaseClient) 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 DatabaseClient) 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 database.
   127  // Parameters:
   128  // resourceGroupName - the name of the resource group. The name is case insensitive.
   129  // accountName - cosmos DB database account name.
   130  // databaseRid - cosmos DB database rid.
   131  // filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be
   132  // filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and
   133  // timeGrain. The supported operator is eq.
   134  func (client DatabaseClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, filter string) (result MetricListResult, err error) {
   135  	if tracing.IsEnabled() {
   136  		ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseClient.ListMetrics")
   137  		defer func() {
   138  			sc := -1
   139  			if result.Response.Response != nil {
   140  				sc = result.Response.Response.StatusCode
   141  			}
   142  			tracing.EndSpan(ctx, sc, err)
   143  		}()
   144  	}
   145  	if err := validation.Validate([]validation.Validation{
   146  		{TargetValue: client.SubscriptionID,
   147  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   148  		{TargetValue: resourceGroupName,
   149  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   150  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   151  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   152  		{TargetValue: accountName,
   153  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   154  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   155  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   156  		return result, validation.NewError("documentdb.DatabaseClient", "ListMetrics", err.Error())
   157  	}
   158  
   159  	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, databaseRid, filter)
   160  	if err != nil {
   161  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseClient", "ListMetrics", nil, "Failure preparing request")
   162  		return
   163  	}
   164  
   165  	resp, err := client.ListMetricsSender(req)
   166  	if err != nil {
   167  		result.Response = autorest.Response{Response: resp}
   168  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseClient", "ListMetrics", resp, "Failure sending request")
   169  		return
   170  	}
   171  
   172  	result, err = client.ListMetricsResponder(resp)
   173  	if err != nil {
   174  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseClient", "ListMetrics", resp, "Failure responding to request")
   175  		return
   176  	}
   177  
   178  	return
   179  }
   180  
   181  // ListMetricsPreparer prepares the ListMetrics request.
   182  func (client DatabaseClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, filter string) (*http.Request, error) {
   183  	pathParameters := map[string]interface{}{
   184  		"accountName":       autorest.Encode("path", accountName),
   185  		"databaseRid":       autorest.Encode("path", databaseRid),
   186  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   187  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   188  	}
   189  
   190  	const APIVersion = "2021-03-15"
   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}/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 DatabaseClient) 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 DatabaseClient) 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 data) for the given database.
   223  // Parameters:
   224  // resourceGroupName - the name of the resource group. The name is case insensitive.
   225  // accountName - cosmos DB database account name.
   226  // databaseRid - cosmos DB database rid.
   227  // filter - an OData filter expression that describes a subset of usages to return. The supported parameter is
   228  // name.value (name of the metric, can have an or of multiple names).
   229  func (client DatabaseClient) ListUsages(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, filter string) (result UsagesResult, err error) {
   230  	if tracing.IsEnabled() {
   231  		ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseClient.ListUsages")
   232  		defer func() {
   233  			sc := -1
   234  			if result.Response.Response != nil {
   235  				sc = result.Response.Response.StatusCode
   236  			}
   237  			tracing.EndSpan(ctx, sc, err)
   238  		}()
   239  	}
   240  	if err := validation.Validate([]validation.Validation{
   241  		{TargetValue: client.SubscriptionID,
   242  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   243  		{TargetValue: resourceGroupName,
   244  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   245  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   246  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   247  		{TargetValue: accountName,
   248  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   249  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   250  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   251  		return result, validation.NewError("documentdb.DatabaseClient", "ListUsages", err.Error())
   252  	}
   253  
   254  	req, err := client.ListUsagesPreparer(ctx, resourceGroupName, accountName, databaseRid, filter)
   255  	if err != nil {
   256  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseClient", "ListUsages", nil, "Failure preparing request")
   257  		return
   258  	}
   259  
   260  	resp, err := client.ListUsagesSender(req)
   261  	if err != nil {
   262  		result.Response = autorest.Response{Response: resp}
   263  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseClient", "ListUsages", resp, "Failure sending request")
   264  		return
   265  	}
   266  
   267  	result, err = client.ListUsagesResponder(resp)
   268  	if err != nil {
   269  		err = autorest.NewErrorWithError(err, "documentdb.DatabaseClient", "ListUsages", resp, "Failure responding to request")
   270  		return
   271  	}
   272  
   273  	return
   274  }
   275  
   276  // ListUsagesPreparer prepares the ListUsages request.
   277  func (client DatabaseClient) ListUsagesPreparer(ctx context.Context, resourceGroupName string, accountName string, databaseRid string, filter string) (*http.Request, error) {
   278  	pathParameters := map[string]interface{}{
   279  		"accountName":       autorest.Encode("path", accountName),
   280  		"databaseRid":       autorest.Encode("path", databaseRid),
   281  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   282  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   283  	}
   284  
   285  	const APIVersion = "2021-03-15"
   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}/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 DatabaseClient) 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 DatabaseClient) 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