use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class AbstractResourceStateMatchers method hasStateInConditions.
/**
* Checks all conditions in the supplied resource to see if the type of one of them matches the supplied rebalance state.
*
* @param state he expected rebalance state to be searched for.
* @return
*/
public static Matcher<List<Condition>> hasStateInConditions(KafkaRebalanceState state) {
return new TypeSafeDiagnosingMatcher<>() {
@Override
protected boolean matchesSafely(List<Condition> conditions, Description mismatchDescription) {
mismatchDescription.appendText("was ").appendValue(conditions);
List<String> foundStatuses = new ArrayList<>();
if (conditions == null) {
mismatchDescription.appendText("\n Conditions empty");
return false;
}
for (Condition condition : conditions) {
if (condition == null) {
continue;
}
String type = condition.getType();
if (type.equals(state.toString())) {
return true;
} else {
foundStatuses.add(type);
}
}
mismatchDescription.appendText("\n Condition doesn't have expected value, found " + foundStatuses);
return false;
}
@Override
public void describeTo(final Description description) {
description.appendText("Expected values are ").appendValue(state);
}
};
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class ConnectorMockTest method waitForConnectorCondition.
public void waitForConnectorCondition(String connectorName, String conditionType, String conditionReason) {
Resource<KafkaConnector> resource = Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).withName(connectorName);
waitForStatus(resource, connectorName, s -> {
if (s.getStatus() == null) {
return false;
}
List<Condition> conditions = s.getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if (conditionType.equals(condition.getType()) && (conditionReason == null || conditionReason.equals(condition.getReason()))) {
conditionFound = true;
break;
}
}
}
return conditionFound;
});
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class ZooKeeperSpecCheckerTest method checkZookeeperStorage.
@Test
public void checkZookeeperStorage() {
Map<String, Object> kafkaOptions = new HashMap<>();
kafkaOptions.put(KafkaConfiguration.DEFAULT_REPLICATION_FACTOR, 3);
kafkaOptions.put(KafkaConfiguration.MIN_INSYNC_REPLICAS, 2);
Kafka kafka = new KafkaBuilder(ResourceUtils.createKafka(NAMESPACE, NAME, 3, IMAGE, HEALTH_DELAY, HEALTH_TIMEOUT, null, kafkaOptions, emptyMap(), new EphemeralStorage(), new EphemeralStorage(), null, null, null, null)).editSpec().editZookeeper().withReplicas(1).endZookeeper().endSpec().build();
ZooKeeperSpecChecker checker = generateChecker(kafka);
List<Condition> warnings = checker.run();
assertThat(warnings, hasSize(1));
Condition warning = warnings.get(0);
assertThat(warning.getReason(), is("ZooKeeperStorage"));
assertThat(warning.getStatus(), is("True"));
assertThat(warning.getMessage(), is("A ZooKeeper cluster with a single replica and ephemeral storage will be in a defective state after any restart or rolling update. It is recommended that a minimum of three replicas are used."));
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperator method reconcile.
private Future<Void> reconcile(Reconciliation reconciliation, String host, CruiseControlApi apiClient, KafkaRebalance kafkaRebalance, KafkaRebalanceState currentState, KafkaRebalanceAnnotation rebalanceAnnotation) {
LOGGER.infoCr(reconciliation, "Rebalance action from state [{}]", currentState);
if (Annotations.isReconciliationPausedWithAnnotation(kafkaRebalance)) {
// we need to do this check again because it was triggered by a watcher
KafkaRebalanceStatus status = new KafkaRebalanceStatus();
Set<Condition> unknownAndDeprecatedConditions = validate(reconciliation, kafkaRebalance);
unknownAndDeprecatedConditions.add(StatusUtils.getPausedCondition());
status.setConditions(new ArrayList<>(unknownAndDeprecatedConditions));
return updateStatus(reconciliation, kafkaRebalance, status, null).compose(i -> Future.succeededFuture());
}
if (kafkaRebalance.getSpec().isRebalanceDisk() && !usingJbodStorage) {
String error = "Cannot set rebalanceDisk=true for Kafka clusters with a non-JBOD storage config. " + "Intra-broker balancing only applies to Kafka deployments that use JBOD storage with multiple disks.";
LOGGER.errorCr(reconciliation, "Status updated to [NotReady] due to error: {}", new InvalidResourceException(error).getMessage());
return updateStatus(reconciliation, kafkaRebalance, new KafkaRebalanceStatus(), new InvalidResourceException(error)).mapEmpty();
}
try {
AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> rebalanceOptionsBuilder = convertRebalanceSpecToRebalanceOptions(kafkaRebalance.getSpec());
return computeNextStatus(reconciliation, host, apiClient, kafkaRebalance, currentState, rebalanceAnnotation, rebalanceOptionsBuilder).compose(desiredStatusAndMap -> {
// do a new get to retrieve the current resource state.
return kafkaRebalanceOperator.getAsync(reconciliation.namespace(), reconciliation.name()).compose(currentKafkaRebalance -> {
if (currentKafkaRebalance != null) {
return configMapOperator.reconcile(reconciliation, kafkaRebalance.getMetadata().getNamespace(), kafkaRebalance.getMetadata().getName(), desiredStatusAndMap.getLoadMap()).compose(i -> updateStatus(reconciliation, currentKafkaRebalance, desiredStatusAndMap.getStatus(), null)).compose(updatedKafkaRebalance -> {
String message = "State updated to [{}] ";
if (rawRebalanceAnnotation(updatedKafkaRebalance) == null) {
LOGGER.infoCr(reconciliation, message + "and annotation {} is not set ", rebalanceStateConditionType(updatedKafkaRebalance.getStatus()), ANNO_STRIMZI_IO_REBALANCE);
} else {
LOGGER.infoCr(reconciliation, message + "with annotation {}={} ", rebalanceStateConditionType(updatedKafkaRebalance.getStatus()), ANNO_STRIMZI_IO_REBALANCE, rawRebalanceAnnotation(updatedKafkaRebalance));
}
if (hasRebalanceAnnotation(updatedKafkaRebalance)) {
if (currentState != KafkaRebalanceState.ReconciliationPaused && rebalanceAnnotation != KafkaRebalanceAnnotation.none && !currentState.isValidateAnnotation(rebalanceAnnotation)) {
return Future.succeededFuture();
} else {
LOGGER.infoCr(reconciliation, "Removing annotation {}={}", ANNO_STRIMZI_IO_REBALANCE, rawRebalanceAnnotation(updatedKafkaRebalance));
// Updated KafkaRebalance has rebalance annotation removed as
// action specified by user has been completed.
KafkaRebalance patchedKafkaRebalance = new KafkaRebalanceBuilder(updatedKafkaRebalance).editMetadata().removeFromAnnotations(ANNO_STRIMZI_IO_REBALANCE).endMetadata().build();
return kafkaRebalanceOperator.patchAsync(reconciliation, patchedKafkaRebalance);
}
} else {
LOGGER.debugCr(reconciliation, "No annotation {}", ANNO_STRIMZI_IO_REBALANCE);
return Future.succeededFuture();
}
}).mapEmpty();
} else {
return Future.succeededFuture();
}
}, exception -> {
LOGGER.errorCr(reconciliation, "Status updated to [NotReady] due to error: {}", exception.getMessage());
return updateStatus(reconciliation, kafkaRebalance, new KafkaRebalanceStatus(), exception).mapEmpty();
});
}, exception -> {
LOGGER.errorCr(reconciliation, "Status updated to [NotReady] due to error: {}", exception.getMessage());
return updateStatus(reconciliation, kafkaRebalance, new KafkaRebalanceStatus(), exception).mapEmpty();
});
} catch (IllegalArgumentException e) {
LOGGER.errorCr(reconciliation, "Status updated to [NotReady] due to error: {}", e.getMessage());
return updateStatus(reconciliation, kafkaRebalance, new KafkaRebalanceStatus(), e).mapEmpty();
}
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperator method buildRebalanceStatus.
private MapAndStatus<ConfigMap, KafkaRebalanceStatus> buildRebalanceStatus(KafkaRebalance kafkaRebalance, String sessionID, KafkaRebalanceState cruiseControlState, JsonObject proposalJson, Set<Condition> validation) {
List<Condition> conditions = new ArrayList<>();
conditions.add(StatusUtils.buildRebalanceCondition(cruiseControlState.toString()));
conditions.addAll(validation);
MapAndStatus<ConfigMap, Map<String, Object>> optimizationProposalMapAndStatus = processOptimizationProposal(kafkaRebalance, proposalJson);
return new MapAndStatus<>(optimizationProposalMapAndStatus.getLoadMap(), new KafkaRebalanceStatusBuilder().withSessionId(sessionID).withConditions(conditions).withOptimizationResult(optimizationProposalMapAndStatus.getStatus()).build());
}
Aggregations