constructor()

in packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts [433:539]


  constructor(scope: Construct, id: string, props: WorkerInstanceFleetProps) {
    super(scope, id);

    this.validateProps(props);

    const minCapacity = props.minCapacity ?? 1;
    const signals = minCapacity > 0 ? Signals.waitForMinCapacity({
      timeout: WorkerInstanceFleet.RESOURCE_SIGNAL_TIMEOUT,
    }) : undefined;
    if (signals === undefined) {
      Annotations.of(this).addWarning('Deploying with 0 minimum capacity. If there is an error in the EC2 UserData for this fleet, then your stack deployment will not fail. Watch for errors in your CloudWatch logs.');
    }

    const vpcSubnets = props.vpcSubnets ? props.vpcSubnets : {
      subnetType: SubnetType.PRIVATE_WITH_EGRESS,
    };

    // Launching the fleet with deadline workers.
    this.fleet = new AutoScalingGroup(this, 'Default', {
      vpc: props.vpc,
      instanceType: (props.instanceType ? props.instanceType : InstanceType.of(InstanceClass.T3, InstanceSize.LARGE)),
      machineImage: props.workerMachineImage,
      keyName: props.keyName,
      vpcSubnets,
      securityGroup: props.securityGroup,
      minCapacity,
      maxCapacity: props.maxCapacity,
      desiredCapacity: props.desiredCapacity,
      signals,
      healthCheck: HealthCheck.elb({
        grace: WorkerInstanceFleet.DEFAULT_HEALTH_CHECK_INTERVAL,
      }),
      role: props.role,
      spotPrice: props.spotPrice?.toString(),
      blockDevices: props.blockDevices,
      userData: props.userData,
    });

    this.targetCapacity = parseInt((this.fleet.node.defaultChild as CfnAutoScalingGroup).maxSize, 10);
    this.targetScope = this;
    this.targetToMonitor = this.fleet;
    this.targetCapacityMetric = new Metric({
      namespace: 'AWS/AutoScaling',
      metricName: 'GroupDesiredCapacity',
      dimensionsMap: {
        AutoScalingGroupName: this.fleet.autoScalingGroupName,
      },
      label: 'GroupDesiredCapacity',
    });
    this.targetUpdatePolicy = new Policy(this, 'ASGUpdatePolicy', {
      statements: [new PolicyStatement({
        actions: ['autoscaling:UpdateAutoScalingGroup'],
        resources: [this.fleet.autoScalingGroupArn],
      })],
    });

    (this.fleet.node.defaultChild as CfnAutoScalingGroup).metricsCollection = [{
      granularity: '1Minute',
      metrics: ['GroupDesiredCapacity'],
    }];

    this.grantPrincipal = this.fleet.grantPrincipal;
    this.connections = this.fleet.connections;

    // Configure the health monitoring if provided.
    // Note: This must be done *BEFORE* configuring the worker. We rely on the worker configuration
    // script restarting the launcher.
    this.configureHealthMonitor(props);

    const workerConfig = new WorkerInstanceConfiguration(this, id, {
      worker: this.fleet,
      cloudWatchLogSettings: {
        logGroupPrefix: WorkerInstanceFleet.DEFAULT_LOG_GROUP_PREFIX,
        ...props.logGroupProps,
      },
      renderQueue: props.renderQueue,
      workerSettings: props,
      userDataProvider: props.userDataProvider,
    });
    this.listeningPorts = Port.tcpRange(
      workerConfig.listenerPort,
      workerConfig.listenerPort + WorkerInstanceFleet.MAX_WORKERS_PER_HOST,
    );

    if (props.renderQueue.repository.secretsManagementSettings.enabled) {
      if (!props.vpcSubnets) {
        Annotations.of(this).addWarning(
          'Deadline Secrets Management is enabled on the Repository and VPC subnets have not been supplied. Using dedicated subnets is recommended. See https://github.com/aws/aws-rfdk/blobs/release/packages/aws-rfdk/lib/deadline/README.md#using-dedicated-subnets-for-deadline-components',
        );
      }
      props.renderQueue.configureSecretsManagementAutoRegistration({
        vpc: props.vpc,
        vpcSubnets,
        role: SecretsManagementRole.CLIENT,
        registrationStatus: SecretsManagementRegistrationStatus.REGISTERED,
        dependent: this.fleet,
      });
    }

    // Updating the user data with successful cfn-signal commands.
    if (signals) {
      this.fleet.userData.addSignalOnExitCommand(this.fleet);
    }

    // Tag deployed resources with RFDK meta-data
    tagConstruct(this);
  }