use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.
the class Computer method doDumpExportTable.
/**
* Dumps the contents of the export table.
*/
public void doDumpExportTable(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
// this is a debug probe and may expose sensitive information
checkPermission(Hudson.ADMINISTER);
rsp.setContentType("text/plain");
PrintWriter w = new PrintWriter(rsp.getCompressedWriter(req));
VirtualChannel vc = getChannel();
if (vc instanceof Channel) {
w.println("Master to slave");
((Channel) vc).dumpExportTable(w);
// flush here once so that even if the dump from the slave fails, the client gets some useful info
w.flush();
w.println("\n\n\nSlave to master");
w.print(vc.call(new DumpExportTableTask()));
} else {
w.println(Messages.Computer_BadChannel());
}
w.close();
}
use of hudson.remoting.VirtualChannel in project support-core-plugin by jenkinsci.
the class SupportPlugin method getAllLogRecords.
public List<LogRecord> getAllLogRecords(final Node node) throws IOException, InterruptedException {
if (node != null) {
VirtualChannel channel = node.getChannel();
if (channel != null) {
final Future<List<LogRecord>> future = CallAsyncWrapper.callAsync(channel, new LogFetcher());
try {
return future.get(REMOTE_OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
final LogRecord lr = new LogRecord(Level.WARNING, "Could not retrieve remote log records");
lr.setThrown(e);
return Collections.singletonList(lr);
} catch (TimeoutException e) {
Computer.threadPoolForRemoting.submit(() -> {
List<LogRecord> records;
try {
records = future.get(REMOTE_OPERATION_CACHE_TIMEOUT_SEC, TimeUnit.SECONDS);
} catch (InterruptedException e1) {
final LogRecord lr = new LogRecord(Level.WARNING, "Could not retrieve remote log records");
lr.setThrown(e1);
records = Collections.singletonList(lr);
} catch (ExecutionException e1) {
final LogRecord lr = new LogRecord(Level.WARNING, "Could not retrieve remote log records");
lr.setThrown(e1);
records = Collections.singletonList(lr);
} catch (TimeoutException e1) {
final LogRecord lr = new LogRecord(Level.WARNING, "Could not retrieve remote log records");
lr.setThrown(e1);
records = Collections.singletonList(lr);
future.cancel(true);
}
synchronized (SupportPlugin.this) {
if (logRecords == null) {
logRecords = new WeakHashMap<>();
}
logRecords.put(node, records);
}
});
synchronized (this) {
if (logRecords != null) {
List<LogRecord> result = logRecords.get(node);
if (result != null) {
result = new ArrayList<>(result);
final LogRecord lr = new LogRecord(Level.WARNING, "Using cached remote log records");
lr.setThrown(e);
result.add(lr);
return result;
}
} else {
final LogRecord lr = new LogRecord(Level.WARNING, "No previous cached remote log records");
lr.setThrown(e);
return Collections.singletonList(lr);
}
}
}
}
}
return Collections.emptyList();
}
use of hudson.remoting.VirtualChannel in project support-core-plugin by jenkinsci.
the class BaseCommandOutputContent method runOnNode.
static String runOnNode(Node node, String... command) {
String content = "Exception occurred while retrieving command content";
VirtualChannel chan = node.getChannel();
if (chan == null) {
content = "No connection to node";
} else {
try {
content = chan.call(new BaseCommandOutputContent.CommandLauncher(command));
} catch (IOException | InterruptedException e) {
final LogRecord lr = new LogRecord(Level.FINE, "Could not retrieve command content from {0}");
lr.setParameters(new Object[] { getNodeName(node) });
lr.setThrown(e);
LOGGER.log(lr);
}
}
return content;
}
use of hudson.remoting.VirtualChannel in project support-core-plugin by jenkinsci.
the class DumpExportTableTest method testLargeExportTableTruncated.
@Test
public void testLargeExportTableTruncated() throws Exception {
// Given
DumbSlave onlineAgent = j.createOnlineSlave();
VirtualChannel channel = onlineAgent.getChannel();
// This will generate an export table with 2MB of content.
for (int i = 0; i < 35000; i++) {
channel.export(MockSerializable.class, new MockSerializable() {
});
}
// When
String dumpTableString = SupportTestUtils.invokeComponentToString(new DumpExportTable());
// Then
assertThat(dumpTableString.length(), lessThanOrEqualTo(FileListCapComponent.MAX_FILE_SIZE));
}
use of hudson.remoting.VirtualChannel in project jenkin-qtest-plugin by QASymphony.
the class StoreResultServiceImpl method store.
@Override
public Boolean store(Job job, final SubmittedResult result) throws StoreResultException {
FilePath resultFolder = getResultFolder(job);
try {
resultFolder.mkdirs();
} catch (Exception e) {
throw new StoreResultException(String.format("Cannot make result folder:%s, %s", resultFolder.getName(), e.getMessage()));
}
FilePath resultFile = getResultFile(resultFolder, result.getBuildNumber() / BREAK_FILE_BY);
try {
resultFile.act(new FilePath.FileCallable<String>() {
@Override
public String invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(file.getPath(), true));
writer.write(JsonUtils.toJson(result));
writer.newLine();
return null;
} finally {
if (null != writer)
writer.close();
}
}
@Override
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
}
});
} catch (Exception e) {
throw new StoreResultException("Cannot store result to file:" + e.getMessage());
}
return true;
}
Aggregations