use of io.strimzi.operator.cluster.model.cruisecontrol.BrokerCapacity in project strimzi-kafka-operator by strimzi.
the class CruiseControlTest method testBrokerCapacities.
@ParallelTest
public void testBrokerCapacities() throws JsonProcessingException {
// Test user defined capacities
io.strimzi.api.kafka.model.balancing.BrokerCapacity userDefinedBrokerCapacity = new io.strimzi.api.kafka.model.balancing.BrokerCapacity();
userDefinedBrokerCapacity.setInboundNetwork("50000KB/s");
userDefinedBrokerCapacity.setOutboundNetwork("50000KB/s");
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withBrokerCapacity(userDefinedBrokerCapacity).build();
Kafka resource = createKafka(cruiseControlSpec);
Capacity capacity = new Capacity(resource.getSpec(), kafkaStorage);
assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.toString()));
// Test generated disk capacity
JbodStorage jbodStorage = new JbodStorage();
List<SingleVolumeStorage> volumes = new ArrayList<>();
PersistentClaimStorage p1 = new PersistentClaimStorage();
p1.setId(0);
p1.setSize("50Gi");
volumes.add(p1);
PersistentClaimStorage p2 = new PersistentClaimStorage();
p2.setId(1);
volumes.add(p2);
jbodStorage.setVolumes(volumes);
resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().editKafka().withVersion(KafkaVersionTestUtils.DEFAULT_KAFKA_VERSION).withStorage(jbodStorage).endKafka().withCruiseControl(cruiseControlSpec).endSpec().build();
capacity = new Capacity(resource.getSpec(), jbodStorage);
JsonArray brokerEntries = capacity.generateCapacityConfig().getJsonArray(Capacity.CAPACITIES_KEY);
for (Object brokerEntry : brokerEntries) {
Map<String, Object> brokerCapacity = ((JsonObject) brokerEntry).getJsonObject(Capacity.CAPACITY_KEY).getMap();
assertThat(isJBOD(brokerCapacity), is(true));
}
assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.toString()));
// Test capacity overrides
String inboundNetwork = "50000KB/s";
String inboundNetworkOverride0 = "25000KB/s";
String inboundNetworkOverride1 = "10000KiB/s";
String outboundNetworkOverride1 = "15000KB/s";
int broker0 = 0;
int broker1 = 1;
int broker2 = 2;
List<Integer> overrideList0 = List.of(broker0, broker1, broker2, broker0);
List<Integer> overrideList1 = List.of(broker1);
cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withNewBrokerCapacity().withInboundNetwork(inboundNetwork).addNewOverride().withBrokers(overrideList0).withInboundNetwork(inboundNetworkOverride0).endOverride().addNewOverride().withBrokers(overrideList1).withInboundNetwork(inboundNetworkOverride1).withOutboundNetwork(outboundNetworkOverride1).endOverride().endBrokerCapacity().build();
resource = createKafka(cruiseControlSpec);
capacity = new Capacity(resource.getSpec(), kafkaStorage);
brokerEntries = capacity.generateCapacityConfig().getJsonArray(Capacity.CAPACITIES_KEY);
for (Object brokerEntry : brokerEntries) {
Map<String, Object> brokerCapacity = ((JsonObject) brokerEntry).getJsonObject(Capacity.CAPACITY_KEY).getMap();
assertThat(isJBOD(brokerCapacity), is(false));
}
TreeMap<Integer, BrokerCapacity> capacityEntries = capacity.getCapacityEntries();
assertThat(capacityEntries.get(BrokerCapacity.DEFAULT_BROKER_ID).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetwork)));
assertThat(capacityEntries.get(BrokerCapacity.DEFAULT_BROKER_ID).getOutboundNetwork(), is(BrokerCapacity.DEFAULT_OUTBOUND_NETWORK_CAPACITY_IN_KIB_PER_SECOND));
assertThat(capacityEntries.get(broker0).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetworkOverride0)));
assertThat(capacityEntries.get(broker0).getOutboundNetwork(), is(BrokerCapacity.DEFAULT_OUTBOUND_NETWORK_CAPACITY_IN_KIB_PER_SECOND));
// When the same broker id is specified in brokers list of multiple overrides, use the value specified in the first override.
assertThat(capacityEntries.get(broker1).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetworkOverride0)));
assertThat(capacityEntries.get(broker1).getOutboundNetwork(), is(BrokerCapacity.DEFAULT_OUTBOUND_NETWORK_CAPACITY_IN_KIB_PER_SECOND));
assertThat(capacityEntries.get(broker2).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetworkOverride0)));
assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.toString()));
}
use of io.strimzi.operator.cluster.model.cruisecontrol.BrokerCapacity in project strimzi by strimzi.
the class CruiseControlTest method testBrokerCapacities.
@ParallelTest
public void testBrokerCapacities() throws JsonProcessingException {
// Test user defined capacities
io.strimzi.api.kafka.model.balancing.BrokerCapacity userDefinedBrokerCapacity = new io.strimzi.api.kafka.model.balancing.BrokerCapacity();
userDefinedBrokerCapacity.setInboundNetwork("50000KB/s");
userDefinedBrokerCapacity.setOutboundNetwork("50000KB/s");
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withBrokerCapacity(userDefinedBrokerCapacity).build();
Kafka resource = createKafka(cruiseControlSpec);
Capacity capacity = new Capacity(resource.getSpec(), kafkaStorage);
assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.toString()));
// Test generated disk capacity
JbodStorage jbodStorage = new JbodStorage();
List<SingleVolumeStorage> volumes = new ArrayList<>();
PersistentClaimStorage p1 = new PersistentClaimStorage();
p1.setId(0);
p1.setSize("50Gi");
volumes.add(p1);
PersistentClaimStorage p2 = new PersistentClaimStorage();
p2.setId(1);
volumes.add(p2);
jbodStorage.setVolumes(volumes);
resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().editKafka().withVersion(KafkaVersionTestUtils.DEFAULT_KAFKA_VERSION).withStorage(jbodStorage).endKafka().withCruiseControl(cruiseControlSpec).endSpec().build();
capacity = new Capacity(resource.getSpec(), jbodStorage);
JsonArray brokerEntries = capacity.generateCapacityConfig().getJsonArray(Capacity.CAPACITIES_KEY);
for (Object brokerEntry : brokerEntries) {
Map<String, Object> brokerCapacity = ((JsonObject) brokerEntry).getJsonObject(Capacity.CAPACITY_KEY).getMap();
assertThat(isJBOD(brokerCapacity), is(true));
}
assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.toString()));
// Test capacity overrides
String inboundNetwork = "50000KB/s";
String inboundNetworkOverride0 = "25000KB/s";
String inboundNetworkOverride1 = "10000KiB/s";
String outboundNetworkOverride1 = "15000KB/s";
int broker0 = 0;
int broker1 = 1;
int broker2 = 2;
List<Integer> overrideList0 = List.of(broker0, broker1, broker2, broker0);
List<Integer> overrideList1 = List.of(broker1);
cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withNewBrokerCapacity().withInboundNetwork(inboundNetwork).addNewOverride().withBrokers(overrideList0).withInboundNetwork(inboundNetworkOverride0).endOverride().addNewOverride().withBrokers(overrideList1).withInboundNetwork(inboundNetworkOverride1).withOutboundNetwork(outboundNetworkOverride1).endOverride().endBrokerCapacity().build();
resource = createKafka(cruiseControlSpec);
capacity = new Capacity(resource.getSpec(), kafkaStorage);
brokerEntries = capacity.generateCapacityConfig().getJsonArray(Capacity.CAPACITIES_KEY);
for (Object brokerEntry : brokerEntries) {
Map<String, Object> brokerCapacity = ((JsonObject) brokerEntry).getJsonObject(Capacity.CAPACITY_KEY).getMap();
assertThat(isJBOD(brokerCapacity), is(false));
}
TreeMap<Integer, BrokerCapacity> capacityEntries = capacity.getCapacityEntries();
assertThat(capacityEntries.get(BrokerCapacity.DEFAULT_BROKER_ID).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetwork)));
assertThat(capacityEntries.get(BrokerCapacity.DEFAULT_BROKER_ID).getOutboundNetwork(), is(BrokerCapacity.DEFAULT_OUTBOUND_NETWORK_CAPACITY_IN_KIB_PER_SECOND));
assertThat(capacityEntries.get(broker0).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetworkOverride0)));
assertThat(capacityEntries.get(broker0).getOutboundNetwork(), is(BrokerCapacity.DEFAULT_OUTBOUND_NETWORK_CAPACITY_IN_KIB_PER_SECOND));
// When the same broker id is specified in brokers list of multiple overrides, use the value specified in the first override.
assertThat(capacityEntries.get(broker1).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetworkOverride0)));
assertThat(capacityEntries.get(broker1).getOutboundNetwork(), is(BrokerCapacity.DEFAULT_OUTBOUND_NETWORK_CAPACITY_IN_KIB_PER_SECOND));
assertThat(capacityEntries.get(broker2).getInboundNetwork(), is(Capacity.getThroughputInKiB(inboundNetworkOverride0)));
assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.toString()));
}
Aggregations