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