/** * Obtains the heap dump. */ public HeapDump getHeapDump() throws IOException { return new HeapDump(this,getChannel()); }
/** * Gets the thread dump of the agent JVM. * @return * key is the thread name, and the value is the pre-formatted dump. */ public Map<String,String> getThreadDump() throws IOException, InterruptedException { return RemotingDiagnostics.getThreadDump(getChannel()); }
/** * Gets the current channel, if the node is connected and online, or null. * * This is just a convenience method for {@link Computer#getChannel()} with null check. */ @CheckForNull public final VirtualChannel getChannel() { Computer c = toComputer(); return c==null ? null : c.getChannel(); }
/** * Gets the system properties of the JVM on this computer. * If this is the master, it returns the system property of the master computer. */ public Map<Object,Object> getSystemProperties() throws IOException, InterruptedException { return RemotingDiagnostics.getSystemProperties(getChannel()); }
@Exported public boolean isOffline() { return temporarilyOffline || getChannel()==null; }
@Override protected T monitor(Computer c) throws IOException, InterruptedException { VirtualChannel ch = c.getChannel(); if (ch != null) { Callable<T,IOException> cc = createCallable(c); if (cc!=null) return ch.call(cc); } return null; }
void broadcast() { for (Computer c : Jenkins.getInstance().getComputers()) { if (c.getName().length() > 0) { // i.e. not master VirtualChannel ch = c.getChannel(); if (ch != null) { try { ch.call(this); } catch (Exception x) { Logger.getLogger(LogRecorder.class.getName()).log(Level.WARNING, "could not set up logging on " + c, x); } } } } } }
/** * If this {@link Launcher} is encapsulating an execution on a specific {@link Computer}, * return it. * * <p> * Because of the way internal Hudson abstractions are set up (that is, {@link Launcher} only * needs a {@link VirtualChannel} to do its job and isn't really required that the channel * comes from an existing {@link Computer}), this method may not always the right {@link Computer} instance. * * @return * {@code null} if this launcher is not created from a {@link Computer} object. * @deprecated since 2008-11-16. * See the javadoc for why this is inherently unreliable. If you are trying to * figure out the current {@link Computer} from within a build, use * {@link FilePath#toComputer()} or {@link Computer#currentComputer()}. */ @Deprecated @CheckForNull public Computer getComputer() { for( Computer c : Jenkins.getInstance().getComputers() ) if(c.getChannel()==channel) return c; return null; }
/** * If this {@link FilePath} represents a file on a particular {@link Computer}, return it. * Otherwise null. * @since 1.571 */ public @CheckForNull Computer toComputer() { Jenkins j = Jenkins.getInstanceOrNull(); if (j != null) { for (Computer c : j.getComputers()) { if (getChannel()==c.getChannel()) { return c; } } } return null; }
future.put(c.getName(), RemotingDiagnostics.getThreadDumpAsync(c.getChannel())); } catch(Exception e) { LOGGER.info("Failed to get thread dump for node " + c.getName() + ": " + e.getMessage());
/** * Returns cached environment variables (copy to prevent modification) for the JVM on this computer. * If this is the master, it returns the system property of the master computer. */ public EnvVars getEnvironment() throws IOException, InterruptedException { EnvVars cachedEnvironment = this.cachedEnvironment; if (cachedEnvironment != null) { return new EnvVars(cachedEnvironment); } cachedEnvironment = EnvVars.getRemote(getChannel()); this.cachedEnvironment = cachedEnvironment; return new EnvVars(cachedEnvironment); }
protected void _doScript(StaplerRequest req, StaplerResponse rsp, String view) throws IOException, ServletException { Jenkins._doScript(req, rsp, req.getView(this, view), getChannel(), getACL()); }
/** * 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(Jenkins.ADMINISTER); rsp.setContentType("text/plain"); try (PrintWriter w = new PrintWriter(rsp.getCompressedWriter(req))) { VirtualChannel vc = getChannel(); if (vc instanceof Channel) { w.println("Master to slave"); ((Channel) vc).dumpExportTable(w); w.flush(); // flush here once so that even if the dump from the agent fails, the client gets some useful info w.println("\n\n\nSlave to master"); w.print(vc.call(new DumpExportTableTask())); } else { w.println(Messages.Computer_BadChannel()); } } }
private static void install(Computer c, TaskListener listener) { try { final List<SlaveRestarter> restarters = new ArrayList<>(SlaveRestarter.all()); VirtualChannel ch = c.getChannel(); if (ch==null) return; // defensive check List<SlaveRestarter> effective = ch.call(new FindEffectiveRestarters(restarters)); LOGGER.log(FINE, "Effective SlaveRestarter on {0}: {1}", new Object[] {c.getName(), effective}); } catch (Throwable e) { Functions.printStackTrace(e, listener.error("Failed to install restarter")); } } private static class FindEffectiveRestarters extends MasterToSlaveCallable<List<SlaveRestarter>, IOException> {
VirtualChannel ch = c.getChannel();
VirtualChannel channel = getChannel(); if(channel==null) return null; // can't compute right now
/** * Performs monitoring across the board. * * @return * For all the computers, report the monitored values. */ protected Map<Computer,T> monitor() throws InterruptedException { Map<Computer,T> data = new HashMap<Computer,T>(); for( Computer c : Jenkins.getInstance().getComputers() ) { try { Thread.currentThread().setName("Monitoring "+c.getDisplayName()+" for "+getDisplayName()); if(c.getChannel()==null) data.put(c,null); else data.put(c,monitor(c)); } catch (RuntimeException e) { LOGGER.log(Level.WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e); } catch (InterruptedException e) { throw (InterruptedException)new InterruptedException("Node monitoring "+c.getDisplayName()+" for "+getDisplayName()+" aborted.").initCause(e); } } return data; }
protected void execute(TaskListener listener) throws IOException, InterruptedException { if (!enabled) return; long now = System.currentTimeMillis(); for (Computer c: Jenkins.get().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 agent 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); } } } }
/** * Obtains the heap dump. */ public HeapDump getHeapDump() throws IOException { return new HeapDump(this,getChannel()); }
/** * Gets the thread dump of the agent JVM. * @return * key is the thread name, and the value is the pre-formatted dump. */ public Map<String,String> getThreadDump() throws IOException, InterruptedException { return RemotingDiagnostics.getThreadDump(getChannel()); }