use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi by strimzi.
the class ZookeeperClusterTest method testStorageReverting.
@ParallelTest
public void testStorageReverting() {
SingleVolumeStorage ephemeral = new EphemeralStorageBuilder().build();
SingleVolumeStorage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
// Test Storage changes and how the are reverted
Kafka ka = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configurationJson, zooConfigurationJson)).editSpec().editZookeeper().withStorage(ephemeral).endZookeeper().endSpec().build();
ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, ka, VERSIONS, persistent, replicas);
assertThat(zc.getStorage(), is(persistent));
ka = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configurationJson, zooConfigurationJson)).editSpec().editZookeeper().withStorage(persistent).endZookeeper().endSpec().build();
zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, ka, VERSIONS, ephemeral, replicas);
// Storage is reverted
assertThat(zc.getStorage(), is(ephemeral));
// Warning status condition is set
assertThat(zc.getWarningConditions().size(), is(1));
assertThat(zc.getWarningConditions().get(0).getReason(), is("ZooKeeperStorage"));
}
use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi by strimzi.
the class Capacity method generateDiskCapacity.
/**
* Generate total disk capacity using the supplied storage configuration
*
* @param storage Storage configuration for Kafka cluster
* @return Disk capacity per broker as a Double
*/
public static Double generateDiskCapacity(Storage storage) {
if (storage instanceof PersistentClaimStorage) {
return getSizeInMiB(((PersistentClaimStorage) storage).getSize());
} else if (storage instanceof EphemeralStorage) {
if (((EphemeralStorage) storage).getSizeLimit() != null) {
return getSizeInMiB(((EphemeralStorage) storage).getSizeLimit());
} else {
return DEFAULT_BROKER_DISK_CAPACITY_IN_MIB;
}
} else if (storage instanceof JbodStorage) {
// The value generated here for JBOD storage is used for tracking the total
// disk capacity per broker. This will NOT be used for the final disk capacity
// configuration since JBOD storage requires a special disk configuration.
List<SingleVolumeStorage> volumeList = ((JbodStorage) storage).getVolumes();
double size = 0;
for (SingleVolumeStorage volume : volumeList) {
size += generateDiskCapacity(volume);
}
return size;
} else {
throw new IllegalStateException("The declared storage '" + storage.getType() + "' is not supported");
}
}
use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi-kafka-operator by strimzi.
the class Capacity method generateJbodDiskCapacity.
/**
* Generate JBOD disk capacity configuration for a broker using the supplied storage configuration
*
* @param storage Storage configuration for Kafka cluster
* @param idx Index of the broker
* @return Disk capacity configuration value as a JsonObject for broker idx
*/
private JsonObject generateJbodDiskCapacity(Storage storage, int idx) {
JsonObject json = new JsonObject();
String size = "";
for (SingleVolumeStorage volume : ((JbodStorage) storage).getVolumes()) {
String name = VolumeUtils.createVolumePrefix(volume.getId(), true);
String path = AbstractModel.KAFKA_MOUNT_PATH + "/" + name + "/" + AbstractModel.KAFKA_LOG_DIR + idx;
if (volume instanceof PersistentClaimStorage) {
size = ((PersistentClaimStorage) volume).getSize();
} else if (volume instanceof EphemeralStorage) {
size = ((EphemeralStorage) volume).getSizeLimit();
}
json.put(path, String.valueOf(Capacity.getSizeInMiB(size)));
}
return json;
}
use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi-kafka-operator by strimzi.
the class CruiseControlTest method testBrokerCapacities.
@ParallelTest
public void testBrokerCapacities() {
// Test user defined capacities
BrokerCapacity userDefinedBrokerCapacity = new 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.generateCapacityConfig()));
// 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(version).withStorage(jbodStorage).endKafka().withCruiseControl(cruiseControlSpec).endSpec().build();
capacity = new Capacity(resource.getSpec(), jbodStorage);
assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.generateCapacityConfig()));
}
use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi-kafka-operator by strimzi.
the class KafkaAssemblyOperatorMockTest method data.
public static Iterable<KafkaAssemblyOperatorMockTest.Params> data() {
int[] replicas = { 1, 3 };
int[] storageOptions = { 0, 1, 2 };
Storage[] kafkaStorageConfigs = { new EphemeralStorage(), new PersistentClaimStorageBuilder().withSize("123").withStorageClass("foo").withDeleteClaim(true).build(), new PersistentClaimStorageBuilder().withSize("123").withStorageClass("foo").withDeleteClaim(false).build() };
SingleVolumeStorage[] zkStorageConfigs = { new EphemeralStorage(), new PersistentClaimStorageBuilder().withSize("123").withStorageClass("foo").withDeleteClaim(true).build(), new PersistentClaimStorageBuilder().withSize("123").withStorageClass("foo").withDeleteClaim(false).build() };
ResourceRequirements[] resources = { new ResourceRequirementsBuilder().addToLimits("cpu", new Quantity("5000m")).addToLimits("memory", new Quantity("5000m")).addToRequests("cpu", new Quantity("5000")).addToRequests("memory", new Quantity("5000m")).build() };
List<KafkaAssemblyOperatorMockTest.Params> result = new ArrayList();
for (int replicaCount : replicas) {
for (int storage : storageOptions) {
for (ResourceRequirements resource : resources) {
result.add(new KafkaAssemblyOperatorMockTest.Params(replicaCount, zkStorageConfigs[storage], replicaCount, kafkaStorageConfigs[storage], resource));
}
}
}
return result;
}
Aggregations