summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2022-01-31 14:44:22 +0100
committerSimon Rettberg2022-01-31 14:44:22 +0100
commit083fb22120ed2cc305b2b2ba078bd8b8f1b35567 (patch)
tree59b6fa6cecd8602b378f7eb0fac9d5ec2a2610c9 /src
parentpom: maven-assembly-plugin version must not be pinned (diff)
downloadtmlite-bwlp-083fb22120ed2cc305b2b2ba078bd8b8f1b35567.tar.gz
tmlite-bwlp-083fb22120ed2cc305b2b2ba078bd8b8f1b35567.tar.xz
tmlite-bwlp-083fb22120ed2cc305b2b2ba078bd8b8f1b35567.zip
[WakeOnLan] Add more status output
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java b/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java
index c92f3c9..2391d4d 100644
--- a/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java
+++ b/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java
@@ -19,6 +19,7 @@ import org.openslx.satserver.util.Util;
import org.openslx.satserver.util.WakeOnLanExecutor;
import org.openslx.taskmanager.api.AbstractTask;
import org.openslx.taskmanager.tasks.RemoteExec.Output;
+import org.openslx.taskmanager.tasks.RemoteExec.Result;
import com.google.gson.annotations.Expose;
@@ -76,6 +77,7 @@ public class WakeOnLan extends AbstractTask
// Loop over clients until they all were handled (i.e. methods is empty)
ExecutorService tp = Executors.newFixedThreadPool( ssh.size() > 4 ? 4 : ssh.size() );
Map<String, ArrayList<String>> byMethod;
+ int jobIdCounter = 0;
do {
byMethod = new HashMap<>();
// Fetch next method for all clients
@@ -96,31 +98,53 @@ public class WakeOnLan extends AbstractTask
for ( Entry<String, ArrayList<String>> it : byMethod.entrySet() ) {
String[] parts = it.getKey().split( "//" );
String method = parts[0];
+ List<String> macs = it.getValue();
+ String macString = Strings.join( macs.iterator(), ' ' );
String ip = parts[1];
+ final int jobId = ++jobIdCounter;
if ( method.equalsIgnoreCase( "DIRECT" ) ) {
// Directly from server
waitList.add( tp.submit( () -> {
+ status.addMsg( jobId + ": Waking directly from server: " + macString );
WakeOnLanExecutor wol = new WakeOnLanExecutor( null );
- String[] success = wol.execute( status, it.getValue(), ip, this.port );
+ String[] success = wol.execute( status, macs, ip, this.port );
markSuccess( Arrays.asList( success ) );
+ if ( success.length == macs.size() ) {
+ status.addMsg( jobId + ": Done" );
+ } else {
+ status.addMsg( jobId + ": Some failed" );
+ }
} ) );
} else if ( this.ssh.containsKey( method ) ) {
// Via SSH
waitList.add( tp.submit( () -> {
SshData sshData = this.ssh.get( method );
- String macs = Strings.join( it.getValue().iterator(), ' ' );
- String command = sshData.command.replace( "%MACS%", macs ).replace( "%IP%", ip );
+ status.addMsg( jobId + ": Waking via SSH to " + sshData.ip + ": " + macString );
+ String command = sshData.command.replace( "%MACS%", macString ).replace( "%IP%", ip );
RemoteExec.Client c = new RemoteExec.Client( "x", sshData.ip, sshData.port, sshData.username );
RemoteExec task = new RemoteExec( new RemoteExec.Client[] { c }, sshData.sshkey, sshData.port, command, 5 );
task.execute();
Output s = task.getStatusObject();
- if ( s != null ) {
- if ( s.result != null && s.result.containsKey( "x" ) && s.result.get( "x" ).exitCode == 0 ) {
- markSuccess( Arrays.asList( macs ) );
- }
+ if ( s == null ) {
+ status.addMsg( jobId + ": Task status is null, considering failed" );
+ } else {
if ( !Util.isEmpty( s.error ) ) {
status.addMsg( s.error );
}
+ if ( s.result != null && s.result.containsKey( "x" ) && s.result.get( "x" ).exitCode == 0 ) {
+ markSuccess( macs );
+ status.addMsg( jobId + ": Done" );
+ } else {
+ if ( s.result != null ) {
+ for ( Result sshClient : s.result.values() ) {
+ if ( sshClient == null )
+ continue;
+ status.addMsg( jobId + ": stdout: " + sshClient.stdout + "\n"
+ + jobId + ": stderr: " + sshClient.stderr );
+ }
+ }
+ status.addMsg( jobId + ": Non-zero exit code, considering failed" );
+ }
}
} ) );
} else {
@@ -140,7 +164,9 @@ public class WakeOnLan extends AbstractTask
e.printStackTrace();
}
}
+ // If we had any jobs to do, loop again, otherwise we're done
} while ( !byMethod.isEmpty() );
+ status.addMsg( "Mainloop done" );
if ( this.clients.isEmpty() )
return true;
status.addMsg( "Failed clients:" );