/*
* 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 { Applications } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { HDInsightManagementClient } from "../hDInsightManagementClient";
import { PollerLike, PollOperationState, LroEngine } from "@azure/core-lro";
import { LroImpl } from "../lroImpl";
import {
Application,
ApplicationsListByClusterNextOptionalParams,
ApplicationsListByClusterOptionalParams,
ApplicationsListByClusterResponse,
ApplicationsGetOptionalParams,
ApplicationsGetResponse,
ApplicationsCreateOptionalParams,
ApplicationsCreateResponse,
ApplicationsDeleteOptionalParams,
ApplicationsGetAzureAsyncOperationStatusOptionalParams,
ApplicationsGetAzureAsyncOperationStatusResponse,
ApplicationsListByClusterNextResponse
} from "../models";
///
/** Class containing Applications operations. */
export class ApplicationsImpl implements Applications {
private readonly client: HDInsightManagementClient;
/**
* Initialize a new instance of the class Applications class.
* @param client Reference to the service client
*/
constructor(client: HDInsightManagementClient) {
this.client = client;
}
/**
* Lists all of the applications for the HDInsight cluster.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param options The options parameters.
*/
public listByCluster(
resourceGroupName: string,
clusterName: string,
options?: ApplicationsListByClusterOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByClusterPagingAll(
resourceGroupName,
clusterName,
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.listByClusterPagingPage(
resourceGroupName,
clusterName,
options,
settings
);
}
};
}
private async *listByClusterPagingPage(
resourceGroupName: string,
clusterName: string,
options?: ApplicationsListByClusterOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: ApplicationsListByClusterResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByCluster(
resourceGroupName,
clusterName,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByClusterNext(
resourceGroupName,
clusterName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByClusterPagingAll(
resourceGroupName: string,
clusterName: string,
options?: ApplicationsListByClusterOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByClusterPagingPage(
resourceGroupName,
clusterName,
options
)) {
yield* page;
}
}
/**
* Lists all of the applications for the HDInsight cluster.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param options The options parameters.
*/
private _listByCluster(
resourceGroupName: string,
clusterName: string,
options?: ApplicationsListByClusterOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, clusterName, options },
listByClusterOperationSpec
);
}
/**
* Gets properties of the specified application.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param applicationName The constant value for the application name.
* @param options The options parameters.
*/
get(
resourceGroupName: string,
clusterName: string,
applicationName: string,
options?: ApplicationsGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, clusterName, applicationName, options },
getOperationSpec
);
}
/**
* Creates applications for the HDInsight cluster.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param applicationName The constant value for the application name.
* @param parameters The application create request.
* @param options The options parameters.
*/
async beginCreate(
resourceGroupName: string,
clusterName: string,
applicationName: string,
parameters: Application,
options?: ApplicationsCreateOptionalParams
): Promise<
PollerLike<
PollOperationState,
ApplicationsCreateResponse
>
> {
const directSendOperation = async (
args: coreClient.OperationArguments,
spec: coreClient.OperationSpec
): Promise => {
return this.client.sendOperationRequest(args, spec);
};
const sendOperation = 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 = new LroImpl(
sendOperation,
{ resourceGroupName, clusterName, applicationName, parameters, options },
createOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs,
lroResourceLocationConfig: "location"
});
await poller.poll();
return poller;
}
/**
* Creates applications for the HDInsight cluster.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param applicationName The constant value for the application name.
* @param parameters The application create request.
* @param options The options parameters.
*/
async beginCreateAndWait(
resourceGroupName: string,
clusterName: string,
applicationName: string,
parameters: Application,
options?: ApplicationsCreateOptionalParams
): Promise {
const poller = await this.beginCreate(
resourceGroupName,
clusterName,
applicationName,
parameters,
options
);
return poller.pollUntilDone();
}
/**
* Deletes the specified application on the HDInsight cluster.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param applicationName The constant value for the application name.
* @param options The options parameters.
*/
async beginDelete(
resourceGroupName: string,
clusterName: string,
applicationName: string,
options?: ApplicationsDeleteOptionalParams
): Promise, void>> {
const directSendOperation = async (
args: coreClient.OperationArguments,
spec: coreClient.OperationSpec
): Promise => {
return this.client.sendOperationRequest(args, spec);
};
const sendOperation = 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 = new LroImpl(
sendOperation,
{ resourceGroupName, clusterName, applicationName, options },
deleteOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs,
lroResourceLocationConfig: "location"
});
await poller.poll();
return poller;
}
/**
* Deletes the specified application on the HDInsight cluster.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param applicationName The constant value for the application name.
* @param options The options parameters.
*/
async beginDeleteAndWait(
resourceGroupName: string,
clusterName: string,
applicationName: string,
options?: ApplicationsDeleteOptionalParams
): Promise {
const poller = await this.beginDelete(
resourceGroupName,
clusterName,
applicationName,
options
);
return poller.pollUntilDone();
}
/**
* Gets the async operation status.
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param applicationName The constant value for the application name.
* @param operationId The long running operation id.
* @param options The options parameters.
*/
getAzureAsyncOperationStatus(
resourceGroupName: string,
clusterName: string,
applicationName: string,
operationId: string,
options?: ApplicationsGetAzureAsyncOperationStatusOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, clusterName, applicationName, operationId, options },
getAzureAsyncOperationStatusOperationSpec
);
}
/**
* ListByClusterNext
* @param resourceGroupName The name of the resource group.
* @param clusterName The name of the cluster.
* @param nextLink The nextLink from the previous successful call to the ListByCluster method.
* @param options The options parameters.
*/
private _listByClusterNext(
resourceGroupName: string,
clusterName: string,
nextLink: string,
options?: ApplicationsListByClusterNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, clusterName, nextLink, options },
listByClusterNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByClusterOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/applications",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ApplicationListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.clusterName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/applications/{applicationName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Application
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.clusterName,
Parameters.applicationName
],
headerParameters: [Parameters.accept],
serializer
};
const createOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/applications/{applicationName}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.Application
},
201: {
bodyMapper: Mappers.Application
},
202: {
bodyMapper: Mappers.Application
},
204: {
bodyMapper: Mappers.Application
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
requestBody: Parameters.parameters8,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.clusterName,
Parameters.applicationName
],
headerParameters: [Parameters.contentType, Parameters.accept],
mediaType: "json",
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/applications/{applicationName}",
httpMethod: "DELETE",
responses: {
200: {},
201: {},
202: {},
204: {},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.clusterName,
Parameters.applicationName
],
headerParameters: [Parameters.accept],
serializer
};
const getAzureAsyncOperationStatusOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/applications/{applicationName}/azureasyncoperations/{operationId}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.AsyncOperationResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.clusterName,
Parameters.operationId,
Parameters.applicationName
],
headerParameters: [Parameters.accept],
serializer
};
const listByClusterNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ApplicationListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.clusterName,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};