Skip to content

Commit

Permalink
Merge pull request #45 from christ66/JENKINS-28216
Browse files Browse the repository at this point in the history
[JENKINS-28216] Obtain slave logs using async callable.
  • Loading branch information
christ66 committed Nov 13, 2015
2 parents 4565427 + 7bd076c commit 8305e7f
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/main/java/com/cloudbees/jenkins/support/impl/JenkinsLogs.java
Expand Up @@ -19,8 +19,9 @@
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.PeriodicWork;
import hudson.remoting.*;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.remoting.Future;
import hudson.security.Permission;
import hudson.slaves.Cloud;
import hudson.slaves.SlaveComputer;
Expand All @@ -45,11 +46,7 @@
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.*;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
Expand Down Expand Up @@ -112,9 +109,19 @@ protected void printTo(PrintWriter out) throws IOException {
out.println("N/A");
} else {
try {
List<LogRecord> records = needHack
? SlaveLogFetcher.getLogRecords(computer)
: computer.getLogRecords();
List<LogRecord> records = null;
if (needHack) {
VirtualChannel channel = computer.getChannel();
if (channel != null) {
Future<List<LogRecord>> future = SlaveLogFetcher.getLogRecords(channel);
records = future.get(REMOTE_OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
}

if (records == null) {
records = computer.getLogRecords();
}

for (ListIterator<LogRecord> iterator = records.listIterator(records.size());
iterator.hasPrevious(); ) {
LogRecord logRecord = iterator.previous();
Expand Down Expand Up @@ -458,6 +465,15 @@ public List<LogRecord> call() throws RuntimeException {
}
}

public static Future<List<LogRecord>> getLogRecords(@NonNull VirtualChannel channel) throws IOException {
return channel.callAsync(new SlaveLogFetcher());
}

/**
* @deprecated Please use getLogRecords(Channel) instead. This method is synchronous which could cause
* the channel to block.
*/
@Deprecated
public static List<LogRecord> getLogRecords(Computer computer) throws IOException, InterruptedException {
VirtualChannel channel = computer.getChannel();
if (channel == null) {
Expand Down

0 comments on commit 8305e7f

Please sign in to comment.