Search in sources :

Example 1 with PersistentClaimStorageOverride

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverride in project strimzi-kafka-operator by strimzi.

the class StorageDiff method isOverrideChangeAllowed.

/**
 * Validates the changes to the storage overrides and decides whether they are allowed or not. Allowed changes are
 * those to nodes which will be added, removed or which do nto exist yet.
 *
 * @param current           Current Storage configuration
 * @param desired           New storage configuration
 * @param currentReplicas   Current number of replicas
 * @param desiredReplicas   Desired number of replicas
 * @return                  True if only allowed override changes were done, false othewise
 */
private boolean isOverrideChangeAllowed(Storage current, Storage desired, int currentReplicas, int desiredReplicas) {
    List<PersistentClaimStorageOverride> currentOverrides = ((PersistentClaimStorage) current).getOverrides();
    if (currentOverrides == null) {
        currentOverrides = Collections.emptyList();
    }
    List<PersistentClaimStorageOverride> desiredOverrides = ((PersistentClaimStorage) desired).getOverrides();
    if (desiredOverrides == null) {
        desiredOverrides = Collections.emptyList();
    }
    // We care only about the nodes which existed before this reconciliation and will still exist after it
    int existedAndWillExist = Math.min(currentReplicas, desiredReplicas);
    for (int i = 0; i < existedAndWillExist; i++) {
        int nodeId = i;
        PersistentClaimStorageOverride currentOverride = currentOverrides.stream().filter(override -> override.getBroker() == nodeId).findFirst().orElse(null);
        PersistentClaimStorageOverride desiredOverride = desiredOverrides.stream().filter(override -> override.getBroker() == nodeId).findFirst().orElse(null);
        if (currentOverride != null && desiredOverride != null) {
            // Both overrides exist but are not equal
            if (!currentOverride.equals(desiredOverride)) {
                return false;
            }
        } else if (currentOverride != null || desiredOverride != null) {
            // One of them is null while the other is not null => they differ
            return false;
        }
    }
    return true;
}
Also used : PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) PersistentClaimStorageOverride(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverride)

Example 2 with PersistentClaimStorageOverride

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverride in project strimzi by strimzi.

the class StorageDiff method isOverrideChangeAllowed.

/**
 * Validates the changes to the storage overrides and decides whether they are allowed or not. Allowed changes are
 * those to nodes which will be added, removed or which do nto exist yet.
 *
 * @param current           Current Storage configuration
 * @param desired           New storage configuration
 * @param currentReplicas   Current number of replicas
 * @param desiredReplicas   Desired number of replicas
 * @return                  True if only allowed override changes were done, false othewise
 */
private boolean isOverrideChangeAllowed(Storage current, Storage desired, int currentReplicas, int desiredReplicas) {
    List<PersistentClaimStorageOverride> currentOverrides = ((PersistentClaimStorage) current).getOverrides();
    if (currentOverrides == null) {
        currentOverrides = Collections.emptyList();
    }
    List<PersistentClaimStorageOverride> desiredOverrides = ((PersistentClaimStorage) desired).getOverrides();
    if (desiredOverrides == null) {
        desiredOverrides = Collections.emptyList();
    }
    // We care only about the nodes which existed before this reconciliation and will still exist after it
    int existedAndWillExist = Math.min(currentReplicas, desiredReplicas);
    for (int i = 0; i < existedAndWillExist; i++) {
        int nodeId = i;
        PersistentClaimStorageOverride currentOverride = currentOverrides.stream().filter(override -> override.getBroker() == nodeId).findFirst().orElse(null);
        PersistentClaimStorageOverride desiredOverride = desiredOverrides.stream().filter(override -> override.getBroker() == nodeId).findFirst().orElse(null);
        if (currentOverride != null && desiredOverride != null) {
            // Both overrides exist but are not equal
            if (!currentOverride.equals(desiredOverride)) {
                return false;
            }
        } else if (currentOverride != null || desiredOverride != null) {
            // One of them is null while the other is not null => they differ
            return false;
        }
    }
    return true;
}
Also used : PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) PersistentClaimStorageOverride(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverride)

Aggregations

PersistentClaimStorage (io.strimzi.api.kafka.model.storage.PersistentClaimStorage)2 PersistentClaimStorageOverride (io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverride)2