/*
* 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 { Usages } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { SqlManagementClient } from "../sqlManagementClient";
import {
Usage,
UsagesListByInstancePoolNextOptionalParams,
UsagesListByInstancePoolOptionalParams,
UsagesListByInstancePoolResponse,
UsagesListByInstancePoolNextResponse
} from "../models";
///
/** Class containing Usages operations. */
export class UsagesImpl implements Usages {
private readonly client: SqlManagementClient;
/**
* Initialize a new instance of the class Usages class.
* @param client Reference to the service client
*/
constructor(client: SqlManagementClient) {
this.client = client;
}
/**
* Gets all instance pool usage metrics
* @param resourceGroupName The name of the resource group that contains the resource. You can obtain
* this value from the Azure Resource Manager API or the portal.
* @param instancePoolName The name of the instance pool to be retrieved.
* @param options The options parameters.
*/
public listByInstancePool(
resourceGroupName: string,
instancePoolName: string,
options?: UsagesListByInstancePoolOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByInstancePoolPagingAll(
resourceGroupName,
instancePoolName,
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.listByInstancePoolPagingPage(
resourceGroupName,
instancePoolName,
options,
settings
);
}
};
}
private async *listByInstancePoolPagingPage(
resourceGroupName: string,
instancePoolName: string,
options?: UsagesListByInstancePoolOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: UsagesListByInstancePoolResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByInstancePool(
resourceGroupName,
instancePoolName,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByInstancePoolNext(
resourceGroupName,
instancePoolName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByInstancePoolPagingAll(
resourceGroupName: string,
instancePoolName: string,
options?: UsagesListByInstancePoolOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByInstancePoolPagingPage(
resourceGroupName,
instancePoolName,
options
)) {
yield* page;
}
}
/**
* Gets all instance pool usage metrics
* @param resourceGroupName The name of the resource group that contains the resource. You can obtain
* this value from the Azure Resource Manager API or the portal.
* @param instancePoolName The name of the instance pool to be retrieved.
* @param options The options parameters.
*/
private _listByInstancePool(
resourceGroupName: string,
instancePoolName: string,
options?: UsagesListByInstancePoolOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, instancePoolName, options },
listByInstancePoolOperationSpec
);
}
/**
* ListByInstancePoolNext
* @param resourceGroupName The name of the resource group that contains the resource. You can obtain
* this value from the Azure Resource Manager API or the portal.
* @param instancePoolName The name of the instance pool to be retrieved.
* @param nextLink The nextLink from the previous successful call to the ListByInstancePool method.
* @param options The options parameters.
*/
private _listByInstancePoolNext(
resourceGroupName: string,
instancePoolName: string,
nextLink: string,
options?: UsagesListByInstancePoolNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, instancePoolName, nextLink, options },
listByInstancePoolNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByInstancePoolOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.UsageListResult
},
default: {}
},
queryParameters: [Parameters.apiVersion5, Parameters.expandChildren],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.instancePoolName
],
headerParameters: [Parameters.accept],
serializer
};
const listByInstancePoolNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.UsageListResult
},
default: {}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.nextLink,
Parameters.instancePoolName
],
headerParameters: [Parameters.accept],
serializer
};