public List<LogRecord> getLogRecords() throws IOException, InterruptedException { if(channel==null) return Collections.emptyList(); else return channel.call(new SlaveLogFetcher()); }
/** * Returns an {@link FilePathFilter} object that represents all the in-scope filters, * or {@code null} if none is needed. */ public static @CheckForNull FilePathFilter current() { Channel ch = Channel.current(); if (ch==null) return null; return ch.getProperty(FilePathFilterAggregator.KEY); }
@Override public Integer call() { Channel c = Channel.current(); if (c == null) { return -1; } return c.classLoadingPrefetchCacheCount.get(); } }
/** * Handles CLI connection request. */ private void runCliConnect(DataInputStream in, PrintWriter out) throws IOException, InterruptedException { out.println("Welcome"); Channel channel = new Channel("CLI channel from " + s.getInetAddress(), Computer.threadPoolForRemoting, Mode.BINARY, new BufferedInputStream(new SocketInputStream(this.s)), new BufferedOutputStream(new SocketOutputStream(this.s)), null, true); channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl()); channel.join(); }
public static final void main ( final String[] args ) { if ( args.length < 3 ) { System.err.println(JenkinsCLI.class.getName() + " <jenkins_url> <payload_type> <payload_arg>"); System.exit(-1); } final Object payloadObject = Utils.makePayloadObject(args[1], args[2]); String jenkinsUrl = args[ 0 ]; Channel c = null; try { InetSocketAddress isa = JenkinsCLI.getCliPort(jenkinsUrl); c = JenkinsCLI.openChannel(isa); c.call(getPropertyCallable(payloadObject)); } catch ( Throwable e ) { e.printStackTrace(); } finally { if ( c != null ) { try { c.close(); } catch ( IOException e ) { e.printStackTrace(System.err); } } } Utils.releasePayload(args[1], payloadObject); }
channel.setProperty(SlaveComputer.class, this); channel.addListener(new LoggingChannelListener(logger, Level.FINEST) { @Override public void onClosed(Channel c, IOException cause) { channel.addListener(listener); String slaveVersion = channel.call(new SlaveVersion()); log.println("Remoting version: " + slaveVersion); VersionNumber agentVersion = new VersionNumber(slaveVersion); boolean _isUnix = channel.call(new DetectOS()); log.println(_isUnix? hudson.model.Messages.Slave_UnixSlave():hudson.model.Messages.Slave_WindowsSlave()); String defaultCharsetName = channel.call(new DetectDefaultCharset()); remoteFS = channel.call(new AbsolutePath(remoteFS)); log.println("NOTE: Relative remote path resolved to: "+remoteFS); channel.pinClassLoader(getClass().getClassLoader()); channel.call(new SlaveInitializer(DEFAULT_RING_BUFFER_SIZE)); SecurityContext old = ACL.impersonate(ACL.SYSTEM); try { channel.close(); throw new IllegalStateException("Already connected");
public static void applyConfiguration(SAXReader reader, Object context) throws IOException, InterruptedException { Collection<ParserConfigurator> all = Collections.emptyList(); if (Jenkins.getInstanceOrNull()==null) { Channel ch = Channel.current(); if (ch!=null) all = ch.call(new GetParserConfigurators()); } else all = all(); for (ParserConfigurator pc : all) pc.configure(reader,context); } private static class GetParserConfigurators extends SlaveToMasterCallable<Collection<ParserConfigurator>, IOException> {
public Boolean call() throws IOException { try { return Channel.current().preloadJar(this, Ivy.class); } catch (InterruptedException e) { } return false; } }
@Override public synchronized void close() throws IOException { super.close(); // wait for all the output from the process to be picked up try { t2.join(); } catch (InterruptedException e) { // process the interrupt later Thread.currentThread().interrupt(); } } };
public Remote(ProcessTree proxy, Channel ch, boolean vetoersExist) { super(vetoersExist); this.proxy = ch.export(IProcessTree.class,proxy); for (Entry<Integer,OSProcess> e : proxy.processes.entrySet()) processes.put(e.getKey(),new RemoteProcess(e.getValue(),ch)); }
/** * @deprecated Specific to {@link Mode#REMOTING}. */ @Deprecated private Channel connectViaHttp(URL url) throws IOException { LOGGER.log(FINE, "Trying to connect to {0} via Remoting over HTTP", url); FullDuplexHttpStream con = new FullDuplexHttpStream(url, "cli?remoting=true", authorization); Channel ch = new Channel("Chunked connection to " + url, pool,con.getInputStream(),con.getOutputStream()); final long interval = 15*1000; final long timeout = (interval * 3) / 4; new PingThread(ch,timeout,interval) { protected void onDead() { // noop. the point of ping is to keep the connection alive // as most HTTP servers have a rather short read time out } }.start(); return ch; }
@Override public void run(Channel channel) throws Exception, AssertionError { channel.callAsync(payload); } };
public int main(List<String> args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) { // remoting sets the context classloader to the RemoteClassLoader, // which slows down the classloading. we don't load anything from CLI, // so counter that effect. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); PrintStream out = new PrintStream(stdout); PrintStream err = new PrintStream(stderr); String subCmd = args.get(0); CLICommand cmd = CLICommand.clone(subCmd); if(cmd!=null) { cmd.channel = Channel.current(); final CLICommand old = CLICommand.setCurrent(cmd); try { transportAuth = Channel.currentOrFail().getProperty(CLICommand.TRANSPORT_AUTHENTICATION); cmd.setTransportAuth(transportAuth); return cmd.main(args.subList(1,args.size()),locale, stdin, out, err); } finally { CLICommand.setCurrent(old); } } err.println("No such command: "+subCmd); new HelpCommand().main(Collections.emptyList(), locale, stdin, out, err); return -1; }
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); } } } }
public int join() throws InterruptedException, IOException { try { return p.join(); } finally { // make sure I/O is delivered to the remote before we return Channel taskChannel = null; try { // Sync IO will fail automatically if the channel is being closed, no need to use getOpenChannelOrFail() // TODOL Replace by Channel#currentOrFail() when Remoting version allows taskChannel = Channel.current(); if (taskChannel == null) { throw new IOException("No Remoting channel associated with this thread"); } taskChannel.syncIO(); } catch (Throwable t) { // this includes a failure to sync, agent.jar too old, etc LOGGER.log(Level.INFO, "Failed to synchronize IO streams on the channel " + taskChannel, t); } } }
@Override protected void run(final InputStream upload, OutputStream download) throws IOException, InterruptedException { channel = new Channel("HTTP full-duplex channel " + uuid, Computer.threadPoolForRemoting, Mode.BINARY, upload, download, null, restricted); // so that we can detect dead clients, periodically send something PingThread ping = new PingThread(channel) { @Override protected void onDead(Throwable diagnosis) { LOGGER.log(Level.INFO, "Duplex-HTTP session " + uuid + " is terminated", diagnosis); // this will cause the channel to abort and subsequently clean up try { upload.close(); } catch (IOException e) { // this can never happen throw new AssertionError(e); } } @Override protected void onDead() { onDead(null); } }; ping.start(); main(channel); channel.join(); ping.interrupt(); }
public String call() throws Exception { Logger log = Logger.getLogger(SelfRegisteringRemote.class.getName()); Logger.getLogger("org").setLevel(Level.ALL); log.fine("instances " + PropertyUtils.getProperty(SeleniumConstants.PROPERTY_INSTANCE)); SelfRegisteringRemote srr = PropertyUtils.getProperty(SeleniumConstants.PROPERTY_INSTANCE); String url = getRemoteURL(srr); srr.stopRemoteServer(); Channel.current().setProperty(SeleniumConstants.PROPERTY_LOCK, new Object()); return url; }