...

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

View as plain text