public class ClusterControllerImpl extends Object implements ClusterController
This class is designed to allow unit tests. In general, testing the controller on a live cluster is tedious. This class encapsulates the controller algorithm so it can be driven by a simulated cluster.
This object is shared between threads, thus synchronized.
Modifier and Type | Class and Description |
---|---|
static class |
ClusterControllerImpl.State
Controller lifecycle state.
|
Modifier and Type | Field and Description |
---|---|
protected int |
maxRetries
Maximum number of retries for each task launch.
|
Constructor and Description |
---|
ClusterControllerImpl(AMYarnFacade yarn) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancelTask(int id)
Cancels the given task, reducing the target task count.
|
void |
completionAck(Task task,
String propertyKey) |
void |
containerAllocated(Task task) |
void |
containerReleased(Task task) |
void |
containersAllocated(List<org.apache.hadoop.yarn.api.records.Container> containers)
The RM has allocated one or more containers in response to container
requests submitted to the RM.
|
void |
containersCompleted(List<org.apache.hadoop.yarn.api.records.ContainerStatus> statuses)
The Resource Manager reports that containers have completed with the given
statuses.
|
void |
containerStarted(org.apache.hadoop.yarn.api.records.ContainerId containerId)
The NM reports that a container has successfully started.
|
void |
containerStopped(org.apache.hadoop.yarn.api.records.ContainerId containerId)
The Node Manager reports that a container has stopped.
|
void |
enableFailureCheck(boolean flag) |
void |
fireLifecycleChange(TaskLifecycleListener.Event event,
EventContext context) |
int |
getFreeNodeCount()
Get the approximate number of free YARN nodes (those that can
accept a task request.) Starts with the number of nodes from
the node inventory, then subtracts any in-flight requests (which
do not, by definition, have node allocated.)
|
List<Task> |
getHistory() |
int |
getMaxRetries() |
NodeInventory |
getNodeInventory() |
List<SchedulerStateActions> |
getPools() |
float |
getProgress() |
Object |
getProperty(String key) |
ClusterControllerImpl.State |
getState() |
int |
getStopTimeoutMs() |
int |
getTargetCount()
Return the target number of tasks that the controller seeks to maintain.
|
AMYarnFacade |
getYarn() |
boolean |
isLive() |
boolean |
isTaskLive(int id) |
void |
registerLifecycleListener(TaskLifecycleListener listener) |
void |
registerScheduler(Scheduler scheduler)
Define a task type.
|
void |
registryDown() |
void |
releaseHost(String hostName) |
void |
reserveHost(String hostName) |
void |
resizeDelta(int delta)
Request to resize the Drill cluster by a relative amount.
|
int |
resizeTo(int n)
Request to resize the Drill cluster to the given size.
|
void |
setMaxRetries(int value) |
void |
setProperty(String key,
Object value) |
void |
shutDown()
Indicates a request to gracefully shut down the cluster.
|
void |
startAck(Task task,
String propertyKey,
Object value) |
void |
started()
Called when the caller has completed start-up and the controller should
become live.
|
void |
stopTaskFailed(org.apache.hadoop.yarn.api.records.ContainerId containerId,
Throwable t)
The Node Manager API reports that a request sent to the NM to stop a task
has failed.
|
boolean |
succeeded() |
boolean |
supportsDiskResource()
Whether this distribution of YARN supports disk resources.
|
void |
taskEnded(Task task) |
void |
taskGroupCompleted(SchedulerStateActions taskGroup) |
void |
taskRetried(Task task) |
void |
taskStartFailed(org.apache.hadoop.yarn.api.records.ContainerId containerId,
Throwable t)
The RM API reports that an attempt to start a container has failed locally.
|
void |
tick(long curTime)
Called by the timer ("pulse") thread to trigger time-based events.
|
void |
updateRMStatus()
Get an update from YARN on available resources.
|
void |
visit(ControllerVisitor visitor)
Allow an observer to see a consistent view of the controller's
state by performing the visit in a synchronized block.
|
void |
visitTasks(TaskVisitor visitor)
Allow an observer to see a consistent view of the controller's
task state by performing the visit in a synchronized block.
|
boolean |
waitForCompletion()
Called by the main thread to wait for the normal shutdown of the
controller.
|
public ClusterControllerImpl(AMYarnFacade yarn)
public void enableFailureCheck(boolean flag)
enableFailureCheck
in interface ClusterController
public void registerScheduler(Scheduler scheduler)
registerScheduler
in interface ClusterController
scheduler
- public void started() throws YarnFacadeException, AMException
started
in interface ClusterController
YarnFacadeException
AMException
public void tick(long curTime)
ClusterController
tick
in interface ClusterController
public int getFreeNodeCount()
This approximation does not consider whether the node has sufficient resources to run a task; only whether the node itself exists.
getFreeNodeCount
in interface ClusterController
public void updateRMStatus()
updateRMStatus
in interface ClusterController
public void containersAllocated(List<org.apache.hadoop.yarn.api.records.Container> containers)
ClusterController
containersAllocated
in interface ClusterController
containers
- the set of containers provided by YARNpublic void containerStarted(org.apache.hadoop.yarn.api.records.ContainerId containerId)
ClusterController
containerStarted
in interface ClusterController
containerId
- the container which startedpublic void taskStartFailed(org.apache.hadoop.yarn.api.records.ContainerId containerId, Throwable t)
ClusterController
taskStartFailed
in interface ClusterController
containerId
- the container that failed to launcht
- the error that occurredpublic void containerStopped(org.apache.hadoop.yarn.api.records.ContainerId containerId)
ClusterController
containerStopped
in interface ClusterController
public void containersCompleted(List<org.apache.hadoop.yarn.api.records.ContainerStatus> statuses)
ClusterController
containersCompleted
in interface ClusterController
public float getProgress()
getProgress
in interface ClusterController
public void stopTaskFailed(org.apache.hadoop.yarn.api.records.ContainerId containerId, Throwable t)
ClusterController
stopTaskFailed
in interface ClusterController
containerId
- the container that failed to stopt
- the reason that the stop request failedpublic void resizeDelta(int delta)
ClusterController
resizeDelta
in interface ClusterController
delta
- the amount of change. Can be positive (to grow) or negative (to
shrink the cluster)public int resizeTo(int n)
ClusterController
resizeTo
in interface ClusterController
n
- the desired cluster sizepublic void shutDown()
ClusterController
shutDown
in interface ClusterController
public boolean waitForCompletion()
ClusterController
waitForCompletion
in interface ClusterController
public boolean isLive()
public boolean succeeded()
public void containerAllocated(Task task)
public AMYarnFacade getYarn()
public void containerReleased(Task task)
public void taskEnded(Task task)
public void taskRetried(Task task)
public void taskGroupCompleted(SchedulerStateActions taskGroup)
public int getMaxRetries()
public int getStopTimeoutMs()
public void reserveHost(String hostName)
reserveHost
in interface RegistryHandler
public void releaseHost(String hostName)
releaseHost
in interface RegistryHandler
public NodeInventory getNodeInventory()
public void setProperty(String key, Object value)
setProperty
in interface ClusterController
public Object getProperty(String key)
getProperty
in interface ClusterController
public void registerLifecycleListener(TaskLifecycleListener listener)
registerLifecycleListener
in interface ClusterController
public void fireLifecycleChange(TaskLifecycleListener.Event event, EventContext context)
public void setMaxRetries(int value)
setMaxRetries
in interface ClusterController
public int getTargetCount()
ClusterController
getTargetCount
in interface ClusterController
public ClusterControllerImpl.State getState()
public void visit(ControllerVisitor visitor)
ClusterController
visit
in interface ClusterController
public List<SchedulerStateActions> getPools()
public void visitTasks(TaskVisitor visitor)
ClusterController
visitTasks
in interface ClusterController
public boolean isTaskLive(int id)
isTaskLive
in interface ClusterController
public boolean cancelTask(int id)
ClusterController
cancelTask
in interface ClusterController
public void completionAck(Task task, String propertyKey)
completionAck
in interface RegistryHandler
public void startAck(Task task, String propertyKey, Object value)
startAck
in interface RegistryHandler
public boolean supportsDiskResource()
ClusterController
supportsDiskResource
in interface ClusterController
public void registryDown()
registryDown
in interface RegistryHandler
Copyright © 1970 The Apache Software Foundation. All rights reserved.