public MesosSlaveInfo getMesosSlaveInfoForLabel(Label label) {
    if (!matchesLabel(label)) {
      return null;
    }

    if (label == null) {
      if (getLabelString() == null) {
        return this;
      } else {
        return null;
      }
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return this;
    }

    if (!containerInfo.getDockerImageCustomizable()) {
      return null;
    }

    String customImage = getCustomImage(label);
    if (customImage == null) {
      return null;
    }

    return copyWithDockerImage(label.toString(), customImage);
  }
  /**
   * Check if the label in the slave matches the provided label, either both are null or are the
   * same.
   *
   * @param label
   * @return Whether the slave label matches.
   */
  public boolean matchesLabel(@CheckForNull Label label) {

    if (label == null || getLabelString() == null) {
      return label == null && getLabelString() == null;
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return true;
    }

    if (containerInfo == null || !containerInfo.getDockerImageCustomizable()) {
      return false;
    }

    String customImage = getCustomImage(label);
    return customImage != null
        && getLabelWithoutCustomImage(label, customImage).matches(Label.parse(getLabelString()));
  }
  /** Initializes data structure that we don't persist. */
  public Object readResolve() {
    if (configVersion < 1) {
      try {
        convert1();
      } catch (Throwable t) {
        LOGGER.log(Level.SEVERE, "Can't convert old values to new (double conversion?): ", t);
      }

      configVersion = 1;
    }

    try {
      labelSet = Label.parse(labelString); // fails sometimes under debugger
    } catch (Throwable t) {
      LOGGER.log(Level.SEVERE, "Can't parse labels: ", t);
    }

    return this;
  }
  @DataBoundConstructor
  public DockerTemplate(
      DockerTemplateBase dockerTemplateBase,
      String labelString,
      String remoteFs,
      String remoteFsMapping,
      String instanceCapStr) {
    this.dockerTemplateBase = dockerTemplateBase;
    this.labelString = Util.fixNull(labelString);
    this.remoteFs = Strings.isNullOrEmpty(remoteFs) ? "/home/jenkins" : remoteFs;
    this.remoteFsMapping = remoteFsMapping;

    if (instanceCapStr.equals("")) {
      this.instanceCap = Integer.MAX_VALUE;
    } else {
      this.instanceCap = Integer.parseInt(instanceCapStr);
    }

    labelSet = Label.parse(labelString);
  }
Example #5
0
  /** Initializes data structure that we don't persist. */
  protected Object readResolve() {
    labelSet = Label.parse(labels);
    securityGroupSet = parseSecurityGroups();

    /**
     * In releases of this plugin prior to 1.18, template-specific instance caps could be configured
     * but were not enforced. As a result, it was possible to have the instance cap for a template
     * be configured to 0 (zero) with no ill effects. Starting with version 1.18, template-specific
     * instance caps are enforced, so if a configuration has a cap of zero for a template, no
     * instances will be launched from that template. Since there is no practical value of
     * intentionally setting the cap to zero, this block will override such a setting to a value
     * that means 'no cap'.
     */
    if (instanceCap == 0) {
      instanceCap = Integer.MAX_VALUE;
    }

    if (amiType == null) {
      amiType = new UnixData(rootCommandPrefix, sshPort);
    }
    return this;
  }
 /**
  * Initializes data structure that we don't persist.
  */
 protected Object readResolve() {
     labelSet = Label.parse(labelString);
     return this;
 }