1 package devices
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 IotHubClient struct {
20 BaseClient
21 }
22
23
24 func NewIotHubClient(subscriptionID string) IotHubClient {
25 return NewIotHubClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewIotHubClientWithBaseURI(baseURI string, subscriptionID string) IotHubClient {
31 return IotHubClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40
41 func (client IotHubClient) ManualFailover(ctx context.Context, iotHubName string, failoverInput FailoverInput, resourceGroupName string) (result IotHubManualFailoverFuture, err error) {
42 if tracing.IsEnabled() {
43 ctx = tracing.StartSpan(ctx, fqdn+"/IotHubClient.ManualFailover")
44 defer func() {
45 sc := -1
46 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47 sc = result.FutureAPI.Response().StatusCode
48 }
49 tracing.EndSpan(ctx, sc, err)
50 }()
51 }
52 if err := validation.Validate([]validation.Validation{
53 {TargetValue: failoverInput,
54 Constraints: []validation.Constraint{{Target: "failoverInput.FailoverRegion", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
55 return result, validation.NewError("devices.IotHubClient", "ManualFailover", err.Error())
56 }
57
58 req, err := client.ManualFailoverPreparer(ctx, iotHubName, failoverInput, resourceGroupName)
59 if err != nil {
60 err = autorest.NewErrorWithError(err, "devices.IotHubClient", "ManualFailover", nil, "Failure preparing request")
61 return
62 }
63
64 result, err = client.ManualFailoverSender(req)
65 if err != nil {
66 err = autorest.NewErrorWithError(err, "devices.IotHubClient", "ManualFailover", result.Response(), "Failure sending request")
67 return
68 }
69
70 return
71 }
72
73
74 func (client IotHubClient) ManualFailoverPreparer(ctx context.Context, iotHubName string, failoverInput FailoverInput, resourceGroupName string) (*http.Request, error) {
75 pathParameters := map[string]interface{}{
76 "iotHubName": autorest.Encode("path", iotHubName),
77 "resourceGroupName": autorest.Encode("path", resourceGroupName),
78 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
79 }
80
81 const APIVersion = "2021-03-31"
82 queryParameters := map[string]interface{}{
83 "api-version": APIVersion,
84 }
85
86 preparer := autorest.CreatePreparer(
87 autorest.AsContentType("application/json; charset=utf-8"),
88 autorest.AsPost(),
89 autorest.WithBaseURL(client.BaseURI),
90 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{iotHubName}/failover", pathParameters),
91 autorest.WithJSON(failoverInput),
92 autorest.WithQueryParameters(queryParameters))
93 return preparer.Prepare((&http.Request{}).WithContext(ctx))
94 }
95
96
97
98 func (client IotHubClient) ManualFailoverSender(req *http.Request) (future IotHubManualFailoverFuture, err error) {
99 var resp *http.Response
100 future.FutureAPI = &azure.Future{}
101 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
102 if err != nil {
103 return
104 }
105 var azf azure.Future
106 azf, err = azure.NewFutureFromResponse(resp)
107 future.FutureAPI = &azf
108 future.Result = future.result
109 return
110 }
111
112
113
114 func (client IotHubClient) ManualFailoverResponder(resp *http.Response) (result autorest.Response, err error) {
115 err = autorest.Respond(
116 resp,
117 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
118 autorest.ByClosing())
119 result.Response = resp
120 return
121 }
122
View as plain text