Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.
Closed
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
10 changes: 10 additions & 0 deletions packages/cdk/apps/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ if (customTagsJsonString) {
customTagsMap = JSON.parse(customTagsJsonString);
}

// If user specified adapter custom envs, add them to the stack parameters, so they will be persisted in SSM Parameter Store.
const customWesEnvVarsJsonString = getContextOrDefault<Maybe<string>>(app.node, "CUSTOM_WES_ENV_VARS");
if (customWesEnvVarsJsonString) {
stackParameters.push({
name: "customWesEnvVars",
value: customWesEnvVarsJsonString,
description: "JSON string of custom env vars to be used to pass to WES adapter",
});
}

new CoreStack(app, `${PRODUCT_NAME}-Core`, {
vpcId,
bucketName,
Expand Down
10 changes: 10 additions & 0 deletions packages/cdk/lib/env/context-app-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class ContextAppParameters {
* Map of custom tags to be applied to all the infrastructure in the context.
*/
public readonly customTags: { [key: string]: string };
/**
* Environment variables to be passed to
*/
public readonly customWesEnvVars?: { [key: string]: string };

constructor(node: Node) {
const instanceTypeStrings = getEnvStringListOrDefault(node, "BATCH_COMPUTE_INSTANCE_TYPES");
Expand Down Expand Up @@ -142,6 +146,12 @@ export class ContextAppParameters {
} else {
this.customTags = {};
}

const customWesEnvVars = getEnvStringOrDefault(node, "CUSTOM_WES_ENV_VARS");

if (customWesEnvVars) {
this.customWesEnvVars = JSON.parse(customWesEnvVars);
}
}

public getContextBucketPath(): string {
Expand Down
30 changes: 14 additions & 16 deletions packages/cdk/lib/stacks/engines/cromwell-engine-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class CromwellEngineConstruct extends EngineConstruct {
contextName: params.contextName,
userId: params.userId,
engineEndpoint: this.engine.loadBalancer.loadBalancerDnsName,
customEnvs: params.customWesEnvVars,
});
this.adapterLogGroup = lambda.logGroup;

Expand Down Expand Up @@ -130,21 +131,18 @@ export class CromwellEngineConstruct extends EngineConstruct {
return engine;
}

private renderAdapterLambda({ role, jobQueueArn, engineLogGroupName, projectName, contextName, userId, engineEndpoint, vpc }) {
return super.renderPythonLambda(
this,
"CromwellWesAdapterLambda",
role,
{
ENGINE_NAME: "cromwell",
ENGINE_ENDPOINT: engineEndpoint,
ENGINE_LOG_GROUP: engineLogGroupName,
JOB_QUEUE: jobQueueArn,
PROJECT_NAME: projectName,
CONTEXT_NAME: contextName,
USER_ID: userId,
},
vpc
);
private renderAdapterLambda({ role, jobQueueArn, engineLogGroupName, projectName, contextName, userId, engineEndpoint, vpc, customEnvs }) {
const environment = {
...customEnvs,
ENGINE_NAME: "cromwell",
ENGINE_ENDPOINT: engineEndpoint,
ENGINE_LOG_GROUP: engineLogGroupName,
JOB_QUEUE: jobQueueArn,
PROJECT_NAME: projectName,
CONTEXT_NAME: contextName,
USER_ID: userId,
};

return super.renderPythonLambda(this, "CromwellWesAdapterLambda", role, environment, vpc);
}
}
24 changes: 11 additions & 13 deletions packages/cdk/lib/stacks/engines/miniwdl-engine-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class MiniwdlEngineConstruct extends EngineConstruct {
jobDefinitionArn: this.miniwdlEngine.headJobDefinition.jobDefinitionArn,
rootDirS3Uri: rootDirS3Uri,
vpc: props.contextParameters.usePublicSubnets ? undefined : props.vpc,
customEnvs: props.contextParameters.customWesEnvVars,
});
this.adapterLogGroup = lambda.logGroup;

Expand Down Expand Up @@ -144,18 +145,15 @@ export class MiniwdlEngineConstruct extends EngineConstruct {
return [this.batchHead.role, this.batchWorkers.role];
}

private renderAdapterLambda({ role, jobQueueArn, jobDefinitionArn, rootDirS3Uri, vpc }) {
return super.renderPythonLambda(
this,
"MiniWDLWesAdapterLambda",
role,
{
ENGINE_NAME: ENGINE_MINIWDL,
JOB_QUEUE: jobQueueArn,
JOB_DEFINITION: jobDefinitionArn,
OUTPUT_DIR_S3_URI: rootDirS3Uri,
},
vpc
);
private renderAdapterLambda({ role, jobQueueArn, jobDefinitionArn, rootDirS3Uri, vpc, customEnvs }) {
const environment = {
...customEnvs,
ENGINE_NAME: ENGINE_MINIWDL,
JOB_QUEUE: jobQueueArn,
JOB_DEFINITION: jobDefinitionArn,
OUTPUT_DIR_S3_URI: rootDirS3Uri,
};

return super.renderPythonLambda(this, "MiniWDLWesAdapterLambda", role, environment, vpc);
}
}
24 changes: 11 additions & 13 deletions packages/cdk/lib/stacks/engines/nextflow-engine-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class NextflowEngineConstruct extends EngineConstruct {
jobDefinitionArn: this.nextflowEngine.headJobDefinition.jobDefinitionArn,
engineLogGroupName: engineLogGroup.logGroupName,
vpc: props.contextParameters.usePublicSubnets ? undefined : props.vpc,
customEnvs: props.contextParameters.customWesEnvVars,
});
this.adapterLogGroup = lambda.logGroup;

Expand All @@ -82,18 +83,15 @@ export class NextflowEngineConstruct extends EngineConstruct {
};
}

