Skip to content

Commit

Permalink
feat(deadline): configure worker listener port (#257)
Browse files Browse the repository at this point in the history
Fixes #190

Either a default port or a user supplied port will be configured for all
workers to listen on, for remote requests such as requsting  their log
stream. A helper method is also provided to open up the port in the worker
fleet's security group to any provided IConnectable, like another security
group or a CIDR.
  • Loading branch information
horsmand committed Dec 11, 2020
1 parent 510eb86 commit 6e518d4
Show file tree
Hide file tree
Showing 10 changed files with 1,317 additions and 377 deletions.
225 changes: 0 additions & 225 deletions packages/aws-rfdk/lib/core/test/asset-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,228 +29,3 @@ export const INSTALL_MONGODB_3_6_SCRIPT_LINUX = {
export const MONGODB_INSTANCE_3_6_SCRIPT = {
Bucket: stringLike('AssetParameters*S3Bucket352E624B'),
};

export function linuxDownloadRunScriptBoilerplate(script: { Bucket: string, Key: string }) {
return [
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
'\')\naws s3 cp \'s3://',
{Ref: script.Bucket},
'/',
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
'\' \'/tmp/',
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
'\'\n' +
'set -e\n' +
'chmod +x \'/tmp/',
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{
Ref: script.Key,
},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
'\'\n\'/tmp/',
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
];
}

export function windowsDownloadRunScriptBoilerplate(script: { Bucket: string, Key: string }) {
return [
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
'\' ) -ea 0\nRead-S3Object -BucketName \'',
{Ref: script.Bucket},
'\' -key \'',
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
'\' -file \'C:/temp/',
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
'\' -ErrorAction Stop\n&\'C:/temp/',
{
'Fn::Select': [
0,
{
'Fn::Split': [
'||',
{
Ref: script.Key,
},
],
},
],
},
{
'Fn::Select': [
1,
{
'Fn::Split': [
'||',
{Ref: script.Key},
],
},
],
},
];
}
36 changes: 35 additions & 1 deletion packages/aws-rfdk/lib/deadline/lib/worker-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as path from 'path';
import {
OperatingSystemType,
} from '@aws-cdk/aws-ec2';
import { Asset } from '@aws-cdk/aws-s3-assets';
import {
Construct,
Duration,
Expand Down Expand Up @@ -116,6 +117,16 @@ export interface WorkerSettings {
* @default - Worker is not assigned to any region
*/
readonly region?: string;

/**
* The port to configure the worker to listen on for remote commands such as
* requests for its log stream. If more than one worker is present on a single
* host, connsecutive ports will be opened, starting with the supplied port,
* up to the maximum number of workers defined by the WorkerInstanceFleet.
*
* @default 56032
*/
readonly listenerPort?: number;
}

/**
Expand Down Expand Up @@ -178,16 +189,29 @@ export interface WorkerInstanceConfigurationProps {
* environments.
*/
export class WorkerInstanceConfiguration extends Construct {
/**
* The default port to use for a worker to listen on for remote commands.
*/
private static readonly DEFAULT_LISTENER_PORT = 56032;

/**
* @inheritdoc
*/
public readonly listenerPort: number;

constructor(scope: Construct, id: string, props: WorkerInstanceConfigurationProps) {
super(scope, id);
props.userDataProvider?.preCloudWatchAgent(props.worker);
if (props.cloudwatchLogSettings) {
this.configureCloudWatchLogStream(props.worker, id, props.cloudwatchLogSettings);
}
props.userDataProvider?.preRenderQueueConfiguration(props.worker);
props.renderQueue?.configureClientInstance({ host: props.worker});
props.renderQueue?.configureClientInstance({ host: props.worker });
props.userDataProvider?.preWorkerConfiguration(props.worker);

this.listenerPort = props.workerSettings?.listenerPort ?? WorkerInstanceConfiguration.DEFAULT_LISTENER_PORT;
this.configureWorkerSettings(props.worker, id, props.workerSettings);

props.userDataProvider?.postWorkerLaunch(props.worker);
}

Expand Down Expand Up @@ -257,6 +281,14 @@ export class WorkerInstanceConfiguration extends Construct {
'scripts/',
),
});
const configureWorkerPortAsset = new Asset(this, `${id}WorkerListenerScript`, {
path: path.join(__dirname, '..', 'scripts', 'python', 'worker-listening-port.py'),
});

const configWorkerPortLocalPath = worker.userData.addS3DownloadCommand({
bucket: configureWorkerPortAsset.bucket,
bucketKey: configureWorkerPortAsset.s3ObjectKey,
});

// Converting to lower case, as groups and pools are all stored in lower case in deadline.
const groups = settings?.groups?.map(val => val.toLowerCase()).join(',') ?? '';
Expand All @@ -269,6 +301,8 @@ export class WorkerInstanceConfiguration extends Construct {
`'${pools}'`,
`'${settings?.region ?? ''}'`,
`'${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`,
this.listenerPort.toString(),
configWorkerPortLocalPath,
],
});
}
Expand Down
Loading

0 comments on commit 6e518d4

Please sign in to comment.