public class UniqueHostAttrConstraint extends java.lang.Object implements ConstraintEvaluator
For example, if you specify the host attribute ZoneAttribute
, the evaluator will place the co-tasks
such that each task is in a different zone. Note that because of this, if more tasks are submitted than there
are zones available for them, the excess tasks will not be assigned to any hosts. If instead you want to
implement a load balancing strategy, use BalancedHostAttrConstraint
instead.
If you construct this evaluator without passing in a host attribute name, it will use the host name as the host attribute by which it uniquely identifies hosts.
ConstraintEvaluator.Result
Constructor and Description |
---|
UniqueHostAttrConstraint(Func1<java.lang.String,java.util.Set<java.lang.String>> coTasksGetter)
Create this constraint evaluator with the given co-tasks of a group.
|
UniqueHostAttrConstraint(Func1<java.lang.String,java.util.Set<java.lang.String>> coTasksGetter,
java.lang.String hostAttributeName)
Create this constraint evaluator with the given co-tasks of a group and a given host attribute name.
|
Modifier and Type | Method and Description |
---|---|
ConstraintEvaluator.Result |
evaluate(TaskRequest taskRequest,
VirtualMachineCurrentState targetVM,
TaskTrackerState taskTrackerState)
Determines whether a particular target host is appropriate for a particular task request by rejecting any
host that has the same value for the unique constraint attribute as another host that is already assigned
a co-task of the specified task request.
|
java.lang.String |
getName()
Returns the name of this constraint evaluator as a String in the form of the name of this class followed
by a dash followed by the host attribute name that this evaluator uses to uniquely identify the host.
|
public UniqueHostAttrConstraint(Func1<java.lang.String,java.util.Set<java.lang.String>> coTasksGetter)
UniqueHostAttrConstraint(coTasksGetter, null)
.coTasksGetter
- a single-argument function that, given a task ID, returns the set of task IDs of its
co-taskspublic UniqueHostAttrConstraint(Func1<java.lang.String,java.util.Set<java.lang.String>> coTasksGetter, java.lang.String hostAttributeName)
coTasksGetter
- a single-argument function that, given a task ID, returns the set of task IDs of its
co-taskshostAttributeName
- the name of the host attribute whose value is to be unique for each co-task's
host assignment. If this is null
, this indicates that the host name is
to be unique for each co-task's host assignment.public java.lang.String getName()
getName
in interface ConstraintEvaluator
public ConstraintEvaluator.Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState)
evaluate
in interface ConstraintEvaluator
taskRequest
- describes the task being considered for assignment to the hosttargetVM
- describes the host being considered as a target for the tasktaskTrackerState
- describes the state of tasks previously assigned or already running throughout
the systemtaskRequest
, or an
unsuccessful Result otherwise