use of com.linkedin.kafka.cruisecontrol.analyzer.BalancingConstraint in project cruise-control by linkedin.
the class AbstractGoal method configure.
@Override
public void configure(Map<String, ?> configs) {
_balancingConstraint = new BalancingConstraint(new KafkaCruiseControlConfig(configs, false));
String numWindowsString = (String) configs.get(KafkaCruiseControlConfig.NUM_METRICS_WINDOWS_CONFIG);
if (numWindowsString != null && !numWindowsString.isEmpty()) {
_numWindows = Integer.parseInt(numWindowsString);
}
String minMonitoredPartitionPercentageString = (String) configs.get(KafkaCruiseControlConfig.MIN_VALID_PARTITION_RATIO_CONFIG);
if (minMonitoredPartitionPercentageString != null && !minMonitoredPartitionPercentageString.isEmpty()) {
_minMonitoredPartitionPercentage = Double.parseDouble(minMonitoredPartitionPercentageString);
}
}
use of com.linkedin.kafka.cruisecontrol.analyzer.BalancingConstraint in project cruise-control by linkedin.
the class KafkaAssignerDiskUsageDistributionGoalTest method test.
@Test
public void test() {
Properties props = KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties();
props.setProperty(KafkaCruiseControlConfig.MAX_REPLICAS_PER_BROKER_CONFIG, Long.toString(10L));
props.setProperty(KafkaCruiseControlConfig.DISK_BALANCE_THRESHOLD_CONFIG, "1.05");
BalancingConstraint balancingConstraint = new BalancingConstraint(new KafkaCruiseControlConfig(props));
KafkaAssignerDiskUsageDistributionGoal goal = new KafkaAssignerDiskUsageDistributionGoal(balancingConstraint);
ClusterModel clusterModel = createClusterModel();
goal.optimize(clusterModel, Collections.emptySet(), Collections.emptySet());
for (Broker b : clusterModel.brokers()) {
System.out.println("Broker " + b.id() + " = " + b.load().expectedUtilizationFor(DISK));
}
}
use of com.linkedin.kafka.cruisecontrol.analyzer.BalancingConstraint in project cruise-control by linkedin.
the class KafkaAssignerDiskUsageDistributionGoalTest method testSwapReplicas.
@Test
public void testSwapReplicas() {
Properties props = KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties();
props.setProperty(KafkaCruiseControlConfig.MAX_REPLICAS_PER_BROKER_CONFIG, Long.toString(10L));
props.setProperty(KafkaCruiseControlConfig.DISK_BALANCE_THRESHOLD_CONFIG, "1.05");
BalancingConstraint balancingConstraint = new BalancingConstraint(new KafkaCruiseControlConfig(props));
KafkaAssignerDiskUsageDistributionGoal goal = new KafkaAssignerDiskUsageDistributionGoal(balancingConstraint);
ClusterModel clusterModel = createClusterModel();
double meanDiskUsage = clusterModel.load().expectedUtilizationFor(DISK) / clusterModel.capacityFor(DISK);
assertTrue(goal.swapReplicas(clusterModel.broker(0), clusterModel.broker(1), meanDiskUsage, clusterModel, Collections.emptySet()));
assertFalse(goal.swapReplicas(clusterModel.broker(0), clusterModel.broker(2), meanDiskUsage, clusterModel, Collections.emptySet()));
assertTrue(goal.swapReplicas(clusterModel.broker(2), clusterModel.broker(3), meanDiskUsage, clusterModel, Collections.emptySet()));
}
use of com.linkedin.kafka.cruisecontrol.analyzer.BalancingConstraint in project cruise-control by linkedin.
the class KafkaAssignerDiskUsageDistributionGoalTest method testFindReplicaToSwapWith.
@Test
public void testFindReplicaToSwapWith() {
Properties props = KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties();
props.setProperty(KafkaCruiseControlConfig.MAX_REPLICAS_PER_BROKER_CONFIG, Long.toString(10L));
props.setProperty(KafkaCruiseControlConfig.DISK_BALANCE_THRESHOLD_CONFIG, "1.05");
BalancingConstraint balancingConstraint = new BalancingConstraint(new KafkaCruiseControlConfig(props));
KafkaAssignerDiskUsageDistributionGoal goal = new KafkaAssignerDiskUsageDistributionGoal(balancingConstraint);
ClusterModel clusterModel = createClusterModel();
Broker b2 = clusterModel.broker(2);
Replica r = b2.replica(T0P1);
assertNull(goal.findReplicaToSwapWith(r, sortedReplicaAscend(clusterModel.broker(1)), 30, 10, 90, clusterModel));
// The replicas on broker 3 are of the following sizes
// T0P0: 10
// T0P2: 20
// T1P1: 30
// T2P2: 50
// T2P1: 60
// T1P0: 80
// Only T0P0 and T1P1 are eligible to swap with r.
findReplicaToSwapWithAndVerify(Arrays.asList(-1.0, 5.0, 10.0, 20.0, 21.0, 60.0, 100.0), Arrays.asList(T0P0, T0P0, T0P0, T0P0, T1P1, T1P1, T1P1), 9, 90, r, 3, clusterModel, goal);
findReplicaToSwapWithAndVerify(Arrays.asList(-1.0, 5.0, 10.0, 20.0, 21.0, 60.0, 100.0), Arrays.asList(T1P1, T1P1, T1P1, T1P1, T1P1, T1P1, T1P1), 10, 31, r, 3, clusterModel, goal);
findReplicaToSwapWithAndVerify(Arrays.asList(-1.0, 5.0, 10.0, 20.0, 21.0, 60.0, 100.0), Arrays.asList(T0P0, T0P0, T0P0, T0P0, T0P0, T0P0, T0P0), 9, 30, r, 3, clusterModel, goal);
findReplicaToSwapWithAndVerify(Arrays.asList(-1.0, 5.0, 10.0, 20.0, 21.0, 60.0, 100.0), Arrays.asList(null, null, null, null, null, null, null), 10, 30, r, 3, clusterModel, goal);
}
use of com.linkedin.kafka.cruisecontrol.analyzer.BalancingConstraint in project cruise-control by linkedin.
the class KafkaAssignerDiskUsageDistributionGoal method configure.
@Override
public void configure(Map<String, ?> configs) {
_balancingConstraint = new BalancingConstraint(new KafkaCruiseControlConfig(configs, false));
String minMonitoredPartitionPercentageString = (String) configs.get(KafkaCruiseControlConfig.MIN_VALID_PARTITION_RATIO_CONFIG);
if (minMonitoredPartitionPercentageString != null && !minMonitoredPartitionPercentageString.isEmpty()) {
_minMonitoredPartitionPercentage = Double.parseDouble(minMonitoredPartitionPercentageString);
}
}
Aggregations