private renderAdapterLambda({ role, jobQueueArn, jobDefinitionArn, engineLogGroupName, vpc }) {
return super.renderPythonLambda(
this,
"NextflowWesAdapterLambda",
role,
{
ENGINE_NAME: "nextflow",
JOB_QUEUE: jobQueueArn,
JOB_DEFINITION: jobDefinitionArn,
ENGINE_LOG_GROUP: engineLogGroupName,
},
vpc
);
private renderAdapterLambda({ role, jobQueueArn, jobDefinitionArn, engineLogGroupName, vpc, customEnvs }) {
const environment = {
...customEnvs,
ENGINE_NAME: "nextflow",
JOB_QUEUE: jobQueueArn,
JOB_DEFINITION: jobDefinitionArn,
ENGINE_LOG_GROUP: engineLogGroupName,
};

return super.renderPythonLambda(this, "NextflowWesAdapterLambda", role, environment, vpc);
}
}
32 changes: 15 additions & 17 deletions packages/cdk/lib/stacks/engines/snakemake-engine-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class SnakemakeEngineConstruct extends EngineConstruct {
taskQueueArn: this.batchWorkers.jobQueue.jobQueueArn,
fsapId: this.snakemakeEngine.fsap.accessPointId,
outputBucket: params.getEngineBucketPath(),
customEnvs: contextParameters.customWesEnvVars,
});
this.adapterLogGroup = lambda.logGroup;

Expand Down Expand Up @@ -173,22 +174,19 @@ export class SnakemakeEngineConstruct extends EngineConstruct {
});
}

