use of hudson.slaves.SlaveComputer in project support-core-plugin by jenkinsci.
the class SlaveLogs method addContents.
@Override
public void addContents(@NonNull Container container) {
// expensive remote computation are pooled together and executed later concurrently across all the agents
List<java.util.concurrent.Callable<List<FileContent>>> tasks = Lists.newArrayList();
// id is awkward because of backward compatibility
SmartLogFetcher logFetcher = new SmartLogFetcher("cache", new LogFilenameFilter());
SmartLogFetcher winswLogFetcher = new SmartLogFetcher("winsw", new WinswLogfileFilter());
final boolean needHack = SlaveLogFetcher.isRequired();
for (final Node node : Jenkins.getInstance().getNodes()) {
if (node.toComputer() instanceof SlaveComputer) {
container.add(new PrintedContent("nodes/slave/" + node.getNodeName() + "/jenkins.log") {
@Override
protected void printTo(PrintWriter out) throws IOException {
Computer computer = node.toComputer();
if (computer == null) {
out.println("N/A");
} else {
try {
List<LogRecord> records = null;
if (needHack) {
VirtualChannel channel = computer.getChannel();
if (channel != null) {
hudson.remoting.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();
out.print(LOG_FORMATTER.format(logRecord));
}
} catch (Throwable e) {
out.println();
SupportLogFormatter.printStackTrace(e, out);
}
}
out.flush();
}
});
}
addSlaveJulLogRecords(container, tasks, node, logFetcher);
addWinsStdoutStderrLog(tasks, node, winswLogFetcher);
}
// execute all the expensive computations in parallel to speed up the time
if (!tasks.isEmpty()) {
ExecutorService service = Executors.newFixedThreadPool(Math.max(1, Math.min(Runtime.getRuntime().availableProcessors() * 2, tasks.size())), new ExceptionCatchingThreadFactory(new DaemonThreadFactory()));
try {
long expiresNanoTime = System.nanoTime() + TimeUnit.SECONDS.toNanos(SupportPlugin.REMOTE_OPERATION_CACHE_TIMEOUT_SEC);
for (java.util.concurrent.Future<List<FileContent>> r : service.invokeAll(tasks, SupportPlugin.REMOTE_OPERATION_CACHE_TIMEOUT_SEC, TimeUnit.SECONDS)) {
try {
for (FileContent c : r.get(Math.max(1, expiresNanoTime - System.nanoTime()), TimeUnit.NANOSECONDS)) {
container.add(c);
}
} catch (ExecutionException e) {
LOGGER.log(Level.WARNING, "Could not retrieve some of the remote node extra logs", e);
} catch (TimeoutException e) {
LOGGER.log(Level.WARNING, "Could not retrieve some of the remote node extra logs", e);
r.cancel(false);
}
}
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Could not retrieve some of the remote node extra logs", e);
} finally {
service.shutdown();
}
}
}
use of hudson.slaves.SlaveComputer in project support-core-plugin by jenkinsci.
the class FileDescriptorLimit method addContents.
private void addContents(@NonNull Container container, @NonNull final Node node) {
Computer c = node.toComputer();
if (c == null) {
return;
}
if (c instanceof SlaveComputer && !Boolean.TRUE.equals(((SlaveComputer) c).isUnix())) {
return;
}
if (!node.createLauncher(TaskListener.NULL).isUnix()) {
return;
}
String name;
if (node instanceof Jenkins) {
name = "master";
} else {
name = "slave/" + node.getNodeName();
}
container.add(new Content("nodes/" + name + "/file-descriptors.txt") {
@Override
public void writeTo(OutputStream os) throws IOException {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(os, "utf-8")));
out.println(node.getDisplayName());
out.println("======");
out.println();
try {
out.println(getUlimit(node));
} catch (IOException e) {
SupportLogFormatter.printStackTrace(e, out);
} finally {
out.flush();
}
}
});
}
Aggregations