1package documentdb 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "net/http" 26) 27 28// PercentileSourceTargetClient is the azure Cosmos DB Database Service Resource Provider REST API 29type PercentileSourceTargetClient struct { 30 BaseClient 31} 32 33// NewPercentileSourceTargetClient creates an instance of the PercentileSourceTargetClient client. 34func NewPercentileSourceTargetClient(subscriptionID string) PercentileSourceTargetClient { 35 return NewPercentileSourceTargetClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewPercentileSourceTargetClientWithBaseURI creates an instance of the PercentileSourceTargetClient client. 39func NewPercentileSourceTargetClientWithBaseURI(baseURI string, subscriptionID string) PercentileSourceTargetClient { 40 return PercentileSourceTargetClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// ListMetrics retrieves the metrics determined by the given filter for the given account, source and target region. 44// This url is only for PBS and Replication Latency data 45// Parameters: 46// resourceGroupName - name of an Azure resource group. 47// accountName - cosmos DB database account name. 48// sourceRegion - source region from which data is written. Cosmos DB region, with spaces between words and 49// each word capitalized. 50// targetRegion - target region to which data is written. Cosmos DB region, with spaces between words and each 51// word capitalized. 52// filter - an OData filter expression that describes a subset of metrics to return. The parameters that can be 53// filtered are name.value (name of the metric, can have an or of multiple names), startTime, endTime, and 54// timeGrain. The supported operator is eq. 55func (client PercentileSourceTargetClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, sourceRegion string, targetRegion string, filter string) (result PercentileMetricListResult, err error) { 56 if err := validation.Validate([]validation.Validation{ 57 {TargetValue: resourceGroupName, 58 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 59 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 60 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 61 {TargetValue: accountName, 62 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 63 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 64 return result, validation.NewError("documentdb.PercentileSourceTargetClient", "ListMetrics", err.Error()) 65 } 66 67 req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, sourceRegion, targetRegion, filter) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", nil, "Failure preparing request") 70 return 71 } 72 73 resp, err := client.ListMetricsSender(req) 74 if err != nil { 75 result.Response = autorest.Response{Response: resp} 76 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", resp, "Failure sending request") 77 return 78 } 79 80 result, err = client.ListMetricsResponder(resp) 81 if err != nil { 82 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", resp, "Failure responding to request") 83 } 84 85 return 86} 87 88// ListMetricsPreparer prepares the ListMetrics request. 89func (client PercentileSourceTargetClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, sourceRegion string, targetRegion string, filter string) (*http.Request, error) { 90 pathParameters := map[string]interface{}{ 91 "accountName": autorest.Encode("path", accountName), 92 "resourceGroupName": autorest.Encode("path", resourceGroupName), 93 "sourceRegion": autorest.Encode("path", sourceRegion), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 "targetRegion": autorest.Encode("path", targetRegion), 96 } 97 98 const APIVersion = "2015-04-08" 99 queryParameters := map[string]interface{}{ 100 "$filter": autorest.Encode("query", filter), 101 "api-version": APIVersion, 102 } 103 104 preparer := autorest.CreatePreparer( 105 autorest.AsGet(), 106 autorest.WithBaseURL(client.BaseURI), 107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/sourceRegion/{sourceRegion}/targetRegion/{targetRegion}/percentile/metrics", pathParameters), 108 autorest.WithQueryParameters(queryParameters)) 109 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 110} 111 112// ListMetricsSender sends the ListMetrics request. The method will close the 113// http.Response Body if it receives an error. 114func (client PercentileSourceTargetClient) ListMetricsSender(req *http.Request) (*http.Response, error) { 115 return autorest.SendWithSender(client, req, 116 azure.DoRetryWithRegistration(client.Client)) 117} 118 119// ListMetricsResponder handles the response to the ListMetrics request. The method always 120// closes the http.Response Body. 121func (client PercentileSourceTargetClient) ListMetricsResponder(resp *http.Response) (result PercentileMetricListResult, err error) { 122 err = autorest.Respond( 123 resp, 124 client.ByInspecting(), 125 azure.WithErrorUnlessStatusCode(http.StatusOK), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131