public abstract class AbstractGoal extends Object implements Goal
Goal.ClusterModelStatsComparator
Modifier and Type | Field and Description |
---|---|
protected BalancingConstraint |
balancingConstraint |
protected boolean |
finished |
protected double |
minMonitoredPartitionPercentage |
protected int |
numWindows |
protected GoalOptimizationResult.Builder |
optimizationResultBuilder |
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 SortedSet<Broker> |
brokersToBalance(ClusterModel clusterModel)
Get sorted brokers that the rebalance process will go over to apply balancing actions to replicas they contain.
|
protected void |
changeObservership(ClusterModel clusterModel,
org.apache.kafka.common.TopicPartition tp,
int replicaId) |
void |
configure(Map<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,
Collection<Broker> candidateBrokers,
ActionType action,
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,
Collection<Disk> candidateDisks,
Set<Goal> optimizedGoals)
Attempt to move replica between disks of the same broker.
|
abstract String |
name()
Get the name of this goal.
|
GoalOptimizationResult |
optimize(ClusterModel clusterModel,
Set<Goal> optimizedGoals,
OptimizationOptions optimizationOptions)
The entry-point to a goal, this method mutates the given #
ClusterModel object by optimizing it
in accordance to the goal |
protected abstract void |
rebalanceForBroker(Broker broker,
ClusterModel clusterModel,
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,
Set<String> excludedTopics)
Check whether the replica should be excluded from the rebalance.
|
String |
toString() |
protected abstract void |
updateGoalState(ClusterModel clusterModel,
Set<String> excludedTopics)
Update goal state after one round of self-healing / rebalance.
|
protected void |
updateReplicationFactor(ClusterModel clusterModel,
Map<Short,Set<String>> topicsByReplicationFactor,
Set<Integer> brokersExcludedForReplicaMovement) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
actionAcceptance, canChangeReplicationFactor, clusterModelCompletenessRequirements, clusterModelStatsComparator, finish, isHardGoal
protected boolean finished
protected BalancingConstraint balancingConstraint
protected int numWindows
protected double minMonitoredPartitionPercentage
protected GoalOptimizationResult.Builder optimizationResultBuilder
public AbstractGoal()
public void configure(Map<String,?> configs)
CruiseControlConfigurable
configure
in interface CruiseControlConfigurable
public GoalOptimizationResult optimize(ClusterModel clusterModel, Set<Goal> optimizedGoals, OptimizationOptions optimizationOptions) throws OptimizationFailureException
ClusterModel
object by optimizing it
in accordance to the goaloptimize
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.GoalOptimizationResult
denoting whether the goal was met after the optimization and whether any replica movements were made.
Note that for hard goals, the implementation should just throw exceptions if the goal is not met.OptimizationFailureException
- if the goal is a hard goal and it failed to optimize the given cluster modelpublic abstract String name()
Goal
protected static boolean shouldExclude(Replica replica, Set<String> excludedTopics)
replica
- the replica to check.excludedTopics
- the excluded topics set.protected abstract 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, Set<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, 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, Collection<Broker> candidateBrokers, ActionType action, 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 void changeObservership(ClusterModel clusterModel, org.apache.kafka.common.TopicPartition tp, int replicaId)
protected void updateReplicationFactor(ClusterModel clusterModel, Map<Short,Set<String>> topicsByReplicationFactor, Set<Integer> brokersExcludedForReplicaMovement)
protected Disk maybeMoveReplicaBetweenDisks(ClusterModel clusterModel, Replica replica, Collection<Disk> candidateDisks, 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.