/*
* 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 { TopQueryStatistics } 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 {
QueryStatistic,
TopQueryStatisticsInput,
TopQueryStatisticsListByServerNextOptionalParams,
TopQueryStatisticsListByServerOptionalParams,
TopQueryStatisticsListByServerResponse,
TopQueryStatisticsGetOptionalParams,
TopQueryStatisticsGetResponse,
TopQueryStatisticsListByServerNextResponse
} from "../models";
///
/** Class containing TopQueryStatistics operations. */
export class TopQueryStatisticsImpl implements TopQueryStatistics {
private readonly client: MariaDBManagementClient;
/**
* Initialize a new instance of the class TopQueryStatistics class.
* @param client Reference to the service client
*/
constructor(client: MariaDBManagementClient) {
this.client = client;
}
/**
* Retrieve the Query-Store top queries for specified metric and aggregation.
* @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 top query statistics.
* @param options The options parameters.
*/
public listByServer(
resourceGroupName: string,
serverName: string,
parameters: TopQueryStatisticsInput,
options?: TopQueryStatisticsListByServerOptionalParams
): 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: TopQueryStatisticsInput,
options?: TopQueryStatisticsListByServerOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: TopQueryStatisticsListByServerResponse;
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: TopQueryStatisticsInput,
options?: TopQueryStatisticsListByServerOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByServerPagingPage(
resourceGroupName,
serverName,
parameters,
options
)) {
yield* page;
}
}
/**
* Retrieve the query statistic for specified identifier.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param serverName The name of the server.
* @param queryStatisticId The Query Statistic identifier.
* @param options The options parameters.
*/
get(
resourceGroupName: string,
serverName: string,
queryStatisticId: string,
options?: TopQueryStatisticsGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, serverName, queryStatisticId, options },
getOperationSpec
);
}
/**
* Retrieve the Query-Store top queries for specified metric and aggregation.
* @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 top query statistics.
* @param options The options parameters.
*/
private _listByServer(
resourceGroupName: string,
serverName: string,
parameters: TopQueryStatisticsInput,
options?: TopQueryStatisticsListByServerOptionalParams
): 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 top query 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: TopQueryStatisticsInput,
nextLink: string,
options?: TopQueryStatisticsListByServerNextOptionalParams
): 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}/topQueryStatistics/{queryStatisticId}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.QueryStatistic
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.serverName,
Parameters.queryStatisticId
],
headerParameters: [Parameters.accept],
serializer
};
const listByServerOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMariaDB/servers/{serverName}/topQueryStatistics",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.TopQueryStatisticsResultList
},
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.TopQueryStatisticsResultList
},
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
};