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); } } } } } }
Set<Computer> skipped = new HashSet<>(); for (Computer c : Jenkins.getInstance().getComputers()) { try { VirtualChannel ch = c.getChannel(); futures.put(c,ch.callAsync(cc)); LOGGER.log(WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e); } catch (IOException e) { LOGGER.log(WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e);
/** * 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. } }
@Override public void execute(Launcher launcher, @SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLogger console) throws DockerException { if (containerIds == null || containerIds.isEmpty()) { throw new IllegalArgumentException("At least one parameter is required"); } String containerIdsRes = Resolver.buildVar(build, containerIds); List<String> ids = Arrays.asList(containerIdsRes.split(",")); try { Config cfgData = getConfig(build); Descriptor<?> descriptor = Jenkins.getInstance().getDescriptor(DockerBuilder.class); for (String id : ids) { id = id.trim(); launcher.getChannel().call(new RestartContainerRemoteCallable(cfgData, descriptor, id, timeout)); console.logInfo("restarted container id " + id); } } catch (Exception e) { console.logError("failed to restart containers ids " + ids); e.printStackTrace(); throw new IllegalArgumentException(e); } }
public static Long calculateWorkspaceDiskUsageForPath(FilePath workspace, ArrayList<FilePath> exceeded) throws IOException, InterruptedException{ Long diskUsage = 0l; if(workspace.exists()){ try{ diskUsage = workspace.getChannel().callAsync(new DiskUsageCallable(workspace, exceeded)).get(Jenkins.getInstance().getPlugin(DiskUsagePlugin.class).getConfiguration().getTimeoutWorkspace(), TimeUnit.MINUTES); } catch(Exception e){ Logger.getLogger(DiskUsageUtil.class.getName()).log(Level.WARNING, "Disk usage fails to calculate workspace for file path " + workspace.getRemote() + " through channel " + workspace.getChannel(),e); } } return diskUsage; }
@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)); }
/** * 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> {
final PluginWrapper wrapper = Jenkins.getInstance().getPluginManager().getPlugin(DependencyCheckDescriptor.PLUGIN_ID); listener.getLogger().println(OUT_TAG + wrapper.getLongName() + " v" + wrapper.getVersion()); final boolean isMaster = build.getExecutor().getOwner().getNode() == Jenkins.getInstance(); success = launcher.getChannel().call(new DependencyCheckExecutor(options, listener, classLoader)); } else { success = launcher.getChannel().call(new DependencyCheckExecutor(options, listener));
public Proc launch(ProcStarter ps) throws IOException { final OutputStream out = ps.stdout == 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 ? null : new RemoteInputStream(ps.stdin); final String workDir = ps.pwd==null ? null : ps.pwd.getRemote(); return new RemoteProc(getChannel().callAsync(new RemoteLaunchCallable(ps.commands, ps.masks, ps.envs, in, out, err, workDir, listener))); }
/** * Determines the CPU of the given node. */ public static CPU of(Node n) throws IOException,InterruptedException, DetectionFailedException { return n.getChannel().call(new Callable<CPU,DetectionFailedException>() { public CPU call() throws DetectionFailedException { return current(); } }); }
@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; }
public boolean perform() throws Exception { FilePath rootFileObject = new FilePath(this.workspace, config.getRootObject()); final DeployerContext deployerContext = new DeployerContext(config, rootFileObject, listener); final VirtualChannel channel = launcher.getChannel(); if (null == channel) throw new IllegalStateException("Null Channel (?)"); final Future<Boolean> booleanFuture = channel.callAsync(new SlaveDeployerCallable(deployerContext)); return booleanFuture.get(); } }
/** * Delete the slave, terminate or suspend the instance. * Can be called either by doDoDelete() or from JCloudsRetentionStrategy. * Whether the instance gets terminated or suspended is handled in * {@link JCloudsSlave#_terminate} * * @throws InterruptedException if the deletion gets interrupted. * @throws IOException if an error occurs. */ public void deleteSlave() throws IOException, InterruptedException { if (isIdle()) { // Fixes JENKINS-27471 LOGGER.info("Deleting slave: " + getName()); JCloudsSlave slave = getNode(); if (null != slave ) { final VirtualChannel ch = slave.getChannel(); if (null != ch) { ch.close(); } slave.terminate(); Jenkins.getInstance().removeNode(slave); } } else { LOGGER.info(String.format("Slave %s is not idle, postponing deletion", getName())); // Fixes JENKINS-28403 final JCloudsSlave node = getNode(); if (null != node && !node.isPendingDelete()) { node.setPendingDelete(true); } } }
public Map<String, SeleniumRunOptions> getConfigurations() { PluginImpl.getPlugin().validateAdmin(); try { return computer.getNode().getRootPath().getChannel().call(new GetConfigurations()); } catch (Exception e) { return Collections.emptyMap(); } }
/** * 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()); }
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> {
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()); }
/** * Starts a {@link PortForwarder} accepting remotely at the given channel, * which connects by using the given connector. * * @return * A {@link Closeable} that can be used to shut the port forwarding down. */ public static ListeningPort create(VirtualChannel ch, final int acceptingPort, Forwarder forwarder) throws IOException, InterruptedException { // need a remotable reference final Forwarder proxy = ch.export(Forwarder.class, forwarder); return ch.call(new Callable<ListeningPort,IOException>() { public ListeningPort call() throws IOException { PortForwarder t = new PortForwarder(acceptingPort, proxy); t.start(); return Channel.current().export(ListeningPort.class,t); } }); }
/** * 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()); } } }