/* * 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 { JobExecutions } 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 { JobExecution, JobExecutionsListByAgentNextOptionalParams, JobExecutionsListByAgentOptionalParams, JobExecutionsListByAgentResponse, JobExecutionsListByJobNextOptionalParams, JobExecutionsListByJobOptionalParams, JobExecutionsListByJobResponse, JobExecutionsCancelOptionalParams, JobExecutionsCreateOptionalParams, JobExecutionsCreateResponse, JobExecutionsGetOptionalParams, JobExecutionsGetResponse, JobExecutionsCreateOrUpdateOptionalParams, JobExecutionsCreateOrUpdateResponse, JobExecutionsListByAgentNextResponse, JobExecutionsListByJobNextResponse } from "../models"; /// /** Class containing JobExecutions operations. */ export class JobExecutionsImpl implements JobExecutions { private readonly client: SqlManagementClient; /** * Initialize a new instance of the class JobExecutions class. * @param client Reference to the service client */ constructor(client: SqlManagementClient) { this.client = client; } /** * Lists all executions in a job agent. * @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 jobAgentName The name of the job agent. * @param options The options parameters. */ public listByAgent( resourceGroupName: string, serverName: string, jobAgentName: string, options?: JobExecutionsListByAgentOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByAgentPagingAll( resourceGroupName, serverName, jobAgentName, 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.listByAgentPagingPage( resourceGroupName, serverName, jobAgentName, options, settings ); } }; } private async *listByAgentPagingPage( resourceGroupName: string, serverName: string, jobAgentName: string, options?: JobExecutionsListByAgentOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: JobExecutionsListByAgentResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByAgent( resourceGroupName, serverName, jobAgentName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByAgentNext( resourceGroupName, serverName, jobAgentName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByAgentPagingAll( resourceGroupName: string, serverName: string, jobAgentName: string, options?: JobExecutionsListByAgentOptionalParams ): AsyncIterableIterator { for await (const page of this.listByAgentPagingPage( resourceGroupName, serverName, jobAgentName, options )) { yield* page; } } /** * Lists a job's executions. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job to get. * @param options The options parameters. */ public listByJob( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, options?: JobExecutionsListByJobOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByJobPagingAll( resourceGroupName, serverName, jobAgentName, jobName, 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.listByJobPagingPage( resourceGroupName, serverName, jobAgentName, jobName, options, settings ); } }; } private async *listByJobPagingPage( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, options?: JobExecutionsListByJobOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: JobExecutionsListByJobResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByJob( resourceGroupName, serverName, jobAgentName, jobName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByJobNext( resourceGroupName, serverName, jobAgentName, jobName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByJobPagingAll( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, options?: JobExecutionsListByJobOptionalParams ): AsyncIterableIterator { for await (const page of this.listByJobPagingPage( resourceGroupName, serverName, jobAgentName, jobName, options )) { yield* page; } } /** * Lists all executions in a job agent. * @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 jobAgentName The name of the job agent. * @param options The options parameters. */ private _listByAgent( resourceGroupName: string, serverName: string, jobAgentName: string, options?: JobExecutionsListByAgentOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, jobAgentName, options }, listByAgentOperationSpec ); } /** * Requests cancellation of a job execution. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job. * @param jobExecutionId The id of the job execution to cancel. * @param options The options parameters. */ cancel( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, jobExecutionId: string, options?: JobExecutionsCancelOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options }, cancelOperationSpec ); } /** * Starts an elastic job execution. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job to get. * @param options The options parameters. */ async beginCreate( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, options?: JobExecutionsCreateOptionalParams ): Promise< SimplePollerLike< OperationState, JobExecutionsCreateResponse > > { 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, jobAgentName, jobName, options }, spec: createOperationSpec }); const poller = await createHttpPoller< JobExecutionsCreateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Starts an elastic job execution. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job to get. * @param options The options parameters. */ async beginCreateAndWait( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, options?: JobExecutionsCreateOptionalParams ): Promise { const poller = await this.beginCreate( resourceGroupName, serverName, jobAgentName, jobName, options ); return poller.pollUntilDone(); } /** * Lists a job's executions. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job to get. * @param options The options parameters. */ private _listByJob( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, options?: JobExecutionsListByJobOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, jobAgentName, jobName, options }, listByJobOperationSpec ); } /** * Gets a job execution. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job. * @param jobExecutionId The id of the job execution * @param options The options parameters. */ get( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, jobExecutionId: string, options?: JobExecutionsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options }, getOperationSpec ); } /** * Creates or updates a job execution. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job to get. * @param jobExecutionId The job execution id to create the job execution under. * @param options The options parameters. */ async beginCreateOrUpdate( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, jobExecutionId: string, options?: JobExecutionsCreateOrUpdateOptionalParams ): Promise< SimplePollerLike< OperationState, JobExecutionsCreateOrUpdateResponse > > { 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, jobAgentName, jobName, jobExecutionId, options }, spec: createOrUpdateOperationSpec }); const poller = await createHttpPoller< JobExecutionsCreateOrUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); await poller.poll(); return poller; } /** * Creates or updates a job execution. * @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 jobAgentName The name of the job agent. * @param jobName The name of the job to get. * @param jobExecutionId The job execution id to create the job execution under. * @param options The options parameters. */ async beginCreateOrUpdateAndWait( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, jobExecutionId: string, options?: JobExecutionsCreateOrUpdateOptionalParams ): Promise { const poller = await this.beginCreateOrUpdate( resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options ); return poller.pollUntilDone(); } /** * ListByAgentNext * @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 jobAgentName The name of the job agent. * @param nextLink The nextLink from the previous successful call to the ListByAgent method. * @param options The options parameters. */ private _listByAgentNext( resourceGroupName: string, serverName: string, jobAgentName: string, nextLink: string, options?: JobExecutionsListByAgentNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, jobAgentName, nextLink, options }, listByAgentNextOperationSpec ); } /** * ListByJobNext * @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 jobAgentName The name of the job agent. * @param jobName The name of the job to get. * @param nextLink The nextLink from the previous successful call to the ListByJob method. * @param options The options parameters. */ private _listByJobNext( resourceGroupName: string, serverName: string, jobAgentName: string, jobName: string, nextLink: string, options?: JobExecutionsListByJobNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, serverName, jobAgentName, jobName, nextLink, options }, listByJobNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listByAgentOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/executions", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.JobExecutionListResult }, default: {} }, queryParameters: [ Parameters.skip, Parameters.apiVersion3, Parameters.createTimeMin, Parameters.createTimeMax, Parameters.endTimeMin, Parameters.endTimeMax, Parameters.isActive, Parameters.top ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.jobAgentName ], headerParameters: [Parameters.accept], serializer }; const cancelOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/cancel", httpMethod: "POST", responses: { 200: {}, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.jobAgentName, Parameters.jobName, Parameters.jobExecutionId ], serializer }; const createOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.JobExecution }, 201: { bodyMapper: Mappers.JobExecution }, 202: { bodyMapper: Mappers.JobExecution }, 204: { bodyMapper: Mappers.JobExecution }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.jobAgentName, Parameters.jobName ], headerParameters: [Parameters.accept], serializer }; const listByJobOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.JobExecutionListResult }, default: {} }, queryParameters: [ Parameters.skip, Parameters.apiVersion3, Parameters.createTimeMin, Parameters.createTimeMax, Parameters.endTimeMin, Parameters.endTimeMax, Parameters.isActive, Parameters.top ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.jobAgentName, Parameters.jobName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.JobExecution }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.jobAgentName, Parameters.jobName, Parameters.jobExecutionId ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.JobExecution }, 201: { bodyMapper: Mappers.JobExecution }, 202: { bodyMapper: Mappers.JobExecution }, 204: { bodyMapper: Mappers.JobExecution }, default: {} }, queryParameters: [Parameters.apiVersion3], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.jobAgentName, Parameters.jobName, Parameters.jobExecutionId ], headerParameters: [Parameters.accept], serializer }; const listByAgentNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.JobExecutionListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.nextLink, Parameters.jobAgentName ], headerParameters: [Parameters.accept], serializer }; const listByJobNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.JobExecutionListResult }, default: {} }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.serverName, Parameters.nextLink, Parameters.jobAgentName, Parameters.jobName ], headerParameters: [Parameters.accept], serializer };