private renderAdapterLambda({ vpc, role, jobQueueArn, jobDefinitionArn, taskQueueArn, workflowRoleArn, fsapId, outputBucket }) {
return super.renderPythonLambda(
this,
"SnakemakeWesAdapterLambda",
role,
{
ENGINE_NAME: "snakemake",
JOB_QUEUE: jobQueueArn,
JOB_DEFINITION: jobDefinitionArn,
TASK_QUEUE: taskQueueArn,
WORKFLOW_ROLE: workflowRoleArn,
FSAP_ID: fsapId,
OUTPUT_DIR_S3_URI: outputBucket,
TIME: Date.now().toString(),
},
vpc
);
private renderAdapterLambda({ vpc, role, jobQueueArn, jobDefinitionArn, taskQueueArn, workflowRoleArn, fsapId, outputBucket, customEnvs }) {
const environment = {
...customEnvs,
ENGINE_NAME: "snakemake",
JOB_QUEUE: jobQueueArn,
JOB_DEFINITION: jobDefinitionArn,
TASK_QUEUE: taskQueueArn,
WORKFLOW_ROLE: workflowRoleArn,
FSAP_ID: fsapId,
OUTPUT_DIR_S3_URI: outputBucket,
TIME: Date.now().toString(),
};

return super.renderPythonLambda(this, "SnakemakeWesAdapterLambda", role, environment, vpc);
}
}
12 changes: 12 additions & 0 deletions packages/cli/internal/pkg/aws/cdk/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (client Client) Bootstrap(appDir string, context []string, executionName st
// Add AGC version and custom tags to the bootstrap stack.
agcVersionKey := constants.AgcVersionEnvKey + "="
customTagsKey := constants.CustomTagEnvKey + "="
customWesEnvVarsKey := constants.CustomWesEnvVarEnvKey + "="
for _, c := range context {
if strings.HasPrefix(c, agcVersionKey) {
version := strings.TrimPrefix(c, agcVersionKey)
Expand All @@ -38,6 +39,17 @@ func (client Client) Bootstrap(appDir string, context []string, executionName st
cmdArgs = append(cmdArgs, "--tags", fmt.Sprintf("%s=%s", k, v))
}
}
if strings.HasPrefix(c, customWesEnvVarsKey) {
jsonStr := strings.TrimPrefix(c, customWesEnvVarsKey)
customWesEnvVarsMap := make(map[string]interface{})
err := json.Unmarshal([]byte(jsonStr), &customWesEnvVarsMap)
if err != nil {
return nil, err
}
for k, v := range customWesEnvVarsMap {
cmdArgs = append(cmdArgs, "--customWesEnvVars", fmt.Sprintf("%s=%s", k, v))
}
}
}

cmdArgs = appendContextArguments(cmdArgs, context)
Expand Down
14 changes: 11 additions & 3 deletions packages/cli/internal/pkg/aws/ssm/get_common_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
)

const (
parameterPrefix = "/agc/_common"
outputBucketParameter = "bucket"
customTagsParameter = "customTags"
parameterPrefix = "/agc/_common"
outputBucketParameter = "bucket"
customTagsParameter = "customTags"
customWesEnvVarsParameter = "customWesEnvVars"
)

