Class FileMonitoringTask.FileMonitoringController
- java.lang.Object
-
- org.jenkinsci.plugins.durabletask.Controller
-
- org.jenkinsci.plugins.durabletask.FileMonitoringTask.FileMonitoringController
-
- All Implemented Interfaces:
Serializable
- Enclosing class:
- FileMonitoringTask
protected static class FileMonitoringTask.FileMonitoringController extends Controller
Tails a log file and watches for an exit status file. Must be remotable so thatwatch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener)
can transfer the implementation.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FileMonitoringController(FilePath ws)
Deprecated.protected
FileMonitoringController(FilePath ws, String cookieValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup(FilePath workspace)
Cleans up after a task is done.FilePath
controlDir(FilePath ws)
Directory in which this controller can place files.Integer
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.String
getDiagnostics(FilePath workspace, Launcher launcher)
Should be overridden to provide specific information about the status of an external process, for diagnostic purposes.FilePath
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.FilePath
getLogFile(FilePath workspace)
File in which the stdout/stderr (or, ifDurableTask.captureOutput()
is called, just stderr) is written.protected byte[]
getOutput(FilePath workspace)
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[]
getOutput(FilePath workspace, Launcher launcher)
Obtain the process output.FilePath
getOutputFile(FilePath workspace)
File in which the stdout is written, ifDurableTask.captureOutput()
is called.FilePath
getResultFile(FilePath workspace)
File in which the exit code of the process should be reported.void
stop(FilePath workspace, Launcher launcher)
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.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 Detail
-
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 Detail
-
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:
DurableTask.charset(java.nio.charset.Charset)
,DurableTask.defaultCharset()
-
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:
DurableTask.charset(java.nio.charset.Charset)
,DurableTask.defaultCharset()
-
getOutput
protected byte[] getOutput(FilePath workspace) throws IOException, InterruptedException
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
public void cleanup(FilePath workspace) throws IOException, InterruptedException
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
public FilePath controlDir(FilePath ws) throws IOException, InterruptedException
Directory in which this controller can place files. Unique among all the controllers sharing the same workspace.- Throws:
IOException
InterruptedException
-
getResultFile
public FilePath getResultFile(FilePath workspace) throws IOException, InterruptedException
File in which the exit code of the process should be reported.- Throws:
IOException
InterruptedException
-
getLogFile
public FilePath getLogFile(FilePath workspace) throws IOException, InterruptedException
File in which the stdout/stderr (or, ifDurableTask.captureOutput()
is called, just stderr) is written.- Throws:
IOException
InterruptedException
-
getOutputFile
public FilePath getOutputFile(FilePath workspace) throws IOException, InterruptedException
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
public FilePath getLastLocationFile(FilePath workspace) throws IOException, InterruptedException
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
-
-