1package mysql 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/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// RecommendedActionsClient is the the Microsoft Azure management API provides create, read, update, and delete 30// functionality for Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and 31// configurations with new business model. 32type RecommendedActionsClient struct { 33 BaseClient 34} 35 36// NewRecommendedActionsClient creates an instance of the RecommendedActionsClient client. 37func NewRecommendedActionsClient(subscriptionID string) RecommendedActionsClient { 38 return NewRecommendedActionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewRecommendedActionsClientWithBaseURI creates an instance of the RecommendedActionsClient client using a custom 42// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 43// stack). 44func NewRecommendedActionsClientWithBaseURI(baseURI string, subscriptionID string) RecommendedActionsClient { 45 return RecommendedActionsClient{NewWithBaseURI(baseURI, subscriptionID)} 46} 47 48// Get retrieve recommended actions from the advisor. 49// Parameters: 50// resourceGroupName - the name of the resource group. The name is case insensitive. 51// serverName - the name of the server. 52// advisorName - the advisor name for recommendation action. 53// recommendedActionName - the recommended action name. 54func (client RecommendedActionsClient) Get(ctx context.Context, resourceGroupName string, serverName string, advisorName string, recommendedActionName string) (result RecommendationAction, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/RecommendedActionsClient.Get") 57 defer func() { 58 sc := -1 59 if result.Response.Response != nil { 60 sc = result.Response.Response.StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 if err := validation.Validate([]validation.Validation{ 66 {TargetValue: client.SubscriptionID, 67 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 68 {TargetValue: resourceGroupName, 69 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 70 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 71 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 72 return result, validation.NewError("mysql.RecommendedActionsClient", "Get", err.Error()) 73 } 74 75 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, advisorName, recommendedActionName) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "Get", nil, "Failure preparing request") 78 return 79 } 80 81 resp, err := client.GetSender(req) 82 if err != nil { 83 result.Response = autorest.Response{Response: resp} 84 err = autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "Get", resp, "Failure sending request") 85 return 86 } 87 88 result, err = client.GetResponder(resp) 89 if err != nil { 90 err = autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "Get", resp, "Failure responding to request") 91 return 92 } 93 94 return 95} 96 97// GetPreparer prepares the Get request. 98func (client RecommendedActionsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, advisorName string, recommendedActionName string) (*http.Request, error) { 99 pathParameters := map[string]interface{}{ 100 "advisorName": autorest.Encode("path", advisorName), 101 "recommendedActionName": autorest.Encode("path", recommendedActionName), 102 "resourceGroupName": autorest.Encode("path", resourceGroupName), 103 "serverName": autorest.Encode("path", serverName), 104 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 105 } 106 107 const APIVersion = "2018-06-01" 108 queryParameters := map[string]interface{}{ 109 "api-version": APIVersion, 110 } 111 112 preparer := autorest.CreatePreparer( 113 autorest.AsGet(), 114 autorest.WithBaseURL(client.BaseURI), 115 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}", pathParameters), 116 autorest.WithQueryParameters(queryParameters)) 117 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 118} 119 120// GetSender sends the Get request. The method will close the 121// http.Response Body if it receives an error. 122func (client RecommendedActionsClient) GetSender(req *http.Request) (*http.Response, error) { 123 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 124} 125 126// GetResponder handles the response to the Get request. The method always 127// closes the http.Response Body. 128func (client RecommendedActionsClient) GetResponder(resp *http.Response) (result RecommendationAction, err error) { 129 err = autorest.Respond( 130 resp, 131 azure.WithErrorUnlessStatusCode(http.StatusOK), 132 autorest.ByUnmarshallingJSON(&result), 133 autorest.ByClosing()) 134 result.Response = autorest.Response{Response: resp} 135 return 136} 137 138// ListByServer retrieve recommended actions from the advisor. 139// Parameters: 140// resourceGroupName - the name of the resource group. The name is case insensitive. 141// serverName - the name of the server. 142// advisorName - the advisor name for recommendation action. 143// sessionID - the recommendation action session identifier. 144func (client RecommendedActionsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string, advisorName string, sessionID string) (result RecommendationActionsResultListPage, err error) { 145 if tracing.IsEnabled() { 146 ctx = tracing.StartSpan(ctx, fqdn+"/RecommendedActionsClient.ListByServer") 147 defer func() { 148 sc := -1 149 if result.rarl.Response.Response != nil { 150 sc = result.rarl.Response.Response.StatusCode 151 } 152 tracing.EndSpan(ctx, sc, err) 153 }() 154 } 155 if err := validation.Validate([]validation.Validation{ 156 {TargetValue: client.SubscriptionID, 157 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 158 {TargetValue: resourceGroupName, 159 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 160 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 161 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 162 return result, validation.NewError("mysql.RecommendedActionsClient", "ListByServer", err.Error()) 163 } 164 165 result.fn = client.listByServerNextResults 166 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName, advisorName, sessionID) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "ListByServer", nil, "Failure preparing request") 169 return 170 } 171 172 resp, err := client.ListByServerSender(req) 173 if err != nil { 174 result.rarl.Response = autorest.Response{Response: resp} 175 err = autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "ListByServer", resp, "Failure sending request") 176 return 177 } 178 179 result.rarl, err = client.ListByServerResponder(resp) 180 if err != nil { 181 err = autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "ListByServer", resp, "Failure responding to request") 182 return 183 } 184 if result.rarl.hasNextLink() && result.rarl.IsEmpty() { 185 err = result.NextWithContext(ctx) 186 return 187 } 188 189 return 190} 191 192// ListByServerPreparer prepares the ListByServer request. 193func (client RecommendedActionsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string, advisorName string, sessionID string) (*http.Request, error) { 194 pathParameters := map[string]interface{}{ 195 "advisorName": autorest.Encode("path", advisorName), 196 "resourceGroupName": autorest.Encode("path", resourceGroupName), 197 "serverName": autorest.Encode("path", serverName), 198 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 199 } 200 201 const APIVersion = "2018-06-01" 202 queryParameters := map[string]interface{}{ 203 "api-version": APIVersion, 204 } 205 if len(sessionID) > 0 { 206 queryParameters["sessionId"] = autorest.Encode("query", sessionID) 207 } 208 209 preparer := autorest.CreatePreparer( 210 autorest.AsGet(), 211 autorest.WithBaseURL(client.BaseURI), 212 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/advisors/{advisorName}/recommendedActions", pathParameters), 213 autorest.WithQueryParameters(queryParameters)) 214 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 215} 216 217// ListByServerSender sends the ListByServer request. The method will close the 218// http.Response Body if it receives an error. 219func (client RecommendedActionsClient) ListByServerSender(req *http.Request) (*http.Response, error) { 220 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 221} 222 223// ListByServerResponder handles the response to the ListByServer request. The method always 224// closes the http.Response Body. 225func (client RecommendedActionsClient) ListByServerResponder(resp *http.Response) (result RecommendationActionsResultList, err error) { 226 err = autorest.Respond( 227 resp, 228 azure.WithErrorUnlessStatusCode(http.StatusOK), 229 autorest.ByUnmarshallingJSON(&result), 230 autorest.ByClosing()) 231 result.Response = autorest.Response{Response: resp} 232 return 233} 234 235// listByServerNextResults retrieves the next set of results, if any. 236func (client RecommendedActionsClient) listByServerNextResults(ctx context.Context, lastResults RecommendationActionsResultList) (result RecommendationActionsResultList, err error) { 237 req, err := lastResults.recommendationActionsResultListPreparer(ctx) 238 if err != nil { 239 return result, autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "listByServerNextResults", nil, "Failure preparing next results request") 240 } 241 if req == nil { 242 return 243 } 244 resp, err := client.ListByServerSender(req) 245 if err != nil { 246 result.Response = autorest.Response{Response: resp} 247 return result, autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "listByServerNextResults", resp, "Failure sending next results request") 248 } 249 result, err = client.ListByServerResponder(resp) 250 if err != nil { 251 err = autorest.NewErrorWithError(err, "mysql.RecommendedActionsClient", "listByServerNextResults", resp, "Failure responding to next results request") 252 } 253 return 254} 255 256// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 257func (client RecommendedActionsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string, advisorName string, sessionID string) (result RecommendationActionsResultListIterator, err error) { 258 if tracing.IsEnabled() { 259 ctx = tracing.StartSpan(ctx, fqdn+"/RecommendedActionsClient.ListByServer") 260 defer func() { 261 sc := -1 262 if result.Response().Response.Response != nil { 263 sc = result.page.Response().Response.Response.StatusCode 264 } 265 tracing.EndSpan(ctx, sc, err) 266 }() 267 } 268 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName, advisorName, sessionID) 269 return 270} 271