"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.MultiNodeJobDefinition=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),batch_generated_1=require("./batch.generated"),ecs_job_definition_1=require("./ecs-job-definition"),job_definition_base_1=require("./job-definition-base"),core_1=require("../../core");class MultiNodeJobDefinition extends job_definition_base_1.JobDefinitionBase{static fromJobDefinitionArn(scope,id,jobDefinitionArn){const jobDefinitionName=core_1.Stack.of(scope).splitArn(jobDefinitionArn,core_1.ArnFormat.SLASH_RESOURCE_NAME).resourceName;class Import extends job_definition_base_1.JobDefinitionBase{constructor(){super(...arguments),this.jobDefinitionArn=jobDefinitionArn,this.jobDefinitionName=jobDefinitionName,this.enabled=!0}}return new Import(scope,id)}constructor(scope,id,props){super(scope,id,props);try{jsiiDeprecationWarnings.aws_cdk_lib_aws_batch_MultiNodeJobDefinitionProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,MultiNodeJobDefinition),error}this.containers=props.containers??[],this.mainNode=props.mainNode,this.instanceType=props.instanceType,this.propagateTags=props?.propagateTags;const resource=new batch_generated_1.CfnJobDefinition(this,"Resource",{...(0,job_definition_base_1.baseJobDefinitionProperties)(this),type:"multinode",jobDefinitionName:props.jobDefinitionName,propagateTags:this.propagateTags,nodeProperties:{mainNode:this.mainNode??0,nodeRangeProperties:core_1.Lazy.any({produce:()=>this.containers.map(container=>({targetNodes:container.startNode+":"+container.endNode,container:{...container.container._renderContainerDefinition(),instanceType:this.instanceType.toString()}}))}),numNodes:core_1.Lazy.number({produce:()=>computeNumNodes(this.containers)})},platformCapabilities:[ecs_job_definition_1.Compatibility.EC2]});this.jobDefinitionArn=this.getResourceArnAttribute(resource.ref,{service:"batch",resource:"job-definition",resourceName:this.physicalName}),this.jobDefinitionName=this.getResourceNameAttribute(resource.ref),this.node.addValidation({validate:()=>validateContainers(this.containers)})}addContainer(container){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_batch_MultiNodeContainer(container)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addContainer),error}this.containers.push(container)}}exports.MultiNodeJobDefinition=MultiNodeJobDefinition,_a=JSII_RTTI_SYMBOL_1,MultiNodeJobDefinition[_a]={fqn:"aws-cdk-lib.aws_batch.MultiNodeJobDefinition",version:"2.96.1"};function computeNumNodes(containers){let result=0;for(const container of containers)result+=container.endNode-container.startNode+1;return result}function validateContainers(containers){return containers.length===0?["multinode job has no containers!"]:[]}
