1package servicefabric 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/tracing" 14 "net/http" 15) 16 17// ServicesClient is the service Fabric Management Client 18type ServicesClient struct { 19 BaseClient 20} 21 22// NewServicesClient creates an instance of the ServicesClient client. 23func NewServicesClient(subscriptionID string) ServicesClient { 24 return NewServicesClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewServicesClientWithBaseURI creates an instance of the ServicesClient client using a custom endpoint. Use this 28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewServicesClientWithBaseURI(baseURI string, subscriptionID string) ServicesClient { 30 return ServicesClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// Create create or update a Service Fabric service resource with the specified name. 34// Parameters: 35// resourceGroupName - the name of the resource group. 36// clusterName - the name of the cluster resource. 37// applicationName - the name of the application resource. 38// serviceName - the name of the service resource in the format of {applicationName}~{serviceName}. 39// parameters - the service resource. 40func (client ServicesClient) Create(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string, parameters ServiceResource) (result ServicesCreateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Create") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 req, err := client.CreatePreparer(ctx, resourceGroupName, clusterName, applicationName, serviceName, parameters) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Create", nil, "Failure preparing request") 54 return 55 } 56 57 result, err = client.CreateSender(req) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Create", nil, "Failure sending request") 60 return 61 } 62 63 return 64} 65 66// CreatePreparer prepares the Create request. 67func (client ServicesClient) CreatePreparer(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string, parameters ServiceResource) (*http.Request, error) { 68 pathParameters := map[string]interface{}{ 69 "applicationName": autorest.Encode("path", applicationName), 70 "clusterName": autorest.Encode("path", clusterName), 71 "resourceGroupName": autorest.Encode("path", resourceGroupName), 72 "serviceName": autorest.Encode("path", serviceName), 73 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 74 } 75 76 const APIVersion = "2019-03-01-preview" 77 queryParameters := map[string]interface{}{ 78 "api-version": APIVersion, 79 } 80 81 preparer := autorest.CreatePreparer( 82 autorest.AsContentType("application/json; charset=utf-8"), 83 autorest.AsPut(), 84 autorest.WithBaseURL(client.BaseURI), 85 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceFabric/clusters/{clusterName}/applications/{applicationName}/services/{serviceName}", pathParameters), 86 autorest.WithJSON(parameters), 87 autorest.WithQueryParameters(queryParameters)) 88 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 89} 90 91// CreateSender sends the Create request. The method will close the 92// http.Response Body if it receives an error. 93func (client ServicesClient) CreateSender(req *http.Request) (future ServicesCreateFuture, err error) { 94 var resp *http.Response 95 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 96 if err != nil { 97 return 98 } 99 var azf azure.Future 100 azf, err = azure.NewFutureFromResponse(resp) 101 future.FutureAPI = &azf 102 future.Result = future.result 103 return 104} 105 106// CreateResponder handles the response to the Create request. The method always 107// closes the http.Response Body. 108func (client ServicesClient) CreateResponder(resp *http.Response) (result ServiceResource, err error) { 109 err = autorest.Respond( 110 resp, 111 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117 118// Delete delete a Service Fabric service resource with the specified name. 119// Parameters: 120// resourceGroupName - the name of the resource group. 121// clusterName - the name of the cluster resource. 122// applicationName - the name of the application resource. 123// serviceName - the name of the service resource in the format of {applicationName}~{serviceName}. 124func (client ServicesClient) Delete(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string) (result ServicesDeleteFuture, err error) { 125 if tracing.IsEnabled() { 126 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Delete") 127 defer func() { 128 sc := -1 129 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 130 sc = result.FutureAPI.Response().StatusCode 131 } 132 tracing.EndSpan(ctx, sc, err) 133 }() 134 } 135 req, err := client.DeletePreparer(ctx, resourceGroupName, clusterName, applicationName, serviceName) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Delete", nil, "Failure preparing request") 138 return 139 } 140 141 result, err = client.DeleteSender(req) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Delete", nil, "Failure sending request") 144 return 145 } 146 147 return 148} 149 150// DeletePreparer prepares the Delete request. 151func (client ServicesClient) DeletePreparer(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string) (*http.Request, error) { 152 pathParameters := map[string]interface{}{ 153 "applicationName": autorest.Encode("path", applicationName), 154 "clusterName": autorest.Encode("path", clusterName), 155 "resourceGroupName": autorest.Encode("path", resourceGroupName), 156 "serviceName": autorest.Encode("path", serviceName), 157 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 158 } 159 160 const APIVersion = "2019-03-01-preview" 161 queryParameters := map[string]interface{}{ 162 "api-version": APIVersion, 163 } 164 165 preparer := autorest.CreatePreparer( 166 autorest.AsDelete(), 167 autorest.WithBaseURL(client.BaseURI), 168 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceFabric/clusters/{clusterName}/applications/{applicationName}/services/{serviceName}", pathParameters), 169 autorest.WithQueryParameters(queryParameters)) 170 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 171} 172 173// DeleteSender sends the Delete request. The method will close the 174// http.Response Body if it receives an error. 175func (client ServicesClient) DeleteSender(req *http.Request) (future ServicesDeleteFuture, err error) { 176 var resp *http.Response 177 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 178 if err != nil { 179 return 180 } 181 var azf azure.Future 182 azf, err = azure.NewFutureFromResponse(resp) 183 future.FutureAPI = &azf 184 future.Result = future.result 185 return 186} 187 188// DeleteResponder handles the response to the Delete request. The method always 189// closes the http.Response Body. 190func (client ServicesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 191 err = autorest.Respond( 192 resp, 193 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 194 autorest.ByClosing()) 195 result.Response = resp 196 return 197} 198 199// Get get a Service Fabric service resource created or in the process of being created in the Service Fabric 200// application resource. 201// Parameters: 202// resourceGroupName - the name of the resource group. 203// clusterName - the name of the cluster resource. 204// applicationName - the name of the application resource. 205// serviceName - the name of the service resource in the format of {applicationName}~{serviceName}. 206func (client ServicesClient) Get(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string) (result ServiceResource, err error) { 207 if tracing.IsEnabled() { 208 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Get") 209 defer func() { 210 sc := -1 211 if result.Response.Response != nil { 212 sc = result.Response.Response.StatusCode 213 } 214 tracing.EndSpan(ctx, sc, err) 215 }() 216 } 217 req, err := client.GetPreparer(ctx, resourceGroupName, clusterName, applicationName, serviceName) 218 if err != nil { 219 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Get", nil, "Failure preparing request") 220 return 221 } 222 223 resp, err := client.GetSender(req) 224 if err != nil { 225 result.Response = autorest.Response{Response: resp} 226 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Get", resp, "Failure sending request") 227 return 228 } 229 230 result, err = client.GetResponder(resp) 231 if err != nil { 232 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Get", resp, "Failure responding to request") 233 return 234 } 235 236 return 237} 238 239// GetPreparer prepares the Get request. 240func (client ServicesClient) GetPreparer(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string) (*http.Request, error) { 241 pathParameters := map[string]interface{}{ 242 "applicationName": autorest.Encode("path", applicationName), 243 "clusterName": autorest.Encode("path", clusterName), 244 "resourceGroupName": autorest.Encode("path", resourceGroupName), 245 "serviceName": autorest.Encode("path", serviceName), 246 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 247 } 248 249 const APIVersion = "2019-03-01-preview" 250 queryParameters := map[string]interface{}{ 251 "api-version": APIVersion, 252 } 253 254 preparer := autorest.CreatePreparer( 255 autorest.AsGet(), 256 autorest.WithBaseURL(client.BaseURI), 257 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceFabric/clusters/{clusterName}/applications/{applicationName}/services/{serviceName}", pathParameters), 258 autorest.WithQueryParameters(queryParameters)) 259 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 260} 261 262// GetSender sends the Get request. The method will close the 263// http.Response Body if it receives an error. 264func (client ServicesClient) GetSender(req *http.Request) (*http.Response, error) { 265 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 266} 267 268// GetResponder handles the response to the Get request. The method always 269// closes the http.Response Body. 270func (client ServicesClient) GetResponder(resp *http.Response) (result ServiceResource, err error) { 271 err = autorest.Respond( 272 resp, 273 azure.WithErrorUnlessStatusCode(http.StatusOK), 274 autorest.ByUnmarshallingJSON(&result), 275 autorest.ByClosing()) 276 result.Response = autorest.Response{Response: resp} 277 return 278} 279 280// List gets all service resources created or in the process of being created in the Service Fabric application 281// resource. 282// Parameters: 283// resourceGroupName - the name of the resource group. 284// clusterName - the name of the cluster resource. 285// applicationName - the name of the application resource. 286func (client ServicesClient) List(ctx context.Context, resourceGroupName string, clusterName string, applicationName string) (result ServiceResourceList, err error) { 287 if tracing.IsEnabled() { 288 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.List") 289 defer func() { 290 sc := -1 291 if result.Response.Response != nil { 292 sc = result.Response.Response.StatusCode 293 } 294 tracing.EndSpan(ctx, sc, err) 295 }() 296 } 297 req, err := client.ListPreparer(ctx, resourceGroupName, clusterName, applicationName) 298 if err != nil { 299 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "List", nil, "Failure preparing request") 300 return 301 } 302 303 resp, err := client.ListSender(req) 304 if err != nil { 305 result.Response = autorest.Response{Response: resp} 306 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "List", resp, "Failure sending request") 307 return 308 } 309 310 result, err = client.ListResponder(resp) 311 if err != nil { 312 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "List", resp, "Failure responding to request") 313 return 314 } 315 316 return 317} 318 319// ListPreparer prepares the List request. 320func (client ServicesClient) ListPreparer(ctx context.Context, resourceGroupName string, clusterName string, applicationName string) (*http.Request, error) { 321 pathParameters := map[string]interface{}{ 322 "applicationName": autorest.Encode("path", applicationName), 323 "clusterName": autorest.Encode("path", clusterName), 324 "resourceGroupName": autorest.Encode("path", resourceGroupName), 325 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 326 } 327 328 const APIVersion = "2019-03-01-preview" 329 queryParameters := map[string]interface{}{ 330 "api-version": APIVersion, 331 } 332 333 preparer := autorest.CreatePreparer( 334 autorest.AsGet(), 335 autorest.WithBaseURL(client.BaseURI), 336 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceFabric/clusters/{clusterName}/applications/{applicationName}/services", pathParameters), 337 autorest.WithQueryParameters(queryParameters)) 338 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 339} 340 341// ListSender sends the List request. The method will close the 342// http.Response Body if it receives an error. 343func (client ServicesClient) ListSender(req *http.Request) (*http.Response, error) { 344 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 345} 346 347// ListResponder handles the response to the List request. The method always 348// closes the http.Response Body. 349func (client ServicesClient) ListResponder(resp *http.Response) (result ServiceResourceList, err error) { 350 err = autorest.Respond( 351 resp, 352 azure.WithErrorUnlessStatusCode(http.StatusOK), 353 autorest.ByUnmarshallingJSON(&result), 354 autorest.ByClosing()) 355 result.Response = autorest.Response{Response: resp} 356 return 357} 358 359// Update update a Service Fabric service resource with the specified name. 360// Parameters: 361// resourceGroupName - the name of the resource group. 362// clusterName - the name of the cluster resource. 363// applicationName - the name of the application resource. 364// serviceName - the name of the service resource in the format of {applicationName}~{serviceName}. 365// parameters - the service resource for patch operations. 366func (client ServicesClient) Update(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string, parameters ServiceResourceUpdate) (result ServicesUpdateFuture, err error) { 367 if tracing.IsEnabled() { 368 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Update") 369 defer func() { 370 sc := -1 371 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 372 sc = result.FutureAPI.Response().StatusCode 373 } 374 tracing.EndSpan(ctx, sc, err) 375 }() 376 } 377 req, err := client.UpdatePreparer(ctx, resourceGroupName, clusterName, applicationName, serviceName, parameters) 378 if err != nil { 379 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Update", nil, "Failure preparing request") 380 return 381 } 382 383 result, err = client.UpdateSender(req) 384 if err != nil { 385 err = autorest.NewErrorWithError(err, "servicefabric.ServicesClient", "Update", nil, "Failure sending request") 386 return 387 } 388 389 return 390} 391 392// UpdatePreparer prepares the Update request. 393func (client ServicesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, clusterName string, applicationName string, serviceName string, parameters ServiceResourceUpdate) (*http.Request, error) { 394 pathParameters := map[string]interface{}{ 395 "applicationName": autorest.Encode("path", applicationName), 396 "clusterName": autorest.Encode("path", clusterName), 397 "resourceGroupName": autorest.Encode("path", resourceGroupName), 398 "serviceName": autorest.Encode("path", serviceName), 399 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 400 } 401 402 const APIVersion = "2019-03-01-preview" 403 queryParameters := map[string]interface{}{ 404 "api-version": APIVersion, 405 } 406 407 preparer := autorest.CreatePreparer( 408 autorest.AsContentType("application/json; charset=utf-8"), 409 autorest.AsPatch(), 410 autorest.WithBaseURL(client.BaseURI), 411 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceFabric/clusters/{clusterName}/applications/{applicationName}/services/{serviceName}", pathParameters), 412 autorest.WithJSON(parameters), 413 autorest.WithQueryParameters(queryParameters)) 414 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 415} 416 417// UpdateSender sends the Update request. The method will close the 418// http.Response Body if it receives an error. 419func (client ServicesClient) UpdateSender(req *http.Request) (future ServicesUpdateFuture, err error) { 420 var resp *http.Response 421 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 422 if err != nil { 423 return 424 } 425 var azf azure.Future 426 azf, err = azure.NewFutureFromResponse(resp) 427 future.FutureAPI = &azf 428 future.Result = future.result 429 return 430} 431 432// UpdateResponder handles the response to the Update request. The method always 433// closes the http.Response Body. 434func (client ServicesClient) UpdateResponder(resp *http.Response) (result ServiceResource, err error) { 435 err = autorest.Respond( 436 resp, 437 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 438 autorest.ByUnmarshallingJSON(&result), 439 autorest.ByClosing()) 440 result.Response = autorest.Response{Response: resp} 441 return 442} 443