/* * 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 { ScriptExecutionHistory } 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 { RuntimeScriptActionDetail, ScriptExecutionHistoryListByClusterNextOptionalParams, ScriptExecutionHistoryListByClusterOptionalParams, ScriptExecutionHistoryListByClusterResponse, ScriptExecutionHistoryPromoteOptionalParams, ScriptExecutionHistoryListByClusterNextResponse } from "../models"; /// /** Class containing ScriptExecutionHistory operations. */ export class ScriptExecutionHistoryImpl implements ScriptExecutionHistory { private readonly client: HDInsightManagementClient; /** * Initialize a new instance of the class ScriptExecutionHistory class. * @param client Reference to the service client */ constructor(client: HDInsightManagementClient) { this.client = client; } /** * Lists all scripts' execution history for the specified 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?: ScriptExecutionHistoryListByClusterOptionalParams ): 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?: ScriptExecutionHistoryListByClusterOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: ScriptExecutionHistoryListByClusterResponse; 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?: ScriptExecutionHistoryListByClusterOptionalParams ): AsyncIterableIterator { for await (const page of this.listByClusterPagingPage( resourceGroupName, clusterName, options )) { yield* page; } } /** * Lists all scripts' execution history for the specified 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?: ScriptExecutionHistoryListByClusterOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, clusterName, options }, listByClusterOperationSpec ); } /** * Promotes the specified ad-hoc script execution to a persisted script. * @param resourceGroupName The name of the resource group. * @param clusterName The name of the cluster. * @param scriptExecutionId The script execution Id * @param options The options parameters. */ promote( resourceGroupName: string, clusterName: string, scriptExecutionId: string, options?: ScriptExecutionHistoryPromoteOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, clusterName, scriptExecutionId, options }, promoteOperationSpec ); } /** * 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?: ScriptExecutionHistoryListByClusterNextOptionalParams ): 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}/scriptExecutionHistory", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ScriptActionExecutionHistoryList }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.clusterName ], headerParameters: [Parameters.accept], serializer }; const promoteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/scriptExecutionHistory/{scriptExecutionId}/promote", httpMethod: "POST", responses: { 200: {}, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.clusterName, Parameters.scriptExecutionId ], headerParameters: [Parameters.accept], serializer }; const listByClusterNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ScriptActionExecutionHistoryList }, default: { bodyMapper: Mappers.ErrorResponse } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.clusterName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };