/* * 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 { Pools } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { DevCenterClient } from "../devCenterClient"; import { SimplePollerLike, OperationState, createHttpPoller, } from "@azure/core-lro"; import { createLroSpec } from "../lroImpl"; import { Pool, PoolsListByProjectNextOptionalParams, PoolsListByProjectOptionalParams, PoolsListByProjectResponse, PoolsGetOptionalParams, PoolsGetResponse, PoolsCreateOrUpdateOptionalParams, PoolsCreateOrUpdateResponse, PoolUpdate, PoolsUpdateOptionalParams, PoolsUpdateResponse, PoolsDeleteOptionalParams, PoolsDeleteResponse, PoolsRunHealthChecksOptionalParams, PoolsRunHealthChecksResponse, PoolsListByProjectNextResponse, } from "../models"; /// /** Class containing Pools operations. */ export class PoolsImpl implements Pools { private readonly client: DevCenterClient; /** * Initialize a new instance of the class Pools class. * @param client Reference to the service client */ constructor(client: DevCenterClient) { this.client = client; } /** * Lists pools for a project * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param options The options parameters. */ public listByProject( resourceGroupName: string, projectName: string, options?: PoolsListByProjectOptionalParams, ): PagedAsyncIterableIterator { const iter = this.listByProjectPagingAll( resourceGroupName, projectName, 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.listByProjectPagingPage( resourceGroupName, projectName, options, settings, ); }, }; } private async *listByProjectPagingPage( resourceGroupName: string, projectName: string, options?: PoolsListByProjectOptionalParams, settings?: PageSettings, ): AsyncIterableIterator { let result: PoolsListByProjectResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByProject( resourceGroupName, projectName, options, ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByProjectNext( resourceGroupName, projectName, continuationToken, options, ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByProjectPagingAll( resourceGroupName: string, projectName: string, options?: PoolsListByProjectOptionalParams, ): AsyncIterableIterator { for await (const page of this.listByProjectPagingPage( resourceGroupName, projectName, options, )) { yield* page; } } /** * Lists pools for a project * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param options The options parameters. */ private _listByProject( resourceGroupName: string, projectName: string, options?: PoolsListByProjectOptionalParams, ): Promise { return this.client.sendOperationRequest( { resourceGroupName, projectName, options }, listByProjectOperationSpec, ); } /** * Gets a machine pool * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param options The options parameters. */ get( resourceGroupName: string, projectName: string, poolName: string, options?: PoolsGetOptionalParams, ): Promise { return this.client.sendOperationRequest( { resourceGroupName, projectName, poolName, options }, getOperationSpec, ); } /** * Creates or updates a machine pool * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param body Represents a machine pool * @param options The options parameters. */ async beginCreateOrUpdate( resourceGroupName: string, projectName: string, poolName: string, body: Pool, options?: PoolsCreateOrUpdateOptionalParams, ): Promise< SimplePollerLike< OperationState, PoolsCreateOrUpdateResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ) => { let currentRawResponse: coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown, ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON(), }, }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, projectName, poolName, body, options }, spec: createOrUpdateOperationSpec, }); const poller = await createHttpPoller< PoolsCreateOrUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation", }); await poller.poll(); return poller; } /** * Creates or updates a machine pool * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param body Represents a machine pool * @param options The options parameters. */ async beginCreateOrUpdateAndWait( resourceGroupName: string, projectName: string, poolName: string, body: Pool, options?: PoolsCreateOrUpdateOptionalParams, ): Promise { const poller = await this.beginCreateOrUpdate( resourceGroupName, projectName, poolName, body, options, ); return poller.pollUntilDone(); } /** * Partially updates a machine pool * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param body Represents a machine pool * @param options The options parameters. */ async beginUpdate( resourceGroupName: string, projectName: string, poolName: string, body: PoolUpdate, options?: PoolsUpdateOptionalParams, ): Promise< SimplePollerLike, PoolsUpdateResponse> > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ) => { let currentRawResponse: coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown, ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON(), }, }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, projectName, poolName, body, options }, spec: updateOperationSpec, }); const poller = await createHttpPoller< PoolsUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation", }); await poller.poll(); return poller; } /** * Partially updates a machine pool * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param body Represents a machine pool * @param options The options parameters. */ async beginUpdateAndWait( resourceGroupName: string, projectName: string, poolName: string, body: PoolUpdate, options?: PoolsUpdateOptionalParams, ): Promise { const poller = await this.beginUpdate( resourceGroupName, projectName, poolName, body, options, ); return poller.pollUntilDone(); } /** * Deletes a machine pool * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param options The options parameters. */ async beginDelete( resourceGroupName: string, projectName: string, poolName: string, options?: PoolsDeleteOptionalParams, ): Promise< SimplePollerLike, PoolsDeleteResponse> > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ) => { let currentRawResponse: coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown, ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON(), }, }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, projectName, poolName, options }, spec: deleteOperationSpec, }); const poller = await createHttpPoller< PoolsDeleteResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation", }); await poller.poll(); return poller; } /** * Deletes a machine pool * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param options The options parameters. */ async beginDeleteAndWait( resourceGroupName: string, projectName: string, poolName: string, options?: PoolsDeleteOptionalParams, ): Promise { const poller = await this.beginDelete( resourceGroupName, projectName, poolName, options, ); return poller.pollUntilDone(); } /** * Triggers a refresh of the pool status. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param options The options parameters. */ async beginRunHealthChecks( resourceGroupName: string, projectName: string, poolName: string, options?: PoolsRunHealthChecksOptionalParams, ): Promise< SimplePollerLike< OperationState, PoolsRunHealthChecksResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ) => { let currentRawResponse: coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown, ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON(), }, }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, projectName, poolName, options }, spec: runHealthChecksOperationSpec, }); const poller = await createHttpPoller< PoolsRunHealthChecksResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation", }); await poller.poll(); return poller; } /** * Triggers a refresh of the pool status. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param poolName Name of the pool. * @param options The options parameters. */ async beginRunHealthChecksAndWait( resourceGroupName: string, projectName: string, poolName: string, options?: PoolsRunHealthChecksOptionalParams, ): Promise { const poller = await this.beginRunHealthChecks( resourceGroupName, projectName, poolName, options, ); return poller.pollUntilDone(); } /** * ListByProjectNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param nextLink The nextLink from the previous successful call to the ListByProject method. * @param options The options parameters. */ private _listByProjectNext( resourceGroupName: string, projectName: string, nextLink: string, options?: PoolsListByProjectNextOptionalParams, ): Promise { return this.client.sendOperationRequest( { resourceGroupName, projectName, nextLink, options }, listByProjectNextOperationSpec, ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByProjectOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/pools", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PoolListResult, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion, Parameters.top], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, ], headerParameters: [Parameters.accept], serializer, }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/pools/{poolName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.Pool, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, Parameters.poolName, ], headerParameters: [Parameters.accept], serializer, }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/pools/{poolName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.Pool, }, 201: { bodyMapper: Mappers.Pool, }, 202: { bodyMapper: Mappers.Pool, }, 204: { bodyMapper: Mappers.Pool, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, requestBody: Parameters.body14, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, Parameters.poolName, ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer, }; const updateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/pools/{poolName}", httpMethod: "PATCH", responses: { 200: { bodyMapper: Mappers.Pool, }, 201: { bodyMapper: Mappers.Pool, }, 202: { bodyMapper: Mappers.Pool, }, 204: { bodyMapper: Mappers.Pool, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, requestBody: Parameters.body15, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, Parameters.poolName, ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer, }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/pools/{poolName}", httpMethod: "DELETE", responses: { 200: { headersMapper: Mappers.PoolsDeleteHeaders, }, 201: { headersMapper: Mappers.PoolsDeleteHeaders, }, 202: { headersMapper: Mappers.PoolsDeleteHeaders, }, 204: { headersMapper: Mappers.PoolsDeleteHeaders, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, Parameters.poolName, ], headerParameters: [Parameters.accept], serializer, }; const runHealthChecksOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}/pools/{poolName}/runHealthChecks", httpMethod: "POST", responses: { 200: { headersMapper: Mappers.PoolsRunHealthChecksHeaders, }, 201: { headersMapper: Mappers.PoolsRunHealthChecksHeaders, }, 202: { headersMapper: Mappers.PoolsRunHealthChecksHeaders, }, 204: { headersMapper: Mappers.PoolsRunHealthChecksHeaders, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, Parameters.poolName, ], headerParameters: [Parameters.accept], serializer, }; const listByProjectNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.PoolListResult, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.nextLink, Parameters.projectName, ], headerParameters: [Parameters.accept], serializer, };