Class VSphereHostSelection

java.lang.Object
org.jenkinsci.plugins.vsphere.tools.VSphereHostSelection

public final class VSphereHostSelection extends Object
Pure, yavijava-free logic for picking a "best" ESXi host out of a cluster's members, given per-host stats and an optional admin-supplied allow-list. Kept free of vSphere API types so it can be unit-tested without a live vCenter connection.
  • Field Details

  • Method Details

    • parseAllowList

      public static Set<String> parseAllowList(String hostSelectionCandidatesCsv)
      Parses a comma-separated allow-list of host names, trimming whitespace and discarding empty entries. Returns an empty (not null) set when the input is null/blank, meaning "no restriction".
    • toCsv

      public static String toCsv(Collection<String> hosts)
      Joins a collection of host names back into the comma-separated form used by the classic config UI textbox. Returns "" (not null) for a null/empty input, so this is safe to use directly as a form field's current value.
    • parseAllowListOrNull

      public static Set<String> parseAllowListOrNull(String hostSelectionCandidatesCsv)
      Like parseAllowList(java.lang.String), but preserves the "not set at all" case as null instead of collapsing it to an empty set - needed so a blank hostSelectionCandidatesAsString can mean "inherit the cloud-level default" (see resolveCandidates(java.util.Set<java.lang.String>, java.util.Set<java.lang.String>)) while a deliberately non-blank-but-hostless value (e.g. a lone comma) can still mean "explicitly override to no restriction". Blank/whitespace-only input (including a single space) is treated as "not set"; anything else is parsed normally, which may still yield an empty (non-null) set.
    • toAllowListString

      public static String toAllowListString(Set<String> hosts)
      The inverse of parseAllowListOrNull(java.lang.String): renders null as "" (inherit), an empty set as a single comma (a visible, non-blank marker for "explicitly no restriction" that round-trips back through parseAllowListOrNull(java.lang.String) to an empty - not null - set), and anything else as the plain comma-separated form.
    • resolveMode

      public static String resolveMode(String cloudDefault, String override)
      Resolves a template/build-step's hostSelectionMode against its cloud's default: blank/null defers to cloudDefault; HOST_SELECTION_MODE_NONE explicitly disables host selection regardless of the cloud default; any other value (a real mode) wins outright.
    • resolveCandidates

      public static Set<String> resolveCandidates(Set<String> cloudDefault, Set<String> override)
      Resolves a template/build-step's hostSelectionCandidates against its cloud's default: null (never set at this level) defers to cloudDefault; any explicitly-set value - including an empty set, meaning "explicitly no restriction" - wins outright.
    • filterCandidates

      public static List<VSphereHostSelection.HostCandidate> filterCandidates(List<VSphereHostSelection.HostCandidate> candidates, Set<String> allowList)
      Filters candidates down to ones that are usable (connected, not in maintenance mode) and, if the allow-list is non-empty, whose name is in it. An empty/null allow-list means "consider every usable host".
    • pickLeastLoaded

      public static VSphereHostSelection.HostCandidate pickLeastLoaded(List<VSphereHostSelection.HostCandidate> candidates)
      Picks the candidate with the lowest load fraction, excluding any candidate whose stats are unavailable. Returns null if no candidate has usable stats.
    • listOf

      Convenience: same as calling Arrays.asList(T...) for tests.