@Override public void onClosed(Channel channel, IOException cause) { LOGGER.fine("Terminating ping thread for " + channel.getName()); isInClosed.set(true); t.interrupt(); // make sure the ping thread is terminated } });
/** Keep in a separate method so we do not even try to do class loading on {@link PingFailureAnalyzer} from an agent JVM. */ private void analyze(Throwable cause) { for (PingFailureAnalyzer pfa : PingFailureAnalyzer.all()) { try { pfa.onPingFailure(channel, cause); } catch (IOException ex) { LOGGER.log(Level.WARNING, "Ping failure analyzer " + pfa.getClass().getName() + " failed for " + channel.getName(), ex); } } } @Deprecated
@VisibleForTesting /*package*/ void install(Channel channel, @CheckForNull SlaveComputer c) { if (pingTimeoutSeconds < 1 || pingIntervalSeconds < 1) { LOGGER.warning("Agent ping is disabled"); return; } // set up ping from both directions, so that in case of a router dropping a connection, // both sides can notice it and take compensation actions. try { channel.call(new SetUpRemotePing(pingTimeoutSeconds, pingIntervalSeconds)); LOGGER.fine("Set up a remote ping for " + channel.getName()); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to set up a ping for " + channel.getName(), e); } setUpPingForChannel(channel, c, pingTimeoutSeconds, pingIntervalSeconds, true); }
@Override protected void onDead(Throwable cause) { if (analysis) { analyze(cause); } boolean inClosed = isInClosed.get(); // Disassociate computer channel before closing it if (computer != null) { Exception exception = cause instanceof Exception ? (Exception) cause: new IOException(cause); computer.disconnect(new OfflineCause.ChannelTermination(exception)); } if (inClosed) { LOGGER.log(Level.FINE,"Ping failed after the channel "+channel.getName()+" is already partially closed.",cause); } else { LOGGER.log(Level.INFO,"Ping failed. Terminating the channel "+channel.getName()+".",cause); } } /** Keep in a separate method so we do not even try to do class loading on {@link PingFailureAnalyzer} from an agent JVM. */
@VisibleForTesting @Restricted(NoExternalUse.class) public static void setUpPingForChannel(final Channel channel, final SlaveComputer computer, int timeoutSeconds, int intervalSeconds, final boolean analysis) { LOGGER.log(Level.FINE, "setting up ping on {0} with a {1} seconds interval and {2} seconds timeout", new Object[] {channel.getName(), intervalSeconds, timeoutSeconds}); final AtomicBoolean isInClosed = new AtomicBoolean(false); final PingThread t = new PingThread(channel, timeoutSeconds * 1000L, intervalSeconds * 1000L) {
/** * Constructor. * @param channel the {@link Channel}. */ private Ref(@CheckForNull Channel channel) { this.name = channel != null ? channel.getName() : "unknown (null reference)"; this.channel = channel; }
@Override public void onRead(Channel channel, Command cmd, long blockSize) { if (logger.isLoggable(level)) { logger.log(level, channel.getName() + " read " + blockSize + ": " + cmd); } }
@Override public void onWrite(Channel channel, Command cmd, long blockSize) { if (logger.isLoggable(level)) { logger.log(level, channel.getName() + " wrote " + blockSize + ": " + cmd); } }
public ChannelStateException(@CheckForNull Channel channel, @Nonnull String message) { super(message); channelRef = channel != null ? new WeakReference<>(channel) : null; channelName = channel != null ? channel.getName() : "unknown"; }
public ChannelStateException(@CheckForNull Channel channel, String message, @CheckForNull Throwable cause) { super(message, cause); channelRef = channel != null ? new WeakReference<>(channel) : null; channelName = channel != null ? channel.getName() : "unknown"; }
@Override public void onJar(Channel channel, File jar) { if (logger.isLoggable(level)) { logger.log(level, channel.getName() + " sending " + jar + " of length " + jar.length()); } } }
@Override public void onClosed(Channel channel, IOException cause) { LOGGER.fine("Terminating ping thread for " + channel.getName()); isInClosed.set(true); t.interrupt(); // make sure the ping thread is terminated } });
/** Keep in a separate method so we do not even try to do class loading on {@link PingFailureAnalyzer} from an agent JVM. */ private void analyze(Throwable cause) { for (PingFailureAnalyzer pfa : PingFailureAnalyzer.all()) { try { pfa.onPingFailure(channel, cause); } catch (IOException ex) { LOGGER.log(Level.WARNING, "Ping failure analyzer " + pfa.getClass().getName() + " failed for " + channel.getName(), ex); } } } @Deprecated
Future<URL> _resolveJarURL(Channel channel) throws IOException, InterruptedException { JarCache c = channel.getJarCache(); if (c == null) { throw new IOException(String.format("Failed to resolve a jar %016x%016x. JAR Cache is disabled for the channel %s", sum1, sum2, channel.getName())); } return c.resolve(channel, sum1, sum2); // throw (IOException)new IOException(String.format("Failed to resolve a jar %016x%016x",sum1,sum2)).initCause(e); }
public ReaderThread(CommandReceiver receiver) { super("Channel reader thread: "+channel.getName()); this.receiver = receiver; setUncaughtExceptionHandler((t, e) -> { LOGGER.log(Level.SEVERE, "Uncaught exception in SynchronousCommandTransport.ReaderThread " + t, e); channel.terminate(new IOException("Unexpected reader termination", e)); }); }
public static SlaveInstaller createFor(Channel c) throws InterruptedException { for (SlaveInstallerFactory f : all()) { try { SlaveInstaller si = f.createIfApplicable(c); if (si!=null) return si; } catch (IOException e) { LOGGER.log(Level.WARNING, f+" has failed on "+c.getName(),e); // try the next one } } return null; }
public void handle(byte[] payload) { try { Command cmd = Command.readFrom(channel, payload); receiver.handle(cmd); } catch (IOException | ClassNotFoundException e) { LOGGER.log(Level.WARNING, "Failed to construct Command in channel " + channel.getName(), e); } }
/** * If the build was workflow, get the ID of that channel. */ public static Optional<DockerCloud> getCloudForChannel(VirtualChannel channel) { if( channel instanceof Channel) { Channel c = (Channel)channel; Node node = Jenkins.getInstance().getNode( c.getName() ); if (node instanceof DockerTransientNode) { return Optional.of(((DockerTransientNode) node).getCloud()); } } return Optional.empty(); }
public static String getAgentName(FilePath ws) { if (ws.getChannel() != null) { return ws.getChannel() instanceof LocalChannel ? "Master" : ((Channel) ws.getChannel()).getName(); } return "Unknown"; }
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject(); System.setProperty("attack", attack + ">" + getChannelForSerialization().getName()); }