/** * Returns the possibly empty set of labels that are assigned to this node, * including the automatic {@link #getSelfLabel() self label}, manually * assigned labels and dynamically assigned labels via the * {@link LabelFinder} extension point. * * This method has a side effect of updating the hudson-wide set of labels * and should be called after events that will change that - e.g. a agent * connecting. */ @Exported public Set<LabelAtom> getAssignedLabels() { Set<LabelAtom> r = Label.parse(getLabelString()); r.add(getSelfLabel()); r.addAll(getDynamicLabels()); return Collections.unmodifiableSet(r); }
return FormValidation.ok(); // nothing typed yet try { Label.parseExpression(value); } catch (ANTLRException e) { return FormValidation.error(e, Messages.AbstractProject_AssignedLabelString_InvalidBooleanExpression(e.getMessage())); Jenkins j = Jenkins.getInstance(); Label l = j.getLabel(value); if (l.isEmpty()) { for (LabelAtom a : l.listAtoms()) { if (a.isEmpty()) { LabelAtom nearest = LabelAtom.findNearest(a.getName()); return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch_DidYouMean(a.getName(),nearest.getDisplayName())); return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch()); .getExtensionList(AbstractProject.LabelValidator.class)) { FormValidation result = v.check(project, l); if (!FormValidation.Kind.OK.equals(result.kind)) { return FormValidation.okWithMarkup(Messages.AbstractProject_LabelLink( j.getRootUrl(), Util.escape(l.getName()), l.getUrl(), l.getNodes().size(), l.getClouds().size()) );
/** * Gets all {@link Node}s that belong to this label. */ @Exported public Set<Node> getNodes() { Set<Node> nodes = this.nodes; if(nodes!=null) return nodes; Set<Node> r = new HashSet<>(); Jenkins h = Jenkins.getInstance(); if(this.matches(h)) r.add(h); for (Node n : h.getNodes()) { if(this.matches(n)) r.add(n); } return this.nodes = Collections.unmodifiableSet(r); }
public String getShortDescription() { if (label.isEmpty()) { return Messages.Queue_LabelHasNoNodes(label.getName()); } else { return Messages.Queue_AllNodesOffline(label.getName()); } } }
/** * Puts the label name into a parenthesis if the given operator will have a higher precedence. */ static String paren(LabelOperatorPrecedence op, Label l) { if (op.compareTo(l.precedence())<0) return '('+l.getExpression()+')'; return l.getExpression(); }
long running = Jenkins.getInstance().getInjector().getInstance(Uptime.class).getUptime(); long remaining = TimeUnit.MINUTES.toMillis(10)-running; if (remaining>0 && /* this logic breaks tests of polling */!Functions.getIsUnitTest()) { listener.getLogger().print(Messages.AbstractProject_AwaitingWorkspaceToComeOnline(remaining/1000)); listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")"); return NO_CHANGES; listener.getLogger().print(Messages.AbstractProject_AwaitingWorkspaceToComeOnline(running/1000)); listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")"); return NO_CHANGES; if (label != null && label.isSelfLabel()) { listener.getLogger().print(Messages.AbstractProject_NoWorkspace()); listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")"); return NO_CHANGES; return BUILD_NOW; } else { WorkspaceList l = b.getBuiltOn().toComputer().getWorkspaceList(); return pollWithWorkspace(listener, scm, b, ws, l);
List<Node> allNodes = Jenkins.getInstance().getNodes(); if(label.getNodes().isEmpty()) { return false; return label.isOffline(); } else { if(canRoam) { for (Node n : Jenkins.getInstance().getNodes()) { Computer c = n.toComputer(); if (c != null && c.isOnline() && c.isAcceptingTasks() && n.getMode() == Mode.NORMAL) {
/** * Returns true if all the nodes of this label is offline. */ @Exported public boolean isOffline() { for (Node n : getNodes()) { Computer c = n.toComputer(); if(c != null && !c.isOffline()) return false; } return true; }
/** * Returns a human readable text that explains this label. */ @Exported public String getDescription() { Set<Node> nodes = getNodes(); if(nodes.isEmpty()) { Set<Cloud> clouds = getClouds(); if(clouds.isEmpty()) return Messages.Label_InvalidLabel(); return Messages.Label_ProvisionedFrom(toString(clouds)); } if(nodes.size()==1) return nodes.iterator().next().getNodeDescription(); return Messages.Label_GroupOf(toString(nodes)); }
public AutoCompletionCandidates doAutoCompleteLabel(@QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); Set<Label> labels = Jenkins.getInstance().getLabels(); List<String> queries = new AutoCompleteSeeder(value).getSeeds(); for (String term : queries) { for (Label l : labels) { if (l.getName().startsWith(term)) { c.add(l.getName()); } } } return c; }
public CauseOfBlockage getCauseOfBlockage() { Jenkins jenkins = Jenkins.getInstance(); if(isBlockedByShutdown(task)) return CauseOfBlockage.fromMessage(Messages._Queue_HudsonIsAboutToShutDown()); List<CauseOfBlockage> causesOfBlockage = transientCausesOfBlockage; Label label = getAssignedLabel(); List<Node> allNodes = jenkins.getNodes(); if (allNodes.isEmpty()) label = null; // no master/agent. pointless to talk about nodes if (label != null) { Set<Node> nodes = label.getNodes(); if (label.isOffline()) { if (nodes.size() != 1) return new BecauseLabelIsOffline(label); else return new BecauseNodeIsOffline(nodes.iterator().next()); } else { if (causesOfBlockage != null && label.getIdleExecutors() > 0) { return new CompositeCauseOfBlockage(causesOfBlockage); } if (nodes.size() != 1) return new BecauseLabelIsBusy(label); else return new BecauseNodeIsBusy(nodes.iterator().next()); } } else if (causesOfBlockage != null && new ComputerSet().getIdleExecutors() > 0) { return new CompositeCauseOfBlockage(causesOfBlockage); } else { return CauseOfBlockage.createNeedsMoreExecutor(Messages._Queue_WaitingForNextAvailableExecutor()); } }
/** * Alias for {@link #getDisplayName()}. */ @Exported(visibility=2) public final String getName() { return getDisplayName(); }
/** * Number of busy {@link Executor}s that are carrying out some work right now. */ @Exported public int getBusyExecutors() { int r=0; for (Node n : getNodes()) { Computer c = n.toComputer(); if(c!=null && c.isOnline()) r += c.countBusy(); } return r; }
/** * Number of idle {@link Executor}s that can start working immediately. */ @Exported public int getIdleExecutors() { int r=0; for (Node n : getNodes()) { Computer c = n.toComputer(); if(c!=null && (c.isOnline() || c.isConnecting()) && c.isAcceptingTasks()) r += c.countIdle(); } return r; }
/** * Sets the assigned label. */ public void setAssignedLabel(Label l) throws IOException { if(l==null) { canRoam = true; assignedNode = null; } else { canRoam = false; if(l== Jenkins.getInstance().getSelfLabel()) assignedNode = null; else assignedNode = l.getExpression(); } save(); }
/** * Number of total {@link Executor}s that belong to this label that are functioning. * <p> * This excludes executors that belong to offline nodes. */ @Exported public int getTotalExecutors() { int r=0; for (Node n : getNodes()) { Computer c = n.toComputer(); if(c!=null && c.isOnline()) r += c.countExecutors(); } return r; }
/** * Returns a list of auto completion candidates. * * @return candidates */ public AutoCompletionCandidates doAutoCompleteLabel() { AutoCompletionCandidates candidates = new AutoCompletionCandidates(); List<Node> masterNodeList = Jenkins.getInstance().getNodes(); for (Node node : masterNodeList) { try { for (LabelAtom atom : Label.parseExpression(node.getLabelString()).listAtoms()) { candidates.add(atom.getName()); } } catch (ANTLRException e) { // invalid expression, skipped } } return candidates; }
for (TopLevelItem topLevelItem : Jenkins.getInstance().getItemMap().values()) { if (topLevelItem instanceof AbstractProject) { final AbstractProject project = (AbstractProject) topLevelItem; if (matches(project.getAssignedLabelString())) { result++; if (i instanceof AbstractProject) { final AbstractProject project = (AbstractProject) i; if (matches(project.getAssignedLabelString())) { result++;
public Boolean call() throws ANTLRException { Node n = Jenkins.getInstance().getNode(nodeName); if (n == null) return false; return Label.parseExpression(labelExpr).matches(n); }