public static void startSeleniumNode(Computer c, TaskListener listener, String conf)
      throws IOException, InterruptedException {
    LOGGER.fine("Examining if we need to start Selenium Grid Node");

    final PluginImpl p = Hudson.getInstance().getPlugin(PluginImpl.class);

    final String exclusions = p.getExclusionPatterns();
    List<String> exclusionPatterns = new ArrayList<String>();
    if (StringUtils.hasText(exclusions)) {
      exclusionPatterns = Arrays.asList(exclusions.split(SEPARATOR));
    }
    if (exclusionPatterns.size() > 0) {
      // loop over all the labels and check if we need to exclude a node
      // based on the exlusionPatterns
      for (Label label : c.getNode().getAssignedLabels()) {
        for (String pattern : exclusionPatterns) {
          if (label.toString().matches(pattern)) {
            LOGGER.fine(
                "Node "
                    + c.getNode().getDisplayName()
                    + " is excluded from Selenium Grid because its label '"
                    + label
                    + "' matches exclusion pattern '"
                    + pattern
                    + "'");
            return;
          }
        }
      }
    }

    final String masterName = PluginImpl.getMasterHostName();
    if (masterName == null) {
      listener
          .getLogger()
          .println(
              "Unable to determine the host name of the master. Skipping Selenium execution. "
                  + "Please "
                  + HyperlinkNote.encodeTo("/configure", "configure the Jenkins URL")
                  + " from the system configuration screen.");
      return;
    }

    // make sure that Selenium Hub is started before we start RCs.
    try {
      p.waitForHubLaunch();
    } catch (ExecutionException e) {
      throw new IOException2("Failed to wait for the Hub launch to complete", e);
    }

    List<SeleniumGlobalConfiguration> confs = getPlugin().getGlobalConfigurationForComputer(c);
    if (confs == null || confs.size() == 0) {
      LOGGER.fine(
          "There is no matching configurations for that computer. Skipping selenium execution.");
      return;
    }

    String nodehost = c.getHostName();
    if (nodehost == null) {
      LOGGER.warning("Unable to determine node's hostname. Skipping");
      return;
    }

    listener
        .getLogger()
        .println(
            "Starting Selenium nodes on " + ("".equals(c.getName()) ? "(master)" : c.getName()));

    for (SeleniumGlobalConfiguration config : confs) {
      if ((conf != null && config.getName().equals(conf)) || conf == null) {
        try {
          config.start(c, listener);
        } catch (ExecutionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
Esempio n. 2
0
 @Override
 public String getShortDescription() {
   return "Retry of " + HyperlinkNote.encodeTo("../../../" + getUrl(), getBuildName());
 }