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 {TargetValue: accountName,
65 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
66 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
67 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
68 return result, validation.NewError("documentdb.PercentileSourceTargetClient", "ListMetrics", err.Error())
69 }
70
71 req, err := client.ListMetricsPreparer(ctx, resourceGroupName, accountName, sourceRegion, targetRegion, filter)
72 if err != nil {
73 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", nil, "Failure preparing request")
74 return
75 }
76
77 resp, err := client.ListMetricsSender(req)
78 if err != nil {
79 result.Response = autorest.Response{Response: resp}
80 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", resp, "Failure sending request")
81 return
82 }
83
84 result, err = client.ListMetricsResponder(resp)
85 if err != nil {
86 err = autorest.NewErrorWithError(err, "documentdb.PercentileSourceTargetClient", "ListMetrics", resp, "Failure responding to request")
87 return
88 }
89
90 return
91 }
92
93
94 func (client PercentileSourceTargetClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, accountName string, sourceRegion string, targetRegion string, filter string) (*http.Request, error) {
95 pathParameters := map[string]interface{}{
96 "accountName": autorest.Encode("path", accountName),
97 "resourceGroupName": autorest.Encode("path", resourceGroupName),
98 "sourceRegion": autorest.Encode("path", sourceRegion),
99 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
100 "targetRegion": autorest.Encode("path", targetRegion),
101 }
102
103 const APIVersion = "2021-11-15-preview"
104 queryParameters := map[string]interface{}{
105 "$filter": autorest.Encode("query", filter),
106 "api-version": APIVersion,
107 }
108
109 preparer := autorest.CreatePreparer(
110 autorest.AsGet(),
111 autorest.WithBaseURL(client.BaseURI),
112 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/sourceRegion/{sourceRegion}/targetRegion/{targetRegion}/percentile/metrics", pathParameters),
113 autorest.WithQueryParameters(queryParameters))
114 return preparer.Prepare((&http.Request{}).WithContext(ctx))
115 }
116
117
118
119 func (client PercentileSourceTargetClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
120 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
121 }
122
123
124
125 func (client PercentileSourceTargetClient) ListMetricsResponder(resp *http.Response) (result PercentileMetricListResult, err error) {
126 err = autorest.Respond(
127 resp,
128 azure.WithErrorUnlessStatusCode(http.StatusOK),
129 autorest.ByUnmarshallingJSON(&result),
130 autorest.ByClosing())
131 result.Response = autorest.Response{Response: resp}
132 return
133 }
134
View as plain text