Package org.jenkinsci.remoting.engine
Class WorkDirManager
- java.lang.Object
-
- org.jenkinsci.remoting.engine.WorkDirManager
-
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public class WorkDirManager extends Object
Performs working directory management in remoting. Using this manager remoting can initialize its working directory and put the data there. The structure of the directory is described inWorkDirManager.DirType
.- Since:
- 3.8
- Author:
- Oleg Nenashev
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WorkDirManager.DirType
Defines components of the Working directory.
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_FAIL_IF_WORKDIR_IS_MISSING
Default value for the behavior when the requested working directory is missing.static String
JUL_CONFIG_FILE_SYSTEM_PROPERTY_NAME
Name of the standard System Property, which points to thejava.util.logging
config file.static String
SUPPORTED_INTERNAL_DIR_NAME_MASK
Regular expression, which declares restrictions of the remoting internal directory symbols
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disable(WorkDirManager.DirType dir)
static WorkDirManager
getInstance()
Retrieves the instance of theWorkDirManager
.File
getLocation(WorkDirManager.DirType type)
Path
getLocationPath(WorkDirManager.DirType type)
GetPath
of the directory.File
getLoggingConfigFile()
Gets path to the property file with JUL settings.Path
initializeWorkDir(File workDir, String internalDir, boolean failIfMissing)
Initializes the working directory for the agent.void
setLoggingConfig(File configFile)
Sets path to the Logging JUL property file with logging settings.void
setupLogging(Path internalDirPath, Path overrideLogPath)
Sets up logging subsystem in the working directory.
-
-
-
Field Detail
-
DEFAULT_FAIL_IF_WORKDIR_IS_MISSING
public static final boolean DEFAULT_FAIL_IF_WORKDIR_IS_MISSING
Default value for the behavior when the requested working directory is missing. The default value isfalse
, because otherwise agents would fail on the first startup.- See Also:
- Constant Field Values
-
SUPPORTED_INTERNAL_DIR_NAME_MASK
public static final String SUPPORTED_INTERNAL_DIR_NAME_MASK
Regular expression, which declares restrictions of the remoting internal directory symbols- See Also:
- Constant Field Values
-
JUL_CONFIG_FILE_SYSTEM_PROPERTY_NAME
public static final String JUL_CONFIG_FILE_SYSTEM_PROPERTY_NAME
Name of the standard System Property, which points to thejava.util.logging
config file.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
@NonNull public static WorkDirManager getInstance()
Retrieves the instance of theWorkDirManager
. Currently the implementation is hardcoded, but it may change in the future.- Returns:
- Workspace manager
-
disable
public void disable(@NonNull WorkDirManager.DirType dir)
-
getLocation
@CheckForNull public File getLocation(@NonNull WorkDirManager.DirType type)
-
getLocationPath
@CheckForNull public Path getLocationPath(@NonNull WorkDirManager.DirType type) throws IOException
GetPath
of the directory.- Parameters:
type
- Type of the directory- Returns:
- Path
- Throws:
IOException
- Invalid path, e.g. ig the root directory is incorrect- Since:
- 3.14
-
setLoggingConfig
public void setLoggingConfig(@NonNull File configFile)
Sets path to the Logging JUL property file with logging settings.- Parameters:
configFile
- config file
-
getLoggingConfigFile
@CheckForNull public File getLoggingConfigFile()
Gets path to the property file with JUL settings. This method checks the value passed fromsetLoggingConfig(java.io.File)
first. If the value is not specified, it also checks the standardjava.util.logging.config.file
System property.- Returns:
- Path to the logging config file.
null
if it cannot be found.
-
initializeWorkDir
@CheckForNull public Path initializeWorkDir(@CheckForNull File workDir, @NonNull String internalDir, boolean failIfMissing) throws IOException
Initializes the working directory for the agent. Within the working directory the method also initializes a working directory for internal needs (like logging)- Parameters:
workDir
- Working directoryinternalDir
- Name of the remoting internal data directory within the working directory. The range of the supported symbols is restricted toSUPPORTED_INTERNAL_DIR_NAME_MASK
.failIfMissing
- Fail the initialization if the workDir or internalDir are missing. This option presumes that the workspace structure gets initialized previously in order to ensure that we do not start up with a borked instance (e.g. if a mount gets disconnected).- Returns:
- Initialized directory for internal files within workDir or
null
if it is disabled - Throws:
IOException
- Workspace allocation issue (e.g. the specified directory is not writable). In such case Remoting should not start up at all.
-
setupLogging
public void setupLogging(@CheckForNull Path internalDirPath, @CheckForNull Path overrideLogPath) throws IOException
Sets up logging subsystem in the working directory. If the logging system is already initialized, do nothing- Parameters:
internalDirPath
- Path to the internal remoting directory within the WorkDir. If this value andoverrideLogPath
are null, the logging subsystem woill not be initialized at alloverrideLogPath
- Overrides the common location of the remoting log. If specified, logging system will be initialized in the legacy way. Ifnull
, the behavior is defined byinternalDirPath
.- Throws:
IOException
- Initialization error
-
-