1package sql 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// JobTargetGroupsClient is the the Azure SQL Database management API provides a RESTful set of web services that 19// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, 20// and delete databases. 21type JobTargetGroupsClient struct { 22 BaseClient 23} 24 25// NewJobTargetGroupsClient creates an instance of the JobTargetGroupsClient client. 26func NewJobTargetGroupsClient(subscriptionID string) JobTargetGroupsClient { 27 return NewJobTargetGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewJobTargetGroupsClientWithBaseURI creates an instance of the JobTargetGroupsClient client using a custom endpoint. 31// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 32func NewJobTargetGroupsClientWithBaseURI(baseURI string, subscriptionID string) JobTargetGroupsClient { 33 return JobTargetGroupsClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// CreateOrUpdate creates or updates a target group. 37// Parameters: 38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 39// from the Azure Resource Manager API or the portal. 40// serverName - the name of the server. 41// jobAgentName - the name of the job agent. 42// targetGroupName - the name of the target group. 43// parameters - the requested state of the target group. 44func (client JobTargetGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, targetGroupName string, parameters JobTargetGroup) (result JobTargetGroup, err error) { 45 if tracing.IsEnabled() { 46 ctx = tracing.StartSpan(ctx, fqdn+"/JobTargetGroupsClient.CreateOrUpdate") 47 defer func() { 48 sc := -1 49 if result.Response.Response != nil { 50 sc = result.Response.Response.StatusCode 51 } 52 tracing.EndSpan(ctx, sc, err) 53 }() 54 } 55 if err := validation.Validate([]validation.Validation{ 56 {TargetValue: parameters, 57 Constraints: []validation.Constraint{{Target: "parameters.JobTargetGroupProperties", Name: validation.Null, Rule: false, 58 Chain: []validation.Constraint{{Target: "parameters.JobTargetGroupProperties.Members", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 59 return result, validation.NewError("sql.JobTargetGroupsClient", "CreateOrUpdate", err.Error()) 60 } 61 62 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, jobAgentName, targetGroupName, parameters) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "CreateOrUpdate", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.CreateOrUpdateSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "CreateOrUpdate", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.CreateOrUpdateResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "CreateOrUpdate", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 85func (client JobTargetGroupsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, targetGroupName string, parameters JobTargetGroup) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "jobAgentName": autorest.Encode("path", jobAgentName), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "serverName": autorest.Encode("path", serverName), 90 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 91 "targetGroupName": autorest.Encode("path", targetGroupName), 92 } 93 94 const APIVersion = "2017-03-01-preview" 95 queryParameters := map[string]interface{}{ 96 "api-version": APIVersion, 97 } 98 99 preparer := autorest.CreatePreparer( 100 autorest.AsContentType("application/json; charset=utf-8"), 101 autorest.AsPut(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}", pathParameters), 104 autorest.WithJSON(parameters), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 110// http.Response Body if it receives an error. 111func (client JobTargetGroupsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 112 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113} 114 115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 116// closes the http.Response Body. 117func (client JobTargetGroupsClient) CreateOrUpdateResponder(resp *http.Response) (result JobTargetGroup, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// Delete deletes a target group. 128// Parameters: 129// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 130// from the Azure Resource Manager API or the portal. 131// serverName - the name of the server. 132// jobAgentName - the name of the job agent. 133// targetGroupName - the name of the target group. 134func (client JobTargetGroupsClient) Delete(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, targetGroupName string) (result autorest.Response, err error) { 135 if tracing.IsEnabled() { 136 ctx = tracing.StartSpan(ctx, fqdn+"/JobTargetGroupsClient.Delete") 137 defer func() { 138 sc := -1 139 if result.Response != nil { 140 sc = result.Response.StatusCode 141 } 142 tracing.EndSpan(ctx, sc, err) 143 }() 144 } 145 req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, jobAgentName, targetGroupName) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "Delete", nil, "Failure preparing request") 148 return 149 } 150 151 resp, err := client.DeleteSender(req) 152 if err != nil { 153 result.Response = resp 154 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "Delete", resp, "Failure sending request") 155 return 156 } 157 158 result, err = client.DeleteResponder(resp) 159 if err != nil { 160 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "Delete", resp, "Failure responding to request") 161 return 162 } 163 164 return 165} 166 167// DeletePreparer prepares the Delete request. 168func (client JobTargetGroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, targetGroupName string) (*http.Request, error) { 169 pathParameters := map[string]interface{}{ 170 "jobAgentName": autorest.Encode("path", jobAgentName), 171 "resourceGroupName": autorest.Encode("path", resourceGroupName), 172 "serverName": autorest.Encode("path", serverName), 173 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 174 "targetGroupName": autorest.Encode("path", targetGroupName), 175 } 176 177 const APIVersion = "2017-03-01-preview" 178 queryParameters := map[string]interface{}{ 179 "api-version": APIVersion, 180 } 181 182 preparer := autorest.CreatePreparer( 183 autorest.AsDelete(), 184 autorest.WithBaseURL(client.BaseURI), 185 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}", pathParameters), 186 autorest.WithQueryParameters(queryParameters)) 187 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 188} 189 190// DeleteSender sends the Delete request. The method will close the 191// http.Response Body if it receives an error. 192func (client JobTargetGroupsClient) DeleteSender(req *http.Request) (*http.Response, error) { 193 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 194} 195 196// DeleteResponder handles the response to the Delete request. The method always 197// closes the http.Response Body. 198func (client JobTargetGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 199 err = autorest.Respond( 200 resp, 201 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 202 autorest.ByClosing()) 203 result.Response = resp 204 return 205} 206 207// Get gets a target group. 208// Parameters: 209// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 210// from the Azure Resource Manager API or the portal. 211// serverName - the name of the server. 212// jobAgentName - the name of the job agent. 213// targetGroupName - the name of the target group. 214func (client JobTargetGroupsClient) Get(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, targetGroupName string) (result JobTargetGroup, err error) { 215 if tracing.IsEnabled() { 216 ctx = tracing.StartSpan(ctx, fqdn+"/JobTargetGroupsClient.Get") 217 defer func() { 218 sc := -1 219 if result.Response.Response != nil { 220 sc = result.Response.Response.StatusCode 221 } 222 tracing.EndSpan(ctx, sc, err) 223 }() 224 } 225 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, jobAgentName, targetGroupName) 226 if err != nil { 227 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "Get", nil, "Failure preparing request") 228 return 229 } 230 231 resp, err := client.GetSender(req) 232 if err != nil { 233 result.Response = autorest.Response{Response: resp} 234 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "Get", resp, "Failure sending request") 235 return 236 } 237 238 result, err = client.GetResponder(resp) 239 if err != nil { 240 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "Get", resp, "Failure responding to request") 241 return 242 } 243 244 return 245} 246 247// GetPreparer prepares the Get request. 248func (client JobTargetGroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string, targetGroupName string) (*http.Request, error) { 249 pathParameters := map[string]interface{}{ 250 "jobAgentName": autorest.Encode("path", jobAgentName), 251 "resourceGroupName": autorest.Encode("path", resourceGroupName), 252 "serverName": autorest.Encode("path", serverName), 253 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 254 "targetGroupName": autorest.Encode("path", targetGroupName), 255 } 256 257 const APIVersion = "2017-03-01-preview" 258 queryParameters := map[string]interface{}{ 259 "api-version": APIVersion, 260 } 261 262 preparer := autorest.CreatePreparer( 263 autorest.AsGet(), 264 autorest.WithBaseURL(client.BaseURI), 265 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}", pathParameters), 266 autorest.WithQueryParameters(queryParameters)) 267 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 268} 269 270// GetSender sends the Get request. The method will close the 271// http.Response Body if it receives an error. 272func (client JobTargetGroupsClient) GetSender(req *http.Request) (*http.Response, error) { 273 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 274} 275 276// GetResponder handles the response to the Get request. The method always 277// closes the http.Response Body. 278func (client JobTargetGroupsClient) GetResponder(resp *http.Response) (result JobTargetGroup, err error) { 279 err = autorest.Respond( 280 resp, 281 azure.WithErrorUnlessStatusCode(http.StatusOK), 282 autorest.ByUnmarshallingJSON(&result), 283 autorest.ByClosing()) 284 result.Response = autorest.Response{Response: resp} 285 return 286} 287 288// ListByAgent gets all target groups in an agent. 289// Parameters: 290// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 291// from the Azure Resource Manager API or the portal. 292// serverName - the name of the server. 293// jobAgentName - the name of the job agent. 294func (client JobTargetGroupsClient) ListByAgent(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string) (result JobTargetGroupListResultPage, err error) { 295 if tracing.IsEnabled() { 296 ctx = tracing.StartSpan(ctx, fqdn+"/JobTargetGroupsClient.ListByAgent") 297 defer func() { 298 sc := -1 299 if result.jtglr.Response.Response != nil { 300 sc = result.jtglr.Response.Response.StatusCode 301 } 302 tracing.EndSpan(ctx, sc, err) 303 }() 304 } 305 result.fn = client.listByAgentNextResults 306 req, err := client.ListByAgentPreparer(ctx, resourceGroupName, serverName, jobAgentName) 307 if err != nil { 308 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "ListByAgent", nil, "Failure preparing request") 309 return 310 } 311 312 resp, err := client.ListByAgentSender(req) 313 if err != nil { 314 result.jtglr.Response = autorest.Response{Response: resp} 315 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "ListByAgent", resp, "Failure sending request") 316 return 317 } 318 319 result.jtglr, err = client.ListByAgentResponder(resp) 320 if err != nil { 321 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "ListByAgent", resp, "Failure responding to request") 322 return 323 } 324 if result.jtglr.hasNextLink() && result.jtglr.IsEmpty() { 325 err = result.NextWithContext(ctx) 326 return 327 } 328 329 return 330} 331 332// ListByAgentPreparer prepares the ListByAgent request. 333func (client JobTargetGroupsClient) ListByAgentPreparer(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string) (*http.Request, error) { 334 pathParameters := map[string]interface{}{ 335 "jobAgentName": autorest.Encode("path", jobAgentName), 336 "resourceGroupName": autorest.Encode("path", resourceGroupName), 337 "serverName": autorest.Encode("path", serverName), 338 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 339 } 340 341 const APIVersion = "2017-03-01-preview" 342 queryParameters := map[string]interface{}{ 343 "api-version": APIVersion, 344 } 345 346 preparer := autorest.CreatePreparer( 347 autorest.AsGet(), 348 autorest.WithBaseURL(client.BaseURI), 349 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups", pathParameters), 350 autorest.WithQueryParameters(queryParameters)) 351 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 352} 353 354// ListByAgentSender sends the ListByAgent request. The method will close the 355// http.Response Body if it receives an error. 356func (client JobTargetGroupsClient) ListByAgentSender(req *http.Request) (*http.Response, error) { 357 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 358} 359 360// ListByAgentResponder handles the response to the ListByAgent request. The method always 361// closes the http.Response Body. 362func (client JobTargetGroupsClient) ListByAgentResponder(resp *http.Response) (result JobTargetGroupListResult, err error) { 363 err = autorest.Respond( 364 resp, 365 azure.WithErrorUnlessStatusCode(http.StatusOK), 366 autorest.ByUnmarshallingJSON(&result), 367 autorest.ByClosing()) 368 result.Response = autorest.Response{Response: resp} 369 return 370} 371 372// listByAgentNextResults retrieves the next set of results, if any. 373func (client JobTargetGroupsClient) listByAgentNextResults(ctx context.Context, lastResults JobTargetGroupListResult) (result JobTargetGroupListResult, err error) { 374 req, err := lastResults.jobTargetGroupListResultPreparer(ctx) 375 if err != nil { 376 return result, autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "listByAgentNextResults", nil, "Failure preparing next results request") 377 } 378 if req == nil { 379 return 380 } 381 resp, err := client.ListByAgentSender(req) 382 if err != nil { 383 result.Response = autorest.Response{Response: resp} 384 return result, autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "listByAgentNextResults", resp, "Failure sending next results request") 385 } 386 result, err = client.ListByAgentResponder(resp) 387 if err != nil { 388 err = autorest.NewErrorWithError(err, "sql.JobTargetGroupsClient", "listByAgentNextResults", resp, "Failure responding to next results request") 389 } 390 return 391} 392 393// ListByAgentComplete enumerates all values, automatically crossing page boundaries as required. 394func (client JobTargetGroupsClient) ListByAgentComplete(ctx context.Context, resourceGroupName string, serverName string, jobAgentName string) (result JobTargetGroupListResultIterator, err error) { 395 if tracing.IsEnabled() { 396 ctx = tracing.StartSpan(ctx, fqdn+"/JobTargetGroupsClient.ListByAgent") 397 defer func() { 398 sc := -1 399 if result.Response().Response.Response != nil { 400 sc = result.page.Response().Response.Response.StatusCode 401 } 402 tracing.EndSpan(ctx, sc, err) 403 }() 404 } 405 result.page, err = client.ListByAgent(ctx, resourceGroupName, serverName, jobAgentName) 406 return 407} 408