/** * @return The list of strings of computer names (excluding master) * @since 2.14 */ @Nonnull public static List<String> getComputerNames() { final ArrayList<String> names = new ArrayList<String>(); for (Computer c : Jenkins.getInstance().getComputers()) { if (!c.getName().isEmpty()) { names.add(c.getName()); } } return names; }
@Exported(name="computer",inline=true) public Computer[] get_all() { return Jenkins.getInstance().getComputers(); }
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; }
/** * Gets the one off {@link Executor} building this job, if it's being built. * Otherwise null. * @since 1.433 */ public @CheckForNull Executor getOneOffExecutor() { for( Computer c : Jenkins.getInstance().getComputers() ) { for (Executor e : c.getOneOffExecutors()) { if(e.getCurrentExecutable()==this) return e; } } return null; }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected void doRun() { final long startRun = System.currentTimeMillis(); for (final Computer c : Jenkins.get().getComputers()) { Queue.withLock(new Runnable() { @Override public void run() { Node n = c.getNode(); if (n!=null && n.isHoldOffLaunchUntilSave()) return; if (!nextCheck.containsKey(c) || startRun > nextCheck.get(c)) { // at the moment I don't trust strategies to wait more than 60 minutes // strategies need to wait at least one minute final long waitInMins = Math.max(1, Math.min(60, c.getRetentionStrategy().check(c))); nextCheck.put(c, startRun + waitInMins*1000*60 /*MINS->MILLIS*/); } } }); } } }
public List<Computer> getComputers() { Computer[] computers = Jenkins.getInstance().getComputers(); if (!isFilterExecutors()) { return Arrays.asList(computers); } List<Computer> result = new ArrayList<Computer>(); HashSet<Label> labels = new HashSet<Label>(); for (Item item : getItems()) { if (item instanceof AbstractProject<?, ?>) { labels.addAll(((AbstractProject<?, ?>) item).getRelevantLabels()); } } for (Computer c : computers) { if (isRelevant(labels, c)) result.add(c); } return result; }
/** * 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; }
for (Computer c : Jenkins.getInstance().getComputers()) { if (c.getName().length() == 0) { continue; // master
for (Computer c : getComputers()) { try { future.put(c.getName(), RemotingDiagnostics.getThreadDumpAsync(c.getChannel()));
/** * Finds the executor currently running a given process. * @param executable a possibly running executable * @return the executor (possibly a {@link OneOffExecutor}) whose {@link Executor#getCurrentExecutable} matches that, * or null if it could not be found (for example because the execution has already completed) * @since 1.607 */ @CheckForNull public static Executor of(Executable executable) { Jenkins jenkins = Jenkins.getInstanceOrNull(); // TODO confirm safe to assume non-null and use getInstance() if (jenkins == null) { return null; } for (Computer computer : jenkins.getComputers()) { for (Executor executor : computer.getAllExecutors()) { if (executor.getCurrentExecutable() == executable) { return executor; } } } return null; }
@Override public boolean isReadyToRestart() throws IOException, InterruptedException { for (Computer c : Jenkins.getInstance().getComputers()) { if (c.isOnline()) { for (Executor e : c.getAllExecutors()) { if (blocksRestart(e)) { return false; } } } } return true; } private static boolean blocksRestart(Executor e) {
Set<Computer> skipped = new HashSet<>(); for (Computer c : Jenkins.getInstance().getComputers()) { try { VirtualChannel ch = c.getChannel();
/** * 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; }
@Override public int computeTotalExecutors() { int r=0; for (Computer c : Jenkins.getInstance().getComputers()) { Node node = c.getNode(); if (node != null && node.getMode() == Mode.NORMAL && c.isOnline()) { r += c.countExecutors(); } } return r; }
@Override public int computeIdleExecutors() { int r=0; for (Computer c : Jenkins.getInstance().getComputers()) { Node node = c.getNode(); if (node != null && node.getMode() == Mode.NORMAL && (c.isOnline() || c.isConnecting()) && c.isAcceptingTasks()) { r += c.countIdle(); } } return r; }
for (Computer c : Jenkins.getInstance().getComputers()) { if (c.isOffline()) continue; for (Executor e : c.getExecutors()) {
if (c.isOffline() && c.isLaunchSupported()) { final HashMap<Computer, Integer> availableComputers = new HashMap<>(); for (Computer o : Jenkins.get().getComputers()) { if ((o.isOnline() || o.isConnecting()) && o.isPartiallyIdle() && o.isAcceptingTasks()) { final int idleExecutors = o.countIdle();
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); } } } }
for( Computer c : j.getComputers() ) { JSONObject n = new JSONObject(); if(c.getNode()==j) {