public class Scheduler extends Object implements InstanceListener, SlotAvailabilityListener, SlotProvider
The scheduler supports two scheduling modes:
NoResourceAvailableException
.Constructor and Description |
---|
Scheduler(Executor executor)
Creates a new scheduler.
|
Modifier and Type | Method and Description |
---|---|
Future<SimpleSlot> |
allocateSlot(ScheduledUnit task,
boolean allowQueued)
Allocating slot with specific requirement.
|
protected SimpleSlot |
getFreeSlotForTask(ExecutionVertex vertex,
Iterable<TaskManagerLocation> requestedLocations,
boolean localOnly)
Gets a suitable instance to schedule the vertex execution to.
|
Map<String,List<Instance>> |
getInstancesByHost() |
protected SimpleSlot |
getNewSlotForSharingGroup(ExecutionVertex vertex,
Iterable<TaskManagerLocation> requestedLocations,
SlotSharingGroupAssignment groupAssignment,
CoLocationConstraint constraint,
boolean localOnly)
Tries to allocate a new slot for a vertex that is part of a slot sharing group.
|
int |
getNumberOfAvailableInstances() |
int |
getNumberOfAvailableSlots()
NOTE: In the presence of multi-threaded operations, this number may be inexact.
|
int |
getNumberOfInstancesWithAvailableSlots() |
int |
getNumberOfLocalizedAssignments() |
int |
getNumberOfNonLocalizedAssignments() |
int |
getNumberOfUnconstrainedAssignments() |
int |
getTotalNumberOfSlots() |
void |
instanceDied(Instance instance)
Called when an instance died.
|
void |
newInstanceAvailable(Instance instance)
Called when a new instance becomes available.
|
void |
newSlotAvailable(Instance instance) |
void |
shutdown()
Shuts the scheduler down.
|
public Scheduler(Executor executor)
public void shutdown()
public Future<SimpleSlot> allocateSlot(ScheduledUnit task, boolean allowQueued)
SlotProvider
allocateSlot
in interface SlotProvider
task
- The task to allocate the slot forallowQueued
- Whether allow the task be queued if we do not have enough resourceprotected SimpleSlot getFreeSlotForTask(ExecutionVertex vertex, Iterable<TaskManagerLocation> requestedLocations, boolean localOnly)
NOTE: This method does is not thread-safe, it needs to be synchronized by the caller.
vertex
- The task to run.null
, if no instance is available.protected SimpleSlot getNewSlotForSharingGroup(ExecutionVertex vertex, Iterable<TaskManagerLocation> requestedLocations, SlotSharingGroupAssignment groupAssignment, CoLocationConstraint constraint, boolean localOnly)
This method will try to allocate a slot from one of the local instances, and fall back to non-local instances, if permitted.
vertex
- The vertex to allocate the slot for.requestedLocations
- The locations that are considered local. May be null or empty, if the
vertex has no location preferences.groupAssignment
- The slot sharing group of the vertex. Mandatory parameter.constraint
- The co-location constraint of the vertex. May be null.localOnly
- Flag to indicate if non-local choices are acceptable.null
, if no slot is available.public void newSlotAvailable(Instance instance)
newSlotAvailable
in interface SlotAvailabilityListener
public void newInstanceAvailable(Instance instance)
InstanceListener
newInstanceAvailable
in interface InstanceListener
instance
- The instance that became available.public void instanceDied(Instance instance)
InstanceListener
instanceDied
in interface InstanceListener
instance
- The instance that died.public int getNumberOfAvailableSlots()
public int getTotalNumberOfSlots()
public int getNumberOfAvailableInstances()
public int getNumberOfInstancesWithAvailableSlots()
public int getNumberOfUnconstrainedAssignments()
public int getNumberOfLocalizedAssignments()
public int getNumberOfNonLocalizedAssignments()
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.