From e5bc27fde798db4563175b7fb67c637497b294ab Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Tue, 30 Jul 2024 10:16:26 +0200 Subject: [PATCH] Add option to only execute a single given job --- .../chronos/agent/AbstractChronosAgent.java | 76 +++++++++++-------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java index 7f6c244..736e6da 100644 --- a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java @@ -46,6 +46,8 @@ of this software and associated documentation files (the "Software"), to deal import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.ZipParameters; @@ -72,6 +74,10 @@ public abstract class AbstractChronosAgent extends Thread { private final AbortedMonitor abortedMonitor = new AbortedMonitor(); private final ChronosHttpClient chronos; + @Getter + @Setter + private Integer singleJobId = null; + private volatile boolean running = true; private volatile Thread agent; @@ -148,40 +154,45 @@ public void run() { // (1) Requesting new job final ChronosJob job; - try { - if ( !alreadyPrintedWaitingForJob ) { - log.info( "Requesting new job." ); - } - job = this.chronos.getNextJob( getSupportedSystemNames(), getEnvironment() ); // throws NoSuchElementException, ChronosException, IOException, InterruptedException - } catch ( NoSuchElementException ex ) { - if ( !alreadyPrintedWaitingForJob ) { - log.debug( "No job scheduled.", ex ); - System.out.print( "Waiting for job" ); - alreadyPrintedWaitingForJob = true; - } else { - System.out.print( "." ); - } - + if ( singleJobId == null ) { try { - SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE ); - } catch ( InterruptedException ignored2 ) { - // Ignore. Maybe this agent is to be shutdown. - } - - continue mainLoop; // !! Important !! -- Reloop - - } catch ( Exception ex ) { - log.error( "IOException for chronos.getNextJob(" + Arrays.toString( getSupportedSystemNames() ) + "," + getEnvironment() + ")", ex ); + if ( !alreadyPrintedWaitingForJob ) { + log.info( "Requesting new job." ); + } + job = this.chronos.getNextJob( getSupportedSystemNames(), getEnvironment() ); // throws NoSuchElementException, ChronosException, IOException, InterruptedException + } catch ( NoSuchElementException ex ) { + if ( !alreadyPrintedWaitingForJob ) { + log.debug( "No job scheduled.", ex ); + System.out.print( "Waiting for job" ); + alreadyPrintedWaitingForJob = true; + } else { + System.out.print( "." ); + } + + try { + SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE ); + } catch ( InterruptedException ignored2 ) { + // Ignore. Maybe this agent is to be shutdown. + } + + continue mainLoop; // !! Important !! -- Reloop + + } catch ( Exception ex ) { + log.error( "IOException for chronos.getNextJob(" + Arrays.toString( getSupportedSystemNames() ) + "," + getEnvironment() + ")", ex ); + + try { + SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE ); + } catch ( InterruptedException ignored ) { + // Ignore. Maybe this agent is to be shutdown. + } + + alreadyPrintedWaitingForJob = false; + continue mainLoop; // !! Important !! -- Reloop - try { - SLEEPING_TIME_UNIT.sleep( SLEEPING_TIME_VALUE ); - } catch ( InterruptedException ignored ) { - // Ignore. Maybe this agent is to be shutdown. } - - alreadyPrintedWaitingForJob = false; - continue mainLoop; // !! Important !! -- Reloop - + } else { + job = this.chronos.getJob( singleJobId ); + this.running = false; // only execute loop once } alreadyPrintedWaitingForJob = false; @@ -732,6 +743,9 @@ private void cancelAndRemoveObservable() { AbortedMonitor.this.tasks.remove( this.observable ); this.cancel(); } + } + } + }