Search in sources :

Example 6 with VirtualChannel

use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.

the class ConnectionActivityMonitor method execute.

protected void execute(TaskListener listener) throws IOException, InterruptedException {
    if (!enabled)
        return;
    long now = System.currentTimeMillis();
    for (Computer c : Hudson.getInstance().getComputers()) {
        VirtualChannel ch = c.getChannel();
        if (ch instanceof Channel) {
            Channel channel = (Channel) ch;
            if (now - channel.getLastHeard() > TIME_TILL_PING) {
                // haven't heard from this slave for a while.
                Long lastPing = (Long) channel.getProperty(ConnectionActivityMonitor.class);
                if (lastPing != null && now - lastPing > TIMEOUT) {
                    LOGGER.info("Repeated ping attempts failed on " + c.getName() + ". Disconnecting");
                    c.disconnect(OfflineCause.create(Messages._ConnectionActivityMonitor_OfflineCause()));
                } else {
                    // send a ping. if we receive a reply, it will be reflected in the next getLastHeard() call.
                    channel.callAsync(PING_COMMAND);
                    if (lastPing == null)
                        channel.setProperty(ConnectionActivityMonitor.class, now);
                }
            } else {
                // we are receiving data nicely
                channel.setProperty(ConnectionActivityMonitor.class, null);
            }
        }
    }
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) Channel(hudson.remoting.Channel) VirtualChannel(hudson.remoting.VirtualChannel) Computer(hudson.model.Computer)

Example 7 with VirtualChannel

use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.

the class SU method execute.

/**
     * Starts a new priviledge-escalated environment, execute a closure, and shut it down.
     */
public static <V, T extends Throwable> V execute(TaskListener listener, String rootUsername, String rootPassword, final Callable<V, T> closure) throws T, IOException, InterruptedException {
    VirtualChannel ch = start(listener, rootUsername, rootPassword);
    try {
        return ch.call(closure);
    } finally {
        ch.close();
        // give some time for orderly shutdown, but don't block forever.
        ch.join(3000);
    }
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel)

Example 8 with VirtualChannel

use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.

the class Slave method getClockDifference.

public ClockDifference getClockDifference() throws IOException, InterruptedException {
    VirtualChannel channel = getChannel();
    if (channel == null)
        throw new IOException(getNodeName() + " is offline");
    long startTime = System.currentTimeMillis();
    long slaveTime = channel.call(new GetSystemTime());
    long endTime = System.currentTimeMillis();
    return new ClockDifference((startTime + endTime) / 2 - slaveTime);
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) ClockDifference(hudson.util.ClockDifference) IOException(java.io.IOException)

Example 9 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 10 with VirtualChannel

use of hudson.remoting.VirtualChannel in project hudson-2.x by hudson.

the class FilePath method untarFrom.

/**
     * Reads the given InputStream as a tar file and extracts it into this directory.
     *
     * @param _in
     *      The stream will be closed by this method after it's fully read.
     * @param compression
     *      The compression method in use.
     * @since 1.292
     */
public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException {
    try {
        final InputStream in = new RemoteInputStream(_in);
        act(new FileCallable<Void>() {

            public Void invoke(File dir, VirtualChannel channel) throws IOException {
                readFromTar("input stream", dir, compression.extract(in));
                return null;
            }

            private static final long serialVersionUID = 1L;
        });
    } finally {
        IOUtils.closeQuietly(_in);
    }
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) RemoteInputStream(hudson.remoting.RemoteInputStream) ObjectInputStream(java.io.ObjectInputStream) ZipInputStream(java.util.zip.ZipInputStream) TarInputStream(hudson.org.apache.tools.tar.TarInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RemoteInputStream(hudson.remoting.RemoteInputStream) IOException(java.io.IOException) File(java.io.File)

Aggregations

VirtualChannel (hudson.remoting.VirtualChannel)12 IOException (java.io.IOException)9 File (java.io.File)7 IOException2 (hudson.util.IOException2)3 FileInputStream (java.io.FileInputStream)3 TarInputStream (hudson.org.apache.tools.tar.TarInputStream)2 Channel (hudson.remoting.Channel)2 RemoteInputStream (hudson.remoting.RemoteInputStream)2 BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 ZipInputStream (java.util.zip.ZipInputStream)2 CountingInputStream (org.apache.commons.io.input.CountingInputStream)2 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)2 FileSet (org.apache.tools.ant.types.FileSet)2 FilePath (hudson.FilePath)1 AbstractBuild (hudson.model.AbstractBuild)1 AbstractProject (hudson.model.AbstractProject)1 Computer (hudson.model.Computer)1