/*
* 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 { VirtualClusters } 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 {
VirtualCluster,
VirtualClustersListNextOptionalParams,
VirtualClustersListOptionalParams,
VirtualClustersListResponse,
VirtualClustersListByResourceGroupNextOptionalParams,
VirtualClustersListByResourceGroupOptionalParams,
VirtualClustersListByResourceGroupResponse,
VirtualClustersGetOptionalParams,
VirtualClustersGetResponse,
VirtualClustersDeleteOptionalParams,
VirtualClusterUpdate,
VirtualClustersUpdateOptionalParams,
VirtualClustersUpdateResponse,
VirtualClustersUpdateDnsServersOptionalParams,
VirtualClustersUpdateDnsServersResponse,
VirtualClustersListNextResponse,
VirtualClustersListByResourceGroupNextResponse
} from "../models";
///
/** Class containing VirtualClusters operations. */
export class VirtualClustersImpl implements VirtualClusters {
private readonly client: SqlManagementClient;
/**
* Initialize a new instance of the class VirtualClusters class.
* @param client Reference to the service client
*/
constructor(client: SqlManagementClient) {
this.client = client;
}
/**
* Gets a list of all virtualClusters in the subscription.
* @param options The options parameters.
*/
public list(
options?: VirtualClustersListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(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.listPagingPage(options, settings);
}
};
}
private async *listPagingPage(
options?: VirtualClustersListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: VirtualClustersListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(continuationToken, options);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
options?: VirtualClustersListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(options)) {
yield* page;
}
}
/**
* Gets a list of virtual clusters in a resource 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 options The options parameters.
*/
public listByResourceGroup(
resourceGroupName: string,
options?: VirtualClustersListByResourceGroupOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByResourceGroupPagingAll(resourceGroupName, 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.listByResourceGroupPagingPage(
resourceGroupName,
options,
settings
);
}
};
}
private async *listByResourceGroupPagingPage(
resourceGroupName: string,
options?: VirtualClustersListByResourceGroupOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: VirtualClustersListByResourceGroupResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByResourceGroup(resourceGroupName, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByResourceGroupNext(
resourceGroupName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByResourceGroupPagingAll(
resourceGroupName: string,
options?: VirtualClustersListByResourceGroupOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByResourceGroupPagingPage(
resourceGroupName,
options
)) {
yield* page;
}
}
/**
* Gets a list of all virtualClusters in the subscription.
* @param options The options parameters.
*/
private _list(
options?: VirtualClustersListOptionalParams
): Promise {
return this.client.sendOperationRequest({ options }, listOperationSpec);
}
/**
* Gets a list of virtual clusters in a resource 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 options The options parameters.
*/
private _listByResourceGroup(
resourceGroupName: string,
options?: VirtualClustersListByResourceGroupOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, options },
listByResourceGroupOperationSpec
);
}
/**
* Gets a virtual cluster.
* @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 virtualClusterName The name of the virtual cluster.
* @param options The options parameters.
*/
get(
resourceGroupName: string,
virtualClusterName: string,
options?: VirtualClustersGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, virtualClusterName, options },
getOperationSpec
);
}
/**
* Deletes a virtual cluster.
* @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 virtualClusterName The name of the virtual cluster.
* @param options The options parameters.
*/
async beginDelete(
resourceGroupName: string,
virtualClusterName: string,
options?: VirtualClustersDeleteOptionalParams
): 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, virtualClusterName, options },
spec: deleteOperationSpec
});
const poller = await createHttpPoller>(lro, {
restoreFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Deletes a virtual cluster.
* @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 virtualClusterName The name of the virtual cluster.
* @param options The options parameters.
*/
async beginDeleteAndWait(
resourceGroupName: string,
virtualClusterName: string,
options?: VirtualClustersDeleteOptionalParams
): Promise {
const poller = await this.beginDelete(
resourceGroupName,
virtualClusterName,
options
);
return poller.pollUntilDone();
}
/**
* Updates an existing virtual cluster.
* @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 virtualClusterName The name of the virtual cluster.
* @param parameters The requested virtual cluster resource state.
* @param options The options parameters.
*/
async beginUpdate(
resourceGroupName: string,
virtualClusterName: string,
parameters: VirtualClusterUpdate,
options?: VirtualClustersUpdateOptionalParams
): Promise<
SimplePollerLike<
OperationState,
VirtualClustersUpdateResponse
>
> {
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, virtualClusterName, parameters, options },
spec: updateOperationSpec
});
const poller = await createHttpPoller<
VirtualClustersUpdateResponse,
OperationState
>(lro, {
restoreFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Updates an existing virtual cluster.
* @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 virtualClusterName The name of the virtual cluster.
* @param parameters The requested virtual cluster resource state.
* @param options The options parameters.
*/
async beginUpdateAndWait(
resourceGroupName: string,
virtualClusterName: string,
parameters: VirtualClusterUpdate,
options?: VirtualClustersUpdateOptionalParams
): Promise {
const poller = await this.beginUpdate(
resourceGroupName,
virtualClusterName,
parameters,
options
);
return poller.pollUntilDone();
}
/**
* Synchronizes the DNS server settings used by the managed instances inside the given virtual cluster.
* @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 virtualClusterName The name of the virtual cluster.
* @param options The options parameters.
*/
async beginUpdateDnsServers(
resourceGroupName: string,
virtualClusterName: string,
options?: VirtualClustersUpdateDnsServersOptionalParams
): Promise<
SimplePollerLike<
OperationState,
VirtualClustersUpdateDnsServersResponse
>
> {
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, virtualClusterName, options },
spec: updateDnsServersOperationSpec
});
const poller = await createHttpPoller<
VirtualClustersUpdateDnsServersResponse,
OperationState
>(lro, {
restoreFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Synchronizes the DNS server settings used by the managed instances inside the given virtual cluster.
* @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 virtualClusterName The name of the virtual cluster.
* @param options The options parameters.
*/
async beginUpdateDnsServersAndWait(
resourceGroupName: string,
virtualClusterName: string,
options?: VirtualClustersUpdateDnsServersOptionalParams
): Promise {
const poller = await this.beginUpdateDnsServers(
resourceGroupName,
virtualClusterName,
options
);
return poller.pollUntilDone();
}
/**
* ListNext
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
nextLink: string,
options?: VirtualClustersListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ nextLink, options },
listNextOperationSpec
);
}
/**
* ListByResourceGroupNext
* @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 nextLink The nextLink from the previous successful call to the ListByResourceGroup method.
* @param options The options parameters.
*/
private _listByResourceGroupNext(
resourceGroupName: string,
nextLink: string,
options?: VirtualClustersListByResourceGroupNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, nextLink, options },
listByResourceGroupNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.Sql/virtualClusters",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.VirtualClusterListResult
},
default: {}
},
queryParameters: [Parameters.apiVersion8],
urlParameters: [Parameters.$host, Parameters.subscriptionId],
headerParameters: [Parameters.accept],
serializer
};
const listByResourceGroupOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.VirtualClusterListResult
},
default: {}
},
queryParameters: [Parameters.apiVersion8],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.VirtualCluster
},
default: {}
},
queryParameters: [Parameters.apiVersion8],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.virtualClusterName
],
headerParameters: [Parameters.accept],
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}",
httpMethod: "DELETE",
responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} },
queryParameters: [Parameters.apiVersion8],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.virtualClusterName
],
serializer
};
const updateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}",
httpMethod: "PATCH",
responses: {
200: {
bodyMapper: Mappers.VirtualCluster
},
201: {
bodyMapper: Mappers.VirtualCluster
},
202: {
bodyMapper: Mappers.VirtualCluster
},
204: {
bodyMapper: Mappers.VirtualCluster
},
default: {}
},
requestBody: Parameters.parameters89,
queryParameters: [Parameters.apiVersion8],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.virtualClusterName
],
headerParameters: [Parameters.contentType, Parameters.accept],
mediaType: "json",
serializer
};
const updateDnsServersOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}/updateManagedInstanceDnsServers",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.UpdateVirtualClusterDnsServersOperation
},
201: {
bodyMapper: Mappers.UpdateVirtualClusterDnsServersOperation
},
202: {
bodyMapper: Mappers.UpdateVirtualClusterDnsServersOperation
},
204: {
bodyMapper: Mappers.UpdateVirtualClusterDnsServersOperation
},
default: {}
},
queryParameters: [Parameters.apiVersion8],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.virtualClusterName
],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.VirtualClusterListResult
},
default: {}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};
const listByResourceGroupNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.VirtualClusterListResult
},
default: {}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};