Class ResponderTask
- java.lang.Object
-
- com.dtolabs.rundeck.core.execution.utils.ResponderTask
-
- All Implemented Interfaces:
java.util.concurrent.Callable<ResponderTask.ResponderResult>
public class ResponderTask extends java.lang.Object implements java.util.concurrent.Callable<ResponderTask.ResponderResult>
ResponderTask interacts with an input and outputstream, using aResponder
instance to define the interaction. It looks for lines on the input stream that match the "inputSuccess" regular expression (e.g. password prompt). If it detects the "inputFailure" regular expression, it fails. If successful, it writes the "inputString" to the output stream.
After writing to the output stream, It then looks for a certain "responseSuccess" regular expression. If successful it completes successfully. If it detects a "responseFailure" regular expression in the output, it fails.
If aResponderTask.ResultHandler
is set, it will call the handleResult method after the response logic.
If it the thread running the ResponderTask is interrupted, then the process will stop as soon as it is detected.
ImplementsCallable
so it can be submitted to aExecutorService
.
Example: wait for "[sudo] password for user: ", write a password, and fail on "try again" response:
- inputSuccessPattern: '^\[sudo\] password for .+: '
- responseFailurePattern: '^.*try again.*'
- failOnResponseThreshold: false
- InputMaxLines: 12
- inputString: 'password'
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResponderTask.ResponderResult
Result from a responder execution, which contains success, the original Responder, a failure reason if unsuccessful and a boolean indicating if the process was interrupted.static interface
ResponderTask.ResultHandler
Handles result of responder thread runstatic class
ResponderTask.Sequence<T extends ResponderTask.SuccessResult>
Creates a callable by executing the first step, and only if successful executing the next step.static interface
ResponderTask.SuccessResult
Success/failure result interface
-
Constructor Summary
Constructors Constructor Description ResponderTask(Responder responder, java.io.InputStream inputStream, java.io.OutputStream outputStream, ResponderTask.ResultHandler resultHandler)
Create a ResponderTask with a responder, io streams, and result handler which can be null.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResponderTask.ResponderResult
call()
java.util.concurrent.Callable<ResponderTask.ResponderResult>
createSequence(Responder responder)
Create a Callable that will execute another responder if this one is successful, with the same resultHandler for the second one.java.util.concurrent.Callable<ResponderTask.ResponderResult>
createSequence(Responder responder, ResponderTask.ResultHandler resultHandler)
Create a Callable that will execute another responder if this one is successful, with a specified resultHandler for the second one.java.lang.String
getFailureReason()
boolean
isFailed()
boolean
isSuccess()
-
-
-
Constructor Detail
-
ResponderTask
public ResponderTask(Responder responder, java.io.InputStream inputStream, java.io.OutputStream outputStream, ResponderTask.ResultHandler resultHandler)
Create a ResponderTask with a responder, io streams, and result handler which can be null.- Parameters:
responder
- responderinputStream
- inputoutputStream
- outputresultHandler
- handler
-
-
Method Detail
-
call
public ResponderTask.ResponderResult call() throws java.lang.Exception
- Specified by:
call
in interfacejava.util.concurrent.Callable<ResponderTask.ResponderResult>
- Throws:
java.lang.Exception
-
isFailed
public boolean isFailed()
-
createSequence
public java.util.concurrent.Callable<ResponderTask.ResponderResult> createSequence(Responder responder)
Create a Callable that will execute another responder if this one is successful, with the same resultHandler for the second one.- Parameters:
responder
- responder- Returns:
- sequence
-
createSequence
public java.util.concurrent.Callable<ResponderTask.ResponderResult> createSequence(Responder responder, ResponderTask.ResultHandler resultHandler)
Create a Callable that will execute another responder if this one is successful, with a specified resultHandler for the second one.- Parameters:
responder
- responderresultHandler
- handler- Returns:
- sequence
-
isSuccess
public boolean isSuccess()
-
getFailureReason
public java.lang.String getFailureReason()
-
-