From 656eb28bc5dc2cd56600b9688443ffe21672d7d8 Mon Sep 17 00:00:00 2001 From: Jorge Aguilera Date: Tue, 2 Jul 2024 12:34:25 +0200 Subject: [PATCH] fix nomad config issues using environment variables Signed-off-by: Jorge Aguilera --- plugins/nf-nomad/build.gradle | 1 + .../main/nextflow/nomad/config/NomadClientOpts.groovy | 9 +++++---- .../src/main/nextflow/nomad/config/NomadJobOpts.groovy | 4 ++-- .../src/test/nextflow/nomad/NomadConfigSpec.groovy | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/nf-nomad/build.gradle b/plugins/nf-nomad/build.gradle index 4c007ee..9b1eaff 100644 --- a/plugins/nf-nomad/build.gradle +++ b/plugins/nf-nomad/build.gradle @@ -96,6 +96,7 @@ dependencies { test { useJUnitPlatform() jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' + environment 'NOMAD_ADDR', 'http://test-nf-nomad' } jar { diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadClientOpts.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadClientOpts.groovy index a990c45..6c3ab85 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadClientOpts.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadClientOpts.groovy @@ -43,11 +43,12 @@ class NomadClientOpts{ sysEnv = env==null ? new HashMap(System.getenv()) : env - def tmp = (nomadClientOpts.address?.toString() ?: sysEnv.get('NOMAD_ADDR')) + def address = (nomadClientOpts.address?.toString() ?: sysEnv.get('NOMAD_ADDR')) + assert address != null, "Nomad Address is required" - if( !tmp.endsWith("/")) - tmp +="/" - this.address = tmp + API_VERSION + if( !address.endsWith("/")) + address +="/" + this.address = address + API_VERSION this.token = nomadClientOpts.token ?: sysEnv.get('NOMAD_TOKEN') //TODO: Add mTLS properties and env vars diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadJobOpts.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadJobOpts.groovy index 4c918bb..567560a 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadJobOpts.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/config/NomadJobOpts.groovy @@ -44,7 +44,7 @@ class NomadJobOpts{ NomadJobOpts(Map nomadJobOpts, Map env=null){ assert nomadJobOpts!=null - sysEnv = env==null ? new HashMap(System.getenv()) : env + sysEnv = env ?: new HashMap(System.getenv()) deleteOnCompletion = nomadJobOpts.containsKey("deleteOnCompletion") ? nomadJobOpts.deleteOnCompletion : false @@ -53,7 +53,7 @@ class NomadJobOpts{ nomadJobOpts.datacenters : nomadJobOpts.datacenters.toString().split(",")) as List).findAll{it.size()}.unique() }else{ - datacenters = List.of(sysEnv.get('NOMAD_DC')) + datacenters = (sysEnv.get('NOMAD_DC')?:"").split(",") as List } region = nomadJobOpts.region ?: sysEnv.get('NOMAD_REGION') diff --git a/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy b/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy index 916527d..e43ea9a 100644 --- a/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy +++ b/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy @@ -49,7 +49,7 @@ class NomadConfigSpec extends Specification { where: ADDRESS | EXPECTED - null | "${System.getenv('NOMAD_ADDR')}/v1" + null | "http://test-nf-nomad/v1" // see build.gradle "http://nomad" | "http://nomad/v1" }