Class FileMonitoringTask.FileMonitoringController
java.lang.Object
org.jenkinsci.plugins.durabletask.Controller
org.jenkinsci.plugins.durabletask.FileMonitoringTask.FileMonitoringController
- All Implemented Interfaces:
Serializable
- Enclosing class:
- FileMonitoringTask
Tails a log file and watches for an exit status file.
Must be remotable so that
watch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
can transfer the implementation.- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Deprecated.protected
FileMonitoringController
(FilePath ws, String cookieValue) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Cleans up after a task is done.controlDir
(FilePath ws) Directory in which this controller can place files.exitStatus
(FilePath workspace, Launcher launcher, TaskListener listener) Checks whether the task has finished.protected Integer
exitStatus
(FilePath workspace, TaskListener listener) LikeexitStatus(FilePath, Launcher, TaskListener)
but not requesting aLauncher
, which would not be available inwatch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
mode anyway.getDiagnostics
(FilePath workspace, Launcher launcher) Should be overridden to provide specific information about the status of an external process, for diagnostic purposes.getLastLocationFile
(FilePath workspace) File in which a last-read position is stored ifwatch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
is used.getLogFile
(FilePath workspace) File in which the stdout/stderr (or, ifDurableTask.captureOutput()
is called, just stderr) is written.protected byte[]
LikegetOutput(FilePath, Launcher)
but not requesting aLauncher
, which would not be available inwatch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
mode anyway.byte[]
Obtain the process output.getOutputFile
(FilePath workspace) File in which the stdout is written, ifDurableTask.captureOutput()
is called.getResultFile
(FilePath workspace) File in which the exit code of the process should be reported.final void
Tries to stop any running task.void
watch
(FilePath workspace, Handler handler, TaskListener listener) Begins watching the process asynchronously, so that the master may receive notification when output is available or the process has exited.final boolean
writeLog
(FilePath workspace, OutputStream sink) Obtains any new task log output.Methods inherited from class org.jenkinsci.plugins.durabletask.Controller
exitStatus, exitStatus, stop
-
Constructor Details
-
FileMonitoringController
protected FileMonitoringController(FilePath ws, @NonNull String cookieValue) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
FileMonitoringController
@Deprecated protected FileMonitoringController(FilePath ws) throws IOException, InterruptedException Deprecated.- Throws:
IOException
InterruptedException
-
-
Method Details
-
writeLog
public final boolean writeLog(FilePath workspace, OutputStream sink) throws IOException, InterruptedException Description copied from class:Controller
Obtains any new task log output. Could use a serializable field to keep track of how much output has been previously written.- Specified by:
writeLog
in classController
- Parameters:
workspace
- the workspace in usesink
- where to send new log output- Returns:
- true if something was written and the controller should be resaved, false if everything is idle
- Throws:
IOException
InterruptedException
- See Also:
-
exitStatus
public Integer exitStatus(FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException Description copied from class:Controller
Checks whether the task has finished.- Overrides:
exitStatus
in classController
- Parameters:
workspace
- the workspace in uselauncher
- a way to start processes (currently unused)listener
- a way to report special messages- Returns:
- an exit code (zero is successful), or null if the task appears to still be running
- Throws:
IOException
InterruptedException
-
exitStatus
@CheckForNull protected Integer exitStatus(FilePath workspace, TaskListener listener) throws IOException, InterruptedException LikeexitStatus(FilePath, Launcher, TaskListener)
but not requesting aLauncher
, which would not be available inwatch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
mode anyway.- Throws:
IOException
InterruptedException
-
getOutput
public byte[] getOutput(FilePath workspace, Launcher launcher) throws IOException, InterruptedException Description copied from class:Controller
Obtain the process output. Intended for use afterController.exitStatus(FilePath, Launcher)
has returned a non-null status. The result is undefined ifDurableTask.captureOutput()
was not called before launch; generally anIOException
will result.- Overrides:
getOutput
in classController
- Parameters:
workspace
- the workspace in uselauncher
- a way to start processes (currently unused)- Returns:
- the output of the process as raw bytes (may be empty but not null)
- Throws:
IOException
InterruptedException
- See Also:
-
getOutput
LikegetOutput(FilePath, Launcher)
but not requesting aLauncher
, which would not be available inwatch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
mode anyway.- Throws:
IOException
InterruptedException
-
stop
public final void stop(FilePath workspace, Launcher launcher) throws IOException, InterruptedException Description copied from class:Controller
Tries to stop any running task.- Overrides:
stop
in classController
- Parameters:
workspace
- the workspace in uselauncher
- a way to start processes- Throws:
IOException
InterruptedException
-
cleanup
Description copied from class:Controller
Cleans up after a task is done. Should delete any temporary files created byDurableTask.launch(hudson.EnvVars, hudson.FilePath, hudson.Launcher, hudson.model.TaskListener)
.- Specified by:
cleanup
in classController
- Parameters:
workspace
- the workspace in use- Throws:
IOException
InterruptedException
-
controlDir
Directory in which this controller can place files. Unique among all the controllers sharing the same workspace.- Throws:
IOException
InterruptedException
-
getResultFile
File in which the exit code of the process should be reported.- Throws:
IOException
InterruptedException
-
getLogFile
File in which the stdout/stderr (or, ifDurableTask.captureOutput()
is called, just stderr) is written.- Throws:
IOException
InterruptedException
-
getOutputFile
File in which the stdout is written, ifDurableTask.captureOutput()
is called.- Throws:
IOException
InterruptedException
-
getDiagnostics
public String getDiagnostics(FilePath workspace, Launcher launcher) throws IOException, InterruptedException Description copied from class:Controller
Should be overridden to provide specific information about the status of an external process, for diagnostic purposes.- Overrides:
getDiagnostics
in classController
- Returns:
Object.toString()
by default- Throws:
IOException
InterruptedException
-
watch
public void watch(FilePath workspace, Handler handler, TaskListener listener) throws IOException, InterruptedException, ClassCastException Description copied from class:Controller
Begins watching the process asynchronously, so that the master may receive notification when output is available or the process has exited. This should be called as soon as the process is launched, and thereafter whenever reconnecting to the agent. You should not callController.writeLog(hudson.FilePath, java.io.OutputStream)
orController.cleanup(hudson.FilePath)
in this case; you do not need to callController.exitStatus(FilePath, Launcher)
frequently, though it is advisable to still call it occasionally to verify that the process is still running.- Overrides:
watch
in classController
- Parameters:
workspace
- the workspace in usehandler
- a remotable callbacklistener
- a remotable destination for messages- Throws:
IOException
- if initiating the watch fails, for example with aChannelClosedException
InterruptedException
ClassCastException
-
getLastLocationFile
File in which a last-read position is stored ifwatch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
is used.- Throws:
IOException
InterruptedException
-