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	"net/http"
25)
26
27// ClusterUpgradesClient is the client for the ClusterUpgrades methods of the Servicefabric service.
28type ClusterUpgradesClient struct {
29	BaseClient
30}
31
32// NewClusterUpgradesClient creates an instance of the ClusterUpgradesClient client.
33func NewClusterUpgradesClient(timeout *int32) ClusterUpgradesClient {
34	return NewClusterUpgradesClientWithBaseURI(DefaultBaseURI, timeout)
35}
36
37// NewClusterUpgradesClientWithBaseURI creates an instance of the ClusterUpgradesClient client.
38func NewClusterUpgradesClientWithBaseURI(baseURI string, timeout *int32) ClusterUpgradesClient {
39	return ClusterUpgradesClient{NewWithBaseURI(baseURI, timeout)}
40}
41
42// Resume resume cluster upgrades
43// Parameters:
44// resumeClusterUpgrade - the upgrade of the cluster
45func (client ClusterUpgradesClient) Resume(ctx context.Context, resumeClusterUpgrade ResumeClusterUpgrade) (result String, err error) {
46	req, err := client.ResumePreparer(ctx, resumeClusterUpgrade)
47	if err != nil {
48		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Resume", nil, "Failure preparing request")
49		return
50	}
51
52	resp, err := client.ResumeSender(req)
53	if err != nil {
54		result.Response = autorest.Response{Response: resp}
55		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Resume", resp, "Failure sending request")
56		return
57	}
58
59	result, err = client.ResumeResponder(resp)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Resume", resp, "Failure responding to request")
62	}
63
64	return
65}
66
67// ResumePreparer prepares the Resume request.
68func (client ClusterUpgradesClient) ResumePreparer(ctx context.Context, resumeClusterUpgrade ResumeClusterUpgrade) (*http.Request, error) {
69	const APIVersion = "1.0.0"
70	queryParameters := map[string]interface{}{
71		"api-version": APIVersion,
72	}
73	if client.Timeout != nil {
74		queryParameters["timeout"] = autorest.Encode("query", *client.Timeout)
75	}
76
77	preparer := autorest.CreatePreparer(
78		autorest.AsContentType("application/json; charset=utf-8"),
79		autorest.AsPost(),
80		autorest.WithBaseURL(client.BaseURI),
81		autorest.WithPath("/$/MoveToNextUpgradeDomain"),
82		autorest.WithJSON(resumeClusterUpgrade),
83		autorest.WithQueryParameters(queryParameters))
84	return preparer.Prepare((&http.Request{}).WithContext(ctx))
85}
86
87// ResumeSender sends the Resume request. The method will close the
88// http.Response Body if it receives an error.
89func (client ClusterUpgradesClient) ResumeSender(req *http.Request) (*http.Response, error) {
90	return autorest.SendWithSender(client, req,
91		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
92}
93
94// ResumeResponder handles the response to the Resume request. The method always
95// closes the http.Response Body.
96func (client ClusterUpgradesClient) ResumeResponder(resp *http.Response) (result String, err error) {
97	err = autorest.Respond(
98		resp,
99		client.ByInspecting(),
100		azure.WithErrorUnlessStatusCode(http.StatusOK),
101		autorest.ByUnmarshallingJSON(&result.Value),
102		autorest.ByClosing())
103	result.Response = autorest.Response{Response: resp}
104	return
105}
106
107// Rollback rollback cluster upgrades
108func (client ClusterUpgradesClient) Rollback(ctx context.Context) (result String, err error) {
109	req, err := client.RollbackPreparer(ctx)
110	if err != nil {
111		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Rollback", nil, "Failure preparing request")
112		return
113	}
114
115	resp, err := client.RollbackSender(req)
116	if err != nil {
117		result.Response = autorest.Response{Response: resp}
118		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Rollback", resp, "Failure sending request")
119		return
120	}
121
122	result, err = client.RollbackResponder(resp)
123	if err != nil {
124		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Rollback", resp, "Failure responding to request")
125	}
126
127	return
128}
129
130// RollbackPreparer prepares the Rollback request.
131func (client ClusterUpgradesClient) RollbackPreparer(ctx context.Context) (*http.Request, error) {
132	const APIVersion = "1.0.0"
133	queryParameters := map[string]interface{}{
134		"api-version": APIVersion,
135	}
136	if client.Timeout != nil {
137		queryParameters["timeout"] = autorest.Encode("query", *client.Timeout)
138	}
139
140	preparer := autorest.CreatePreparer(
141		autorest.AsPost(),
142		autorest.WithBaseURL(client.BaseURI),
143		autorest.WithPath("/$/RollbackUpgrade"),
144		autorest.WithQueryParameters(queryParameters))
145	return preparer.Prepare((&http.Request{}).WithContext(ctx))
146}
147
148// RollbackSender sends the Rollback request. The method will close the
149// http.Response Body if it receives an error.
150func (client ClusterUpgradesClient) RollbackSender(req *http.Request) (*http.Response, error) {
151	return autorest.SendWithSender(client, req,
152		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
153}
154
155// RollbackResponder handles the response to the Rollback request. The method always
156// closes the http.Response Body.
157func (client ClusterUpgradesClient) RollbackResponder(resp *http.Response) (result String, err error) {
158	err = autorest.Respond(
159		resp,
160		client.ByInspecting(),
161		azure.WithErrorUnlessStatusCode(http.StatusOK),
162		autorest.ByUnmarshallingJSON(&result.Value),
163		autorest.ByClosing())
164	result.Response = autorest.Response{Response: resp}
165	return
166}
167
168// Start start cluster upgrades
169// Parameters:
170// startClusterUpgrade - the description of the start cluster upgrade
171func (client ClusterUpgradesClient) Start(ctx context.Context, startClusterUpgrade StartClusterUpgrade) (result String, err error) {
172	req, err := client.StartPreparer(ctx, startClusterUpgrade)
173	if err != nil {
174		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Start", nil, "Failure preparing request")
175		return
176	}
177
178	resp, err := client.StartSender(req)
179	if err != nil {
180		result.Response = autorest.Response{Response: resp}
181		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Start", resp, "Failure sending request")
182		return
183	}
184
185	result, err = client.StartResponder(resp)
186	if err != nil {
187		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Start", resp, "Failure responding to request")
188	}
189
190	return
191}
192
193// StartPreparer prepares the Start request.
194func (client ClusterUpgradesClient) StartPreparer(ctx context.Context, startClusterUpgrade StartClusterUpgrade) (*http.Request, error) {
195	const APIVersion = "1.0.0"
196	queryParameters := map[string]interface{}{
197		"api-version": APIVersion,
198	}
199	if client.Timeout != nil {
200		queryParameters["timeout"] = autorest.Encode("query", *client.Timeout)
201	}
202
203	preparer := autorest.CreatePreparer(
204		autorest.AsContentType("application/json; charset=utf-8"),
205		autorest.AsPost(),
206		autorest.WithBaseURL(client.BaseURI),
207		autorest.WithPath("/$/Upgrade"),
208		autorest.WithJSON(startClusterUpgrade),
209		autorest.WithQueryParameters(queryParameters))
210	return preparer.Prepare((&http.Request{}).WithContext(ctx))
211}
212
213// StartSender sends the Start request. The method will close the
214// http.Response Body if it receives an error.
215func (client ClusterUpgradesClient) StartSender(req *http.Request) (*http.Response, error) {
216	return autorest.SendWithSender(client, req,
217		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
218}
219
220// StartResponder handles the response to the Start request. The method always
221// closes the http.Response Body.
222func (client ClusterUpgradesClient) StartResponder(resp *http.Response) (result String, err error) {
223	err = autorest.Respond(
224		resp,
225		client.ByInspecting(),
226		azure.WithErrorUnlessStatusCode(http.StatusOK),
227		autorest.ByUnmarshallingJSON(&result.Value),
228		autorest.ByClosing())
229	result.Response = autorest.Response{Response: resp}
230	return
231}
232
233// Update update cluster upgrades
234// Parameters:
235// updateClusterUpgrade - the description of the update cluster upgrade
236func (client ClusterUpgradesClient) Update(ctx context.Context, updateClusterUpgrade UpdateClusterUpgrade) (result String, err error) {
237	req, err := client.UpdatePreparer(ctx, updateClusterUpgrade)
238	if err != nil {
239		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Update", nil, "Failure preparing request")
240		return
241	}
242
243	resp, err := client.UpdateSender(req)
244	if err != nil {
245		result.Response = autorest.Response{Response: resp}
246		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Update", resp, "Failure sending request")
247		return
248	}
249
250	result, err = client.UpdateResponder(resp)
251	if err != nil {
252		err = autorest.NewErrorWithError(err, "servicefabric.ClusterUpgradesClient", "Update", resp, "Failure responding to request")
253	}
254
255	return
256}
257
258// UpdatePreparer prepares the Update request.
259func (client ClusterUpgradesClient) UpdatePreparer(ctx context.Context, updateClusterUpgrade UpdateClusterUpgrade) (*http.Request, error) {
260	const APIVersion = "1.0.0"
261	queryParameters := map[string]interface{}{
262		"api-version": APIVersion,
263	}
264	if client.Timeout != nil {
265		queryParameters["timeout"] = autorest.Encode("query", *client.Timeout)
266	}
267
268	preparer := autorest.CreatePreparer(
269		autorest.AsContentType("application/json; charset=utf-8"),
270		autorest.AsPost(),
271		autorest.WithBaseURL(client.BaseURI),
272		autorest.WithPath("/$/UpdateUpgrade"),
273		autorest.WithJSON(updateClusterUpgrade),
274		autorest.WithQueryParameters(queryParameters))
275	return preparer.Prepare((&http.Request{}).WithContext(ctx))
276}
277
278// UpdateSender sends the Update request. The method will close the
279// http.Response Body if it receives an error.
280func (client ClusterUpgradesClient) UpdateSender(req *http.Request) (*http.Response, error) {
281	return autorest.SendWithSender(client, req,
282		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
283}
284
285// UpdateResponder handles the response to the Update request. The method always
286// closes the http.Response Body.
287func (client ClusterUpgradesClient) UpdateResponder(resp *http.Response) (result String, err error) {
288	err = autorest.Respond(
289		resp,
290		client.ByInspecting(),
291		azure.WithErrorUnlessStatusCode(http.StatusOK),
292		autorest.ByUnmarshallingJSON(&result.Value),
293		autorest.ByClosing())
294	result.Response = autorest.Response{Response: resp}
295	return
296}
297