/* * 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 { ScriptActions } 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, ScriptActionsListByClusterNextOptionalParams, ScriptActionsListByClusterOptionalParams, ScriptActionsListByClusterResponse, ScriptActionsDeleteOptionalParams, ScriptActionsGetExecutionDetailOptionalParams, ScriptActionsGetExecutionDetailResponse, ScriptActionsGetExecutionAsyncOperationStatusOptionalParams, ScriptActionsGetExecutionAsyncOperationStatusResponse, ScriptActionsListByClusterNextResponse } from "../models"; /// /** Class containing ScriptActions operations. */ export class ScriptActionsImpl implements ScriptActions { private readonly client: HDInsightManagementClient; /** * Initialize a new instance of the class ScriptActions class. * @param client Reference to the service client */ constructor(client: HDInsightManagementClient) { this.client = client; } /** * Lists all the persisted script actions 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?: ScriptActionsListByClusterOptionalParams ): 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?: ScriptActionsListByClusterOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: ScriptActionsListByClusterResponse; 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?: ScriptActionsListByClusterOptionalParams ): AsyncIterableIterator { for await (const page of this.listByClusterPagingPage( resourceGroupName, clusterName, options )) { yield* page; } } /** * Deletes a specified persisted script action of the cluster. * @param resourceGroupName The name of the resource group. * @param clusterName The name of the cluster. * @param scriptName The name of the script. * @param options The options parameters. */ delete( resourceGroupName: string, clusterName: string, scriptName: string, options?: ScriptActionsDeleteOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, clusterName, scriptName, options }, deleteOperationSpec ); } /** * Lists all the persisted script actions 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?: ScriptActionsListByClusterOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, clusterName, options }, listByClusterOperationSpec ); } /** * Gets the script execution detail for the given script execution ID. * @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. */ getExecutionDetail( resourceGroupName: string, clusterName: string, scriptExecutionId: string, options?: ScriptActionsGetExecutionDetailOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, clusterName, scriptExecutionId, options }, getExecutionDetailOperationSpec ); } /** * Gets the async operation status of execution operation. * @param resourceGroupName The name of the resource group. * @param clusterName The name of the cluster. * @param operationId The long running operation id. * @param options The options parameters. */ getExecutionAsyncOperationStatus( resourceGroupName: string, clusterName: string, operationId: string, options?: ScriptActionsGetExecutionAsyncOperationStatusOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, clusterName, operationId, options }, getExecutionAsyncOperationStatusOperationSpec ); } /** * 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?: ScriptActionsListByClusterNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, clusterName, nextLink, options }, listByClusterNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/scriptActions/{scriptName}", httpMethod: "DELETE", responses: { 200: {}, 204: {}, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.clusterName, Parameters.scriptName ], headerParameters: [Parameters.accept], serializer }; const listByClusterOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/scriptActions", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ScriptActionsList }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.clusterName ], headerParameters: [Parameters.accept], serializer }; const getExecutionDetailOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/scriptExecutionHistory/{scriptExecutionId}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.RuntimeScriptActionDetail }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.clusterName, Parameters.scriptExecutionId ], headerParameters: [Parameters.accept], serializer }; const getExecutionAsyncOperationStatusOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/executeScriptActions/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 ], headerParameters: [Parameters.accept], serializer }; const listByClusterNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ScriptActionsList }, default: { bodyMapper: Mappers.ErrorResponse } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.clusterName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };