Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deadline): configure worker log listener port #257

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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