-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor NomadService to rely on Builder classes
Signed-off-by: Abhinav Sharma <[email protected]>
- Loading branch information
Showing
15 changed files
with
517 additions
and
206 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
plugins/nf-nomad/src/main/nextflow/nomad/builders/JobBuilder.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,68 @@ | ||
/* | ||
* 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.builders | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Slf4j | ||
import io.nomadproject.client.model.Job | ||
import io.nomadproject.client.model.TaskGroup | ||
|
||
/** | ||
* | ||
* @author Abhinav Sharma <[email protected]> | ||
*/ | ||
|
||
@Slf4j | ||
@CompileStatic | ||
class JobBuilder { | ||
private Job job = new Job() | ||
|
||
JobBuilder id(String id) { | ||
job.ID = id | ||
return this | ||
} | ||
|
||
JobBuilder name(String name) { | ||
job.name = name | ||
return this | ||
} | ||
|
||
JobBuilder type(String type) { | ||
job.type = type | ||
return this | ||
} | ||
|
||
JobBuilder datacenters(List<String> datacenters) { | ||
job.datacenters = datacenters | ||
return this | ||
} | ||
|
||
JobBuilder namespace(String namespace) { | ||
job.namespace = namespace | ||
return this | ||
} | ||
|
||
JobBuilder taskGroups(List<TaskGroup> taskGroups) { | ||
job.taskGroups = taskGroups | ||
return this | ||
} | ||
|
||
Job build() { | ||
return job | ||
} | ||
} |
28 changes: 26 additions & 2 deletions
28
...ow/nomad/models/ConstraintsBuilder.groovy → ...mad/builders/JobConstraintsBuilder.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 |
---|---|---|
@@ -1,11 +1,35 @@ | ||
package nextflow.nomad.models | ||
/* | ||
* 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.builders | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Slf4j | ||
import io.nomadproject.client.model.Constraint | ||
import nextflow.nomad.models.JobConstraintsAttr | ||
import nextflow.nomad.models.JobConstraintsNode | ||
import nextflow.nomad.models.JobConstraints | ||
/** | ||
* | ||
* @author Abhinav Sharma <[email protected]> | ||
**/ | ||
|
||
class ConstraintsBuilder { | ||
@Slf4j | ||
@CompileStatic | ||
class JobConstraintsBuilder { | ||
|
||
static List<Constraint> constraintsSpecToList(JobConstraints spec){ | ||
def constraints = [] as List<Constraint> | ||
|
61 changes: 61 additions & 0 deletions
61
plugins/nf-nomad/src/main/nextflow/nomad/builders/JobSpreadsBuilder.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.builders | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Slf4j | ||
import io.nomadproject.client.model.Spread | ||
import io.nomadproject.client.model.SpreadTarget | ||
import nextflow.nomad.models.JobSpreads | ||
|
||
/** | ||
* Nomad Job Spread Spec Builder | ||
* | ||
* @author Jorge Aguilera <[email protected]> | ||
*/ | ||
|
||
@Slf4j | ||
@CompileStatic | ||
class JobSpreadsBuilder { | ||
|
||
static List<Spread> spreadsSpecToList(JobSpreads spreads){ | ||
def ret = [] as List<Spread> | ||
|
||
spreads.raws.each{raw-> | ||
def targets = [] as List<SpreadTarget> | ||
raw.right.each { | ||
targets.add( new SpreadTarget(value: it.left, percent: it.right) ) | ||
} | ||
ret.add new Spread(attribute: raw.left, weight: raw.middle, spreadTarget: targets) | ||
} | ||
|
||
return ret | ||
} | ||
|
||
|
||
static JobSpreads parseJobSpreads(Map nomadJobOpts){ | ||
if( nomadJobOpts.spreads && nomadJobOpts.spreads instanceof Closure){ | ||
def spec = new JobSpreads() | ||
def closure = (nomadJobOpts.spreads as Closure) | ||
def clone = closure.rehydrate(spec, closure.owner, closure.thisObject) | ||
clone.resolveStrategy = Closure.DELEGATE_FIRST | ||
clone() | ||
spec.validate() | ||
spec | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
plugins/nf-nomad/src/main/nextflow/nomad/builders/TaskBuilder.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,58 @@ | ||
/* | ||
* 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.builders | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Slf4j | ||
import io.nomadproject.client.model.Task | ||
import io.nomadproject.client.model.Resources | ||
|
||
@Slf4j | ||
@CompileStatic | ||
class TaskBuilder { | ||
private Task task = new Task() | ||
|
||
TaskBuilder name(String name) { | ||
task.name = name | ||
return this | ||
} | ||
|
||
TaskBuilder driver(String driver) { | ||
task.driver = driver | ||
return this | ||
} | ||
|
||
TaskBuilder resources(Resources resources) { | ||
task.resources = resources | ||
return this | ||
} | ||
|
||
TaskBuilder config(Map<String, Object> config) { | ||
task.config = config | ||
return this | ||
} | ||
|
||
TaskBuilder env(Map<String, String> env) { | ||
task.env = env | ||
return this | ||
} | ||
|
||
Task build() { | ||
return task | ||
} | ||
} | ||
|
55 changes: 55 additions & 0 deletions
55
plugins/nf-nomad/src/main/nextflow/nomad/builders/TaskGroupBuilder.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,55 @@ | ||
/* | ||
* 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.builders | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Slf4j | ||
import io.nomadproject.client.model.TaskGroup | ||
import io.nomadproject.client.model.ReschedulePolicy | ||
import io.nomadproject.client.model.RestartPolicy | ||
import io.nomadproject.client.model.Task | ||
|
||
@Slf4j | ||
@CompileStatic | ||
class TaskGroupBuilder { | ||
private TaskGroup taskGroup = new TaskGroup() | ||
|
||
TaskGroupBuilder name(String name) { | ||
taskGroup.name = name | ||
return this | ||
} | ||
|
||
TaskGroupBuilder tasks(List<Task> tasks) { | ||
taskGroup.tasks = tasks | ||
return this | ||
} | ||
|
||
TaskGroupBuilder reschedulePolicy(ReschedulePolicy policy) { | ||
taskGroup.reschedulePolicy = policy | ||
return this | ||
} | ||
|
||
TaskGroupBuilder restartPolicy(RestartPolicy policy) { | ||
taskGroup.restartPolicy = policy | ||
return this | ||
} | ||
|
||
TaskGroup build() { | ||
return taskGroup | ||
} | ||
} |
Oops, something went wrong.