/** * Node name. */ public String getName() { return node.getNodeName(); }
public String hash(Node node) { return node.getNodeName(); } };
public String getDisplayName() { return getNodeName(); // default implementation }
@Override public int compare(Node o1, Node o2) { if (o1 == o2) { return 0; } return o1 instanceof Jenkins ? -1 : (o2 instanceof Jenkins ? 1 : o1.getNodeName().compareTo(o2.getNodeName())); } }
public NodeList(Collection<? extends Node> c) { super(c); for (Node node: c) { if (map.put(node.getNodeName(), node) != null) { // make sure that all names are unique throw new IllegalArgumentException(node.getNodeName()+" is defined more than once"); } } }
public String get(int index) { return nodes.get(index).getNodeName(); }
public void run() { Nodes.this.nodes.remove(oldOne.getNodeName()); Nodes.this.nodes.put(newOne.getNodeName(), newOne); jenkins.updateComputerList(); jenkins.trimLabels(); } });
@Override public Boolean call() throws Exception { if (node == nodes.get(node.getNodeName())) { jenkins.trimLabels(); return true; } return false; } });
@Override public void run() { Set<String> toRemove = new HashSet<String>(Nodes.this.nodes.keySet()); for (Node n : nodes) { final String name = n.getNodeName(); toRemove.remove(name); Nodes.this.nodes.put(name, n); } Nodes.this.nodes.keySet().removeAll(toRemove); // directory clean up will be handled by save jenkins.updateComputerList(); jenkins.trimLabels(); } });
@Override public void run() { nodes.put(node.getNodeName(), node); jenkins.updateComputerList(); jenkins.trimLabels(); } });
/** * Gets the special label that represents this node itself. */ @Nonnull @WithBridgeMethods(Label.class) public LabelAtom getSelfLabel() { return LabelAtom.get(getNodeName()); }
/** * Auto-completion for the "copy from" field in the new job page. */ public AutoCompletionCandidates doAutoCompleteCopyNewItemFrom(@QueryParameter final String value) { final AutoCompletionCandidates r = new AutoCompletionCandidates(); for (Node n : Jenkins.getInstance().getNodes()) { if (n.getNodeName().startsWith(value)) r.add(n.getNodeName()); } return r; } }
/** * 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()); }
/** * Actually persists a node on disk. * * @param node the node to be persisted. * @throws IOException if the node could not be persisted. */ private void persistNode(final @Nonnull Node node) throws IOException { // no need for a full save() so we just do the minimum if (node instanceof EphemeralNode) { Util.deleteRecursive(new File(getNodesDir(), node.getNodeName())); } else { XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM, new File(new File(getNodesDir(), node.getNodeName()), "config.xml")); xmlFile.write(node); SaveableListener.fireOnChange(this, xmlFile); } jenkins.getQueue().scheduleMaintenance(); }
@Override public void run() { nodes.compute(node.getNodeName(), (ignoredNodeName, ignoredNode) -> oldNode); jenkins.updateComputerList(); jenkins.trimLabels(); } });
public String getSearchUrl() { Computer c = toComputer(); if (c != null) { return c.getUrl(); } return "computer/" + Util.rawEncode(getNodeName()); }
/** * Called to notify {@link Computer} that its corresponding {@link Node} * configuration is updated. */ protected void setNode(Node node) { assert node!=null; if(node instanceof Slave) this.nodeName = node.getNodeName(); else this.nodeName = null; setNumExecutors(node.getNumExecutors()); if (this.temporarilyOffline) { // When we get a new node, push our current temp offline // status to it (as the status is not carried across // configuration changes that recreate the node). // Since this is also called the very first time this // Computer is created, avoid pushing an empty status // as that could overwrite any status that the Node // brought along from its persisted config data. node.setTemporaryOfflineCause(this.offlineCause); } }
@Override protected int run() throws Exception { final Jenkins jenkins = Jenkins.getActiveInstance(); jenkins.checkPermission(Computer.CREATE); final Node newNode = (Node) Jenkins.XSTREAM2.fromXML(stdin); if (nodeName != null) { // Using deprecated method but it's contract is preserved newNode.setNodeName(nodeName); } if(newNode instanceof Slave) { //change userId too User user = User.current(); ((Slave) newNode).setUserId(user==null ? "anonymous" : user.getId()); } if (jenkins.getNode(newNode.getNodeName()) != null) { throw new IllegalStateException("Node '" + newNode.getNodeName() + "' already exists"); } jenkins.addNode(newNode); return 0; }
@Override public void run() { Computer c = node.toComputer(); if (c != null) { c.recordTermination(); c.disconnect(OfflineCause.create(hudson.model.Messages._Hudson_NodeBeingRemoved())); } if (node == nodes.remove(node.getNodeName())) { jenkins.updateComputerList(); jenkins.trimLabels(); } } });
public static String encodeTo(Node node) { Computer c = node.toComputer(); if (c != null) { return encodeTo("/" + c.getUrl(), node.getDisplayName()); } String nodePath = node == Jenkins.getInstance() ? "(master)" : node.getNodeName(); return encodeTo("/computer/" + nodePath, node.getDisplayName()); }