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 Summary
Modifier and TypeClassDescriptionprotected static class
Executes Command locally.Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
org.apache.zookeeper.Watcher.Event, org.apache.zookeeper.Watcher.WatcherType
-
Field Summary
Modifier and TypeFieldDescriptionprivate String
private org.apache.hadoop.conf.Configuration
private boolean
(package private) org.apache.zookeeper.AsyncCallback.StringCallback
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
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
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
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 final org.slf4j.Logger
(package private) org.apache.zookeeper.Watcher
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
private RetryCounterFactory
(package private) org.apache.zookeeper.AsyncCallback.StatCallback
Callback used while setting status of a given task, Logs given status.(package private) static AtomicBoolean
private org.apache.zookeeper.ZooKeeper
-
Constructor Summary
ConstructorDescriptionChaosAgent
(org.apache.hadoop.conf.Configuration conf, String quorum, String agentName) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 paramsexecWithRetries
(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
void
process
(org.apache.zookeeper.WatchedEvent watchedEvent) private void
private void
register()
registration of ChaosAgent by checking and creating necessary ZNodes.private <E extends Exception>
voidretryOrThrow
(RetryCounter retryCounter, E ex, String user, String cmd) void
run()
void
setStatusOfTaskZNode
(String taskZNode, String status) sets given Status for Task Znode
-
Field Details
-
LOG
-
stopChaosAgent
-
zk
-
quorum
-
agentName
-
conf
-
retryCounterFactory
-
connected
-
newTaskCreatedWatcher
org.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. -
setStatusOfTaskZNodeCallback
org.apache.zookeeper.AsyncCallback.StatCallback setStatusOfTaskZNodeCallbackCallback used while setting status of a given task, Logs given status. -
createZNodeCallback
org.apache.zookeeper.AsyncCallback.StringCallback createZNodeCallbackCallback used while creating a Persistent ZNode tries to create ZNode again if Connection was lost in previous try. -
createEphemeralZNodeCallback
org.apache.zookeeper.AsyncCallback.StringCallback createEphemeralZNodeCallbackCallback used while creating a Ephemeral ZNode tries to create ZNode again if Connection was lost in previous try. -
getTaskForExecutionCallback
org.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. -
getTasksForAgentCallback
org.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
-
initChaosAgent
private 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 usequorum
- ZK QuorumagentName
- AgentName to use
-
createZKConnection
Creates Connection with ZooKeeper.- Throws:
IOException
- if something goes wrong
-
createZNode
Function to create PERSISTENT ZNODE with given path and data given as params- Parameters:
path
- Path at which ZNode to createdata
- Data to put under ZNode
-
createEphemeralZNode
Function to create EPHEMERAL ZNODE with given path and data as params.- Parameters:
path
- Path at which Ephemeral ZNode to createdata
- Data to put under ZNode
-
createIfZNodeNotExists
Checks if given ZNode exists, if not creates a PERSISTENT ZNODE for same.- Parameters:
path
- Path to check for ZNode
-
setStatusOfTaskZNode
sets given Status for Task Znode- Parameters:
taskZNode
- ZNode to set statusstatus
- Status value
-
register
registration of ChaosAgent by checking and creating necessary ZNodes. -
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. -
execWithRetries
Below function executes command with retries with given user. Uses LocalShell to execute a command.- Parameters:
user
- user name, default nonecmd
- Command to execute- Returns:
- A pair of Exit Code and Shell output
- Throws:
IOException
- Exception while executing shell command
-
exec
- Throws:
IOException
-
retryOrThrow
private <E extends Exception> void retryOrThrow(RetryCounter retryCounter, E ex, String user, String cmd) throws E - Throws:
E extends Exception
-
isConnected
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
run
-
process
- Specified by:
process
in interfaceorg.apache.zookeeper.Watcher
-
recreateZKConnection
- Throws:
Exception
-