1package servicefabric
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// ClusterVersionsClient is the service Fabric Management Client
29type ClusterVersionsClient struct {
30	BaseClient
31}
32
33// NewClusterVersionsClient creates an instance of the ClusterVersionsClient client.
34func NewClusterVersionsClient(subscriptionID string) ClusterVersionsClient {
35	return NewClusterVersionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewClusterVersionsClientWithBaseURI creates an instance of the ClusterVersionsClient client using a custom endpoint.
39// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewClusterVersionsClientWithBaseURI(baseURI string, subscriptionID string) ClusterVersionsClient {
41	return ClusterVersionsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Get gets information about an available Service Fabric cluster code version.
45// Parameters:
46// location - the location for the cluster code versions. This is different from cluster location.
47// clusterVersion - the cluster code version.
48func (client ClusterVersionsClient) Get(ctx context.Context, location string, clusterVersion string) (result ClusterCodeVersionsListResult, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/ClusterVersionsClient.Get")
51		defer func() {
52			sc := -1
53			if result.Response.Response != nil {
54				sc = result.Response.Response.StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	req, err := client.GetPreparer(ctx, location, clusterVersion)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "Get", nil, "Failure preparing request")
62		return
63	}
64
65	resp, err := client.GetSender(req)
66	if err != nil {
67		result.Response = autorest.Response{Response: resp}
68		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "Get", resp, "Failure sending request")
69		return
70	}
71
72	result, err = client.GetResponder(resp)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "Get", resp, "Failure responding to request")
75	}
76
77	return
78}
79
80// GetPreparer prepares the Get request.
81func (client ClusterVersionsClient) GetPreparer(ctx context.Context, location string, clusterVersion string) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"clusterVersion": autorest.Encode("path", clusterVersion),
84		"location":       autorest.Encode("path", location),
85		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
86	}
87
88	const APIVersion = "2019-03-01-preview"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsGet(),
95		autorest.WithBaseURL(client.BaseURI),
96		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ServiceFabric/locations/{location}/clusterVersions/{clusterVersion}", pathParameters),
97		autorest.WithQueryParameters(queryParameters))
98	return preparer.Prepare((&http.Request{}).WithContext(ctx))
99}
100
101// GetSender sends the Get request. The method will close the
102// http.Response Body if it receives an error.
103func (client ClusterVersionsClient) GetSender(req *http.Request) (*http.Response, error) {
104	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
105}
106
107// GetResponder handles the response to the Get request. The method always
108// closes the http.Response Body.
109func (client ClusterVersionsClient) GetResponder(resp *http.Response) (result ClusterCodeVersionsListResult, err error) {
110	err = autorest.Respond(
111		resp,
112		client.ByInspecting(),
113		azure.WithErrorUnlessStatusCode(http.StatusOK),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119
120// GetByEnvironment gets information about an available Service Fabric cluster code version by environment.
121// Parameters:
122// location - the location for the cluster code versions. This is different from cluster location.
123// environment - the operating system of the cluster. The default means all.
124// clusterVersion - the cluster code version.
125func (client ClusterVersionsClient) GetByEnvironment(ctx context.Context, location string, environment string, clusterVersion string) (result ClusterCodeVersionsListResult, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/ClusterVersionsClient.GetByEnvironment")
128		defer func() {
129			sc := -1
130			if result.Response.Response != nil {
131				sc = result.Response.Response.StatusCode
132			}
133			tracing.EndSpan(ctx, sc, err)
134		}()
135	}
136	req, err := client.GetByEnvironmentPreparer(ctx, location, environment, clusterVersion)
137	if err != nil {
138		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "GetByEnvironment", nil, "Failure preparing request")
139		return
140	}
141
142	resp, err := client.GetByEnvironmentSender(req)
143	if err != nil {
144		result.Response = autorest.Response{Response: resp}
145		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "GetByEnvironment", resp, "Failure sending request")
146		return
147	}
148
149	result, err = client.GetByEnvironmentResponder(resp)
150	if err != nil {
151		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "GetByEnvironment", resp, "Failure responding to request")
152	}
153
154	return
155}
156
157// GetByEnvironmentPreparer prepares the GetByEnvironment request.
158func (client ClusterVersionsClient) GetByEnvironmentPreparer(ctx context.Context, location string, environment string, clusterVersion string) (*http.Request, error) {
159	pathParameters := map[string]interface{}{
160		"clusterVersion": autorest.Encode("path", clusterVersion),
161		"environment":    autorest.Encode("path", environment),
162		"location":       autorest.Encode("path", location),
163		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
164	}
165
166	const APIVersion = "2019-03-01-preview"
167	queryParameters := map[string]interface{}{
168		"api-version": APIVersion,
169	}
170
171	preparer := autorest.CreatePreparer(
172		autorest.AsGet(),
173		autorest.WithBaseURL(client.BaseURI),
174		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ServiceFabric/locations/{location}/environments/{environment}/clusterVersions/{clusterVersion}", pathParameters),
175		autorest.WithQueryParameters(queryParameters))
176	return preparer.Prepare((&http.Request{}).WithContext(ctx))
177}
178
179// GetByEnvironmentSender sends the GetByEnvironment request. The method will close the
180// http.Response Body if it receives an error.
181func (client ClusterVersionsClient) GetByEnvironmentSender(req *http.Request) (*http.Response, error) {
182	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
183}
184
185// GetByEnvironmentResponder handles the response to the GetByEnvironment request. The method always
186// closes the http.Response Body.
187func (client ClusterVersionsClient) GetByEnvironmentResponder(resp *http.Response) (result ClusterCodeVersionsListResult, err error) {
188	err = autorest.Respond(
189		resp,
190		client.ByInspecting(),
191		azure.WithErrorUnlessStatusCode(http.StatusOK),
192		autorest.ByUnmarshallingJSON(&result),
193		autorest.ByClosing())
194	result.Response = autorest.Response{Response: resp}
195	return
196}
197
198// List gets all available code versions for Service Fabric cluster resources by location.
199// Parameters:
200// location - the location for the cluster code versions. This is different from cluster location.
201func (client ClusterVersionsClient) List(ctx context.Context, location string) (result ClusterCodeVersionsListResult, err error) {
202	if tracing.IsEnabled() {
203		ctx = tracing.StartSpan(ctx, fqdn+"/ClusterVersionsClient.List")
204		defer func() {
205			sc := -1
206			if result.Response.Response != nil {
207				sc = result.Response.Response.StatusCode
208			}
209			tracing.EndSpan(ctx, sc, err)
210		}()
211	}
212	req, err := client.ListPreparer(ctx, location)
213	if err != nil {
214		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "List", nil, "Failure preparing request")
215		return
216	}
217
218	resp, err := client.ListSender(req)
219	if err != nil {
220		result.Response = autorest.Response{Response: resp}
221		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "List", resp, "Failure sending request")
222		return
223	}
224
225	result, err = client.ListResponder(resp)
226	if err != nil {
227		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "List", resp, "Failure responding to request")
228	}
229
230	return
231}
232
233// ListPreparer prepares the List request.
234func (client ClusterVersionsClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) {
235	pathParameters := map[string]interface{}{
236		"location":       autorest.Encode("path", location),
237		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
238	}
239
240	const APIVersion = "2019-03-01-preview"
241	queryParameters := map[string]interface{}{
242		"api-version": APIVersion,
243	}
244
245	preparer := autorest.CreatePreparer(
246		autorest.AsGet(),
247		autorest.WithBaseURL(client.BaseURI),
248		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ServiceFabric/locations/{location}/clusterVersions", pathParameters),
249		autorest.WithQueryParameters(queryParameters))
250	return preparer.Prepare((&http.Request{}).WithContext(ctx))
251}
252
253// ListSender sends the List request. The method will close the
254// http.Response Body if it receives an error.
255func (client ClusterVersionsClient) ListSender(req *http.Request) (*http.Response, error) {
256	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
257}
258
259// ListResponder handles the response to the List request. The method always
260// closes the http.Response Body.
261func (client ClusterVersionsClient) ListResponder(resp *http.Response) (result ClusterCodeVersionsListResult, err error) {
262	err = autorest.Respond(
263		resp,
264		client.ByInspecting(),
265		azure.WithErrorUnlessStatusCode(http.StatusOK),
266		autorest.ByUnmarshallingJSON(&result),
267		autorest.ByClosing())
268	result.Response = autorest.Response{Response: resp}
269	return
270}
271
272// ListByEnvironment gets all available code versions for Service Fabric cluster resources by environment.
273// Parameters:
274// location - the location for the cluster code versions. This is different from cluster location.
275// environment - the operating system of the cluster. The default means all.
276func (client ClusterVersionsClient) ListByEnvironment(ctx context.Context, location string, environment string) (result ClusterCodeVersionsListResult, err error) {
277	if tracing.IsEnabled() {
278		ctx = tracing.StartSpan(ctx, fqdn+"/ClusterVersionsClient.ListByEnvironment")
279		defer func() {
280			sc := -1
281			if result.Response.Response != nil {
282				sc = result.Response.Response.StatusCode
283			}
284			tracing.EndSpan(ctx, sc, err)
285		}()
286	}
287	req, err := client.ListByEnvironmentPreparer(ctx, location, environment)
288	if err != nil {
289		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "ListByEnvironment", nil, "Failure preparing request")
290		return
291	}
292
293	resp, err := client.ListByEnvironmentSender(req)
294	if err != nil {
295		result.Response = autorest.Response{Response: resp}
296		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "ListByEnvironment", resp, "Failure sending request")
297		return
298	}
299
300	result, err = client.ListByEnvironmentResponder(resp)
301	if err != nil {
302		err = autorest.NewErrorWithError(err, "servicefabric.ClusterVersionsClient", "ListByEnvironment", resp, "Failure responding to request")
303	}
304
305	return
306}
307
308// ListByEnvironmentPreparer prepares the ListByEnvironment request.
309func (client ClusterVersionsClient) ListByEnvironmentPreparer(ctx context.Context, location string, environment string) (*http.Request, error) {
310	pathParameters := map[string]interface{}{
311		"environment":    autorest.Encode("path", environment),
312		"location":       autorest.Encode("path", location),
313		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
314	}
315
316	const APIVersion = "2019-03-01-preview"
317	queryParameters := map[string]interface{}{
318		"api-version": APIVersion,
319	}
320
321	preparer := autorest.CreatePreparer(
322		autorest.AsGet(),
323		autorest.WithBaseURL(client.BaseURI),
324		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ServiceFabric/locations/{location}/environments/{environment}/clusterVersions", pathParameters),
325		autorest.WithQueryParameters(queryParameters))
326	return preparer.Prepare((&http.Request{}).WithContext(ctx))
327}
328
329// ListByEnvironmentSender sends the ListByEnvironment request. The method will close the
330// http.Response Body if it receives an error.
331func (client ClusterVersionsClient) ListByEnvironmentSender(req *http.Request) (*http.Response, error) {
332	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
333}
334
335// ListByEnvironmentResponder handles the response to the ListByEnvironment request. The method always
336// closes the http.Response Body.
337func (client ClusterVersionsClient) ListByEnvironmentResponder(resp *http.Response) (result ClusterCodeVersionsListResult, err error) {
338	err = autorest.Respond(
339		resp,
340		client.ByInspecting(),
341		azure.WithErrorUnlessStatusCode(http.StatusOK),
342		autorest.ByUnmarshallingJSON(&result),
343		autorest.ByClosing())
344	result.Response = autorest.Response{Response: resp}
345	return
346}
347