Class VSphereHostSelection
java.lang.Object
org.jenkinsci.plugins.vsphere.tools.VSphereHostSelection
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDescribes one candidate host's name, availability and current load, as needed to decide whether/how favourably it can be used for a new clone. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringExplicit "no host selection" override for a template/build-step'shostSelectionMode, distinct from leaving it blank (which means "inherit the cloud-level default" - seeresolveMode(java.lang.String, java.lang.String)). -
Method Summary
Modifier and TypeMethodDescriptionfilterCandidates(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.listOf(VSphereHostSelection.HostCandidate... candidates) Convenience: same as callingArrays.asList(T...)for tests.parseAllowList(String hostSelectionCandidatesCsv) Parses a comma-separated allow-list of host names, trimming whitespace and discarding empty entries.parseAllowListOrNull(String hostSelectionCandidatesCsv) LikeparseAllowList(java.lang.String), but preserves the "not set at all" case as null instead of collapsing it to an empty set - needed so a blankhostSelectionCandidatesAsStringcan mean "inherit the cloud-level default" (seeresolveCandidates(java.util.Set<java.lang.String>, java.util.Set<java.lang.String>)) while a deliberately non-blank-but-hostless value (e.g.pickLeastLoaded(List<VSphereHostSelection.HostCandidate> candidates) Picks the candidate with the lowest load fraction, excluding any candidate whose stats are unavailable.resolveCandidates(Set<String> cloudDefault, Set<String> override) Resolves a template/build-step'shostSelectionCandidatesagainst its cloud's default: null (never set at this level) defers tocloudDefault; any explicitly-set value - including an empty set, meaning "explicitly no restriction" - wins outright.static StringresolveMode(String cloudDefault, String override) Resolves a template/build-step'shostSelectionModeagainst its cloud's default: blank/null defers tocloudDefault;HOST_SELECTION_MODE_NONEexplicitly disables host selection regardless of the cloud default; any other value (a real mode) wins outright.static StringtoAllowListString(Set<String> hosts) The inverse ofparseAllowListOrNull(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 throughparseAllowListOrNull(java.lang.String)to an empty - not null - set), and anything else as the plain comma-separated form.static StringtoCsv(Collection<String> hosts) Joins a collection of host names back into the comma-separated form used by the classic config UI textbox.
-
Field Details
-
HOST_SELECTION_MODE_NONE
Explicit "no host selection" override for a template/build-step'shostSelectionMode, distinct from leaving it blank (which means "inherit the cloud-level default" - seeresolveMode(java.lang.String, java.lang.String)).- See Also:
-
-
Method Details
-
parseAllowList
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
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
LikeparseAllowList(java.lang.String), but preserves the "not set at all" case as null instead of collapsing it to an empty set - needed so a blankhostSelectionCandidatesAsStringcan mean "inherit the cloud-level default" (seeresolveCandidates(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
The inverse ofparseAllowListOrNull(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 throughparseAllowListOrNull(java.lang.String)to an empty - not null - set), and anything else as the plain comma-separated form. -
resolveMode
Resolves a template/build-step'shostSelectionModeagainst its cloud's default: blank/null defers tocloudDefault;HOST_SELECTION_MODE_NONEexplicitly disables host selection regardless of the cloud default; any other value (a real mode) wins outright. -
resolveCandidates
Resolves a template/build-step'shostSelectionCandidatesagainst its cloud's default: null (never set at this level) defers tocloudDefault; 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
public static List<VSphereHostSelection.HostCandidate> listOf(VSphereHostSelection.HostCandidate... candidates) Convenience: same as callingArrays.asList(T...)for tests.
-