1 package documentdb
2
3
4
5
6
7
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
19 type PercentileSourceTargetClient struct {
20 BaseClient
21 }
22
23
24 func NewPercentileSourceTargetClient(subscriptionID string) PercentileSourceTargetClient {
25 return NewPercentileSourceTargetClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewPercentileSourceTargetClientWithBaseURI(baseURI string, subscriptionID string) PercentileSourceTargetClient {
32 return PercentileSourceTargetClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
40
41
42
43
44
45
46
47 func (client PercentileSourceTargetClient) ListMetrics(ctx context.Context, resourceGroupName string, accountName string, sourceRegion string, targetRegion string, filter string) (result PercentileMetricListResult, err error) {
48 if tracing.IsEnabled() {
49 ctx = tracing.StartSpan(ctx, fqdn+"/PercentileSourceTargetClient.ListMetrics")
50 defer func() {
51 sc := -1
52 if result.Response.Response != nil {
53 sc = result.Response.Response.StatusCode
54 }
55 tracing.EndSpan(ctx, sc, err)
56 }()
57 }
58 if err := validation.Validate([]validation.Validation{
59 {TargetValue: client.SubscriptionID,
60 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
61 {TargetValue: resourceGroupName,
62 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
63 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
64 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
65 {TargetValue: accountName,
66 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
67 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
68 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
69 return result, validation.NewError("documentdb.PercentileSourceTargetClient", "ListMetrics", err.Error())
70 }
71
72 req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, sourceRegion, targetRegion, filter)
73 if err != nil {
74 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", nil, "Failure preparing request")
75 return
76 }
77
78 resp, err := client.ListMetricsSender(req)
79 if err != nil {
80 result.Response = autorest.Response{Response: resp}
81 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", resp, "Failure sending request")
82 return
83 }
84
85 result, err = client.ListMetricsResponder(resp)
86 if err != nil {
87 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", resp, "Failure responding to request")
88 return
89 }
90
91 return
92 }
93
94
95 func (client PercentileSourceTargetClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, sourceRegion string, targetRegion string, filter string) (*http.Request, error) {
96 pathParameters := map[string]interface{}{
97 "accountName": autorest.Encode("path", accountName),
98 "resourceGroupName": autorest.Encode("path", resourceGroupName),
99 "sourceRegion": autorest.Encode("path", sourceRegion),
100 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
101 "targetRegion": autorest.Encode("path", targetRegion),
102 }
103
104 const APIVersion = "2019-08-01"
105 queryParameters := map[string]interface{}{
106 "$filter": autorest.Encode("query", filter),
107 "api-version": APIVersion,
108 }
109
110 preparer := autorest.CreatePreparer(
111 autorest.AsGet(),
112 autorest.WithBaseURL(client.BaseURI),
113 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/sourceRegion/{sourceRegion}/targetRegion/{targetRegion}/percentile/metrics", pathParameters),
114 autorest.WithQueryParameters(queryParameters))
115 return preparer.Prepare((&http.Request{}).WithContext(ctx))
116 }
117
118
119
120 func (client PercentileSourceTargetClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
121 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
122 }
123
124
125
126 func (client PercentileSourceTargetClient) ListMetricsResponder(resp *http.Response) (result PercentileMetricListResult, err error) {
127 err = autorest.Respond(
128 resp,
129 azure.WithErrorUnlessStatusCode(http.StatusOK),
130 autorest.ByUnmarshallingJSON(&result),
131 autorest.ByClosing())
132 result.Response = autorest.Response{Response: resp}
133 return
134 }
135
View as plain text