jenkins.model.Jenkins.getComputers()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(325)

本文整理了Java中jenkins.model.Jenkins.getComputers()方法的一些代码示例,展示了Jenkins.getComputers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getComputers()方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getComputers

Jenkins.getComputers介绍

[英]Gets the read-only list of all Computers.
[中]

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * @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;
}

代码示例来源:origin: jenkinsci/jenkins

@Exported(name="computer",inline=true)
public Computer[] get_all() {
  return Jenkins.getInstance().getComputers();
}

代码示例来源:origin: jenkinsci/jenkins

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);
          }
        }
      }
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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;
}

代码示例来源:origin: jenkinsci/jenkins

/**
   * {@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*/);
          }
        }
      });
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

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;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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;
}

代码示例来源:origin: jenkinsci/jenkins

for (Computer c : Jenkins.getInstance().getComputers()) {
  if (c.getName().length() == 0) {
    continue; // master

代码示例来源:origin: jenkinsci/jenkins

for (Computer c : getComputers()) {
  try {
    future.put(c.getName(), RemotingDiagnostics.getThreadDumpAsync(c.getChannel()));

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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;
}

代码示例来源:origin: jenkinsci/jenkins

@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) {

代码示例来源:origin: jenkinsci/jenkins

Set<Computer> skipped = new HashSet<>();
for (Computer c : Jenkins.getInstance().getComputers()) {
  try {
    VirtualChannel ch = c.getChannel();

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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;
}

代码示例来源:origin: jenkinsci/jenkins

@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;
}

代码示例来源:origin: jenkinsci/jenkins

@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;
}

代码示例来源:origin: jenkinsci/jenkins

for (Computer c : Jenkins.getInstance().getComputers()) {
  if (c.isOffline())  continue;
  for (Executor e : c.getExecutors()) {

代码示例来源:origin: jenkinsci/jenkins

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();

代码示例来源:origin: jenkinsci/jenkins

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);
      }
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

for( Computer c : j.getComputers() ) {
  JSONObject  n = new JSONObject();
  if(c.getNode()==j) {

相关文章

Jenkins类方法