"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.BatchSubmitJob=void 0;const jsiiDeprecationWarnings=require("../../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),iam=require("../../../aws-iam"),sfn=require("../../../aws-stepfunctions"),core_1=require("../../../core"),task_utils_1=require("../private/task-utils");class BatchSubmitJob extends sfn.TaskStateBase{constructor(scope,id,props){var _b,_c;super(scope,id,props),this.props=props;try{jsiiDeprecationWarnings.aws_cdk_lib_aws_stepfunctions_tasks_BatchSubmitJobProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.constructor),error}if(this.integrationPattern=(_b=props.integrationPattern)!==null&&_b!==void 0?_b:sfn.IntegrationPattern.RUN_JOB,task_utils_1.validatePatternSupported(this.integrationPattern,BatchSubmitJob.SUPPORTED_INTEGRATION_PATTERNS),core_1.withResolved(props.arraySize,arraySize=>{if(arraySize!==void 0&&(arraySize<2||arraySize>1e4))throw new Error(`arraySize must be between 2 and 10,000. Received ${arraySize}.`)}),props.dependsOn&&props.dependsOn.length>20)throw new Error(`dependencies must be 20 or less. Received ${props.dependsOn.length}.`);core_1.withResolved(props.attempts,attempts=>{if(attempts!==void 0&&(attempts<1||attempts>10))throw new Error(`attempts must be between 1 and 10. Received ${attempts}.`)}),props.timeout!==void 0&&core_1.withResolved(props.timeout.toSeconds(),timeout=>{if(timeout<60)throw new Error(`attempt duration must be greater than 60 seconds. Received ${timeout} seconds.`)}),!((_c=props.containerOverrides)===null||_c===void 0)&&_c.environment&&Object.keys(props.containerOverrides.environment).forEach(key=>{if(key.match(/^AWS_BATCH/))throw new Error(`Invalid environment variable name: ${key}. Environment variable names starting with 'AWS_BATCH' are reserved.`)}),this.taskPolicies=this.configurePolicyStatements()}_renderTask(){var _b;return{Resource:task_utils_1.integrationResourceArn("batch","submitJob",this.integrationPattern),Parameters:sfn.FieldUtils.renderObject({JobDefinition:this.props.jobDefinitionArn,JobName:this.props.jobName,JobQueue:this.props.jobQueueArn,Parameters:(_b=this.props.payload)===null||_b===void 0?void 0:_b.value,ArrayProperties:this.props.arraySize!==void 0?{Size:this.props.arraySize}:void 0,ContainerOverrides:this.props.containerOverrides?this.configureContainerOverrides(this.props.containerOverrides):void 0,DependsOn:this.props.dependsOn?this.props.dependsOn.map(jobDependency=>({JobId:jobDependency.jobId,Type:jobDependency.type})):void 0,RetryStrategy:this.props.attempts!==void 0?{Attempts:this.props.attempts}:void 0,Timeout:this.props.timeout?{AttemptDurationSeconds:this.props.timeout.toSeconds()}:void 0}),TimeoutSeconds:void 0}}configurePolicyStatements(){return[new iam.PolicyStatement({resources:[core_1.Stack.of(this).formatArn({service:"batch",resource:"job-definition",resourceName:"*"}),this.props.jobQueueArn],actions:["batch:SubmitJob"]}),new iam.PolicyStatement({resources:[core_1.Stack.of(this).formatArn({service:"events",resource:"rule/StepFunctionsGetEventsForBatchJobsRule"})],actions:["events:PutTargets","events:PutRule","events:DescribeRule"]})]}configureContainerOverrides(containerOverrides){var _b;let environment;containerOverrides.environment&&(environment=Object.entries(containerOverrides.environment).map(([key,value])=>({Name:key,Value:value})));let resources=[];return containerOverrides.gpuCount&&resources.push({Type:"GPU",Value:`${containerOverrides.gpuCount}`}),containerOverrides.memory&&resources.push({Type:"MEMORY",Value:`${containerOverrides.memory.toMebibytes()}`}),containerOverrides.vcpus&&resources.push({Type:"VCPU",Value:`${containerOverrides.vcpus}`}),{Command:containerOverrides.command,Environment:environment,InstanceType:(_b=containerOverrides.instanceType)===null||_b===void 0?void 0:_b.toString(),ResourceRequirements:resources.length?resources:void 0}}}exports.BatchSubmitJob=BatchSubmitJob,_a=JSII_RTTI_SYMBOL_1,BatchSubmitJob[_a]={fqn:"aws-cdk-lib.aws_stepfunctions_tasks.BatchSubmitJob",version:"2.21.0"},BatchSubmitJob.SUPPORTED_INTEGRATION_PATTERNS=[sfn.IntegrationPattern.REQUEST_RESPONSE,sfn.IntegrationPattern.RUN_JOB];
//# sourceMappingURL=submit-job.js.map
