@@ -109,6 +109,7 @@ class NomadService implements Closeable{
109
109
JobRegisterResponse jobRegisterResponse = jobsApi. registerJob(jobRegisterRequest, config. jobOpts(). region, config. jobOpts(). namespace, null , null )
110
110
jobRegisterResponse. evalID
111
111
} catch (Throwable e) {
112
+ log. debug(" [NOMAD] Failed to submit ${ job.name} -- Cause: ${ e.message ?: e} " , e)
112
113
throw new ProcessSubmitException (" [NOMAD] Failed to submit ${ job.name} -- Cause: ${ e.message ?: e} " , e)
113
114
}
114
115
@@ -267,27 +268,42 @@ class NomadService implements Closeable{
267
268
}
268
269
269
270
String getJobState (String jobId ){
270
- List<AllocationListStub > allocations = jobsApi. getJobAllocations(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null , null )
271
- AllocationListStub last = allocations?. sort{
272
- it. modifyIndex
273
- }?. last()
274
- String currentState = last?. taskStates?. values()?. last()?. state
275
- log. debug " Task $jobId , state=$currentState "
276
- currentState ?: " Unknown"
271
+ try {
272
+ List<AllocationListStub > allocations = jobsApi. getJobAllocations(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null , null )
273
+ AllocationListStub last = allocations?. sort {
274
+ it. modifyIndex
275
+ }?. last()
276
+ String currentState = last?. taskStates?. values()?. last()?. state
277
+ log. debug " Task $jobId , state=$currentState "
278
+ currentState ?: " Unknown"
279
+ }catch (Exception e){
280
+ log. debug(" [NOMAD] Failed to get jobState ${ jobId} -- Cause: ${ e.message ?: e} " , e)
281
+ " dead"
282
+ }
277
283
}
278
284
279
285
280
286
281
287
boolean checkIfRunning (String jobId ){
282
- Job job = jobsApi. getJob(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null )
283
- log. debug " [NOMAD] checkIfRunning jobID=$job . ID ; status=$job . status "
284
- job. status == " running"
288
+ try {
289
+ Job job = jobsApi. getJob(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null )
290
+ log. debug " [NOMAD] checkIfRunning jobID=$job . ID ; status=$job . status "
291
+ job. status == " running"
292
+ }catch (Exception e){
293
+ log. debug(" [NOMAD] Failed to get jobState ${ jobId} -- Cause: ${ e.message ?: e} " , e)
294
+ false
295
+ }
285
296
}
286
297
287
298
boolean checkIfDead (String jobId ){
288
- Job job = jobsApi. getJob(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null )
289
- log. debug " [NOMAD] checkIfDead jobID=$job . ID ; status=$job . status "
290
- job. status == " dead"
299
+ try {
300
+ Job job = jobsApi. getJob(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null )
301
+ log. debug " [NOMAD] checkIfDead jobID=$job . ID ; status=$job . status "
302
+ job. status == " dead"
303
+ }catch (Exception e){
304
+ log. debug(" [NOMAD] Failed to get job ${ jobId} -- Cause: ${ e.message ?: e} " , e)
305
+ true
306
+ }
291
307
}
292
308
293
309
void kill (String jobId ) {
@@ -300,12 +316,21 @@ class NomadService implements Closeable{
300
316
301
317
protected void purgeJob (String jobId , boolean purge ){
302
318
log. debug " [NOMAD] purgeJob with jobId=${ jobId} "
303
- jobsApi. deleteJob(jobId,config. jobOpts(). region, config. jobOpts(). namespace,null ,null ,purge, true )
319
+ try {
320
+ jobsApi. deleteJob(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , purge, true )
321
+ }catch (Exception e){
322
+ log. debug(" [NOMAD] Failed to delete job ${ jobId} -- Cause: ${ e.message ?: e} " , e)
323
+ }
304
324
}
305
325
306
326
String getClientOfJob (String jobId ) {
307
- List<AllocationListStub > allocations = jobsApi. getJobAllocations(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null , null )
308
- AllocationListStub jobAllocation = allocations. first()
309
- return jobAllocation. nodeName
327
+ try {
328
+ List<AllocationListStub > allocations = jobsApi. getJobAllocations(jobId, config. jobOpts(). region, config. jobOpts(). namespace, null , null , null , null , null , null , null , null )
329
+ AllocationListStub jobAllocation = allocations. first()
330
+ return jobAllocation. nodeName
331
+ }catch (Exception e){
332
+ log. debug(" [NOMAD] Failed to get job allocations ${ jobId} -- Cause: ${ e.message ?: e} " , e)
333
+ throw new ProcessSubmitException (" [NOMAD] Failed to get alloactions ${ jobId} -- Cause: ${ e.message ?: e} " , e)
334
+ }
310
335
}
311
336
}
0 commit comments