Skip to content

fix(glue): restore notifyDelayAfter across different job types #33842

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
100 changes: 81 additions & 19 deletions packages/@aws-cdk/aws-glue-alpha/lib/jobs/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Code } from '../code';
import { MetricType, JobState, WorkerType, GlueVersion } from '../constants';
import { IConnection } from '../connection';
import { ISecurityConfiguration } from '../security-configuration';
import { CfnJob, CfnJobProps } from 'aws-cdk-lib/aws-glue';
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';

/**
* Interface representing a new or an imported Glue Job
Expand All @@ -25,6 +27,11 @@ export interface IJob extends cdk.IResource, iam.IGrantable {
*/
readonly jobArn: string;

/**
* The IAM role associated with this job.
*/
readonly role?: iam.IRole;

/**
* Defines a CloudWatch event rule triggered when something happens with this job.
*
Expand Down Expand Up @@ -131,8 +138,20 @@ export interface ContinuousLoggingProps {
* event-driven flow using the job.
*/
export abstract class JobBase extends cdk.Resource implements IJob {
/**
* Returns the job arn
*/
protected static buildJobArn(scope: constructs.Construct, jobName: string) : string {
return cdk.Stack.of(scope).formatArn({
service: 'glue',
resource: 'job',
resourceName: jobName,
});
}

public abstract readonly jobArn: string;
public abstract readonly jobName: string;
public abstract readonly role?: iam.IRole;
public abstract readonly grantPrincipal: iam.IPrincipal;

/**
Expand Down Expand Up @@ -267,17 +286,6 @@ export abstract class JobBase extends cdk.Resource implements IJob {
private metricJobStateRule(id: string, jobState: JobState): events.Rule {
return this.node.tryFindChild(id) as events.Rule ?? this.onStateChange(id, jobState);
}

/**
* Returns the job arn
*/
protected buildJobArn(scope: constructs.Construct, jobName: string) : string {
return cdk.Stack.of(scope).formatArn({
service: 'glue',
resource: 'job',
resourceName: jobName,
});
}
}

/**
Expand Down Expand Up @@ -448,6 +456,26 @@ export interface JobProps {
* @see https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-glue-arguments.html
**/
readonly continuousLogging?: ContinuousLoggingProps;

/**
* Specifies configuration properties of a notification (optional).
* After a job run starts, the number of minutes to wait before sending a job run delay notification.
*
* @default - undefined
*/
readonly notifyDelayAfter?: cdk.Duration;

/**
* Specifies whether job run queuing is enabled for the job runs for this job.
* A value of true means job run queuing is enabled for the job runs.
* If false or not populated, the job runs will not be considered for queueing.
* If this field does not match the value set in the job run, then the value from
* the job run field will be used. This property must be set to false for flex jobs.
* If this property is enabled, maxRetries must be set to zero.
*
* @default - no job run queuing
*/
readonly jobRunQueuingEnabled?: boolean;
}

/**
Expand All @@ -466,17 +494,52 @@ export abstract class Job extends JobBase {
public static fromJobAttributes(scope: constructs.Construct, id: string, attrs: JobAttributes): IJob {
class Import extends JobBase {
public readonly jobName = attrs.jobName;
public readonly jobArn = this.buildJobArn(scope, attrs.jobName);
public readonly jobArn = Job.buildJobArn(scope, attrs.jobName);
public readonly role = attrs.role;
public readonly grantPrincipal = attrs.role ?? new iam.UnknownPrincipal({ resource: this });
}

return new Import(scope, id);
}

/**
* The IAM role Glue assumes to run this job.
*/
public readonly abstract role: iam.IRole;
* Utility method to help with creating the CfnJob resource.
* It handles common/shared JobProps, while allowing CfnJobProps overrides.
*
* @param scope the scope to create the resource in.
* @param props the JobProps to use for the resource.
* @param cfnProps the CfnJobProps overrides to use for the resource.
* @protected
*/
protected static setupJobResource(scope: constructs.Construct, props: JobProps, cfnProps: CfnJobProps) {
return new CfnJob(scope, 'Resource', {
name: props.jobName,
description: props.description,
executionProperty: props.maxConcurrentRuns ? { maxConcurrentRuns: props.maxConcurrentRuns } : undefined,
timeout: props.timeout?.toMinutes(),
connections: props.connections ? { connections: props.connections.map((connection) => connection.connectionName) } : undefined,
securityConfiguration: props.securityConfiguration?.securityConfigurationName,
maxRetries: props.jobRunQueuingEnabled ? 0 : props.maxRetries,
jobRunQueuingEnabled: props.jobRunQueuingEnabled ? props.jobRunQueuingEnabled : false,
notificationProperty: props.notifyDelayAfter ? { notifyDelayAfter: props.notifyDelayAfter.toMinutes() } : undefined,
tags: props.tags,
...cfnProps,
});
}

