public static Map<Object,Object> getSystemProperties(VirtualChannel channel) throws IOException, InterruptedException { if(channel==null) return Collections.<Object,Object>singletonMap("N/A","N/A"); return channel.call(new GetSystemProperties()); }
/** * Obtains the heap dump in an HPROF file. */ public static FilePath getHeapDump(VirtualChannel channel) throws IOException, InterruptedException { return channel.call(new GetHeapDump()); } private static class GetHeapDump extends MasterToSlaveCallable<FilePath, IOException> {
/** * Gets the {@link FilePath} representation of the "~" directory * (User's home directory in the Unix sense) of the given channel. */ public static FilePath getHomeDirectory(VirtualChannel ch) throws InterruptedException, IOException { return ch.call(new GetHomeDirectory()); } private static class GetHomeDirectory extends MasterToSlaveCallable<FilePath, IOException> {
/** * Executes Groovy script remotely. */ public static String executeGroovy(String script, @Nonnull VirtualChannel channel) throws IOException, InterruptedException { return channel.call(new Script(script)); }
public static Map<String,String> getThreadDump(VirtualChannel channel) throws IOException, InterruptedException { if(channel==null) return Collections.singletonMap("N/A","N/A"); return channel.call(new GetThreadDump()); }
/** * Executes some program on the machine that this {@link FilePath} exists, * so that one can perform local file operations. */ public <V,E extends Throwable> V act(Callable<V,E> callable) throws IOException, InterruptedException, E { if(channel!=null) { // run this on a remote system return channel.call(callable); } else { // the file is on the local machine return callable.call(); } }
public String getShellOrDefault(VirtualChannel channel) { if (shell != null) return shell; String interpreter = null; try { interpreter = channel.call(new Shellinterpreter()); } catch (IOException e) { LOGGER.log(Level.WARNING, null, e); } catch (InterruptedException e) { LOGGER.log(Level.WARNING, null, e); } if (interpreter == null) { interpreter = getShellOrDefault(); } return interpreter; }
@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; }
/** * Gets the executable path of this maven on the given target system. */ public String getExecutable(Launcher launcher) throws IOException, InterruptedException { return launcher.getChannel().call(new GetExecutable()); } private class GetExecutable extends MasterToSlaveCallable<String, IOException> {
/** * Obtains the environment variables of a remote peer. * * @param channel * Can be null, in which case the map indicating "N/A" will be returned. * @return * A fresh copy that can be owned and modified by the caller. */ public static EnvVars getRemote(VirtualChannel channel) throws IOException, InterruptedException { if(channel==null) return new EnvVars("N/A","N/A"); return channel.call(new GetEnvVars()); }
@Override public void kill(final Map<String,String> modelEnvVars) throws IOException, InterruptedException { getChannel().call(new KillTask(modelEnvVars)); }
public ClientAuthenticationCache(Channel channel) throws IOException, InterruptedException { store = (channel==null ? FilePath.localChannel : channel).call(new CredentialsFilePathMasterToSlaveCallable()); if (store.exists()) { try (InputStream istream = store.read()) { props.load(istream); } } }
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); } } } } } }
/** * Estimates the clock difference with this agent. * * @return * always non-null. * @throws InterruptedException * if the operation is aborted. */ public ClockDifference getClockDifference() throws IOException, InterruptedException { VirtualChannel channel = getChannel(); if(channel==null) throw new IOException(getNodeName()+" is offline"); return channel.call(getClockDifferenceCallable()); }
/** * Starts a new privilege-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(); ch.join(3000); // give some time for orderly shutdown, but don't block forever. } }
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> {
/** * Creates a {@link Launcher} for starting processes on the node * that has this file. * @since 1.89 */ public Launcher createLauncher(TaskListener listener) throws IOException, InterruptedException { if(channel==null) return new LocalLauncher(listener); else return new RemoteLauncher(listener,channel,channel.call(new IsUnix())); }
@Override public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); Pipe out = Pipe.createRemoteToLocal(); final String workDir = _workDir==null ? null : _workDir.getRemote(); OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides)); return new Channel("remotely launched channel on "+channel, Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os)); }
private <T> T act(final FileCallable<T> callable, ClassLoader cl) throws IOException, InterruptedException { if(channel!=null) { // run this on a remote system try { DelegatingCallable<T,IOException> wrapper = new FileCallableWrapper<T>(callable, cl); for (FileCallableWrapperFactory factory : ExtensionList.lookup(FileCallableWrapperFactory.class)) { wrapper = factory.wrap(wrapper); } return channel.call(wrapper); } catch (TunneledInterruptedException e) { throw (InterruptedException)new InterruptedException(e.getMessage()).initCause(e); } } else { // the file is on the local machine. return callable.invoke(new File(remote), localChannel); } }
public Proc launch(ProcStarter ps) throws IOException { final OutputStream out = ps.stdout == null || ps.stdoutListener != null ? null : new RemoteOutputStream(new CloseProofOutputStream(ps.stdout)); final OutputStream err = ps.stderr==null ? null : new RemoteOutputStream(new CloseProofOutputStream(ps.stderr)); final InputStream in = (ps.stdin==null || ps.stdin==NULL_INPUT_STREAM) ? null : new RemoteInputStream(ps.stdin,false); final FilePath psPwd = ps.pwd; final String workDir = psPwd==null ? null : psPwd.getRemote(); try { return new ProcImpl(getChannel().call(new RemoteLaunchCallable(ps.commands, ps.masks, ps.envs, in, ps.reverseStdin, out, ps.reverseStdout, err, ps.reverseStderr, ps.quiet, workDir, listener, ps.stdoutListener))); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } }