hudson.model.Node类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.9k)|赞(0)|评价(0)|浏览(168)

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

Node介绍

[英]Base type of Hudson slaves (although in practice, you probably extend Slave to define a new slave type.)

As a special case, Hudson extends from here.
[中]Hudson从属的基本类型(尽管在实践中,您可能会扩展从属以定义新的从属类型。)
作为一个特例,哈德逊从这里开始。

代码示例

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

  1. private WorkspaceOfflineReason workspaceOffline(R build) throws IOException, InterruptedException {
  2. FilePath ws = build.getWorkspace();
  3. Label label = getAssignedLabel();
  4. if (isAllSuitableNodesOffline(build)) {
  5. Collection<Cloud> applicableClouds = label == null ? Jenkins.getInstance().clouds : label.getClouds();
  6. return applicableClouds.isEmpty() ? WorkspaceOfflineReason.all_suitable_nodes_are_offline : WorkspaceOfflineReason.use_ondemand_slave;
  7. }
  8. if (ws==null || !ws.exists()) {
  9. return WorkspaceOfflineReason.nonexisting_workspace;
  10. }
  11. Node builtOn = build.getBuiltOn();
  12. if (builtOn == null) { // node built-on doesn't exist anymore
  13. return WorkspaceOfflineReason.builton_node_gone;
  14. }
  15. if (builtOn.toComputer() == null) { // node still exists, but has 0 executors - o.s.l.t.
  16. return WorkspaceOfflineReason.builton_node_no_executors;
  17. }
  18. return null;
  19. }

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

  1. /**
  2. * Accepts the update to the node configuration.
  3. */
  4. @RequirePOST
  5. public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
  6. checkPermission(CONFIGURE);
  7. String proposedName = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name"));
  8. Jenkins.checkGoodName(proposedName);
  9. Node node = getNode();
  10. if (node == null) {
  11. throw new ServletException("No such node " + nodeName);
  12. }
  13. if ((!proposedName.equals(nodeName))
  14. && Jenkins.getActiveInstance().getNode(proposedName) != null) {
  15. throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name");
  16. }
  17. String nExecutors = req.getSubmittedForm().getString("numExecutors");
  18. if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) {
  19. throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors");
  20. }
  21. Node result = node.reconfigure(req, req.getSubmittedForm());
  22. Jenkins.getInstance().getNodesObject().replaceNode(this.getNode(), result);
  23. // take the user back to the agent top page.
  24. rsp.sendRedirect2("../" + result.getNodeName() + '/');
  25. }

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

  1. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  2. FilePath expected = preferredLocation(tool, node);
  3. Installable inst = getInstallable();
  4. if(inst==null) {
  5. log.getLogger().println("Invalid tool ID "+id);
  6. return expected;
  7. }
  8. if (inst instanceof NodeSpecific) {
  9. inst = (Installable) ((NodeSpecific) inst).forNode(node, log);
  10. }
  11. if(isUpToDate(expected,inst))
  12. return expected;
  13. if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
  14. expected.child(".timestamp").delete(); // we don't use the timestamp
  15. FilePath base = findPullUpDirectory(expected);
  16. if(base!=null && base!=expected)
  17. base.moveAllChildrenTo(expected);
  18. // leave a record for the next up-to-date check
  19. expected.child(".installedFrom").write(inst.url,"UTF-8");
  20. expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
  21. }
  22. return expected;
  23. }

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

  1. public String getShortDescription() {
  2. String name = (node.toComputer() != null) ? node.toComputer().getDisplayName() : node.getDisplayName();
  3. return Messages.Queue_NodeOffline(name);
  4. }

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

  1. public static String encodeTo(Node node) {
  2. Computer c = node.toComputer();
  3. if (c != null) {
  4. return encodeTo("/" + c.getUrl(), node.getDisplayName());
  5. }
  6. String nodePath = node == Jenkins.getInstance() ? "(master)" : node.getNodeName();
  7. return encodeTo("/computer/" + nodePath, node.getDisplayName());
  8. }

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

  1. /**
  2. * Estimates the clock difference with this agent.
  3. *
  4. * @return
  5. * always non-null.
  6. * @throws InterruptedException
  7. * if the operation is aborted.
  8. */
  9. public ClockDifference getClockDifference() throws IOException, InterruptedException {
  10. VirtualChannel channel = getChannel();
  11. if(channel==null)
  12. throw new IOException(getNodeName()+" is offline");
  13. return channel.call(getClockDifferenceCallable());
  14. }

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

  1. listener.getLogger().println("Checking " + item.getFullDisplayName());
  2. for (Node node : nodes) {
  3. FilePath ws = node.getWorkspaceFor(item);
  4. if (ws == null) {
  5. continue; // offline, fine
  6. check = shouldBeDeleted(item, ws, node);
  7. } catch (IOException x) {
  8. Functions.printStackTrace(x, listener.error("Failed to check " + node.getDisplayName()));
  9. continue;
  10. } catch (InterruptedException x) {
  11. Functions.printStackTrace(x, listener.error("Failed to check " + node.getDisplayName()));
  12. continue;
  13. listener.getLogger().println("Deleting " + ws + " on " + node.getDisplayName());
  14. try {
  15. ws.deleteRecursive();
  16. WorkspaceList.tempDir(ws).deleteRecursive();
  17. } catch (IOException x) {
  18. Functions.printStackTrace(x, listener.error("Failed to delete " + ws + " on " + node.getDisplayName()));
  19. } catch (InterruptedException x) {
  20. Functions.printStackTrace(x, listener.error("Failed to delete " + ws + " on " + node.getDisplayName()));

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

  1. @Override
  2. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  3. FilePath dir = preferredLocation(tool, node);
  4. // TODO support Unix scripts with interpreter line (see Shell.buildCommandLine)
  5. FilePath script = dir.createTextTempFile("hudson", getCommandFileExtension(), command);
  6. try {
  7. String cmd[] = getCommandCall(script);
  8. int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join();
  9. if (r != 0) {
  10. throw new IOException("Command returned status " + r);
  11. }
  12. } finally {
  13. script.delete();
  14. }
  15. return dir.child(getToolHome());
  16. }

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

  1. @Override
  2. protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException {
  3. String customWorkspace = getProject().getCustomWorkspace();
  4. if (customWorkspace != null) {
  5. // we allow custom workspaces to be concurrently used between jobs.
  6. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)));
  7. }
  8. return super.decideWorkspace(n, wsl);
  9. }

