diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy index 6390220..624efc2 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy @@ -83,8 +83,13 @@ class NomadConfig { if( dockerVolume ){ log.info "dockerVolume config will be deprecated, use volume type:'docker' name:'name' instead" } - if( nomadJobOpts.volume && nomadJobOpts.volume instanceof Map){ - volumeSpec = new VolumeSpec(nomadJobOpts.volume as Map) + if( nomadJobOpts.volume && nomadJobOpts.volume instanceof Closure){ + this.volumeSpec = new VolumeSpec() + def closure = (nomadJobOpts.volume as Closure) + def clone = closure.rehydrate(this.volumeSpec, closure.owner, closure.thisObject) + clone.resolveStrategy = Closure.DELEGATE_FIRST + clone() + this.volumeSpec.validate() }else{ volumeSpec = null } @@ -93,16 +98,34 @@ class NomadConfig { class VolumeSpec{ - final String type - final String name + private String type + private String name - VolumeSpec(Map volumeConfig){ - if( !VOLUME_TYPES.contains(volumeConfig.type) ) + String getType() { + return type + } + + String getName() { + return name + } + + VolumeSpec type(String type){ + this.type = type + this + } + + VolumeSpec name(String name){ + this.name = name + this + } + + protected validate(){ + if( !VOLUME_TYPES.contains(type) ) { throw new IllegalArgumentException("Volume type $type is not supported") - if( !volumeConfig.name ) + } + if( !this.name ){ throw new IllegalArgumentException("Volume name is required") - this.type = volumeConfig.type - this.name = volumeConfig.name + } } } } diff --git a/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy b/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy index e76eeaa..51fa952 100644 --- a/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy +++ b/plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy @@ -123,7 +123,7 @@ class NomadConfigSpec extends Specification { void "should instantiate a volume spec if specified"() { when: def config = new NomadConfig([ - jobs: [volume:[type:"docker", name:"test"]] + jobs: [volume : { type "docker" name "test" }] ]) then: @@ -133,7 +133,7 @@ class NomadConfigSpec extends Specification { when: def config2 = new NomadConfig([ - jobs: [volume:[type:"csi", name:"test"]] + jobs: [volume : { type "csi" name "test" }] ]) then: @@ -143,7 +143,7 @@ class NomadConfigSpec extends Specification { when: def config3 = new NomadConfig([ - jobs: [volume:[type:"host", name:"test"]] + jobs: [volume : { type "host" name "test" }] ]) then: @@ -153,7 +153,7 @@ class NomadConfigSpec extends Specification { when: new NomadConfig([ - jobs: [volume:[type:"not-supported", name:"test"]] + jobs: [volume : { type "not-supported" name "test" }] ]) then: diff --git a/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy b/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy index 0ed2185..3e7e69d 100644 --- a/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy +++ b/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy @@ -195,7 +195,7 @@ class NomadServiceSpec extends Specification{ address : "http://${mockWebServer.hostName}:${mockWebServer.port}" ], jobs:[ - volume: [ name:'test', type:'csi'] + volume: { type "csi" name "test" } ] ) def service = new NomadService(config)