Class VManagerChartsUtil
Centralises:
- Building the conventional session-input filename
(
${BUILD_NUMBER}.${BUILD_ID}.sessions.input). - Resolving the actual file location given the user's
session sourcechoice and (optionally) custom path. The result is aFilePathso that reads work transparently on a remote agent (Linux or Windows). - Reading the file contents into a list of session names (one per
non-blank, non-
#-comment line).
The class is final with a private constructor — it is a pure
collection of static helpers and is not intended to be instantiated.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidEnforce that the caller has permission to invoke a descriptor'sdoCheckXxx/doFillXxxItemsmethod.static StringdefaultSessionLaunchOutputFileName(Run<?, ?> run) static StringdefaultSessionsFileName(Run<?, ?> run) static FilePathgetCurrentWorkspace(Run<?, ?> run) Best-effort lookup of the directory where the vManager Jenkins Plugin (or a user-supplied pipeline step) is expected to drop the.sessions.input/.session_launch.outputfiles.readSessionNames(FilePath file) Reads session names from the resolved file.readSessionNames(Run<?, ?> run, FilePath workspace, String sessionSource, String userPath) Convenience: resolve and read in one call.static FilePathresolveSessionLaunchOutputFile(Run<?, ?> run, FilePath sessionsInputFile, FilePath workspace) Resolves theFilePathof the fallback.session_launch.outputfile.static FilePathresolveSessionsInputFile(Run<?, ?> run, FilePath workspace, String sessionSource, String userPath) Resolves theFilePathof the sessions input file for this build, applying the rules described onVManagerChartsJobProperty.getSessionSource():PLUGIN(default) — file is in the build workspace and is named perdefaultSessionsFileName(Run).FILEwith empty path — same asPLUGIN.FILEwith a non-empty path — that path is used.
-
Field Details
-
SESSIONS_INPUT_SUFFIX
Suffix used for the conventional per-build session-input file.- See Also:
-
SESSION_LAUNCH_OUTPUT_SUFFIX
Suffix of the per-build file dropped by the vManager Jenkins Plugin (launch mode) listing the IDs of the sessions it just kicked off. Used as a fallback whenSESSIONS_INPUT_SUFFIXis missing.- See Also:
-
-
Method Details
-
checkDescriptorPermission
Enforce that the caller has permission to invoke a descriptor'sdoCheckXxx/doFillXxxItemsmethod.For
Item-scoped descriptors (the model classes in this plugin live under a job's config page),Item.CONFIGUREis the appropriate permission — the same one Jenkins requires to even open the page on which these endpoints are surfaced. When the descriptor is invoked outside an item context (e.g. the globaldescriptorByNameURL), we fall back toJenkins.ADMINISTER.This is paired with
@POSTon each endpoint to ensure the call is CSRF-protected. The method throwsAccessDeniedExceptionwhen the caller lacks the required permission. -
defaultSessionsFileName
- Returns:
- the conventional file name for this run, e.g.
42.42.sessions.input.
-
defaultSessionLaunchOutputFileName
- Returns:
- the conventional fallback file name for this run, e.g.
42.42.session_launch.output— a list of session ids produced by the vManager Jenkins Plugin in launch mode.
-
resolveSessionLaunchOutputFile
public static FilePath resolveSessionLaunchOutputFile(Run<?, ?> run, FilePath sessionsInputFile, FilePath workspace) Resolves theFilePathof the fallback.session_launch.outputfile. We place it next to the resolved sessions-input file (so a custom user path's directory is honoured); if no input file is known we fall back to the workspace root.- Returns:
- the
FilePaththat should contain the session ids (the file may or may not actually exist), ornullwhen neither a sessions-input file nor a workspace is available.
-
getCurrentWorkspace
Best-effort lookup of the directory where the vManager Jenkins Plugin (or a user-supplied pipeline step) is expected to drop the.sessions.input/.session_launch.outputfiles.For freestyle (
AbstractBuild) jobs this is the build's agent workspace.For Pipeline jobs there is no single workspace for the whole build, and walking the flow graph to find
node { }workspaces is unreliable (the node block may have ended by the time we run, agents may be offline, etc.). Instead, for pipeline runs we return the build's controller-side directory (Run.getRootDir(), i.e. the directory that holds the build log) wrapped as a localFilePath. Pipeline users are expected to copy / archive the input files there explicitly (e.g. viaarchiveArtifactsorwriteFileon the controller). -
resolveSessionsInputFile
public static FilePath resolveSessionsInputFile(Run<?, ?> run, FilePath workspace, String sessionSource, String userPath) Resolves theFilePathof the sessions input file for this build, applying the rules described onVManagerChartsJobProperty.getSessionSource():PLUGIN(default) — file is in the build workspace and is named perdefaultSessionsFileName(Run).FILEwith empty path — same asPLUGIN.FILEwith a non-empty path — that path is used. Absolute paths are resolved on the same node/channel as the workspace. Relative paths are resolved against the workspace.
- Returns:
- the
FilePaththat should contain the session names (the file may or may not actually exist), ornullif no workspace is available and no absolute path was given.
-
readSessionNames
Reads session names from the resolved file. Empty lines and lines starting with#are skipped.- Returns:
- an immutable list of session names (possibly empty); never
null. - Throws:
IOExceptionInterruptedException
-
readSessionNames
public static List<String> readSessionNames(Run<?, ?> run, FilePath workspace, String sessionSource, String userPath) throws IOException, InterruptedExceptionConvenience: resolve and read in one call.- Throws:
IOExceptionInterruptedException
-