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