public abstract class AbstractGoal extends java.lang.Object implements Goal
Goal.ClusterModelStatsComparator
Modifier and Type | Field and Description |
---|---|
protected BalancingConstraint |
_balancingConstraint |
protected boolean |
_finished |
protected double |
_minMonitoredPartitionPercentage |
protected int |
_numWindows |
protected boolean |
_succeeded |
Constructor and Description |
---|
AbstractGoal()
Constructor of Abstract Goal class sets the _finished flag to false to signal that the goal requirements have not
been satisfied, yet.
|
Modifier and Type | Method and Description |
---|---|
protected abstract java.util.SortedSet<Broker> |
brokersToBalance(ClusterModel clusterModel)
Get sorted brokers that the rebalance process will go over to apply balancing actions to replicas they contain.
|
void |
configure(java.util.Map<java.lang.String,?> configs)
Configure this class with the given key-value pairs
|
protected abstract void |
initGoalState(ClusterModel clusterModel,
OptimizationOptions optimizationOptions)
Initialize states that this goal requires -- e.g.
|
protected Broker |
maybeApplyBalancingAction(ClusterModel clusterModel,
Replica replica,
java.util.Collection<Broker> candidateBrokers,
ActionType action,
java.util.Set<Goal> optimizedGoals,
OptimizationOptions optimizationOptions)
Attempt to apply the given balancing action to the given replica in the given cluster.
|
protected Disk |
maybeMoveReplicaBetweenDisks(ClusterModel clusterModel,
Replica replica,
java.util.Collection<Disk> candidateDisks,
java.util.Set<Goal> optimizedGoals)
Attempt to move replica between disks of the same broker.
|
abstract java.lang.String |
name()
Get the name of this goal.
|
boolean |
optimize(ClusterModel clusterModel,
java.util.Set<Goal> optimizedGoals,
OptimizationOptions optimizationOptions)
Optimize the given cluster model as needed for this goal.
|
protected abstract void |
rebalanceForBroker(Broker broker,
ClusterModel clusterModel,
java.util.Set<Goal> optimizedGoals,
OptimizationOptions optimizationOptions)
Rebalance the given broker without violating the constraints of the current goal and optimized goals.
|
protected abstract boolean |
selfSatisfied(ClusterModel clusterModel,
BalancingAction action)
Check if requirements of this goal are not violated if this action is applied to the given cluster state,
false otherwise.
|
protected static boolean |
shouldExclude(Replica replica,
java.util.Set<java.lang.String> excludedTopics)
Check whether the replica should be excluded from the rebalance.
|
java.lang.String |
toString() |
protected abstract void |
updateGoalState(ClusterModel clusterModel,
java.util.Set<java.lang.String> excludedTopics)
Update goal state after one round of self-healing / rebalance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
actionAcceptance, canChangeReplicationFactor, clusterModelCompletenessRequirements, clusterModelStatsComparator, finish, isHardGoal
protected boolean _finished
protected boolean _succeeded
protected BalancingConstraint _balancingConstraint
protected int _numWindows
protected double _minMonitoredPartitionPercentage
public AbstractGoal()
public void configure(java.util.Map<java.lang.String,?> configs)
CruiseControlConfigurable
configure
in interface CruiseControlConfigurable
public boolean optimize(ClusterModel clusterModel, java.util.Set<Goal> optimizedGoals, OptimizationOptions optimizationOptions) throws OptimizationFailureException
Goal
The method will be given a cluster model. The goal can try to optimize the cluster model by performing some admin operations (e.g. move replicas or leadership of partitions).
During the optimization, the implementation should make sure that all the previously optimized goals
are still satisfied after this method completes its execution. The implementation can use
Goal.actionAcceptance(BalancingAction, ClusterModel)
to check whether an admin operation
is allowed by a previously optimized goal.
The implementation of a soft goal should return a boolean indicating whether the goal has been met after the optimization or not.
The implementation of a hard goal should throw an OptimizationFailureException
when the goal
cannot be met. This will then fail the entire optimization attempt.
optimize
in interface Goal
clusterModel
- The cluster model reflecting the current state of the cluster. It is a result of the
optimization of the previously optimized goals.optimizedGoals
- Goals that have already been optimized. These goals cannot be violated.optimizationOptions
- Options to take into account during optimization -- e.g. excluded topics.OptimizationFailureException
public abstract java.lang.String name()
Goal
protected static boolean shouldExclude(Replica replica, java.util.Set<java.lang.String> excludedTopics)
replica
- the replica to check.excludedTopics
- the excluded topics set.protected abstract java.util.SortedSet<Broker> brokersToBalance(ClusterModel clusterModel)
clusterModel
- The state of the cluster.protected abstract boolean selfSatisfied(ClusterModel clusterModel, BalancingAction action)
clusterModel
- The state of the cluster.action
- Action containing information about potential modification to the given cluster model.protected abstract void initGoalState(ClusterModel clusterModel, OptimizationOptions optimizationOptions) throws OptimizationFailureException
clusterModel
- The state of the cluster.optimizationOptions
- Options to take into account during optimization -- e.g. excluded topics.OptimizationFailureException
protected abstract void updateGoalState(ClusterModel clusterModel, java.util.Set<java.lang.String> excludedTopics) throws OptimizationFailureException
clusterModel
- The state of the cluster.excludedTopics
- The topics that should be excluded from the optimization action.OptimizationFailureException
protected abstract void rebalanceForBroker(Broker broker, ClusterModel clusterModel, java.util.Set<Goal> optimizedGoals, OptimizationOptions optimizationOptions) throws OptimizationFailureException
broker
- Broker to be balanced.clusterModel
- The state of the cluster.optimizedGoals
- Optimized goals.optimizationOptions
- Options to take into account during optimization -- e.g. excluded topics.OptimizationFailureException
protected Broker maybeApplyBalancingAction(ClusterModel clusterModel, Replica replica, java.util.Collection<Broker> candidateBrokers, ActionType action, java.util.Set<Goal> optimizedGoals, OptimizationOptions optimizationOptions)
clusterModel
- The state of the cluster.replica
- Replica to be applied the given balancing action.candidateBrokers
- Candidate brokers as the potential destination brokers for replica movement or the location
of followers for leadership transfer.action
- Balancing action.optimizedGoals
- Optimized goals.optimizationOptions
- Options to take into account during optimization -- e.g. excluded brokers for leadership.protected Disk maybeMoveReplicaBetweenDisks(ClusterModel clusterModel, Replica replica, java.util.Collection<Disk> candidateDisks, java.util.Set<Goal> optimizedGoals)
clusterModel
- The state of the cluster.replica
- Replica to be moved.candidateDisks
- Candidate disks as the potential destination for replica movement.optimizedGoals
- Optimized goals.public java.lang.String toString()
toString
in class java.lang.Object