/* * 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 { ReplicationLinks } 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 { ReplicationLink, ReplicationLinksListByDatabaseNextOptionalParams, ReplicationLinksListByDatabaseOptionalParams, ReplicationLinksListByDatabaseResponse, ReplicationLinksListByServerNextOptionalParams, ReplicationLinksListByServerOptionalParams, ReplicationLinksListByServerResponse, ReplicationLinksGetOptionalParams, ReplicationLinksGetResponse, ReplicationLinksDeleteOptionalParams, ReplicationLinksFailoverOptionalParams, ReplicationLinksFailoverResponse, ReplicationLinksFailoverAllowDataLossOptionalParams, ReplicationLinksFailoverAllowDataLossResponse, ReplicationLinksListByDatabaseNextResponse, ReplicationLinksListByServerNextResponse } from "../models"; /// /** Class containing ReplicationLinks operations. */ export class ReplicationLinksImpl implements ReplicationLinks { private readonly client: SqlManagementClient; /** * Initialize a new instance of the class ReplicationLinks class. * @param client Reference to the service client */ constructor(client: SqlManagementClient) { this.client = client; } /** * Gets a list of replication links on database. * @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. * @param databaseName The name of the database. * @param options The options parameters. */ public listByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: ReplicationLinksListByDatabaseOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByDatabasePagingAll( resourceGroupName, serverName, databaseName, 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.listByDatabasePagingPage( resourceGroupName, serverName, databaseName, options, settings ); } }; } private async *listByDatabasePagingPage( resourceGroupName: string, serverName: string, databaseName: string, options?: ReplicationLinksListByDatabaseOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: ReplicationLinksListByDatabaseResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByDatabase( resourceGroupName, serverName, databaseName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByDatabaseNext( resourceGroupName, serverName, databaseName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByDatabasePagingAll( resourceGroupName: string, serverName: string, databaseName: string, options?: ReplicationLinksListByDatabaseOptionalParams ): AsyncIterableIterator { for await (const page of this.listByDatabasePagingPage( resourceGroupName, serverName, databaseName, options )) { yield* page; } } /** * Gets a list of replication links. * @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. * @param options The options parameters. */ public listByServer( resourceGroupName: string, serverName: string, options?: ReplicationLinksListByServerOptionalParams ): 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?: ReplicationLinksListByServerOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: ReplicationLinksListByServerResponse; 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?: ReplicationLinksListByServerOptionalParams ): AsyncIterableIterator { for await (const page of this.listByServerPagingPage( resourceGroupName, serverName, options )) { yield* page; } } /** * Gets a list of replication links on database. * @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. * @param databaseName The name of the database. * @param options The options parameters. */ private _listByDatabase( resourceGroupName: string, serverName: string, databaseName: string, options?: ReplicationLinksListByDatabaseOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, options }, listByDatabaseOperationSpec ); } /** * Gets a replication link. * @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. * @param databaseName The name of the database. * @param linkId The name of the replication link. * @param options The options parameters. */ get( resourceGroupName: string, serverName: string, databaseName: string, linkId: string, options?: ReplicationLinksGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, linkId, options }, getOperationSpec ); } /** * Deletes the replication link. * @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. * @param databaseName The name of the database. * @param linkId * @param options The options parameters. */ async beginDelete( resourceGroupName: string, serverName: string, databaseName: string, linkId: string, options?: ReplicationLinksDeleteOptionalParams ): 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, databaseName, linkId, options }, spec: deleteOperationSpec }); const poller = await createHttpPoller>(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Deletes the replication link. * @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. * @param databaseName The name of the database. * @param linkId * @param options The options parameters. */ async beginDeleteAndWait( resourceGroupName: string, serverName: string, databaseName: string, linkId: string, options?: ReplicationLinksDeleteOptionalParams ): Promise { const poller = await this.beginDelete( resourceGroupName, serverName, databaseName, linkId, options ); return poller.pollUntilDone(); } /** * 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. * @param databaseName The name of the database. * @param linkId The name of the replication link. * @param options The options parameters. */ async beginFailover( resourceGroupName: string, serverName: string, databaseName: string, linkId: string, options?: ReplicationLinksFailoverOptionalParams ): Promise< SimplePollerLike< OperationState, ReplicationLinksFailoverResponse > > { 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, databaseName, linkId, options }, spec: failoverOperationSpec }); const poller = await createHttpPoller< ReplicationLinksFailoverResponse, 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. * @param databaseName The name of the database. * @param linkId The name of the replication link. * @param options The options parameters. */ async beginFailoverAndWait( resourceGroupName: string, serverName: string, databaseName: string, linkId: string, options?: ReplicationLinksFailoverOptionalParams ): Promise { const poller = await this.beginFailover( resourceGroupName, serverName, databaseName, linkId, options ); return poller.pollUntilDone(); } /** * Fails over from the current primary server to this server allowing 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. * @param databaseName The name of the database. * @param linkId The name of the replication link. * @param options The options parameters. */ async beginFailoverAllowDataLoss( resourceGroupName: string, serverName: string, databaseName: string, linkId: string, options?: ReplicationLinksFailoverAllowDataLossOptionalParams ): Promise< SimplePollerLike< OperationState, ReplicationLinksFailoverAllowDataLossResponse > > { 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, databaseName, linkId, options }, spec: failoverAllowDataLossOperationSpec }); const poller = await createHttpPoller< ReplicationLinksFailoverAllowDataLossResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Fails over from the current primary server to this server allowing 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. * @param databaseName The name of the database. * @param linkId The name of the replication link. * @param options The options parameters. */ async beginFailoverAllowDataLossAndWait( resourceGroupName: string, serverName: string, databaseName: string, linkId: string, options?: ReplicationLinksFailoverAllowDataLossOptionalParams ): Promise { const poller = await this.beginFailoverAllowDataLoss( resourceGroupName, serverName, databaseName, linkId, options ); return poller.pollUntilDone(); } /** * Gets a list of replication links. * @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. * @param options The options parameters. */ private _listByServer( resourceGroupName: string, serverName: string, options?: ReplicationLinksListByServerOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, options }, listByServerOperationSpec ); } /** * ListByDatabaseNext * @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. * @param databaseName The name of the database. * @param nextLink The nextLink from the previous successful call to the ListByDatabase method. * @param options The options parameters. */ private _listByDatabaseNext( resourceGroupName: string, serverName: string, databaseName: string, nextLink: string, options?: ReplicationLinksListByDatabaseNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, databaseName, nextLink, options }, listByDatabaseNextOperationSpec ); } /** * 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. * @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?: ReplicationLinksListByServerNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, nextLink, options }, listByServerNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByDatabaseOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ReplicationLinkListResult }, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ReplicationLink }, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.linkId ], headerParameters: [Parameters.accept], serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", httpMethod: "DELETE", responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.linkId ], serializer }; const failoverOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.ReplicationLink }, 201: { bodyMapper: Mappers.ReplicationLink }, 202: { bodyMapper: Mappers.ReplicationLink }, 204: { bodyMapper: Mappers.ReplicationLink }, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.linkId ], headerParameters: [Parameters.accept], serializer }; const failoverAllowDataLossOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.ReplicationLink }, 201: { bodyMapper: Mappers.ReplicationLink }, 202: { bodyMapper: Mappers.ReplicationLink }, 204: { bodyMapper: Mappers.ReplicationLink }, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.linkId ], headerParameters: [Parameters.accept], serializer }; const listByServerOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/replicationLinks", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ReplicationLinkListResult }, default: {} }, queryParameters: [Parameters.apiVersion4], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName ], headerParameters: [Parameters.accept], serializer }; const listByDatabaseNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ReplicationLinkListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.databaseName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer }; const listByServerNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ReplicationLinkListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };