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

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

本文整理了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

  1. /**
  2. * @return The list of strings of computer names (excluding master)
  3. * @since 2.14
  4. */
  5. @Nonnull
  6. public static List<String> getComputerNames() {
  7. final ArrayList<String> names = new ArrayList<String>();
  8. for (Computer c : Jenkins.getInstance().getComputers()) {
  9. if (!c.getName().isEmpty()) {
  10. names.add(c.getName());
  11. }
  12. }
  13. return names;
  14. }

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

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

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

  1. void broadcast() {
  2. for (Computer c : Jenkins.getInstance().getComputers()) {
  3. if (c.getName().length() > 0) { // i.e. not master
  4. VirtualChannel ch = c.getChannel();
  5. if (ch != null) {
  6. try {
  7. ch.call(this);
  8. } catch (Exception x) {
  9. Logger.getLogger(LogRecorder.class.getName()).log(Level.WARNING, "could not set up logging on " + c, x);
  10. }
  11. }
  12. }
  13. }
  14. }
  15. }

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

  1. /**
  2. * If this {@link Launcher} is encapsulating an execution on a specific {@link Computer},
  3. * return it.
  4. *
  5. * <p>
  6. * Because of the way internal Hudson abstractions are set up (that is, {@link Launcher} only
  7. * needs a {@link VirtualChannel} to do its job and isn't really required that the channel
  8. * comes from an existing {@link Computer}), this method may not always the right {@link Computer} instance.
  9. *
  10. * @return
  11. * {@code null} if this launcher is not created from a {@link Computer} object.
  12. * @deprecated since 2008-11-16.
  13. * See the javadoc for why this is inherently unreliable. If you are trying to
  14. * figure out the current {@link Computer} from within a build, use
  15. * {@link FilePath#toComputer()} or {@link Computer#currentComputer()}.
  16. */
  17. @Deprecated
  18. @CheckForNull
  19. public Computer getComputer() {
  20. for( Computer c : Jenkins.getInstance().getComputers() )
  21. if(c.getChannel()==channel)
  22. return c;
  23. return null;
  24. }

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

  1. /**
  2. * Gets the one off {@link Executor} building this job, if it's being built.
  3. * Otherwise null.
  4. * @since 1.433
  5. */
  6. public @CheckForNull Executor getOneOffExecutor() {
  7. for( Computer c : Jenkins.getInstance().getComputers() ) {
  8. for (Executor e : c.getOneOffExecutors()) {
  9. if(e.getCurrentExecutable()==this)
  10. return e;
  11. }
  12. }
  13. return null;
  14. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @SuppressWarnings("unchecked")
  5. @Override
  6. protected void doRun() {
  7. final long startRun = System.currentTimeMillis();
  8. for (final Computer c : Jenkins.get().getComputers()) {
  9. Queue.withLock(new Runnable() {
  10. @Override
  11. public void run() {
  12. Node n = c.getNode();
  13. if (n!=null && n.isHoldOffLaunchUntilSave())
  14. return;
  15. if (!nextCheck.containsKey(c) || startRun > nextCheck.get(c)) {
  16. // at the moment I don't trust strategies to wait more than 60 minutes
  17. // strategies need to wait at least one minute
  18. final long waitInMins = Math.max(1, Math.min(60, c.getRetentionStrategy().check(c)));
  19. nextCheck.put(c, startRun + waitInMins*1000*60 /*MINS->MILLIS*/);
  20. }
  21. }
  22. });
  23. }
  24. }
  25. }

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

  1. public List<Computer> getComputers() {
  2. Computer[] computers = Jenkins.getInstance().getComputers();
  3. if (!isFilterExecutors()) {
  4. return Arrays.asList(computers);
  5. }
  6. List<Computer> result = new ArrayList<Computer>();
  7. HashSet<Label> labels = new HashSet<Label>();
  8. for (Item item : getItems()) {
  9. if (item instanceof AbstractProject<?, ?>) {
  10. labels.addAll(((AbstractProject<?, ?>) item).getRelevantLabels());
  11. }
  12. }
  13. for (Computer c : computers) {
  14. if (isRelevant(labels, c)) result.add(c);
  15. }
  16. return result;
  17. }

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

  1. /**
  2. * If this {@link FilePath} represents a file on a particular {@link Computer}, return it.
  3. * Otherwise null.
  4. * @since 1.571
  5. */
  6. public @CheckForNull Computer toComputer() {
  7. Jenkins j = Jenkins.getInstanceOrNull();
  8. if (j != null) {
  9. for (Computer c : j.getComputers()) {
  10. if (getChannel()==c.getChannel()) {
  11. return c;
  12. }
  13. }
  14. }
  15. return null;
  16. }

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

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

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

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

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

  1. /**
  2. * Finds the executor currently running a given process.
  3. * @param executable a possibly running executable
  4. * @return the executor (possibly a {@link OneOffExecutor}) whose {@link Executor#getCurrentExecutable} matches that,
  5. * or null if it could not be found (for example because the execution has already completed)
  6. * @since 1.607
  7. */
  8. @CheckForNull
  9. public static Executor of(Executable executable) {
  10. Jenkins jenkins = Jenkins.getInstanceOrNull(); // TODO confirm safe to assume non-null and use getInstance()
  11. if (jenkins == null) {
  12. return null;
  13. }
  14. for (Computer computer : jenkins.getComputers()) {
  15. for (Executor executor : computer.getAllExecutors()) {
  16. if (executor.getCurrentExecutable() == executable) {
  17. return executor;
  18. }
  19. }
  20. }
  21. return null;
  22. }

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

  1. @Override
  2. public boolean isReadyToRestart() throws IOException, InterruptedException {
  3. for (Computer c : Jenkins.getInstance().getComputers()) {
  4. if (c.isOnline()) {
  5. for (Executor e : c.getAllExecutors()) {
  6. if (blocksRestart(e)) {
  7. return false;
  8. }
  9. }
  10. }
  11. }
  12. return true;
  13. }
  14. private static boolean blocksRestart(Executor e) {

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

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

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

  1. /**
  2. * Performs monitoring across the board.
  3. *
  4. * @return
  5. * For all the computers, report the monitored values.
  6. */
  7. protected Map<Computer,T> monitor() throws InterruptedException {
  8. Map<Computer,T> data = new HashMap<Computer,T>();
  9. for( Computer c : Jenkins.getInstance().getComputers() ) {
  10. try {
  11. Thread.currentThread().setName("Monitoring "+c.getDisplayName()+" for "+getDisplayName());
  12. if(c.getChannel()==null)
  13. data.put(c,null);
  14. else
  15. data.put(c,monitor(c));
  16. } catch (RuntimeException e) {
  17. LOGGER.log(Level.WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e);
  18. } catch (IOException e) {
  19. LOGGER.log(Level.WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e);
  20. } catch (InterruptedException e) {
  21. throw (InterruptedException)new InterruptedException("Node monitoring "+c.getDisplayName()+" for "+getDisplayName()+" aborted.").initCause(e);
  22. }
  23. }
  24. return data;
  25. }

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

  1. @Override
  2. public int computeTotalExecutors() {
  3. int r=0;
  4. for (Computer c : Jenkins.getInstance().getComputers()) {
  5. Node node = c.getNode();
  6. if (node != null && node.getMode() == Mode.NORMAL && c.isOnline()) {
  7. r += c.countExecutors();
  8. }
  9. }
  10. return r;
  11. }

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

  1. @Override
  2. public int computeIdleExecutors() {
  3. int r=0;
  4. for (Computer c : Jenkins.getInstance().getComputers()) {
  5. Node node = c.getNode();
  6. if (node != null && node.getMode() == Mode.NORMAL && (c.isOnline() || c.isConnecting()) && c.isAcceptingTasks()) {
  7. r += c.countIdle();
  8. }
  9. }
  10. return r;
  11. }

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

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

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

  1. if (c.isOffline() && c.isLaunchSupported()) {
  2. final HashMap<Computer, Integer> availableComputers = new HashMap<>();
  3. for (Computer o : Jenkins.get().getComputers()) {
  4. if ((o.isOnline() || o.isConnecting()) && o.isPartiallyIdle() && o.isAcceptingTasks()) {
  5. final int idleExecutors = o.countIdle();

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

  1. protected void execute(TaskListener listener) throws IOException, InterruptedException {
  2. if (!enabled) return;
  3. long now = System.currentTimeMillis();
  4. for (Computer c: Jenkins.get().getComputers()) {
  5. VirtualChannel ch = c.getChannel();
  6. if (ch instanceof Channel) {
  7. Channel channel = (Channel) ch;
  8. if (now-channel.getLastHeard() > TIME_TILL_PING) {
  9. // haven't heard from this agent for a while.
  10. Long lastPing = (Long)channel.getProperty(ConnectionActivityMonitor.class);
  11. if (lastPing!=null && now-lastPing > TIMEOUT) {
  12. LOGGER.info("Repeated ping attempts failed on "+c.getName()+". Disconnecting");
  13. c.disconnect(OfflineCause.create(Messages._ConnectionActivityMonitor_OfflineCause()));
  14. } else {
  15. // send a ping. if we receive a reply, it will be reflected in the next getLastHeard() call.
  16. channel.callAsync(PING_COMMAND);
  17. if (lastPing==null)
  18. channel.setProperty(ConnectionActivityMonitor.class,now);
  19. }
  20. } else {
  21. // we are receiving data nicely
  22. channel.setProperty(ConnectionActivityMonitor.class,null);
  23. }
  24. }
  25. }
  26. }

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

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

相关文章

Jenkins类方法