代码示例来源:origin: jenkinsci/artifactory-plugin

  1. List<Node> nodes = Jenkins.getInstance().getNodes();
  2. for (Node node : nodes) {
  3. if (node == null || node.getChannel() == null) {
  4. continue;
  5. List<DockerImage> partialDockerImages = node.getChannel().call(new MasterToSlaveCallable<List<DockerImage>, IOException>() {
  6. public List<DockerImage> call() throws IOException {
  7. List<DockerImage> dockerImages = new ArrayList<DockerImage>();
  8. dockerImages.addAll(partialDockerImages);
  9. } catch (Exception e) {
  10. listener.getLogger().println("Could not collect docker images from Jenkins node '" + node.getDisplayName() + "' due to: " + e.getMessage());

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

  1. /**
  2. * Creates an environment variable override to be used for launching processes on this node.
  3. *
  4. * @see ProcStarter#envs(Map)
  5. * @since 1.489
  6. */
  7. public @Nonnull EnvVars buildEnvironment(@Nonnull TaskListener listener) throws IOException, InterruptedException {
  8. EnvVars env = new EnvVars();
  9. Node node = getNode();
  10. if (node==null) return env; // bail out
  11. for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) {
  12. nodeProperty.buildEnvVars(env,listener);
  13. }
  14. for (NodeProperty nodeProperty: node.getNodeProperties()) {
  15. nodeProperty.buildEnvVars(env,listener);
  16. }
  17. // TODO: hmm, they don't really belong
  18. String rootUrl = Jenkins.getInstance().getRootUrl();
  19. if(rootUrl!=null) {
  20. env.put("HUDSON_URL", rootUrl); // Legacy.
  21. env.put("JENKINS_URL", rootUrl);
  22. }
  23. return env;
  24. }

代码示例来源:origin: jenkinsci/selenium-plugin

  1. public static void startSeleniumNode(Computer c, TaskListener listener, String conf) throws IOException, InterruptedException {
  2. LOGGER.fine("Examining if we need to start Selenium Grid Node");
  3. final PluginImpl p = Jenkins.getInstance().getPlugin(PluginImpl.class);
  4. for (Label label : c.getNode().getAssignedLabels()) {
  5. for (String pattern : exclusionPatterns) {
  6. if (label.toString().matches(pattern)) {
  7. LOGGER.fine("Node " + c.getNode().getDisplayName() + " is excluded from Selenium Grid because its label '" + label
  8. + "' matches exclusion pattern '" + pattern + "'");
  9. return;
  10. listener.getLogger().println(
  11. "Unable to determine the host name of the master. Skipping Selenium execution. " + "Please "
  12. + HyperlinkNote.encodeTo("/configure", "configure the Jenkins URL") + " from the system configuration screen.");
  13. listener.getLogger().println("Starting Selenium nodes on " + ("".equals(c.getName()) ? "(master)" : c.getName()));

代码示例来源:origin: jenkinsci/shiningpanda-plugin

  1. /**
  2. * Get the home directory for the given node.
  3. *
  4. * @param node
  5. * The node
  6. * @return The home directory
  7. */
  8. public static FilePath get(Node node) {
  9. // Get the potential properties
  10. WorkspaceHomeProperty[] properties = new WorkspaceHomeProperty[] {
  11. node.getNodeProperties().get(WorkspaceHomeProperty.class),
  12. Jenkins.getInstance().getGlobalNodeProperties().get(WorkspaceHomeProperty.class) };
  13. // Go threw the properties
  14. for (WorkspaceHomeProperty property : properties)
  15. // Check if exists
  16. if (property != null)
  17. // Check if valid
  18. if (Util.fixEmpty(property.getHome()) != null)
  19. // Return the home folder
  20. return new FilePath(node.getChannel(), property.getHome());
  21. // Else relative to root
  22. return node.getRootPath().child(Workspace.BASENAME).child("jobs");
  23. }

代码示例来源:origin: org.jenkins-ci.plugins/nodelabelparameter

  1. @Override
  2. public List<AbstractBuildParameters> getParameters(AbstractBuild<?, ?> build, TaskListener listener) {
  3. Computer[] nodes = Jenkins.getInstance().getComputers();
  4. final PrintStream logger = listener.getLogger();
  5. List<AbstractBuildParameters> params = Lists.newArrayList();
  6. for(Computer c : nodes) {
  7. Node n = c.getNode();
  8. if (n!=null && c.isOnline() && c.getNumExecutors()>0) {
  9. params.add(new NodeLabelBuildParameter("label", n.getSelfLabel().getName()));
  10. logger.println("trigger build on "+n.getDisplayName() +" ("+n.getSelfLabel().getName()+")");
  11. }
  12. }
  13. return params;
  14. }

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

  1. public String getToolHome(Node node, ToolInstallation tool, TaskListener log) throws IOException, InterruptedException {
  2. if (node.getRootPath() == null) {
  3. log.error(node.getDisplayName() + " is offline; cannot locate " + tool.getName());
  4. return null;
  5. return installer.performInstallation(tool, node, log).getRemote();
  6. } finally {
  7. semaphore.release();
  8. installer.getDescriptor().getDisplayName(),
  9. tool.getName(),
  10. node.getDisplayName()));
  11. log.getLogger().println(message);

代码示例来源:origin: groupon/DotCi

  1. protected Lease getParentWorkspaceLease(final Node n, final WorkspaceList wsl) throws InterruptedException, IOException {
  2. final DynamicProject mp = getParent().getParent();
  3. final String customWorkspace = mp.getCustomWorkspace();
  4. if (customWorkspace != null) {
  5. // we allow custom workspaces to be concurrently used between
  6. // jobs.
  7. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(this.listener).expand(customWorkspace)));
  8. }
  9. return wsl.allocate(n.getWorkspaceFor(mp), getParentBuild());
  10. }

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

  1. long running = Jenkins.getInstance().getInjector().getInstance(Uptime.class).getUptime();
  2. long remaining = TimeUnit.MINUTES.toMillis(10)-running;
  3. if (remaining>0 && /* this logic breaks tests of polling */!Functions.getIsUnitTest()) {
  4. listener.getLogger().print(Messages.AbstractProject_AwaitingWorkspaceToComeOnline(remaining/1000));
  5. listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")");
  6. return NO_CHANGES;
  7. listener.getLogger().print(Messages.AbstractProject_AwaitingWorkspaceToComeOnline(running/1000));
  8. listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")");
  9. return NO_CHANGES;
  10. if (label != null && label.isSelfLabel()) {
  11. return BUILD_NOW;
  12. } else {
  13. WorkspaceList l = b.getBuiltOn().toComputer().getWorkspaceList();
  14. return pollWithWorkspace(listener, scm, b, ws, l);

代码示例来源:origin: jenkinsci/parameterized-trigger-plugin

  1. @Override
  2. public Action getAction(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException, DontTriggerException {
  3. Node node = build.getBuiltOn();
  4. Label nodeLabel;
  5. // master does not return a node name so add it explicitly.
  6. if(node == null) {
  7. nodeLabel = Jenkins.getInstance().getSelfLabel();
  8. } else {
  9. nodeLabel = node.getSelfLabel();
  10. }
  11. listener.getLogger().println("Returning node parameter for " + nodeLabel.getDisplayName());
  12. return new NodeAction(nodeLabel);
  13. }

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

  1. List<Node> allNodes = Jenkins.getInstance().getNodes();
  2. if(label.getNodes().isEmpty()) {
  3. return false;
  4. return label.isOffline();
  5. } else {
  6. if(canRoam) {
  7. for (Node n : Jenkins.getInstance().getNodes()) {
  8. Computer c = n.toComputer();
  9. if (c != null && c.isOnline() && c.isAcceptingTasks() && n.getMode() == Mode.NORMAL) {

代码示例来源:origin: org.jenkins-ci.plugins.workflow/workflow-cps-global-lib

  1. static void doRetrieve(String name, boolean changelog, @Nonnull SCM scm, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception {
  2. // Adapted from CpsScmFlowDefinition:
  3. SCMStep delegate = new GenericSCMStep(scm);
  4. delegate.setPoll(false); // TODO we have no API for determining if a given SCMHead is branch-like or tag-like; would we want to turn on polling if the former?
  5. delegate.setChangelog(changelog);
  6. FilePath dir;
  7. Node node = Jenkins.getActiveInstance();
  8. if (run.getParent() instanceof TopLevelItem) {
  9. FilePath baseWorkspace = node.getWorkspaceFor((TopLevelItem) run.getParent());
  10. if (baseWorkspace == null) {
  11. throw new IOException(node.getDisplayName() + " may be offline");
  12. }
  13. dir = baseWorkspace.withSuffix(getFilePathSuffix() + "libs").child(name);
  14. } else { // should not happen, but just in case:
  15. throw new AbortException("Cannot check out in non-top-level build");
  16. }
  17. Computer computer = node.toComputer();
  18. if (computer == null) {
  19. throw new IOException(node.getDisplayName() + " may be offline");
  20. }
  21. try (WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(dir)) {
  22. delegate.checkout(run, lease.path, listener, node.createLauncher(listener));
  23. // Cannot add WorkspaceActionImpl to private CpsFlowExecution.flowStartNodeActions; do we care?
  24. // Copy sources with relevant files from the checkout:
  25. lease.path.copyRecursiveTo("src/**/*.groovy,vars/*.groovy,vars/*.txt,resources/", null, target);
  26. }
  27. }

相关文章