func (c *Client) GetCommonParameter(parameterSuffix string) (string, error) {
Expand Down Expand Up @@ -40,3 +41,10 @@ func (c *Client) GetCustomTags() string {
tags, _ := c.GetCommonParameter(customTagsParameter)
return tags
}

func (c *Client) GetCustomWesEnvVars() string {
// Adapter custom envs may not exist, so ignore the error

customWesEnvVars, _ := c.GetCommonParameter(customWesEnvVarsParameter)
return customWesEnvVars
}
12 changes: 12 additions & 0 deletions packages/cli/internal/pkg/aws/ssm/get_common_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@ func TestClient_GetCustomTags_ExpectedValue(t *testing.T) {
actual := client.GetCustomTags()
assert.Equal(t, tags, actual)
}

func TestClient_GetCustomWesEnvVars_ExpectedValue(t *testing.T) {
customWesEnvVars := "customWesEnvVars"
mockSsm := new(ssmMockClient)
client := &Client{mockSsm}
ctx := context.Background()
mockSsm.On("GetParameter", ctx, &ssm.GetParameterInput{Name: aws.String("/agc/_common/customWesEnvVars")}).
Return(&ssm.GetParameterOutput{Parameter: &types.Parameter{Value: aws.String(customWesEnvVars)}}, nil)

actual := client.GetCustomWesEnvVars()
assert.Equal(t, customWesEnvVars, actual)
}
1 change: 1 addition & 0 deletions packages/cli/internal/pkg/aws/ssm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Interface interface {
GetOutputBucket() (string, error)
GetCommonParameter(parameterSuffix string) (string, error)
GetCustomTags() string
GetCustomWesEnvVars() string
}

type ssmInterface interface {
Expand Down
22 changes: 18 additions & 4 deletions packages/cli/internal/pkg/cli/account_activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
accountVpcFlag = "vpc"
publicSubnetsFlag = "usePublicSubnets"
accountTagsFlag = "tags"
accountCustomWesEnvVarsFlag = "customWesEnvVars"
accountBucketFlagDescription = `The name of an S3 bucket that AGC will use to store its data.
An autogenerated name will be used if not specified. A new bucket will be created if the bucket does not exist.`
accountVpcFlagDescription = `The ID of a VPC that AGC will run in.
Expand All @@ -41,17 +42,21 @@ You must enable the usePublicSubnets option in your project context if you use t
accountTagsDescription = `A list of comma separated tags to be applied to all AGC resources in this account
(i.e. --tags "k1=v1","k2=v2"). Each key-value pair must be quoted as shown in the example,
otherwise the parsing will fail.`
customWesEnvVarsDescription = `A list of comma separated WES adapter custom env vars to be passed to WES adapter
(i.e. --customWesEnvVars "k1=v1","k2=v2","k3=[{ \"k4\": { \"k5\": \"v5\" } }]").
Each key-value pair must be quoted as shown in the example, otherwise the parsing will fail.`
cdkCoreDir = ".agc/cdk/apps/core"
bucketPrefix = "agc"
activateKey = "activate"
bootstrapKey = "bootstrap"
)

type accountActivateVars struct {
bucketName string
vpcId string
publicSubnets bool
customTags map[string]string
bucketName string
vpcId string
publicSubnets bool
customTags map[string]string
customWesEnvVars map[string]string
}

type accountActivateOpts struct {
Expand Down Expand Up @@ -135,6 +140,14 @@ func (o accountActivateOpts) generateEnvVars() ([]string, error) {
environmentVars = append(environmentVars, fmt.Sprintf("%s=%s", constants.CustomTagEnvKey, string(jsonBytes)))
}

if o.customWesEnvVars != nil {
jsonBytes, err := json.Marshal(o.customWesEnvVars)
if err != nil {
return nil, err
}
environmentVars = append(environmentVars, fmt.Sprintf("%s=%s", constants.CustomWesEnvVarEnvKey, string(jsonBytes)))
}

vpcId, err := o.getVpcId()
if err != nil {
return nil, err
Expand Down Expand Up @@ -236,5 +249,6 @@ Activate AGC in your AWS account with a custom S3 bucket and VPC.
cmd.Flags().StringVar(&vars.vpcId, accountVpcFlag, "", accountVpcFlagDescription)
cmd.Flags().BoolVar(&vars.publicSubnets, publicSubnetsFlag, false, publicSubnetsFlagDescription)
cmd.Flags().StringToStringVar(&vars.customTags, accountTagsFlag, nil, accountTagsDescription)
cmd.Flags().StringToStringVar(&vars.customWesEnvVars, accountCustomWesEnvVarsFlag, nil, customWesEnvVarsDescription)
return cmd
}
1 change: 1 addition & 0 deletions packages/cli/internal/pkg/cli/context/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
testUserEmail = "[email protected]"
testUserId = "bender123"
testTags = "{\"k1\":\"v1\",\"k2\":\"v2\"}"
testCustomWesEnvVars = "{\"k1\":\"v1\",\"k2\":\"v2\"}"
)

var (
Expand Down
28 changes: 15 additions & 13 deletions packages/cli/internal/pkg/cli/context/context_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const (
)

type contextEnvironment struct {
ProjectName string
ContextName string
UserId string
UserEmail string
OutputBucketName string
CustomTagsJson string
ProjectName string
ContextName string
UserId string
UserEmail string
OutputBucketName string
CustomTagsJson string
CustomWesEnvVarsJson string

EngineName string
FilesystemType string
Expand All @@ -42,13 +43,14 @@ type contextEnvironment struct {

func (input contextEnvironment) ToEnvironmentList() []string {
return environmentMapToList(map[string]string{
"PROJECT": input.ProjectName,
"CONTEXT": input.ContextName,
"USER_ID": input.UserId,
"USER_EMAIL": input.UserEmail,
"OUTPUT_BUCKET": input.OutputBucketName,
"AGC_VERSION": version.Version,
"CUSTOM_TAGS": input.CustomTagsJson,
"PROJECT": input.ProjectName,
"CONTEXT": input.ContextName,
"USER_ID": input.UserId,
"USER_EMAIL": input.UserEmail,
"OUTPUT_BUCKET": input.OutputBucketName,
"AGC_VERSION": version.Version,
"CUSTOM_TAGS": input.CustomTagsJson,
"CUSTOM_WES_ENV_VARS": input.CustomWesEnvVarsJson,

"ENGINE_NAME": input.EngineName,
"FILESYSTEM_TYPE": input.FilesystemType,
Expand Down
Loading