Skip to content

Commit

Permalink
Merge pull request #32 from nextflow-io/abhinav/nomad-env-vars
Browse files Browse the repository at this point in the history
Use env vars as an alternative to client config
  • Loading branch information
abhi18av authored Jun 30, 2024
2 parents aadbf42 + 0ee171e commit 5fb5039
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 236 deletions.
168 changes: 0 additions & 168 deletions plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package nextflow.nomad.config
/*
* Copyright 2023-, Stellenbosch University, South Africa
* Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package nextflow.nomad.config
/**
* Nomad Job Affinity Spec
*
* @author Jorge Aguilera <jagedn@gmail.com>
*/
class AffinitySpec{

private String attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
/*
* Copyright 2023-, Stellenbosch University, South Africa
* Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package nextflow.nomad.config
/**
* Nomad Job Constraint Spec
*
* @author Jorge Aguilera <jagedn@gmail.com>
*/

class ConstraintSpec {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023-, Stellenbosch University, South Africa
* Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nextflow.nomad.config

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j


/**
* Nomad Config
*
* @author Jorge Aguilera <jagedn@gmail.com>
* @author Abhinav Sharma <abhi18av@outlook.com>
*/

@Slf4j
@CompileStatic
class NomadClientOpts{

final static protected API_VERSION = "v1"

private Map<String,String> sysEnv

final String address
final String token

NomadClientOpts(Map nomadClientOpts, Map<String,String> env=null){
assert nomadClientOpts!=null

sysEnv = env==null ? new HashMap<String,String>(System.getenv()) : env

def tmp = (nomadClientOpts.address?.toString() ?: sysEnv.get('NOMAD_ADDR'))

if( !tmp.endsWith("/"))
tmp +="/"
this.address = tmp + API_VERSION
this.token = nomadClientOpts.token ?: sysEnv.get('NOMAD_TOKEN')

//TODO: Add mTLS properties and env vars
// https://developer.hashicorp.com/nomad/docs/commands#mtls-environment-variables
}
}
62 changes: 62 additions & 0 deletions plugins/nf-nomad/src/main/nextflow/nomad/config/NomadConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2023-, Stellenbosch University, South Africa
* Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nextflow.nomad.config

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j


/**
* Nomad Config
*
* @author Jorge Aguilera <jagedn@gmail.com>
* @author Abhinav Sharma <abhi18av@outlook.com>
*/

@Slf4j
@CompileStatic
class NomadConfig {

private NomadClientOpts clientOpts
private NomadJobOpts jobOpts
private NomadDebug debug

NomadConfig(Map nomadConfigMap) {
this.clientOpts = new NomadClientOpts((nomadConfigMap?.client ?: Collections.emptyMap()) as Map)
this.jobOpts = new NomadJobOpts((nomadConfigMap?.jobs ?: Collections.emptyMap()) as Map)
this.debug = new NomadDebug((nomadConfigMap?.debug ?: Collections.emptyMap()) as Map)
}


NomadClientOpts clientOpts() { clientOpts }

NomadJobOpts jobOpts() { jobOpts }

NomadDebug debug() { debug }

static class NomadDebug {

@Delegate
Map<String,Object> target

NomadDebug(Map<String,Object> debug) {
this.target = debug ?: Collections.<String,Object>emptyMap()
}

boolean getJson() { Boolean.valueOf( target.json as String ) }
}
}
Loading

0 comments on commit 5fb5039

Please sign in to comment.