1
2
3
4
5
6
7
8
9
10
11
12
13
14 package anomalydetector
15
16
17
18
19
20
21
22 import (
23 "context"
24 "crypto/tls"
25 "github.com/Azure/go-autorest/autorest"
26 "github.com/Azure/go-autorest/autorest/azure"
27 "github.com/Azure/go-autorest/autorest/validation"
28 "github.com/Azure/go-autorest/tracing"
29 "net/http"
30 )
31
32
33 type BaseClient struct {
34 autorest.Client
35 Endpoint string
36 }
37
38
39 func New(endpoint string) BaseClient {
40 return NewWithoutDefaults(endpoint)
41 }
42
43
44 func NewWithoutDefaults(endpoint string) BaseClient {
45 return BaseClient{
46 Client: autorest.NewClientWithOptions(autorest.ClientOptions{UserAgent: UserAgent(), Renegotiation: tls.RenegotiateFreelyAsClient}),
47 Endpoint: endpoint,
48 }
49 }
50
51
52
53
54
55 func (client BaseClient) DetectChangePoint(ctx context.Context, body ChangePointDetectRequest) (result ChangePointDetectResponse, err error) {
56 if tracing.IsEnabled() {
57 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectChangePoint")
58 defer func() {
59 sc := -1
60 if result.Response.Response != nil {
61 sc = result.Response.Response.StatusCode
62 }
63 tracing.EndSpan(ctx, sc, err)
64 }()
65 }
66 if err := validation.Validate([]validation.Validation{
67 {TargetValue: body,
68 Constraints: []validation.Constraint{{Target: "body.Series", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
69 return result, validation.NewError("anomalydetector.BaseClient", "DetectChangePoint", err.Error())
70 }
71
72 req, err := client.DetectChangePointPreparer(ctx, body)
73 if err != nil {
74 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectChangePoint", nil, "Failure preparing request")
75 return
76 }
77
78 resp, err := client.DetectChangePointSender(req)
79 if err != nil {
80 result.Response = autorest.Response{Response: resp}
81 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectChangePoint", resp, "Failure sending request")
82 return
83 }
84
85 result, err = client.DetectChangePointResponder(resp)
86 if err != nil {
87 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectChangePoint", resp, "Failure responding to request")
88 return
89 }
90
91 return
92 }
93
94
95 func (client BaseClient) DetectChangePointPreparer(ctx context.Context, body ChangePointDetectRequest) (*http.Request, error) {
96 urlParameters := map[string]interface{}{
97 "Endpoint": client.Endpoint,
98 }
99
100 preparer := autorest.CreatePreparer(
101 autorest.AsContentType("application/json; charset=utf-8"),
102 autorest.AsPost(),
103 autorest.WithCustomBaseURL("{Endpoint}/anomalydetector/v1.0", urlParameters),
104 autorest.WithPath("/timeseries/changepoint/detect"),
105 autorest.WithJSON(body))
106 return preparer.Prepare((&http.Request{}).WithContext(ctx))
107 }
108
109
110
111 func (client BaseClient) DetectChangePointSender(req *http.Request) (*http.Response, error) {
112 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
113 }
114
115
116
117 func (client BaseClient) DetectChangePointResponder(resp *http.Response) (result ChangePointDetectResponse, err error) {
118 err = autorest.Respond(
119 resp,
120 azure.WithErrorUnlessStatusCode(http.StatusOK),
121 autorest.ByUnmarshallingJSON(&result),
122 autorest.ByClosing())
123 result.Response = autorest.Response{Response: resp}
124 return
125 }
126
127
128
129
130
131
132 func (client BaseClient) DetectEntireSeries(ctx context.Context, body DetectRequest) (result EntireDetectResponse, err error) {
133 if tracing.IsEnabled() {
134 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectEntireSeries")
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: body,
145 Constraints: []validation.Constraint{{Target: "body.Series", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
146 return result, validation.NewError("anomalydetector.BaseClient", "DetectEntireSeries", err.Error())
147 }
148
149 req, err := client.DetectEntireSeriesPreparer(ctx, body)
150 if err != nil {
151 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectEntireSeries", nil, "Failure preparing request")
152 return
153 }
154
155 resp, err := client.DetectEntireSeriesSender(req)
156 if err != nil {
157 result.Response = autorest.Response{Response: resp}
158 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectEntireSeries", resp, "Failure sending request")
159 return
160 }
161
162 result, err = client.DetectEntireSeriesResponder(resp)
163 if err != nil {
164 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectEntireSeries", resp, "Failure responding to request")
165 return
166 }
167
168 return
169 }
170
171
172 func (client BaseClient) DetectEntireSeriesPreparer(ctx context.Context, body DetectRequest) (*http.Request, error) {
173 urlParameters := map[string]interface{}{
174 "Endpoint": client.Endpoint,
175 }
176
177 preparer := autorest.CreatePreparer(
178 autorest.AsContentType("application/json; charset=utf-8"),
179 autorest.AsPost(),
180 autorest.WithCustomBaseURL("{Endpoint}/anomalydetector/v1.0", urlParameters),
181 autorest.WithPath("/timeseries/entire/detect"),
182 autorest.WithJSON(body))
183 return preparer.Prepare((&http.Request{}).WithContext(ctx))
184 }
185
186
187
188 func (client BaseClient) DetectEntireSeriesSender(req *http.Request) (*http.Response, error) {
189 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
190 }
191
192
193
194 func (client BaseClient) DetectEntireSeriesResponder(resp *http.Response) (result EntireDetectResponse, err error) {
195 err = autorest.Respond(
196 resp,
197 azure.WithErrorUnlessStatusCode(http.StatusOK),
198 autorest.ByUnmarshallingJSON(&result),
199 autorest.ByClosing())
200 result.Response = autorest.Response{Response: resp}
201 return
202 }
203
204
205
206
207
208
209 func (client BaseClient) DetectLastPoint(ctx context.Context, body DetectRequest) (result LastDetectResponse, err error) {
210 if tracing.IsEnabled() {
211 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectLastPoint")
212 defer func() {
213 sc := -1
214 if result.Response.Response != nil {
215 sc = result.Response.Response.StatusCode
216 }
217 tracing.EndSpan(ctx, sc, err)
218 }()
219 }
220 if err := validation.Validate([]validation.Validation{
221 {TargetValue: body,
222 Constraints: []validation.Constraint{{Target: "body.Series", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
223 return result, validation.NewError("anomalydetector.BaseClient", "DetectLastPoint", err.Error())
224 }
225
226 req, err := client.DetectLastPointPreparer(ctx, body)
227 if err != nil {
228 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectLastPoint", nil, "Failure preparing request")
229 return
230 }
231
232 resp, err := client.DetectLastPointSender(req)
233 if err != nil {
234 result.Response = autorest.Response{Response: resp}
235 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectLastPoint", resp, "Failure sending request")
236 return
237 }
238
239 result, err = client.DetectLastPointResponder(resp)
240 if err != nil {
241 err = autorest.NewErrorWithError(err, "anomalydetector.BaseClient", "DetectLastPoint", resp, "Failure responding to request")
242 return
243 }
244
245 return
246 }
247
248
249 func (client BaseClient) DetectLastPointPreparer(ctx context.Context, body DetectRequest) (*http.Request, error) {
250 urlParameters := map[string]interface{}{
251 "Endpoint": client.Endpoint,
252 }
253
254 preparer := autorest.CreatePreparer(
255 autorest.AsContentType("application/json; charset=utf-8"),
256 autorest.AsPost(),
257 autorest.WithCustomBaseURL("{Endpoint}/anomalydetector/v1.0", urlParameters),
258 autorest.WithPath("/timeseries/last/detect"),
259 autorest.WithJSON(body))
260 return preparer.Prepare((&http.Request{}).WithContext(ctx))
261 }
262
263
264
265 func (client BaseClient) DetectLastPointSender(req *http.Request) (*http.Response, error) {
266 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
267 }
268
269
270
271 func (client BaseClient) DetectLastPointResponder(resp *http.Response) (result LastDetectResponse, err error) {
272 err = autorest.Respond(
273 resp,
274 azure.WithErrorUnlessStatusCode(http.StatusOK),
275 autorest.ByUnmarshallingJSON(&result),
276 autorest.ByClosing())
277 result.Response = autorest.Response{Response: resp}
278 return
279 }
280
View as plain text