@InterfaceAudience.Private public class ChaosAgent extends Object implements org.apache.zookeeper.Watcher, Closeable, Runnable
Modifier and Type | Class and Description |
---|---|
protected static class |
ChaosAgent.LocalShell
Executes Command locally.
|
Modifier and Type | Field and Description |
---|---|
private String |
agentName |
private org.apache.hadoop.conf.Configuration |
conf |
private boolean |
connected |
(package private) org.apache.zookeeper.AsyncCallback.StringCallback |
createEphemeralZNodeCallback
Callback used while creating a Ephemeral ZNode tries to create ZNode again if Connection was
lost in previous try.
|
(package private) org.apache.zookeeper.AsyncCallback.StringCallback |
createZNodeCallback
Callback used while creating a Persistent ZNode tries to create ZNode again if Connection was
lost in previous try.
|
(package private) org.apache.zookeeper.AsyncCallback.DataCallback |
getTaskForExecutionCallback
Callback used by getTasksForAgentCallback while getting command, after getting command
successfully, it executes command and set its status with respect to the command type.
|
(package private) org.apache.zookeeper.AsyncCallback.ChildrenCallback |
getTasksForAgentCallback
Callback used while getting Tasks for agent if call executed without Exception, It creates a
separate thread for each children to execute given Tasks parallely.
|
private static org.slf4j.Logger |
LOG |
(package private) org.apache.zookeeper.Watcher |
newTaskCreatedWatcher
Watcher for notifying if any task is assigned to agent or not, by seeking if any Node is being
added to agent as Child.
|
private String |
quorum |
private RetryCounterFactory |
retryCounterFactory |
(package private) org.apache.zookeeper.AsyncCallback.StatCallback |
setStatusOfTaskZNodeCallback
Callback used while setting status of a given task, Logs given status.
|
(package private) static AtomicBoolean |
stopChaosAgent |
private org.apache.zookeeper.ZooKeeper |
zk |
Constructor and Description |
---|
ChaosAgent(org.apache.hadoop.conf.Configuration conf,
String quorum,
String agentName) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
createEphemeralZNode(String path,
byte[] data)
Function to create EPHEMERAL ZNODE with given path and data as params.
|
private void |
createIfZNodeNotExists(String path)
Checks if given ZNode exists, if not creates a PERSISTENT ZNODE for same.
|
private void |
createZKConnection(org.apache.zookeeper.Watcher watcher)
Creates Connection with ZooKeeper.
|
void |
createZNode(String path,
byte[] data)
Function to create PERSISTENT ZNODE with given path and data given as params
|
private Pair<Integer,String> |
exec(String user,
String cmd) |
private Pair<Integer,String> |
execWithRetries(String user,
String cmd)
Below function executes command with retries with given user.
|
private void |
getTasks()
Gets tasks for execution, basically sets Watch on it's respective host's Znode and waits for
tasks to be assigned, also has a getTasksForAgentCallback which handles execution of task.
|
private void |
initChaosAgent(org.apache.hadoop.conf.Configuration conf,
String quorum,
String agentName)
sets global params and initiates connection with ZooKeeper then does registration.
|
private boolean |
isConnected() |
void |
process(org.apache.zookeeper.WatchedEvent watchedEvent) |
private void |
recreateZKConnection() |
private void |
register()
registration of ChaosAgent by checking and creating necessary ZNodes.
|
private <E extends Exception> |
retryOrThrow(RetryCounter retryCounter,
E ex,
String user,
String cmd) |
void |
run() |
void |
setStatusOfTaskZNode(String taskZNode,
String status)
sets given Status for Task Znode
|
private static final org.slf4j.Logger LOG
static AtomicBoolean stopChaosAgent
private org.apache.zookeeper.ZooKeeper zk
private org.apache.hadoop.conf.Configuration conf
private RetryCounterFactory retryCounterFactory
private volatile boolean connected
org.apache.zookeeper.Watcher newTaskCreatedWatcher
org.apache.zookeeper.AsyncCallback.StatCallback setStatusOfTaskZNodeCallback
org.apache.zookeeper.AsyncCallback.StringCallback createZNodeCallback
org.apache.zookeeper.AsyncCallback.StringCallback createEphemeralZNodeCallback
org.apache.zookeeper.AsyncCallback.DataCallback getTaskForExecutionCallback
org.apache.zookeeper.AsyncCallback.ChildrenCallback getTasksForAgentCallback
public ChaosAgent(org.apache.hadoop.conf.Configuration conf, String quorum, String agentName)
private void initChaosAgent(org.apache.hadoop.conf.Configuration conf, String quorum, String agentName)
conf
- initial configuration to usequorum
- ZK QuorumagentName
- AgentName to useprivate void createZKConnection(org.apache.zookeeper.Watcher watcher) throws IOException
IOException
- if something goes wrongpublic void createZNode(String path, byte[] data)
path
- Path at which ZNode to createdata
- Data to put under ZNodepublic void createEphemeralZNode(String path, byte[] data)
path
- Path at which Ephemeral ZNode to createdata
- Data to put under ZNodeprivate void createIfZNodeNotExists(String path)
path
- Path to check for ZNodepublic void setStatusOfTaskZNode(String taskZNode, String status)
taskZNode
- ZNode to set statusstatus
- Status valueprivate void register()
private void getTasks()
private Pair<Integer,String> execWithRetries(String user, String cmd) throws IOException
user
- user name, default nonecmd
- Command to executeIOException
- Exception while executing shell commandprivate Pair<Integer,String> exec(String user, String cmd) throws IOException
IOException
private <E extends Exception> void retryOrThrow(RetryCounter retryCounter, E ex, String user, String cmd) throws E extends Exception
E extends Exception
private boolean isConnected()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void process(org.apache.zookeeper.WatchedEvent watchedEvent)
process
in interface org.apache.zookeeper.Watcher
private void recreateZKConnection() throws Exception
Exception
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.