Package org.apache.hadoop.hbase.chaos
Class ChaosAgent
java.lang.Object
org.apache.hadoop.hbase.chaos.ChaosAgent
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- Runnable,- org.apache.zookeeper.Watcher
@Private
public class ChaosAgent
extends Object
implements org.apache.zookeeper.Watcher, Closeable, Runnable
An agent for executing destructive actions for ChaosMonkey. Uses ZooKeeper Watchers and
 LocalShell, to do the killing and getting status of service on targeted host without SSH. uses
 given ZNode Structure: /perfChaosTest (root) | | /chaosAgents (Used for registration has hostname
 ephemeral nodes as children) | | /chaosAgentTaskStatus (Used for task Execution, has hostname
 persistent nodes as child with tasks as their children) | | /hostname | | /task0000001 (command
 as data) (has two types of command : 1: starts with "exec" for executing a destructive action. 2:
 starts with "bool" for getting only status of service.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classExecutes Command locally.Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcherorg.apache.zookeeper.Watcher.Event, org.apache.zookeeper.Watcher.WatcherType
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate Stringprivate org.apache.hadoop.conf.Configurationprivate boolean(package private) org.apache.zookeeper.AsyncCallback.StringCallbackCallback used while creating a Ephemeral ZNode tries to create ZNode again if Connection was lost in previous try.(package private) org.apache.zookeeper.AsyncCallback.StringCallbackCallback used while creating a Persistent ZNode tries to create ZNode again if Connection was lost in previous try.(package private) org.apache.zookeeper.AsyncCallback.DataCallbackCallback 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.ChildrenCallbackCallback 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 final org.slf4j.Logger(package private) org.apache.zookeeper.WatcherWatcher for notifying if any task is assigned to agent or not, by seeking if any Node is being added to agent as Child.private Stringprivate RetryCounterFactory(package private) org.apache.zookeeper.AsyncCallback.StatCallbackCallback used while setting status of a given task, Logs given status.(package private) static AtomicBooleanprivate org.apache.zookeeper.ZooKeeper
- 
Constructor SummaryConstructorsConstructorDescriptionChaosAgent(org.apache.hadoop.conf.Configuration conf, String quorum, String agentName) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()voidcreateEphemeralZNode(String path, byte[] data) Function to create EPHEMERAL ZNODE with given path and data as params.private voidcreateIfZNodeNotExists(String path) Checks if given ZNode exists, if not creates a PERSISTENT ZNODE for same.private voidcreateZKConnection(org.apache.zookeeper.Watcher watcher) Creates Connection with ZooKeeper.voidcreateZNode(String path, byte[] data) Function to create PERSISTENT ZNODE with given path and data given as paramsexecWithRetries(String user, String cmd) Below function executes command with retries with given user.private voidgetTasks()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 voidinitChaosAgent(org.apache.hadoop.conf.Configuration conf, String quorum, String agentName) sets global params and initiates connection with ZooKeeper then does registration.private booleanvoidprocess(org.apache.zookeeper.WatchedEvent watchedEvent) private voidprivate voidregister()registration of ChaosAgent by checking and creating necessary ZNodes.private <E extends Exception>
 voidretryOrThrow(RetryCounter retryCounter, E ex, String user, String cmd) voidrun()voidsetStatusOfTaskZNode(String taskZNode, String status) sets given Status for Task Znode
- 
Field Details- 
LOG
- 
stopChaosAgent
- 
zk
- 
quorum
- 
agentName
- 
conf
- 
retryCounterFactory
- 
connected
- 
newTaskCreatedWatcherorg.apache.zookeeper.Watcher newTaskCreatedWatcherWatcher for notifying if any task is assigned to agent or not, by seeking if any Node is being added to agent as Child.
- 
setStatusOfTaskZNodeCallbackorg.apache.zookeeper.AsyncCallback.StatCallback setStatusOfTaskZNodeCallbackCallback used while setting status of a given task, Logs given status.
- 
createZNodeCallbackorg.apache.zookeeper.AsyncCallback.StringCallback createZNodeCallbackCallback used while creating a Persistent ZNode tries to create ZNode again if Connection was lost in previous try.
- 
createEphemeralZNodeCallbackorg.apache.zookeeper.AsyncCallback.StringCallback createEphemeralZNodeCallbackCallback used while creating a Ephemeral ZNode tries to create ZNode again if Connection was lost in previous try.
- 
getTaskForExecutionCallbackorg.apache.zookeeper.AsyncCallback.DataCallback getTaskForExecutionCallbackCallback used by getTasksForAgentCallback while getting command, after getting command successfully, it executes command and set its status with respect to the command type.
- 
getTasksForAgentCallbackorg.apache.zookeeper.AsyncCallback.ChildrenCallback getTasksForAgentCallbackCallback used while getting Tasks for agent if call executed without Exception, It creates a separate thread for each children to execute given Tasks parallely.
 
- 
- 
Constructor Details- 
ChaosAgent
 
- 
- 
Method Details- 
initChaosAgentprivate void initChaosAgent(org.apache.hadoop.conf.Configuration conf, String quorum, String agentName) sets global params and initiates connection with ZooKeeper then does registration.- Parameters:
- conf- initial configuration to use
- quorum- ZK Quorum
- agentName- AgentName to use
 
- 
createZKConnectionCreates Connection with ZooKeeper.- Throws:
- IOException- if something goes wrong
 
- 
createZNodeFunction to create PERSISTENT ZNODE with given path and data given as params- Parameters:
- path- Path at which ZNode to create
- data- Data to put under ZNode
 
- 
createEphemeralZNodeFunction to create EPHEMERAL ZNODE with given path and data as params.- Parameters:
- path- Path at which Ephemeral ZNode to create
- data- Data to put under ZNode
 
- 
createIfZNodeNotExistsChecks if given ZNode exists, if not creates a PERSISTENT ZNODE for same.- Parameters:
- path- Path to check for ZNode
 
- 
setStatusOfTaskZNodesets given Status for Task Znode- Parameters:
- taskZNode- ZNode to set status
- status- Status value
 
- 
registerregistration of ChaosAgent by checking and creating necessary ZNodes.
- 
getTasksGets 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.
- 
execWithRetriesBelow function executes command with retries with given user. Uses LocalShell to execute a command.- Parameters:
- user- user name, default none
- cmd- Command to execute
- Returns:
- A pair of Exit Code and Shell output
- Throws:
- IOException- Exception while executing shell command
 
- 
exec- Throws:
- IOException
 
- 
retryOrThrowprivate <E extends Exception> void retryOrThrow(RetryCounter retryCounter, E ex, String user, String cmd) throws E - Throws:
- E extends Exception
 
- 
isConnected
- 
close- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- IOException
 
- 
run
- 
process- Specified by:
- processin interface- org.apache.zookeeper.Watcher
 
- 
recreateZKConnection- Throws:
- Exception
 
 
-