public readonly role?: iam.IRole;
public readonly grantPrincipal: iam.IPrincipal;

protected constructor(scope: constructs.Construct, id: string, props: JobProps) {
super(scope, id, {
physicalName: props.jobName,
});
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);

this.role = props.role;
this.grantPrincipal = props.role;
}

/**
* Check no usage of reserved arguments.
Expand All @@ -497,11 +560,10 @@ export abstract class Job extends JobBase {

/**
* Setup Continuous Logging Properties
* @param role The IAM role to use for continuous logging
* @param props The properties for continuous logging configuration
* @returns String containing the args for the continuous logging command
*/
protected setupContinuousLogging(role: iam.IRole, props: ContinuousLoggingProps | undefined) : any {
protected setupContinuousLogging(props: ContinuousLoggingProps | undefined) : any {
// If the developer has explicitly disabled continuous logging return no args
if (props && !props.enabled) {
return {};
Expand All @@ -519,7 +581,7 @@ export abstract class Job extends JobBase {
// If the developer provided a log group, add its name to the args and update the role.
if (props?.logGroup) {
args['--continuous-log-logGroup'] = props.logGroup.logGroupName;
props.logGroup.grantWrite(role);
props.logGroup.grantWrite(this);
}

if (props?.logStreamPrefix) {
Expand All @@ -534,7 +596,7 @@ export abstract class Job extends JobBase {
}

protected codeS3ObjectUrl(code: Code) {
const s3Location = code.bind(this, this.role).s3Location;
const s3Location = code.bind(this, this).s3Location;
return `s3://${s3Location.bucketName}/${s3Location.objectKey}`;
}
}
Expand Down
57 changes: 4 additions & 53 deletions packages/@aws-cdk/aws-glue-alpha/lib/jobs/pyspark-etl-job.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { CfnJob } from 'aws-cdk-lib/aws-glue';
import { Construct } from 'constructs';
import { JobType, GlueVersion, JobLanguage, PythonVersion, WorkerType } from '../constants';
import { Code } from '../code';
import { SparkJob, SparkJobProps } from './spark-job';
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
import { Job } from './job';

/**
* Properties for creating a Python Spark ETL job
Expand All @@ -16,43 +15,6 @@ export interface PySparkEtlJobProps extends SparkJobProps {
* @default - no extra files
*/
readonly extraPythonFiles?: Code[];

/**
* Additional files, such as configuration files that AWS Glue copies to the working directory of your script before executing it.
*
* @default - no extra files specified.
*
* @see https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-glue-arguments.html
*/
readonly extraFiles?: Code[];

/**
* Extra Jars S3 URL (optional)
* S3 URL where additional jar dependencies are located
* @default - no extra jar files
*/
readonly extraJars?: Code[];

/**
* Setting this value to true prioritizes the customer's extra JAR files in the classpath.
*
* @default false - priority is not given to user-provided jars
*
* @see `--user-jars-first` in https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-glue-arguments.html
*/
readonly extraJarsFirst?: boolean;

/**
* Specifies whether job run queuing is enabled for the job runs for this job.
* A value of true means job run queuing is enabled for the job runs.
* If false or not populated, the job runs will not be considered for queueing.
* If this field does not match the value set in the job run, then the value from
* the job run field will be used. This property must be set to false for flex jobs.
* If this property is enabled, maxRetries must be set to zero.
*
* @default false
*/
readonly jobRunQueuingEnabled?: boolean;
}

/**
Expand All @@ -76,19 +38,15 @@ export class PySparkEtlJob extends SparkJob {
*/
constructor(scope: Construct, id: string, props: PySparkEtlJobProps) {
super(scope, id, props);
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);

// Combine command line arguments into a single line item
const defaultArguments = {
...this.executableArguments(props),
...this.nonExecutableCommonArguments(props),
};

const jobResource = new CfnJob(this, 'Resource', {
name: props.jobName,
description: props.description,
role: this.role.roleArn,
const jobResource = Job.setupJobResource(this, props, {
role: this.role!.roleArn,
command: {
name: JobType.ETL,
scriptLocation: this.codeS3ObjectUrl(props.script),
Expand All @@ -97,18 +55,11 @@ export class PySparkEtlJob extends SparkJob {
glueVersion: props.glueVersion ?? GlueVersion.V4_0,
workerType: props.workerType ?? WorkerType.G_1X,
numberOfWorkers: props.numberOfWorkers ? props.numberOfWorkers : 10,
maxRetries: props.jobRunQueuingEnabled ? 0 : props.maxRetries,
jobRunQueuingEnabled: props.jobRunQueuingEnabled ? props.jobRunQueuingEnabled : false,
executionProperty: props.maxConcurrentRuns ? { maxConcurrentRuns: props.maxConcurrentRuns } : undefined,
timeout: props.timeout?.toMinutes(),
connections: props.connections ? { connections: props.connections.map((connection) => connection.connectionName) } : undefined,
securityConfiguration: props.securityConfiguration?.securityConfigurationName,
tags: props.tags,
defaultArguments,
});

const resourceName = this.getResourceNameAttribute(jobResource.ref);
this.jobArn = this.buildJobArn(this, resourceName);
this.jobArn = Job.buildJobArn(this, resourceName);
this.jobName = resourceName;
}

Expand Down
50 changes: 4 additions & 46 deletions packages/@aws-cdk/aws-glue-alpha/lib/jobs/pyspark-flex-etl-job.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,21 @@
import { CfnJob } from 'aws-cdk-lib/aws-glue';
import { Construct } from 'constructs';
import { JobType, GlueVersion, JobLanguage, PythonVersion, WorkerType, ExecutionClass } from '../constants';
import * as cdk from 'aws-cdk-lib/core';
import { Code } from '../code';
import { SparkJob, SparkJobProps } from './spark-job';
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
import { Job } from './job';

/**
* Properties for PySparkFlexEtlJob
*/
export interface PySparkFlexEtlJobProps extends SparkJobProps {
/**
* Specifies configuration properties of a notification (optional).
* After a job run starts, the number of minutes to wait before sending a job run delay notification.
* @default - undefined
*/
readonly notifyDelayAfter?: cdk.Duration;

/**
* Extra Python Files S3 URL (optional)
* S3 URL where additional python dependencies are located
*
* @default - no extra files
*/
readonly extraPythonFiles?: Code[];

/**
* Additional files, such as configuration files that AWS Glue copies to the working directory of your script before executing it.
*
* @default - no extra files specified.
*
* @see https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-glue-arguments.html
*/
readonly extraFiles?: Code[];

/**
* Extra Jars S3 URL (optional)
* S3 URL where additional jar dependencies are located
* @default - no extra jar files
*/
readonly extraJars?: Code[];

/**
* Setting this value to true prioritizes the customer's extra JAR files in the classpath.
*
* @default false - priority is not given to user-provided jars
*
* @see `--user-jars-first` in https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-glue-arguments.html
*/
readonly extraJarsFirst?: boolean;
}

/**
Expand Down Expand Up @@ -81,10 +48,8 @@ export class PySparkFlexEtlJob extends SparkJob {
...this.nonExecutableCommonArguments(props),
};

const jobResource = new CfnJob(this, 'Resource', {
name: props.jobName,
description: props.description,
role: this.role.roleArn,
const jobResource = Job.setupJobResource(this, props, {
role: this.role!.roleArn,
command: {
name: JobType.ETL,
scriptLocation: this.codeS3ObjectUrl(props.script),
Expand All @@ -94,20 +59,13 @@ export class PySparkFlexEtlJob extends SparkJob {
workerType: props.workerType ? props.workerType : WorkerType.G_1X,
numberOfWorkers: props.numberOfWorkers ? props.numberOfWorkers : 10,
maxRetries: props.maxRetries,
executionProperty: props.maxConcurrentRuns ? { maxConcurrentRuns: props.maxConcurrentRuns } : undefined,
notificationProperty: props.notifyDelayAfter ? { notifyDelayAfter: props.notifyDelayAfter.toMinutes() } : undefined,
timeout: props.timeout?.toMinutes(),
connections: props.connections ? { connections: props.connections.map((connection) => connection.connectionName) } : undefined,
securityConfiguration: props.securityConfiguration?.securityConfigurationName,
tags: props.tags,
executionClass: ExecutionClass.FLEX,
jobRunQueuingEnabled: false,
defaultArguments,

});

const resourceName = this.getResourceNameAttribute(jobResource.ref);
this.jobArn = this.buildJobArn(this, resourceName);
this.jobArn = Job.buildJobArn(this, resourceName);
this.jobName = resourceName;
}

Expand Down
Loading