-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Constraints (Node and Attr) (#66)
* implement ConstraintNodeSpec Signed-off-by: Jorge Aguilera <[email protected]> * implement ConstraintAttrSpec Signed-off-by: Jorge Aguilera <[email protected]> * Constraints refactor to introduce a specific models package (#68) * refactor the package organization to create a separate package for models * Refactor the test folder and add license headers * move contraintsbuilder to model Signed-off-by: Jorge Aguilera <[email protected]> * refactor and new "raw" dsl to include open constraints Signed-off-by: Jorge Aguilera <[email protected]> * iterate upon the constraint config [ci skip] * fix nomadlab typos Signed-off-by: Jorge Aguilera <[email protected]> * use cloud cache in sun-nomadlab [ci skip] --------- Signed-off-by: Jorge Aguilera <[email protected]> Co-authored-by: Abhinav Sharma <[email protected]> Co-authored-by: Abhinav Sharma <[email protected]>
- Loading branch information
1 parent
6ee5725
commit f9d8834
Showing
20 changed files
with
908 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version=0.1.1 | ||
version=0.1.2 | ||
github_organization=nextflow-io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
plugins/nf-nomad/src/main/nextflow/nomad/models/ConstraintsBuilder.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package nextflow.nomad.models | ||
|
||
import io.nomadproject.client.model.Constraint | ||
import nextflow.nomad.models.JobConstraintsAttr | ||
import nextflow.nomad.models.JobConstraintsNode | ||
import nextflow.nomad.models.JobConstraints | ||
|
||
class ConstraintsBuilder { | ||
|
||
static List<Constraint> constraintsSpecToList(JobConstraints spec){ | ||
def constraints = [] as List<Constraint> | ||
if( spec?.nodeSpecs ){ | ||
def nodes = spec.nodeSpecs | ||
?.collect({ nodeConstraints(it)}) | ||
?.flatten() as List<Constraint> | ||
constraints.addAll(nodes) | ||
} | ||
if( spec?.attrSpecs ){ | ||
def nodes = spec.attrSpecs | ||
?.collect({ attrConstraints(it)}) | ||
?.flatten() as List<Constraint> | ||
constraints.addAll(nodes) | ||
} | ||
return constraints | ||
} | ||
|
||
protected static List<Constraint> nodeConstraints(JobConstraintsNode nodeSpec){ | ||
def ret = nodeSpec.raws?.collect{ triple-> | ||
return new Constraint() | ||
.ltarget('${'+triple.left+'}') | ||
.operand(triple.middle) | ||
.rtarget(triple.right) | ||
} as List<Constraint> | ||
ret | ||
} | ||
|
||
protected static List<Constraint> attrConstraints(JobConstraintsAttr nodeSpec) { | ||
def ret = nodeSpec.raws?.collect{ triple-> | ||
return new Constraint() | ||
.ltarget('${'+triple.left+'}') | ||
.operand(triple.middle) | ||
.rtarget(triple.right) | ||
} as List<Constraint> | ||
ret | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,13 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.nomad.config | ||
package nextflow.nomad.models | ||
/** | ||
* Nomad Job Affinity Spec | ||
* | ||
* @author Jorge Aguilera <[email protected]> | ||
*/ | ||
class AffinitySpec{ | ||
class JobAffinity { | ||
|
||
private String attribute | ||
private String operator | ||
|
@@ -44,22 +44,22 @@ class AffinitySpec{ | |
return weight | ||
} | ||
|
||
AffinitySpec attribute(String attribute){ | ||
JobAffinity attribute(String attribute){ | ||
this.attribute=attribute | ||
this | ||
} | ||
|
||
AffinitySpec operator(String operator){ | ||
JobAffinity operator(String operator){ | ||
this.operator = operator | ||
this | ||
} | ||
|
||
AffinitySpec value(String value){ | ||
JobAffinity value(String value){ | ||
this.value = value | ||
this | ||
} | ||
|
||
AffinitySpec weight(int weight){ | ||
JobAffinity weight(int weight){ | ||
this.weight = weight | ||
this | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,14 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.nomad.config | ||
package nextflow.nomad.models | ||
/** | ||
* Nomad Job Constraint Spec | ||
* | ||
* @author Jorge Aguilera <[email protected]> | ||
*/ | ||
|
||
class ConstraintSpec { | ||
class JobConstraint { | ||
|
||
private String attribute | ||
private String operator | ||
|
@@ -40,17 +40,17 @@ class ConstraintSpec { | |
return value | ||
} | ||
|
||
ConstraintSpec attribute(String attribute){ | ||
JobConstraint attribute(String attribute){ | ||
this.attribute=attribute | ||
this | ||
} | ||
|
||
ConstraintSpec operator(String operator){ | ||
JobConstraint operator(String operator){ | ||
this.operator = operator | ||
this | ||
} | ||
|
||
ConstraintSpec value(String value){ | ||
JobConstraint value(String value){ | ||
this.value = value | ||
this | ||
} | ||
|
61 changes: 61 additions & 0 deletions
61
plugins/nf-nomad/src/main/nextflow/nomad/models/JobConstraints.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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.models | ||
|
||
/** | ||
* Nomad Job Constraint Spec | ||
* | ||
* @author Jorge Aguilera <[email protected]> | ||
*/ | ||
|
||
class JobConstraints { | ||
|
||
List<JobConstraintsNode> nodeSpecs = [] | ||
List<JobConstraintsAttr> attrSpecs = [] | ||
|
||
JobConstraints node(@DelegatesTo(JobConstraintsNode)Closure closure){ | ||
JobConstraintsNode constraintSpec = new JobConstraintsNode() | ||
def clone = closure.rehydrate(constraintSpec, closure.owner, closure.thisObject) | ||
clone.resolveStrategy = Closure.DELEGATE_FIRST | ||
clone() | ||
nodeSpecs << constraintSpec | ||
this | ||
} | ||
|
||
JobConstraints attr(@DelegatesTo(JobConstraintsAttr)Closure closure){ | ||
JobConstraintsAttr constraintSpec = new JobConstraintsAttr() | ||
def clone = closure.rehydrate(constraintSpec, closure.owner, closure.thisObject) | ||
clone.resolveStrategy = Closure.DELEGATE_FIRST | ||
clone() | ||
attrSpecs << constraintSpec | ||
this | ||
} | ||
|
||
void validate(){ | ||
|
||
} | ||
|
||
static JobConstraints parse(@DelegatesTo(JobConstraints)Closure closure){ | ||
JobConstraints constraintsSpec = new JobConstraints() | ||
def clone = closure.rehydrate(constraintsSpec, closure.owner, closure.thisObject) | ||
clone.resolveStrategy = Closure.DELEGATE_FIRST | ||
clone() | ||
constraintsSpec.validate() | ||
constraintsSpec | ||
} | ||
} |
Oops, something went wrong.