Skip to content

Commit

Permalink
Use icav2 construct to handle cttso v2 statechanges
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiswl committed May 1, 2024
1 parent dd80758 commit c70d94c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/stacks/cttsov2Icav2PipelineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getCttsov2Icav2PipelineManagerStackProps = (
stage: AppStage
): Cttsov2Icav2PipelineManagerConfig => {
return {
ssmParameterList: [cttsov2Icav2PipelineIdSSMParameterPath],
pipelineIdSsmPath: cttsov2Icav2PipelineIdSSMParameterPath,
icav2CopyBatchUtilityStateMachineName: icav2CopyBatchUtilityName,
cttsov2LaunchStateMachineArnSsmParameterPath: cttsov2Icav2PipelineSfnSSMArn,
cttsov2LaunchStateMachineNameSsmParameterPath: cttsov2Icav2PipelineSfnSSMName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Cttsov2Icav2PipelineTable extends cdk.Stack {
this,
'cttsov2_icav2_pipeline_table',
{
table_name: props.dynamodbTableName,
tableName: props.dynamodbTableName,
}
);

Expand All @@ -37,7 +37,7 @@ export class Cttsov2Icav2PipelineTable extends cdk.Stack {
'cttsov2_icav2_pipeline_table_arn_ssm_path',
{
parameterName: props.cttsov2Icav2DynamodbTableArnSsmParameterPath,
stringValue: dynamodb_table.table_name_arn,
stringValue: dynamodb_table.tableNameArn,
}
).parameterName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import * as events_targets from 'aws-cdk-lib/aws-events-targets';
import { DefinitionBody } from 'aws-cdk-lib/aws-stepfunctions';

import { PythonFunction } from '@aws-cdk/aws-lambda-python-alpha';
import { Icav2AnalysisEventHandlerConstruct } from '../../../../../../components/dynamodb-icav2-handle-event-change-sfn';

interface Cttsov2Icav2ManagerConstructProps {
/* Stack Objects */
dynamodbTableObj: dynamodb.ITableV2;
icav2AccessTokenSecretObj: secretsManager.ISecret;
lambdaLayerObj: lambda.ILayerVersion;
icav2CopyBatchStateMachineObj: sfn.IStateMachine;
ssmParameterObjList: ssm.IStringParameter[]; // List of parameters the workflow session state machine will need access to
pipelineIdSSMParameterObj: ssm.IStringParameter; // List of parameters the workflow session state machine will need access to
eventbusObj: events.IEventBus;
/* Lambdas paths */
generateDbUuidLambdaPath: string; // __dirname + '/../../../lambdas/generate_db_uuid'
Expand Down Expand Up @@ -63,9 +64,9 @@ export class Cttsov2Icav2PipelineManagerConstruct extends Construct {
);

// Add each of the ssm parameters to the lambda role policy
props.ssmParameterObjList.forEach((ssm_parameter_obj) => {
ssm_parameter_obj.grantRead(<iam.IRole>launch_cttso_nextflow_pipeline_lambda_obj.role);
});
props.pipelineIdSSMParameterObj.grantRead(
<iam.IRole>launch_cttso_nextflow_pipeline_lambda_obj.role
);

// generate_db_uuid_lambda_path lambda
// Doesnt need any ssm parameters
Expand Down Expand Up @@ -143,9 +144,9 @@ export class Cttsov2Icav2PipelineManagerConstruct extends Construct {
);

// Add each of the ssm parameters to the lambda role policy
props.ssmParameterObjList.forEach((ssm_parameter_obj) => {
ssm_parameter_obj.grantRead(<iam.IRole>upload_samplesheet_to_cache_dir_lambda_obj.role);
});
props.pipelineIdSSMParameterObj.grantRead(
<iam.IRole>upload_samplesheet_to_cache_dir_lambda_obj.role
);

// Specify the statemachine and replace the arn placeholders with the lambda arns defined above
const stateMachine = new sfn.StateMachine(
Expand Down Expand Up @@ -228,6 +229,26 @@ export class Cttsov2Icav2PipelineManagerConstruct extends Construct {
// Allow the statemachine to submit events to the event bus
props.eventbusObj.grantPutEventsTo(stateMachine.role);

// Create statemachine for handling any state changes of the pipeline
const statechange_statemachine = new Icav2AnalysisEventHandlerConstruct(
this,
'cttso_icav2_statechange_handler',
{
// Table name //
tableName: props.dynamodbTableObj.tableName,
// Name of future statemachine
stateMachineName: 'cttsov2Icav2StateChangeHandlerSfn',
// Statemachine substitutions we need to pass
// FIXME Also not set in stone
eventBusName: props.eventbusObj.eventBusName,
detailType: 'ctTSOv2StateChange',
source: 'orcabus.cttso_v2',
// Filters
// FIXME - if the pipeline ID changes, we need to redeploy the stack?
pipelineId: props.pipelineIdSSMParameterObj.stringValue,
}
);

// Set outputs
this.cttsov2LaunchStateMachineName = stateMachine.stateMachineName;
this.cttsov2LaunchStateMachineArn = stateMachine.stateMachineArn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import path from 'path';

export interface Cttsov2Icav2PipelineManagerConfig {
icav2TokenSecretId: string; // "/icav2/umccr-prod/service-production-jwt-token-secret-arn"
ssmParameterList: string[]; // List of parameters the workflow session state machine will need access to
pipelineIdSsmPath: string; // List of parameters the workflow session state machine will need access to
icav2CopyBatchUtilityStateMachineName: string;
cttsov2LaunchStateMachineArnSsmParameterPath: string;
cttsov2LaunchStateMachineNameSsmParameterPath: string;
Expand Down Expand Up @@ -60,8 +60,10 @@ export class Cttsov2Icav2PipelineManagerStack extends cdk.Stack {
});

// Set ssm parameter object list
const ssm_parameter_obj_list = props.ssmParameterList.map((ssm_parameter_path: string) =>
ssm.StringParameter.fromStringParameterName(this, ssm_parameter_path, ssm_parameter_path)
const pipeline_id_ssm_obj_list = ssm.StringParameter.fromStringParameterName(
this,
props.pipelineIdSsmPath,
props.pipelineIdSsmPath
);

// Get event bus
Expand All @@ -73,7 +75,7 @@ export class Cttsov2Icav2PipelineManagerStack extends cdk.Stack {
icav2AccessTokenSecretObj: icav2_access_token_secret_obj,
lambdaLayerObj: lambda_layer_obj.lambdaLayerVersionObj,
icav2CopyBatchStateMachineObj: icav2_copy_batch_stack_state_machine_obj,
ssmParameterObjList: ssm_parameter_obj_list,
pipelineIdSSMParameterObj: pipeline_id_ssm_obj_list,
eventbusObj: eventbus_obj,
/* Lambdas paths */
generateDbUuidLambdaPath: path.join(__dirname, '../lambdas/generate_db_uuid'), // __dirname + '/../../../lambdas/generate_uuid'
Expand Down

0 comments on commit c70d94c

Please sign in to comment.