1package hdinsight
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
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// VirtualMachinesClient is the hDInsight Management Client
19type VirtualMachinesClient struct {
20	BaseClient
21}
22
23// NewVirtualMachinesClient creates an instance of the VirtualMachinesClient client.
24func NewVirtualMachinesClient(subscriptionID string) VirtualMachinesClient {
25	return NewVirtualMachinesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewVirtualMachinesClientWithBaseURI creates an instance of the VirtualMachinesClient client using a custom endpoint.
29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewVirtualMachinesClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachinesClient {
31	return VirtualMachinesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// GetAsyncOperationStatus gets the async operation status.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// clusterName - the name of the cluster.
38// operationID - the long running operation id.
39func (client VirtualMachinesClient) GetAsyncOperationStatus(ctx context.Context, resourceGroupName string, clusterName string, operationID string) (result AsyncOperationResult, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.GetAsyncOperationStatus")
42		defer func() {
43			sc := -1
44			if result.Response.Response != nil {
45				sc = result.Response.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	req, err := client.GetAsyncOperationStatusPreparer(ctx, resourceGroupName, clusterName, operationID)
51	if err != nil {
52		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "GetAsyncOperationStatus", nil, "Failure preparing request")
53		return
54	}
55
56	resp, err := client.GetAsyncOperationStatusSender(req)
57	if err != nil {
58		result.Response = autorest.Response{Response: resp}
59		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "GetAsyncOperationStatus", resp, "Failure sending request")
60		return
61	}
62
63	result, err = client.GetAsyncOperationStatusResponder(resp)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "GetAsyncOperationStatus", resp, "Failure responding to request")
66		return
67	}
68
69	return
70}
71
72// GetAsyncOperationStatusPreparer prepares the GetAsyncOperationStatus request.
73func (client VirtualMachinesClient) GetAsyncOperationStatusPreparer(ctx context.Context, resourceGroupName string, clusterName string, operationID string) (*http.Request, error) {
74	pathParameters := map[string]interface{}{
75		"clusterName":       autorest.Encode("path", clusterName),
76		"operationId":       autorest.Encode("path", operationID),
77		"resourceGroupName": autorest.Encode("path", resourceGroupName),
78		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
79	}
80
81	const APIVersion = "2018-06-01-preview"
82	queryParameters := map[string]interface{}{
83		"api-version": APIVersion,
84	}
85
86	preparer := autorest.CreatePreparer(
87		autorest.AsGet(),
88		autorest.WithBaseURL(client.BaseURI),
89		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/restartHosts/azureasyncoperations/{operationId}", pathParameters),
90		autorest.WithQueryParameters(queryParameters))
91	return preparer.Prepare((&http.Request{}).WithContext(ctx))
92}
93
94// GetAsyncOperationStatusSender sends the GetAsyncOperationStatus request. The method will close the
95// http.Response Body if it receives an error.
96func (client VirtualMachinesClient) GetAsyncOperationStatusSender(req *http.Request) (*http.Response, error) {
97	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
98}
99
100// GetAsyncOperationStatusResponder handles the response to the GetAsyncOperationStatus request. The method always
101// closes the http.Response Body.
102func (client VirtualMachinesClient) GetAsyncOperationStatusResponder(resp *http.Response) (result AsyncOperationResult, err error) {
103	err = autorest.Respond(
104		resp,
105		azure.WithErrorUnlessStatusCode(http.StatusOK),
106		autorest.ByUnmarshallingJSON(&result),
107		autorest.ByClosing())
108	result.Response = autorest.Response{Response: resp}
109	return
110}
111
112// ListHosts lists the HDInsight clusters hosts
113// Parameters:
114// resourceGroupName - the name of the resource group.
115// clusterName - the name of the cluster.
116func (client VirtualMachinesClient) ListHosts(ctx context.Context, resourceGroupName string, clusterName string) (result ListHostInfo, err error) {
117	if tracing.IsEnabled() {
118		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.ListHosts")
119		defer func() {
120			sc := -1
121			if result.Response.Response != nil {
122				sc = result.Response.Response.StatusCode
123			}
124			tracing.EndSpan(ctx, sc, err)
125		}()
126	}
127	req, err := client.ListHostsPreparer(ctx, resourceGroupName, clusterName)
128	if err != nil {
129		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "ListHosts", nil, "Failure preparing request")
130		return
131	}
132
133	resp, err := client.ListHostsSender(req)
134	if err != nil {
135		result.Response = autorest.Response{Response: resp}
136		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "ListHosts", resp, "Failure sending request")
137		return
138	}
139
140	result, err = client.ListHostsResponder(resp)
141	if err != nil {
142		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "ListHosts", resp, "Failure responding to request")
143		return
144	}
145
146	return
147}
148
149// ListHostsPreparer prepares the ListHosts request.
150func (client VirtualMachinesClient) ListHostsPreparer(ctx context.Context, resourceGroupName string, clusterName string) (*http.Request, error) {
151	pathParameters := map[string]interface{}{
152		"clusterName":       autorest.Encode("path", clusterName),
153		"resourceGroupName": autorest.Encode("path", resourceGroupName),
154		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
155	}
156
157	const APIVersion = "2018-06-01-preview"
158	queryParameters := map[string]interface{}{
159		"api-version": APIVersion,
160	}
161
162	preparer := autorest.CreatePreparer(
163		autorest.AsPost(),
164		autorest.WithBaseURL(client.BaseURI),
165		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/listHosts", pathParameters),
166		autorest.WithQueryParameters(queryParameters))
167	return preparer.Prepare((&http.Request{}).WithContext(ctx))
168}
169
170// ListHostsSender sends the ListHosts request. The method will close the
171// http.Response Body if it receives an error.
172func (client VirtualMachinesClient) ListHostsSender(req *http.Request) (*http.Response, error) {
173	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
174}
175
176// ListHostsResponder handles the response to the ListHosts request. The method always
177// closes the http.Response Body.
178func (client VirtualMachinesClient) ListHostsResponder(resp *http.Response) (result ListHostInfo, err error) {
179	err = autorest.Respond(
180		resp,
181		azure.WithErrorUnlessStatusCode(http.StatusOK),
182		autorest.ByUnmarshallingJSON(&result.Value),
183		autorest.ByClosing())
184	result.Response = autorest.Response{Response: resp}
185	return
186}
187
188// RestartHosts restarts the specified HDInsight cluster hosts.
189// Parameters:
190// resourceGroupName - the name of the resource group.
191// clusterName - the name of the cluster.
192// hosts - the list of hosts to restart
193func (client VirtualMachinesClient) RestartHosts(ctx context.Context, resourceGroupName string, clusterName string, hosts []string) (result VirtualMachinesRestartHostsFuture, err error) {
194	if tracing.IsEnabled() {
195		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.RestartHosts")
196		defer func() {
197			sc := -1
198			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
199				sc = result.FutureAPI.Response().StatusCode
200			}
201			tracing.EndSpan(ctx, sc, err)
202		}()
203	}
204	if err := validation.Validate([]validation.Validation{
205		{TargetValue: hosts,
206			Constraints: []validation.Constraint{{Target: "hosts", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
207		return result, validation.NewError("hdinsight.VirtualMachinesClient", "RestartHosts", err.Error())
208	}
209
210	req, err := client.RestartHostsPreparer(ctx, resourceGroupName, clusterName, hosts)
211	if err != nil {
212		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "RestartHosts", nil, "Failure preparing request")
213		return
214	}
215
216	result, err = client.RestartHostsSender(req)
217	if err != nil {
218		err = autorest.NewErrorWithError(err, "hdinsight.VirtualMachinesClient", "RestartHosts", nil, "Failure sending request")
219		return
220	}
221
222	return
223}
224
225// RestartHostsPreparer prepares the RestartHosts request.
226func (client VirtualMachinesClient) RestartHostsPreparer(ctx context.Context, resourceGroupName string, clusterName string, hosts []string) (*http.Request, error) {
227	pathParameters := map[string]interface{}{
228		"clusterName":       autorest.Encode("path", clusterName),
229		"resourceGroupName": autorest.Encode("path", resourceGroupName),
230		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
231	}
232
233	const APIVersion = "2018-06-01-preview"
234	queryParameters := map[string]interface{}{
235		"api-version": APIVersion,
236	}
237
238	preparer := autorest.CreatePreparer(
239		autorest.AsContentType("application/json; charset=utf-8"),
240		autorest.AsPost(),
241		autorest.WithBaseURL(client.BaseURI),
242		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/restartHosts", pathParameters),
243		autorest.WithJSON(hosts),
244		autorest.WithQueryParameters(queryParameters))
245	return preparer.Prepare((&http.Request{}).WithContext(ctx))
246}
247
248// RestartHostsSender sends the RestartHosts request. The method will close the
249// http.Response Body if it receives an error.
250func (client VirtualMachinesClient) RestartHostsSender(req *http.Request) (future VirtualMachinesRestartHostsFuture, err error) {
251	var resp *http.Response
252	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
253	if err != nil {
254		return
255	}
256	var azf azure.Future
257	azf, err = azure.NewFutureFromResponse(resp)
258	future.FutureAPI = &azf
259	future.Result = future.result
260	return
261}
262
263// RestartHostsResponder handles the response to the RestartHosts request. The method always
264// closes the http.Response Body.
265func (client VirtualMachinesClient) RestartHostsResponder(resp *http.Response) (result autorest.Response, err error) {
266	err = autorest.Respond(
267		resp,
268		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
269		autorest.ByClosing())
270	result.Response = resp
271	return
272}
273