Skip to content

Commit

Permalink
configure volume using a closure instead a map
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Aguilera <jagedn@gmail.com>
  • Loading branch information
jagedn committed Mar 1, 2024
1 parent cf6b465 commit 374996e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
41 changes: 32 additions & 9 deletions plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>)
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
}
Expand All @@ -93,16 +98,34 @@ class NomadConfig {

class VolumeSpec{

final String type
final String name
private String type
private String name

VolumeSpec(Map<String, String> 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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 374996e

Please sign in to comment.