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// WaitStatisticsClient 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 WaitStatisticsClient struct { 33 BaseClient 34} 35 36// NewWaitStatisticsClient creates an instance of the WaitStatisticsClient client. 37func NewWaitStatisticsClient(subscriptionID string) WaitStatisticsClient { 38 return NewWaitStatisticsClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewWaitStatisticsClientWithBaseURI creates an instance of the WaitStatisticsClient client using a custom endpoint. 42// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 43func NewWaitStatisticsClientWithBaseURI(baseURI string, subscriptionID string) WaitStatisticsClient { 44 return WaitStatisticsClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// Get retrieve wait statistics for specified identifier. 48// Parameters: 49// resourceGroupName - the name of the resource group. The name is case insensitive. 50// serverName - the name of the server. 51// waitStatisticsID - the Wait Statistic identifier. 52func (client WaitStatisticsClient) Get(ctx context.Context, resourceGroupName string, serverName string, waitStatisticsID string) (result WaitStatistic, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/WaitStatisticsClient.Get") 55 defer func() { 56 sc := -1 57 if result.Response.Response != nil { 58 sc = result.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: client.SubscriptionID, 65 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 66 {TargetValue: resourceGroupName, 67 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 68 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 69 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 70 return result, validation.NewError("mysql.WaitStatisticsClient", "Get", err.Error()) 71 } 72 73 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, waitStatisticsID) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "Get", nil, "Failure preparing request") 76 return 77 } 78 79 resp, err := client.GetSender(req) 80 if err != nil { 81 result.Response = autorest.Response{Response: resp} 82 err = autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "Get", resp, "Failure sending request") 83 return 84 } 85 86 result, err = client.GetResponder(resp) 87 if err != nil { 88 err = autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "Get", resp, "Failure responding to request") 89 return 90 } 91 92 return 93} 94 95// GetPreparer prepares the Get request. 96func (client WaitStatisticsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, waitStatisticsID string) (*http.Request, error) { 97 pathParameters := map[string]interface{}{ 98 "resourceGroupName": autorest.Encode("path", resourceGroupName), 99 "serverName": autorest.Encode("path", serverName), 100 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 101 "waitStatisticsId": autorest.Encode("path", waitStatisticsID), 102 } 103 104 const APIVersion = "2018-06-01" 105 queryParameters := map[string]interface{}{ 106 "api-version": APIVersion, 107 } 108 109 preparer := autorest.CreatePreparer( 110 autorest.AsGet(), 111 autorest.WithBaseURL(client.BaseURI), 112 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/waitStatistics/{waitStatisticsId}", pathParameters), 113 autorest.WithQueryParameters(queryParameters)) 114 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 115} 116 117// GetSender sends the Get request. The method will close the 118// http.Response Body if it receives an error. 119func (client WaitStatisticsClient) GetSender(req *http.Request) (*http.Response, error) { 120 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 121} 122 123// GetResponder handles the response to the Get request. The method always 124// closes the http.Response Body. 125func (client WaitStatisticsClient) GetResponder(resp *http.Response) (result WaitStatistic, err error) { 126 err = autorest.Respond( 127 resp, 128 azure.WithErrorUnlessStatusCode(http.StatusOK), 129 autorest.ByUnmarshallingJSON(&result), 130 autorest.ByClosing()) 131 result.Response = autorest.Response{Response: resp} 132 return 133} 134 135// ListByServer retrieve wait statistics for specified aggregation window. 136// Parameters: 137// resourceGroupName - the name of the resource group. The name is case insensitive. 138// serverName - the name of the server. 139// parameters - the required parameters for retrieving wait statistics. 140func (client WaitStatisticsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string, parameters WaitStatisticsInput) (result WaitStatisticsResultListPage, err error) { 141 if tracing.IsEnabled() { 142 ctx = tracing.StartSpan(ctx, fqdn+"/WaitStatisticsClient.ListByServer") 143 defer func() { 144 sc := -1 145 if result.wsrl.Response.Response != nil { 146 sc = result.wsrl.Response.Response.StatusCode 147 } 148 tracing.EndSpan(ctx, sc, err) 149 }() 150 } 151 if err := validation.Validate([]validation.Validation{ 152 {TargetValue: client.SubscriptionID, 153 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 154 {TargetValue: resourceGroupName, 155 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 156 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 157 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 158 {TargetValue: parameters, 159 Constraints: []validation.Constraint{{Target: "parameters.WaitStatisticsInputProperties", Name: validation.Null, Rule: true, 160 Chain: []validation.Constraint{{Target: "parameters.WaitStatisticsInputProperties.ObservationStartTime", Name: validation.Null, Rule: true, Chain: nil}, 161 {Target: "parameters.WaitStatisticsInputProperties.ObservationEndTime", Name: validation.Null, Rule: true, Chain: nil}, 162 {Target: "parameters.WaitStatisticsInputProperties.AggregationWindow", Name: validation.Null, Rule: true, Chain: nil}, 163 }}}}}); err != nil { 164 return result, validation.NewError("mysql.WaitStatisticsClient", "ListByServer", err.Error()) 165 } 166 167 result.fn = client.listByServerNextResults 168 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName, parameters) 169 if err != nil { 170 err = autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "ListByServer", nil, "Failure preparing request") 171 return 172 } 173 174 resp, err := client.ListByServerSender(req) 175 if err != nil { 176 result.wsrl.Response = autorest.Response{Response: resp} 177 err = autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "ListByServer", resp, "Failure sending request") 178 return 179 } 180 181 result.wsrl, err = client.ListByServerResponder(resp) 182 if err != nil { 183 err = autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "ListByServer", resp, "Failure responding to request") 184 return 185 } 186 if result.wsrl.hasNextLink() && result.wsrl.IsEmpty() { 187 err = result.NextWithContext(ctx) 188 return 189 } 190 191 return 192} 193 194// ListByServerPreparer prepares the ListByServer request. 195func (client WaitStatisticsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string, parameters WaitStatisticsInput) (*http.Request, error) { 196 pathParameters := map[string]interface{}{ 197 "resourceGroupName": autorest.Encode("path", resourceGroupName), 198 "serverName": autorest.Encode("path", serverName), 199 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 200 } 201 202 const APIVersion = "2018-06-01" 203 queryParameters := map[string]interface{}{ 204 "api-version": APIVersion, 205 } 206 207 preparer := autorest.CreatePreparer( 208 autorest.AsContentType("application/json; charset=utf-8"), 209 autorest.AsGet(), 210 autorest.WithBaseURL(client.BaseURI), 211 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/waitStatistics", pathParameters), 212 autorest.WithJSON(parameters), 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 WaitStatisticsClient) 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 WaitStatisticsClient) ListByServerResponder(resp *http.Response) (result WaitStatisticsResultList, 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 WaitStatisticsClient) listByServerNextResults(ctx context.Context, lastResults WaitStatisticsResultList) (result WaitStatisticsResultList, err error) { 237 req, err := lastResults.waitStatisticsResultListPreparer(ctx) 238 if err != nil { 239 return result, autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "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.WaitStatisticsClient", "listByServerNextResults", resp, "Failure sending next results request") 248 } 249 result, err = client.ListByServerResponder(resp) 250 if err != nil { 251 err = autorest.NewErrorWithError(err, "mysql.WaitStatisticsClient", "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 WaitStatisticsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string, parameters WaitStatisticsInput) (result WaitStatisticsResultListIterator, err error) { 258 if tracing.IsEnabled() { 259 ctx = tracing.StartSpan(ctx, fqdn+"/WaitStatisticsClient.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, parameters) 269 return 270} 271