Search in sources :

Example 1 with BrokerCapacityConfigFileResolver

use of com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigFileResolver in project cruise-control by linkedin.

the class RandomCluster method generate.

/**
 * Create a random cluster with the given number of racks, brokers and broker capacity.
 *
 * @param clusterProperties Cluster properties specifying number of racks and brokers.
 * @return Cluster with the specified number of racks and brokers.
 */
public static ClusterModel generate(Map<ClusterProperty, Number> clusterProperties) {
    int numRacks = clusterProperties.get(ClusterProperty.NUM_RACKS).intValue();
    int numBrokers = clusterProperties.get(ClusterProperty.NUM_BROKERS).intValue();
    BrokerCapacityConfigFileResolver configFileResolver = new BrokerCapacityConfigFileResolver();
    configFileResolver.configure(Collections.singletonMap(BrokerCapacityConfigFileResolver.CAPACITY_CONFIG_FILE, RandomCluster.class.getClassLoader().getResource("DefaultCapacityConfig.json").getFile()));
    if (numRacks > numBrokers || numBrokers <= 0 || numRacks <= 0) {
        throw new IllegalArgumentException("Random 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.
    for (int i = 0; i < numRacks; i++) {
        cluster.createBroker(Integer.toString(i), Integer.toString(i), i, configFileResolver.capacityForBroker("", "", i));
    }
    // Assign the rest of the brokers over racks randomly.
    for (int i = numRacks; i < numBrokers; i++) {
        int randomRackId = uniformlyRandom(0, numRacks - 1, TestConstants.SEED_BASE + i);
        cluster.createBroker(Integer.toString(randomRackId), Integer.toString(i), i, configFileResolver.capacityForBroker("", "", i));
    }
    return cluster;
}
Also used : ClusterModel(com.linkedin.kafka.cruisecontrol.model.ClusterModel) BrokerCapacityConfigFileResolver(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigFileResolver) ModelGeneration(com.linkedin.kafka.cruisecontrol.monitor.ModelGeneration)

Aggregations

BrokerCapacityConfigFileResolver (com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigFileResolver)1 ClusterModel (com.linkedin.kafka.cruisecontrol.model.ClusterModel)1 ModelGeneration (com.linkedin.kafka.cruisecontrol.monitor.ModelGeneration)1