Search in sources :

Example 16 with VirtualChannel

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();
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) VirtualChannel(hudson.remoting.VirtualChannel) Channel(hudson.remoting.Channel) PrintWriter(java.io.PrintWriter)

Example 17 with VirtualChannel

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();
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) LogRecord(java.util.logging.LogRecord) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ExtensionList(hudson.ExtensionList) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) WeakHashMap(java.util.WeakHashMap)

Example 18 with VirtualChannel

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;
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) LogRecord(java.util.logging.LogRecord) IOException(java.io.IOException)

Example 19 with VirtualChannel

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));
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(hudson.slaves.DumbSlave) Test(org.junit.Test)

Example 20 with VirtualChannel

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;
}
Also used : FilePath(hudson.FilePath) VirtualChannel(hudson.remoting.VirtualChannel) FileWriter(java.io.FileWriter) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) IOException(java.io.IOException) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) BufferedWriter(java.io.BufferedWriter) RoleChecker(org.jenkinsci.remoting.RoleChecker) File(java.io.File)

Aggregations

VirtualChannel (hudson.remoting.VirtualChannel)21 IOException (java.io.IOException)14 File (java.io.File)9 LogRecord (java.util.logging.LogRecord)4 FilePath (hudson.FilePath)3 IOException2 (hudson.util.IOException2)3 FileInputStream (java.io.FileInputStream)3 StoreResultException (com.qasymphony.ci.plugin.exception.StoreResultException)2 Computer (hudson.model.Computer)2 TarInputStream (hudson.org.apache.tools.tar.TarInputStream)2 Channel (hudson.remoting.Channel)2 RemoteInputStream (hudson.remoting.RemoteInputStream)2 BufferedInputStream (java.io.BufferedInputStream)2 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2