use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi 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 by strimzi.
the class VolumeUtils method createPodSetVolumes.
/**
* Generates the list of data volumes as used in PodSets and individual Pods. This includes both ephemeral and
* persistent data volumes. This method calls itself recursively to create the volumes from a JBOD storage array.
* When it does so, it sets the {@code jbod} parameter to {@code true}. When called from outside, it should be set
* to {@code false}.
*
* @param podName Name of the pod used to name the volumes
* @param storage Storage configuration
* @param jbod Indicates that the storage is part of JBOD storage and volume names are created accordingly
*
* @return List of data volumes to be included in the StrimziPodSet pod
*/
public static List<Volume> createPodSetVolumes(String podName, Storage storage, boolean jbod) {
List<Volume> volumes = new ArrayList<>();
if (storage != null) {
if (storage instanceof JbodStorage) {
for (SingleVolumeStorage volume : ((JbodStorage) storage).getVolumes()) {
// it's called recursively for setting the information from the current volume
volumes.addAll(createPodSetVolumes(podName, volume, true));
}
} else if (storage instanceof EphemeralStorage) {
EphemeralStorage ephemeralStorage = (EphemeralStorage) storage;
volumes.add(createEmptyDirVolume(createVolumePrefix(ephemeralStorage.getId(), jbod), ephemeralStorage.getSizeLimit(), null));
} else if (storage instanceof PersistentClaimStorage) {
String name = createVolumePrefix(((PersistentClaimStorage) storage).getId(), jbod);
volumes.add(createPvcVolume(name, name + "-" + podName));
}
}
return volumes;
}
use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi by strimzi.
the class AbstractModel method createPersistentVolumeClaims.
/**
* Creates list of PersistentVolumeClaims required by stateful deployments (Kafka and Zoo). This method calls itself
* recursively to handle volumes inside JBOD storage. When it calls itself to handle the volumes inside JBOD array,
* the {@code jbod} flag should be set to {@code true}. When called from outside, it should be set to {@code false}.
*
* @param storage The storage configuration
* @param jbod Indicator whether the {@code storage} is part of JBOD array or not
*
* @return List with Persistent Volume Claims
*/
protected List<PersistentVolumeClaim> createPersistentVolumeClaims(Storage storage, boolean jbod) {
List<PersistentVolumeClaim> pvcs = new ArrayList<>();
if (storage != null) {
if (storage instanceof PersistentClaimStorage) {
PersistentClaimStorage persistentStorage = (PersistentClaimStorage) storage;
String pvcBaseName = VolumeUtils.createVolumePrefix(persistentStorage.getId(), jbod) + "-" + name;
for (int i = 0; i < replicas; i++) {
pvcs.add(createPersistentVolumeClaim(i, pvcBaseName + "-" + i, persistentStorage));
}
} else if (storage instanceof JbodStorage) {
for (SingleVolumeStorage volume : ((JbodStorage) storage).getVolumes()) {
// it's called recursively for setting the information from the current volume
pvcs.addAll(createPersistentVolumeClaims(volume, true));
}
}
}
return pvcs;
}
use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi by strimzi.
the class KafkaBrokerConfigurationBuilderTest method testJbodStorageLogDirs.
@ParallelTest
public void testJbodStorageLogDirs() {
SingleVolumeStorage vol1 = new PersistentClaimStorageBuilder().withId(1).withSize("1Ti").withStorageClass("aws-ebs").withDeleteClaim(true).build();
SingleVolumeStorage vol2 = new EphemeralStorageBuilder().withId(2).withSizeLimit("5Gi").build();
SingleVolumeStorage vol5 = new PersistentClaimStorageBuilder().withId(5).withSize("10Ti").withStorageClass("aws-ebs").withDeleteClaim(false).build();
Storage storage = new JbodStorageBuilder().withVolumes(vol1, vol2, vol5).build();
String configuration = new KafkaBrokerConfigurationBuilder(Reconciliation.DUMMY_RECONCILIATION).withLogDirs(VolumeUtils.createVolumeMounts(storage, "/var/lib/kafka", false)).build();
assertThat(configuration, isEquivalent("log.dirs=/var/lib/kafka/data-1/kafka-log${STRIMZI_BROKER_ID},/var/lib/kafka/data-2/kafka-log${STRIMZI_BROKER_ID},/var/lib/kafka/data-5/kafka-log${STRIMZI_BROKER_ID}"));
}
use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage in project strimzi by strimzi.
the class KafkaAssemblyOperatorTest method data.
public static Iterable<Params> data() {
boolean[] metricsOpenShiftAndEntityOperatorOptions = { true, false };
SingleVolumeStorage[] storageConfig = { new EphemeralStorage(), new PersistentClaimStorageBuilder().withSize("123").withStorageClass("foo").withDeleteClaim(true).build() };
List<Map<String, Object>> configs = asList(null, emptyMap(), singletonMap("foo", "bar"));
List<Params> result = new ArrayList<>();
for (boolean metricsOpenShiftAndEntityOperator : metricsOpenShiftAndEntityOperatorOptions) {
for (Map<String, Object> config : configs) {
for (SingleVolumeStorage storage : storageConfig) {
EntityOperatorSpec eoConfig;
if (metricsOpenShiftAndEntityOperator) {
eoConfig = new EntityOperatorSpecBuilder().withUserOperator(new EntityUserOperatorSpecBuilder().build()).withTopicOperator(new EntityTopicOperatorSpecBuilder().build()).build();
} else {
eoConfig = null;
}
List<GenericKafkaListener> listeners = new ArrayList<>(3);
listeners.add(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build());
listeners.add(new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().build());
if (metricsOpenShiftAndEntityOperator) {
// On OpenShift, use Routes
listeners.add(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.ROUTE).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().build());
} else {
// On Kube, use nodeports
listeners.add(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().build());
}
result.add(new Params(metricsOpenShiftAndEntityOperator, metricsOpenShiftAndEntityOperator, listeners, config, config, storage, storage, eoConfig));
}
}
}
return result;
}
Aggregations