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