/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */ import { BastionHostLinux , IMachineImage , IVpc , Port , } from '@aws-cdk/aws-ec2' ; import * as cdk from '@aws-cdk/core' ; import { IHost , InstanceUserDataProvider , IRenderQueue , IWorkerFleet , UsageBasedLicense , UsageBasedLicensing , WorkerInstanceFleet , } from 'aws-rfdk/deadline' ; import { HealthMonitor , IHealthMonitor , SessionManagerHelper , } from 'aws-rfdk' ; import { Asset } from '@aws-cdk/aws-s3-assets' ; import * as path from 'path' ; import { Subnets } from './subnets' ; /**
 * Properties for  ComputeTier .
  export interface ComputeTierProps extends cdk . StackProps { /**
     * The VPC to deploy resources into.
     */ readonly vpc : IVpc ; /**
     * The  IRenderQueue that Deadline Workers connect to.
      readonly renderQueue : IRenderQueue ; /**
     * The  IMachineImage to use for Workers (needs Deadline Client installed).
      readonly workerMachineImage : IMachineImage ; /**
     * The name of the EC2 keypair to associate with Worker nodes.
     */ readonly keyPairName ? : string ; /**
     * The bastion host to allow connection to Worker nodes.
     */ readonly bastion ? : BastionHostLinux ; /**
     * Licensing source for UBL for worker nodes.
     */ readonly usageBasedLicensing ? : UsageBasedLicensing ; /**
     * List of the usage-based liceses that the worker nodes will be served.
     */ readonly licenses ? : UsageBasedLicense [ ] ; } class UserDataProvider extends InstanceUserDataProvider { preCloudWatchAgent ( host ) { host . userData . addCommands ( 'echo preCloudWatchAgent' ) ; } preRenderQueueConfiguration ( host ) { host . userData . addCommands ( 'echo preRenderQueueConfiguration' ) ; } preWorkerConfiguration ( host ) { host . userData . addCommands ( 'echo preWorkerConfiguration' ) ; } postWorkerLaunch ( host ) { host . userData . addCommands ( 'echo postWorkerLaunch' ) ; if ( host . node . scope != undefined ) { const testScript = new Asset ( host . node . scope as cdk . Construct , 'SampleAsset' , { path : path . join ( __dirname , '..' , '..' , 'scripts' , 'configure_worker.sh' ) } ) ; testScript . grantRead ( host ) ; const localPath = host . userData . addS3DownloadCommand ( { bucket : testScript . bucket , bucketKey : testScript . s3ObjectKey , } ) ; host . userData . addExecuteFileCommand ( { filePath : localPath , } ) ; } } } /**
 * The computer tier consists of raw compute power. For a Deadline render farm,
 * this will be the fleet of Worker nodes that render Deadline jobs.
 */ export class ComputeTier extends cdk . Stack { /**
     * The  IWorkerFleet .
      public readonly workerFleet : IWorkerFleet ; /**
     * The  IHealthMonitor used to maintain the worker fleet.
      public readonly healthMonitor : IHealthMonitor ; /**
     * Initializes a new instance of  ComputeTier .
     *  param scope param id param props constructor ( scope , id , props ) { super ( scope , id , props ) ; this . healthMonitor = new HealthMonitor ( this , 'HealthMonitor' , { vpc : props . vpc , vpcSubnets : { subnetGroupName : Subnets . INFRASTRUCTURE . name , } , deletionProtection : false , } ) ; this . workerFleet = new WorkerInstanceFleet ( this , 'WorkerFleet' , { vpc : props . vpc , vpcSubnets : { subnetGroupName : Subnets . WORKERS . name , } , renderQueue : props . renderQueue , workerMachineImage : props . workerMachineImage , healthMonitor : this . healthMonitor , keyName : props . keyPairName , userDataProvider : new UserDataProvider ( this , 'UserDataProvider' ) , } ) ; SessionManagerHelper . grantPermissionsTo ( this . workerFleet ) ; if ( props . usageBasedLicensing && props . licenses ) { props . usageBasedLicensing . grantPortAccess ( this . workerFleet , props . licenses ) ; } if ( props . bastion ) { this . workerFleet . connections . allowFrom ( props . bastion , Port . tcp ( 22 ) ) ; } } }