From 13a53fd2874082f700500f9aa38437bab79f7348 Mon Sep 17 00:00:00 2001 From: alexiswl <8197659+alexiswl@users.noreply.github.com> Date: Thu, 2 May 2024 08:48:19 +1000 Subject: [PATCH] Use icav2 construct to handle cttso v2 statechanges --- config/stacks/cttsov2Icav2PipelineManager.ts | 2 +- .../deploy/stack.ts | 4 +-- .../constructs/cttsov2-icav2-manager/index.ts | 35 +++++++++++++++---- .../cttso-v2-pipeline-manager/deploy/stack.ts | 10 +++--- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/config/stacks/cttsov2Icav2PipelineManager.ts b/config/stacks/cttsov2Icav2PipelineManager.ts index 74cc6f641..ff3f74f26 100644 --- a/config/stacks/cttsov2Icav2PipelineManager.ts +++ b/config/stacks/cttsov2Icav2PipelineManager.ts @@ -27,7 +27,7 @@ export const getCttsov2Icav2PipelineManagerStackProps = ( stage: AppStage ): Cttsov2Icav2PipelineManagerConfig => { return { - ssmParameterList: [cttsov2Icav2PipelineIdSSMParameterPath], + pipelineIdSsmPath: cttsov2Icav2PipelineIdSSMParameterPath, icav2CopyBatchUtilityStateMachineName: icav2CopyBatchUtilityName, cttsov2LaunchStateMachineArnSsmParameterPath: cttsov2Icav2PipelineSfnSSMArn, cttsov2LaunchStateMachineNameSsmParameterPath: cttsov2Icav2PipelineSfnSSMName, diff --git a/lib/workload/stateful/stacks/cttso-v2-pipeline-dynamo-db/deploy/stack.ts b/lib/workload/stateful/stacks/cttso-v2-pipeline-dynamo-db/deploy/stack.ts index 5322f62de..23db012bf 100644 --- a/lib/workload/stateful/stacks/cttso-v2-pipeline-dynamo-db/deploy/stack.ts +++ b/lib/workload/stateful/stacks/cttso-v2-pipeline-dynamo-db/deploy/stack.ts @@ -25,7 +25,7 @@ export class Cttsov2Icav2PipelineTable extends cdk.Stack { this, 'cttsov2_icav2_pipeline_table', { - table_name: props.dynamodbTableName, + tableName: props.dynamodbTableName, } ); @@ -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; diff --git a/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/constructs/cttsov2-icav2-manager/index.ts b/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/constructs/cttsov2-icav2-manager/index.ts index 33897e2e7..11ac76c15 100644 --- a/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/constructs/cttsov2-icav2-manager/index.ts +++ b/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/constructs/cttsov2-icav2-manager/index.ts @@ -12,6 +12,7 @@ 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 */ @@ -19,7 +20,7 @@ interface Cttsov2Icav2ManagerConstructProps { 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' @@ -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(launch_cttso_nextflow_pipeline_lambda_obj.role); - }); + props.pipelineIdSSMParameterObj.grantRead( + launch_cttso_nextflow_pipeline_lambda_obj.role + ); // generate_db_uuid_lambda_path lambda // Doesnt need any ssm parameters @@ -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(upload_samplesheet_to_cache_dir_lambda_obj.role); - }); + props.pipelineIdSSMParameterObj.grantRead( + 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( @@ -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; diff --git a/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/stack.ts b/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/stack.ts index 2e58e56a0..3e0e50577 100644 --- a/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/stack.ts +++ b/lib/workload/stateless/stacks/cttso-v2-pipeline-manager/deploy/stack.ts @@ -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; @@ -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 @@ -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'