/* * 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 { FailoverGroups } 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 { SimplePollerLike, OperationState, createHttpPoller } from "@azure/core-lro"; import { createLroSpec } from "../lroImpl"; import { FailoverGroup, FailoverGroupsListByServerNextOptionalParams, FailoverGroupsListByServerOptionalParams, FailoverGroupsListByServerResponse, FailoverGroupsGetOptionalParams, FailoverGroupsGetResponse, FailoverGroupsCreateOrUpdateOptionalParams, FailoverGroupsCreateOrUpdateResponse, FailoverGroupsDeleteOptionalParams, FailoverGroupUpdate, FailoverGroupsUpdateOptionalParams, FailoverGroupsUpdateResponse, FailoverGroupsFailoverOptionalParams, FailoverGroupsFailoverResponse, FailoverGroupsForceFailoverAllowDataLossOptionalParams, FailoverGroupsForceFailoverAllowDataLossResponse, FailoverGroupsListByServerNextResponse } from "../models"; /// /** Class containing FailoverGroups operations. */ export class FailoverGroupsImpl implements FailoverGroups { private readonly client: SqlManagementClient; /** * Initialize a new instance of the class FailoverGroups class. * @param client Reference to the service client */ constructor(client: SqlManagementClient) { this.client = client; } /** * Lists the failover groups in a server. * @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 serverName The name of the server containing the failover group. * @param options The options parameters. */ public listByServer( resourceGroupName: string, serverName: string, options?: FailoverGroupsListByServerOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByServerPagingAll( resourceGroupName, serverName, 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, options, settings ); } }; } private async *listByServerPagingPage( resourceGroupName: string, serverName: string, options?: FailoverGroupsListByServerOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: FailoverGroupsListByServerResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByServer(resourceGroupName, serverName, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByServerNext( resourceGroupName, serverName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByServerPagingAll( resourceGroupName: string, serverName: string, options?: FailoverGroupsListByServerOptionalParams ): AsyncIterableIterator { for await (const page of this.listByServerPagingPage( resourceGroupName, serverName, options )) { yield* page; } } /** * Gets a failover group. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param options The options parameters. */ get( resourceGroupName: string, serverName: string, failoverGroupName: string, options?: FailoverGroupsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, failoverGroupName, options }, getOperationSpec ); } /** * Creates or updates a failover group. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param parameters The failover group parameters. * @param options The options parameters. */ async beginCreateOrUpdate( resourceGroupName: string, serverName: string, failoverGroupName: string, parameters: FailoverGroup, options?: FailoverGroupsCreateOrUpdateOptionalParams ): Promise< SimplePollerLike< OperationState, FailoverGroupsCreateOrUpdateResponse > > { 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, serverName, failoverGroupName, parameters, options }, spec: createOrUpdateOperationSpec }); const poller = await createHttpPoller< FailoverGroupsCreateOrUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Creates or updates a failover group. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param parameters The failover group parameters. * @param options The options parameters. */ async beginCreateOrUpdateAndWait( resourceGroupName: string, serverName: string, failoverGroupName: string, parameters: FailoverGroup, options?: FailoverGroupsCreateOrUpdateOptionalParams ): Promise { const poller = await this.beginCreateOrUpdate( resourceGroupName, serverName, failoverGroupName, parameters, options ); return poller.pollUntilDone(); } /** * Deletes a failover group. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param options The options parameters. */ async beginDelete( resourceGroupName: string, serverName: string, failoverGroupName: string, options?: FailoverGroupsDeleteOptionalParams ): Promise, void>> { 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, serverName, failoverGroupName, options }, spec: deleteOperationSpec }); const poller = await createHttpPoller>(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Deletes a failover group. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param options The options parameters. */ async beginDeleteAndWait( resourceGroupName: string, serverName: string, failoverGroupName: string, options?: FailoverGroupsDeleteOptionalParams ): Promise { const poller = await this.beginDelete( resourceGroupName, serverName, failoverGroupName, options ); return poller.pollUntilDone(); } /** * Updates a failover group. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param parameters The failover group parameters. * @param options The options parameters. */ async beginUpdate( resourceGroupName: string, serverName: string, failoverGroupName: string, parameters: FailoverGroupUpdate, options?: FailoverGroupsUpdateOptionalParams ): Promise< SimplePollerLike< OperationState, FailoverGroupsUpdateResponse > > { 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, serverName, failoverGroupName, parameters, options }, spec: updateOperationSpec }); const poller = await createHttpPoller< FailoverGroupsUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Updates a failover group. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param parameters The failover group parameters. * @param options The options parameters. */ async beginUpdateAndWait( resourceGroupName: string, serverName: string, failoverGroupName: string, parameters: FailoverGroupUpdate, options?: FailoverGroupsUpdateOptionalParams ): Promise { const poller = await this.beginUpdate( resourceGroupName, serverName, failoverGroupName, parameters, options ); return poller.pollUntilDone(); } /** * Lists the failover groups in a server. * @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 serverName The name of the server containing the failover group. * @param options The options parameters. */ private _listByServer( resourceGroupName: string, serverName: string, options?: FailoverGroupsListByServerOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, options }, listByServerOperationSpec ); } /** * Fails over from the current primary server to this server. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param options The options parameters. */ async beginFailover( resourceGroupName: string, serverName: string, failoverGroupName: string, options?: FailoverGroupsFailoverOptionalParams ): Promise< SimplePollerLike< OperationState, FailoverGroupsFailoverResponse > > { 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, serverName, failoverGroupName, options }, spec: failoverOperationSpec }); const poller = await createHttpPoller< FailoverGroupsFailoverResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Fails over from the current primary server to this server. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param options The options parameters. */ async beginFailoverAndWait( resourceGroupName: string, serverName: string, failoverGroupName: string, options?: FailoverGroupsFailoverOptionalParams ): Promise { const poller = await this.beginFailover( resourceGroupName, serverName, failoverGroupName, options ); return poller.pollUntilDone(); } /** * Fails over from the current primary server to this server. This operation might result in data loss. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param options The options parameters. */ async beginForceFailoverAllowDataLoss( resourceGroupName: string, serverName: string, failoverGroupName: string, options?: FailoverGroupsForceFailoverAllowDataLossOptionalParams ): Promise< SimplePollerLike< OperationState, FailoverGroupsForceFailoverAllowDataLossResponse > > { 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, serverName, failoverGroupName, options }, spec: forceFailoverAllowDataLossOperationSpec }); const poller = await createHttpPoller< FailoverGroupsForceFailoverAllowDataLossResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Fails over from the current primary server to this server. This operation might result in data loss. * @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 serverName The name of the server containing the failover group. * @param failoverGroupName The name of the failover group. * @param options The options parameters. */ async beginForceFailoverAllowDataLossAndWait( resourceGroupName: string, serverName: string, failoverGroupName: string, options?: FailoverGroupsForceFailoverAllowDataLossOptionalParams ): Promise { const poller = await this.beginForceFailoverAllowDataLoss( resourceGroupName, serverName, failoverGroupName, options ); return poller.pollUntilDone(); } /** * ListByServerNext * @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 serverName The name of the server containing the failover group. * @param nextLink The nextLink from the previous successful call to the ListByServer method. * @param options The options parameters. */ private _listByServerNext( resourceGroupName: string, serverName: string, nextLink: string, options?: FailoverGroupsListByServerNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, nextLink, options }, listByServerNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.FailoverGroup }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.failoverGroupName ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.FailoverGroup }, 201: { bodyMapper: Mappers.FailoverGroup }, 202: { bodyMapper: Mappers.FailoverGroup }, 204: { bodyMapper: Mappers.FailoverGroup }, default: {} }, requestBody: Parameters.parameters18, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.failoverGroupName ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", httpMethod: "DELETE", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.failoverGroupName ], serializer }; const updateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", httpMethod: "PATCH", responses: { 200: { bodyMapper: Mappers.FailoverGroup }, 201: { bodyMapper: Mappers.FailoverGroup }, 202: { bodyMapper: Mappers.FailoverGroup }, 204: { bodyMapper: Mappers.FailoverGroup }, default: {} }, requestBody: Parameters.parameters19, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.failoverGroupName ], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const listByServerOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.FailoverGroupListResult }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName ], headerParameters: [Parameters.accept], serializer }; const failoverOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.FailoverGroup }, 201: { bodyMapper: Mappers.FailoverGroup }, 202: { bodyMapper: Mappers.FailoverGroup }, 204: { bodyMapper: Mappers.FailoverGroup }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.failoverGroupName ], headerParameters: [Parameters.accept], serializer }; const forceFailoverAllowDataLossOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.FailoverGroup }, 201: { bodyMapper: Mappers.FailoverGroup }, 202: { bodyMapper: Mappers.FailoverGroup }, 204: { bodyMapper: Mappers.FailoverGroup }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.failoverGroupName ], headerParameters: [Parameters.accept], serializer }; const listByServerNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.FailoverGroupListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };