/* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { WaitStatistics } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { MariaDBManagementClient } from "../mariaDBManagementClient"; import { WaitStatistic, WaitStatisticsInput, WaitStatisticsListByServerNextOptionalParams, WaitStatisticsListByServerOptionalParams, WaitStatisticsListByServerResponse, WaitStatisticsGetOptionalParams, WaitStatisticsGetResponse, WaitStatisticsListByServerNextResponse } from "../models"; /// /** Class containing WaitStatistics operations. */ export class WaitStatisticsImpl implements WaitStatistics { private readonly client: MariaDBManagementClient; /** * Initialize a new instance of the class WaitStatistics class. * @param client Reference to the service client */ constructor(client: MariaDBManagementClient) { this.client = client; } /** * Retrieve wait statistics for specified aggregation window. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param serverName The name of the server. * @param parameters The required parameters for retrieving wait statistics. * @param options The options parameters. */ public listByServer( resourceGroupName: string, serverName: string, parameters: WaitStatisticsInput, options?: WaitStatisticsListByServerOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByServerPagingAll( resourceGroupName, serverName, parameters, options ); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listByServerPagingPage( resourceGroupName, serverName, parameters, options, settings ); } }; } private async *listByServerPagingPage( resourceGroupName: string, serverName: string, parameters: WaitStatisticsInput, options?: WaitStatisticsListByServerOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: WaitStatisticsListByServerResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByServer( resourceGroupName, serverName, parameters, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByServerNext( resourceGroupName, serverName, parameters, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByServerPagingAll( resourceGroupName: string, serverName: string, parameters: WaitStatisticsInput, options?: WaitStatisticsListByServerOptionalParams ): AsyncIterableIterator { for await (const page of this.listByServerPagingPage( resourceGroupName, serverName, parameters, options )) { yield* page; } } /** * Retrieve wait statistics for specified identifier. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param serverName The name of the server. * @param waitStatisticsId The Wait Statistic identifier. * @param options The options parameters. */ get( resourceGroupName: string, serverName: string, waitStatisticsId: string, options?: WaitStatisticsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, waitStatisticsId, options }, getOperationSpec ); } /** * Retrieve wait statistics for specified aggregation window. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param serverName The name of the server. * @param parameters The required parameters for retrieving wait statistics. * @param options The options parameters. */ private _listByServer( resourceGroupName: string, serverName: string, parameters: WaitStatisticsInput, options?: WaitStatisticsListByServerOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, parameters, options }, listByServerOperationSpec ); } /** * ListByServerNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param serverName The name of the server. * @param parameters The required parameters for retrieving wait statistics. * @param nextLink The nextLink from the previous successful call to the ListByServer method. * @param options The options parameters. */ private _listByServerNext( resourceGroupName: string, serverName: string, parameters: WaitStatisticsInput, nextLink: string, options?: WaitStatisticsListByServerNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, parameters, nextLink, options }, listByServerNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMariaDB/servers/{serverName}/waitStatistics/{waitStatisticsId}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.WaitStatistic }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.waitStatisticsId ], headerParameters: [Parameters.accept], serializer }; const listByServerOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMariaDB/servers/{serverName}/waitStatistics", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.WaitStatisticsResultList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const listByServerNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.WaitStatisticsResultList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.nextLink ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer };