Skip to content

Commit 36560b2

Browse files
committed
map further statuses to running or completed
1 parent aef5a4d commit 36560b2

File tree

7 files changed

+55
-28
lines changed

7 files changed

+55
-28
lines changed

plugins/nf-nomad/src/main/nextflow/nomad/builders/JobBuilder.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class JobBuilder {
126126

127127
def task = createTask(taskRun, args, env, jobOpts)
128128
def taskGroup = new TaskGroup(
129-
name: "group",
129+
name: "nf-taskgroup",
130130
tasks: [ task ],
131131
reschedulePolicy: taskReschedulePolicy,
132132
restartPolicy: taskRestartPolicy

plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ class NomadService implements Closeable{
126126
it.modifyIndex
127127
}?.last() : null
128128
TaskState currentState = last?.taskStates?.values()?.last()
129-
log.debug "Task $jobId , state=${currentState?.state}"
129+
log.debug "[NOMAD] getTaskStatus $jobId , state=${currentState?.state}"
130130
currentState ?: new TaskState(state: "unknown", failed: true, finishedAt: OffsetDateTime.now())
131131
}catch(Exception e){
132-
log.debug("[NOMAD] Failed to get jobState ${jobId} -- Cause: ${e.message ?: e}", e)
132+
log.debug("[NOMAD] getTaskStatus Failed to get jobState ${jobId} -- Cause: ${e.message ?: e}", e)
133133
new TaskState(state: "unknown", failed: true, finishedAt: OffsetDateTime.now())
134134
}
135135
}
@@ -142,10 +142,10 @@ class NomadService implements Closeable{
142142
jobsApi.getJob(jobId, config.jobOpts().region, config.jobOpts().namespace,
143143
null, null, null, null, null, null, null)
144144
}
145-
log.debug "[NOMAD] checkIfRunning jobID=$job.ID; status=$job.status"
145+
log.debug "[NOMAD] getJobStatus jobID=$job.ID; status=$job.status"
146146
job.status
147147
}catch (Exception e){
148-
log.debug("[NOMAD] Failed to get jobState ${jobId} -- Cause: ${e.message ?: e}", e)
148+
log.debug("[NOMAD] getJobStatus Failed to get jobState ${jobId} -- Cause: ${e.message ?: e}", e)
149149
"unknown"
150150
}
151151
}

plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadTaskHandler.groovy

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,41 @@ class NomadTaskHandler extends TaskHandler implements FusionAwareTask {
7272
this.exitFile = task.workDir.resolve(TaskRun.CMD_EXIT)
7373
}
7474

75+
76+
//-------------------------------------------------
77+
//
78+
// NOTE: From https://github.com/hashicorp/nomad/blob/6a41dc7b2f1fdbbc5a20ed267b4ad25fc2a14489/api/jobs.go#L1263-L1287
79+
//
80+
//-------------------------------------------------
81+
// type JobChildrenSummary struct {
82+
// Pending int64
83+
// Running int64
84+
// Dead int64
85+
// }
86+
//-------------------------------------------------
87+
// type TaskGroupSummary struct {
88+
// Queued int
89+
// Complete int
90+
// Failed int
91+
// Running int
92+
// Starting int
93+
// Lost int
94+
// Unknown int
95+
// }
96+
//-------------------------------------------------
97+
98+
7599
@Override
76100
boolean checkIfRunning() {
77-
if( !jobName ) throw new IllegalStateException("Missing Nomad Job name -- cannot check if running")
101+
if( !jobName ) throw new IllegalStateException("[NOMAD] Missing Nomad Job name -- cannot check if running")
78102
if(isSubmitted()) {
79103
def state = taskState0()
104+
105+
log.debug "[NOMAD] checkIfRunning task=$task.name; state=${state?.state}"
106+
80107
// include `terminated` state to allow the handler status to progress
81-
if( state && ( ["running","terminated"].contains(state.state))){
82-
status = TaskStatus.RUNNING
108+
if( state && ( ["running","pending","unknown"].contains(state.state))){
109+
this.status = TaskStatus.RUNNING
83110
determineClientNode()
84111
return true
85112
}
@@ -89,15 +116,14 @@ class NomadTaskHandler extends TaskHandler implements FusionAwareTask {
89116

90117
@Override
91118
boolean checkIfCompleted() {
92-
if( !jobName ) throw new IllegalStateException("Missing Nomad Job name -- cannot check if running")
119+
if( !jobName ) throw new IllegalStateException("[NOMAD] Missing Nomad Job name -- cannot check if running")
120+
def isFinished = false
93121

94122
def state = taskState0()
95123

96-
final isFinished = state && (state.finishedAt != null || state.state == "unknow")
97-
98-
log.debug "[NOMAD] checkIfCompleted task.name=$task.name; state=${state?.state} completed=$isFinished"
124+
log.debug "[NOMAD] checkIfCompleted task=$task.name; state=${state?.state}"
99125

100-
if (isFinished) {
126+
if( state && ( ["dead","complete"].contains(state.state))){
101127
// finalize the task
102128
task.exitStatus = readExitFile()
103129
task.stdout = outputFile
@@ -193,7 +219,7 @@ class NomadTaskHandler extends TaskHandler implements FusionAwareTask {
193219
if (!status || delta >= 1_000) {
194220

195221
def newState = nomadService.getTaskState(jobName)
196-
log.debug "[NOMAD] Check jobState: jobName=$jobName currentState=${state?.state} newState=${newState?.state}"
222+
log.debug "[NOMAD] taskState0 jobName=$jobName currentState=${state?.state} newState=${newState?.state}"
197223

198224
if (newState) {
199225
state = newState

plugins/nf-nomad/src/test/nextflow/nomad/NomadDSLSpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class NomadDSLSpec extends Dsl2Spec{
125125
}
126126

127127
when:
128-
def SCRIPT = '''
128+
def SCRIPT = '''
129129
process sayHello{
130130
container 'ubuntu:22.0.4'
131131
input:
@@ -136,10 +136,10 @@ class NomadDSLSpec extends Dsl2Spec{
136136
"""
137137
echo '$x world!\'
138138
"""
139-
}
139+
}
140140
workflow {
141141
channel.of('hi!') | sayHello | view
142-
}
142+
}
143143
'''
144144
and:
145145
def result = new MockScriptRunner([

plugins/nf-nomad/src/test/nextflow/nomad/builders/JobBuilderSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class JobBuilderSpec extends Specification {
8989
def taskGroup = JobBuilder.createTaskGroup(taskRun, args, env, jobOpts)
9090

9191
then:
92-
taskGroup.name == "group"
92+
taskGroup.name == "nf-taskgroup"
9393
taskGroup.tasks.size() == 1
9494
taskGroup.tasks[0].name == "nf-task"
9595
taskGroup.tasks[0].config.image == "test-container"

plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class NomadServiceSpec extends Specification{
149149
body.Job.Name == name
150150
body.Job.Type == "batch"
151151
body.Job.TaskGroups.size() == 1
152-
body.Job.TaskGroups[0].Name == "group"
152+
body.Job.TaskGroups[0].Name == "nf-taskgroup"
153153
body.Job.TaskGroups[0].Tasks.size() == 1
154154
body.Job.TaskGroups[0].Tasks[0].Name == "nf-task"
155155
body.Job.TaskGroups[0].Tasks[0].Resources.Cores == 1
@@ -224,7 +224,7 @@ class NomadServiceSpec extends Specification{
224224
body.Job.Name == name
225225
body.Job.Type == "batch"
226226
body.Job.TaskGroups.size() == 1
227-
body.Job.TaskGroups[0].Name == "group"
227+
body.Job.TaskGroups[0].Name == "nf-taskgroup"
228228
body.Job.TaskGroups[0].Tasks.size() == 1
229229
body.Job.TaskGroups[0].Tasks[0].Name == "nf-task"
230230
body.Job.TaskGroups[0].Tasks[0].Resources.Cores == 1

validation/sun-nomadlab/nextflow.config

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ wave {
2727
fusion {
2828
enabled = true
2929
exportStorageCredentials = true
30+
logLevel = 'verbose' // 'info' | 'debug'
3031
}
3132

3233
nomad {
@@ -45,15 +46,15 @@ nomad {
4546

4647
volume = { type "host" name "scratch" }
4748

48-
constraints = {
49-
// attr {
50-
// unique = [hostname:'nomad03']
51-
// //raw 'platform.aws.instance-type', '=', 'm4.xlarge'
49+
// constraints = {
50+
// // attr {
51+
// // unique = [hostname:'nomad03']
52+
// // //raw 'platform.aws.instance-type', '=', 'm4.xlarge'
5253

53-
node {
54-
unique = [name: "nomad03"]
55-
}
54+
// node {
55+
// unique = [name: "nomad03"]
56+
// }
5657

57-
}
58+
// }
5859
}
5960
}

0 commit comments

Comments
 (0)