use of com.linkedin.kafka.cruisecontrol.model.ClusterModel in project cruise-control by linkedin.
the class KafkaAssignerDiskUsageDistributionGoalTest method testCanSwap.
@Test
public void testCanSwap() {
KafkaAssignerDiskUsageDistributionGoal goal = new KafkaAssignerDiskUsageDistributionGoal();
ClusterModel clusterModel = createClusterModel();
Replica r1 = clusterModel.broker(0).replica(T0P0);
Replica r2 = clusterModel.broker(1).replica(T2P0);
assertTrue("Replicas in the same rack should be good to swap", goal.canSwap(r1, r2, clusterModel));
assertTrue("Replicas in the same rack should be good to swap", goal.canSwap(r2, r1, clusterModel));
r2 = clusterModel.broker(1).replica(T1P0);
assertFalse("Should not be able to swap replica with different roles.", goal.canSwap(r1, r2, clusterModel));
assertFalse("Should not be able to swap replica with different roles.", goal.canSwap(r2, r1, clusterModel));
r2 = clusterModel.broker(2).replica(T2P1);
assertFalse("Should not be able to put two replicas in the same broker", goal.canSwap(r1, r2, clusterModel));
assertFalse("Should not be able to put two replicas in the same broker", goal.canSwap(r2, r1, clusterModel));
r2 = clusterModel.broker(3).replica(T2P2);
assertFalse("Should not be able to put two replicas in the same rack", goal.canSwap(r1, r2, clusterModel));
assertFalse("Should not be able to put two replicas in the same rack", goal.canSwap(r2, r1, clusterModel));
r1 = clusterModel.broker(3).replica(T0P2);
r2 = clusterModel.broker(4).replica(T1P2);
assertTrue("Should be able to swap", goal.canSwap(r1, r2, clusterModel));
assertTrue("Should be able to swap", goal.canSwap(r2, r1, clusterModel));
}
use of com.linkedin.kafka.cruisecontrol.model.ClusterModel in project cruise-control by linkedin.
the class DeterministicCluster method smallClusterModel.
/**
* Generates a small scale cluster.
* <p>
* <li>Number of Partitions: 10.</li>
* <li>Topics: T1, T2</li>
* <li>Replication factor/Topic: T1: 2, T2: 2</li>
* <li>Partitions/Topic: T1: 6, T2: 4</li>
* <p>
* <h3>Replica Distribution</h3>
* <li>B0: T1_P1_leader, T1_P2_follower, T2_P3_leader, T2_P2_leader</li>
* <li>B1: T1_P2_leader, T2_P1_leader, T2_P3_follower</li>
* <li>B2: T2_P2_follower, T1_P1_follower, T2_P1_follower</li>
* <p>
* <h3>Load on Partitions</h3>
* <p>
* <ul>
* <li>T1_P1_leader:</li>
* <ul>
* <li>CPU: 100.0</li>
* <li>DISK: 75.0</li>
* <li>INBOUND NW: 100.0</li>
* <li>OUTBOUND NW: 130.0</li>
* </ul>
* <li>T1_P1_follower:</li>
* <ul>
* <li>CPU: 5.0</li>
* <li>DISK: 75.0</li>
* <li>INBOUND NW: 100.0</li>
* <li>OUTBOUND NW: 0.0</li>
* </ul>
* <li>T1_P2_leader:</li>
* <ul>
* <li>CPU: 40.5</li>
* <li>DISK: 55.0</li>
* <li>INBOUND NW: 90.0</li>
* <li>OUTBOUND NW: 110.0</li>
* </ul>
* <li>T1_P2_follower:</li>
* <ul>
* <li>CPU: 80.5</li>
* <li>DISK: 55.0</li>
* <li>INBOUND NW: 90.0</li>
* <li>OUTBOUND NW: 0.0</li>
* </ul>
* <li>T2_P1_leader:</li>
* <ul>
* <li>CPU: 5.0</li>
* <li>DISK: 5.0</li>
* <li>INBOUND NW: 5.0</li>
* <li>OUTBOUND NW: 6.0</li>
* </ul>
* <li>T2_P1_follower:</li>
* <ul>
* <li>CPU: 4.0</li>
* <li>DISK: 5.0</li>
* <li>INBOUND NW: 5.0</li>
* <li>OUTBOUND NW: 0.0</li>
* </ul>
* <li>T2_P2_leader:</li>
* <ul>
* <li>CPU: 100.0</li>
* <li>DISK: 55.0</li>
* <li>INBOUND NW: 25.0</li>
* <li>OUTBOUND NW: 45.0</li>
* </ul>
* <li>T2_P2_follower:</li>
* <ul>
* <li>CPU: 20.5</li>
* <li>DISK: 55.0</li>
* <li>INBOUND NW: 25.0</li>
* <li>OUTBOUND NW: 0.0</li>
* </ul>
* <li>T2_P3_leader:</li>
* <ul>
* <li>CPU: 85.0</li>
* <li>DISK: 95.0</li>
* <li>INBOUND NW: 45.0</li>
* <li>OUTBOUND NW: 120.0</li>
* </ul>
* <li>T2_P3_follower:</li>
* <ul>
* <li>CPU: 55.0</li>
* <li>DISK: 95.0</li>
* <li>INBOUND NW: 45.0</li>
* <li>OUTBOUND NW: 0.0</li>
* </ul>
* </ul>
*
* @return Small scale cluster.
*/
public static ClusterModel smallClusterModel(Map<Resource, Double> brokerCapacity) {
List<Integer> orderedRackIdsOfBrokers = Arrays.asList(0, 0, 1);
ClusterModel cluster = getHomogeneousDeterministicCluster(2, orderedRackIdsOfBrokers, brokerCapacity);
// Create topic partition.
TopicPartition pInfoT10 = new TopicPartition("T1", 0);
TopicPartition pInfoT11 = new TopicPartition("T1", 1);
TopicPartition pInfoT20 = new TopicPartition("T2", 0);
TopicPartition pInfoT21 = new TopicPartition("T2", 1);
TopicPartition pInfoT22 = new TopicPartition("T2", 2);
// Create replicas for topic: T1.
cluster.createReplica("0", 0, pInfoT10, 0, true);
cluster.createReplica("1", 2, pInfoT10, 1, false);
cluster.createReplica("0", 1, pInfoT11, 0, true);
cluster.createReplica("0", 0, pInfoT11, 1, false);
// Create replicas for topic: T2.
cluster.createReplica("0", 1, pInfoT20, 0, true);
cluster.createReplica("1", 2, pInfoT20, 1, false);
cluster.createReplica("0", 0, pInfoT21, 0, true);
cluster.createReplica("1", 2, pInfoT21, 1, false);
cluster.createReplica("0", 0, pInfoT22, 0, true);
cluster.createReplica("0", 1, pInfoT22, 1, false);
// Create snapshots and push them to the cluster.
List<Long> windows = Collections.singletonList(1L);
cluster.setReplicaLoad("0", 0, pInfoT10, createLoad(100.0, 100.0, 130.0, 75.0), windows);
cluster.setReplicaLoad("1", 2, pInfoT10, createLoad(5.0, 100.0, 0.0, 75.0), windows);
cluster.setReplicaLoad("0", 1, pInfoT11, createLoad(40.5, 90.0, 110.0, 55.0), windows);
cluster.setReplicaLoad("0", 0, pInfoT11, createLoad(80.5, 90.0, 0.0, 55.0), windows);
cluster.setReplicaLoad("0", 1, pInfoT20, createLoad(5.0, 5.0, 6.0, 5.0), windows);
cluster.setReplicaLoad("1", 2, pInfoT20, createLoad(4.0, 5.0, 0.0, 5.0), windows);
cluster.setReplicaLoad("0", 0, pInfoT21, createLoad(100.0, 25.0, 45.0, 55.0), windows);
cluster.setReplicaLoad("1", 2, pInfoT21, createLoad(20.5, 25.0, 0.0, 55.0), windows);
cluster.setReplicaLoad("0", 0, pInfoT22, createLoad(85.0, 45.0, 120.0, 95.0), windows);
cluster.setReplicaLoad("0", 1, pInfoT22, createLoad(55.0, 45.0, 0.0, 95.0), windows);
return cluster;
}
use of com.linkedin.kafka.cruisecontrol.model.ClusterModel in project cruise-control by linkedin.
the class DeterministicCluster method rackAwareUnsatisfiable.
// two racks, three brokers, one partition, three replicas.
public static ClusterModel rackAwareUnsatisfiable() {
ClusterModel cluster = rackAwareSatisfiable();
TopicPartition pInfoT10 = new TopicPartition("T1", 0);
cluster.createReplica("1", 2, pInfoT10, 2, false);
cluster.setReplicaLoad("1", 2, pInfoT10, KafkaCruiseControlUnitTestUtils.getAggregatedMetricValues(60.0, 100.0, 130.0, 75.0), Collections.singletonList(1L));
return cluster;
}
use of com.linkedin.kafka.cruisecontrol.model.ClusterModel in project cruise-control by linkedin.
the class DeterministicCluster method rackAwareSatisfiable.
// Two racks, three brokers, one partition, two replicas
public static ClusterModel rackAwareSatisfiable() {
List<Integer> orderedRackIdsOfBrokers = Arrays.asList(0, 0, 1);
ClusterModel cluster = DeterministicCluster.getHomogeneousDeterministicCluster(2, orderedRackIdsOfBrokers, TestConstants.BROKER_CAPACITY);
// Create topic partition.
TopicPartition pInfoT10 = new TopicPartition("T1", 0);
// Create replicas for topic: T1.
cluster.createReplica("0", 0, pInfoT10, 0, true);
cluster.createReplica("0", 1, pInfoT10, 1, false);
// Create snapshots and push them to the cluster.
List<Long> windows = Collections.singletonList(1L);
cluster.setReplicaLoad("0", 0, pInfoT10, KafkaCruiseControlUnitTestUtils.getAggregatedMetricValues(40.0, 100.0, 130.0, 75.0), windows);
cluster.setReplicaLoad("0", 1, pInfoT10, KafkaCruiseControlUnitTestUtils.getAggregatedMetricValues(5.0, 100.0, 0.0, 75.0), windows);
return cluster;
}
use of com.linkedin.kafka.cruisecontrol.model.ClusterModel in project cruise-control by linkedin.
the class DeterministicCluster method getHomogeneousDeterministicCluster.
/**
* Creates a deterministic cluster with the given number of racks and the broker distribution.
*
* @param numRacks Number of racks in ToR architecture.
* @param orderedRackIdsOfBrokers Specifies the rack id for each broker.
* @param brokerCapacity Healthy broker capacity.
* @return Cluster with the specified number of racks and broker distribution.
*/
public static ClusterModel getHomogeneousDeterministicCluster(int numRacks, List<Integer> orderedRackIdsOfBrokers, Map<Resource, Double> brokerCapacity) {
int numBrokers = orderedRackIdsOfBrokers.size();
// Sanity checks.
if (numRacks > numBrokers || numBrokers <= 0 || numRacks <= 0 || brokerCapacity.get(Resource.CPU) < 0 || brokerCapacity.get(Resource.DISK) < 0 || brokerCapacity.get(Resource.NW_IN) < 0 || brokerCapacity.get(Resource.NW_OUT) < 0) {
throw new IllegalArgumentException("Deterministic cluster generation failed due to bad input.");
}
// Create cluster.
ClusterModel cluster = new ClusterModel(new ModelGeneration(0, 0L), 1.0);
// Create racks and add them to cluster.
for (int i = 0; i < numRacks; i++) {
cluster.createRack(Integer.toString(i));
}
// Create brokers and assign a broker to each rack.
int brokerId = 0;
for (Integer rackId : orderedRackIdsOfBrokers) {
cluster.createBroker(rackId.toString(), Integer.toString(brokerId), brokerId, brokerCapacity);
brokerId++;
}
return cluster;
}
Aggregations