use of io.strimzi.api.kafka.model.status.Condition in project strimzi 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 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 by strimzi.
the class StatusDiffTest method testStatusDiff.
@ParallelTest
public void testStatusDiff() {
ListenerStatus ls1 = new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build();
ListenerStatus ls2 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9093).build()).build();
ListenerStatus ls3 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9094).build()).build();
Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready2").withStatus("True").build();
KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
KafkaStatus status3 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
KafkaStatus status4 = new KafkaStatusBuilder().withConditions(condition1, condition2).withListeners(ls1).build();
KafkaStatus status5 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls3).build();
KafkaStatus status6 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls3, ls1).build();
StatusDiff diff = new StatusDiff(status1, status2);
assertThat(diff.isEmpty(), is(true));
diff = new StatusDiff(status1, status3);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status1, status4);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status3, status4);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status3, status5);
assertThat(diff.isEmpty(), is(false));
diff = new StatusDiff(status5, status6);
assertThat(diff.isEmpty(), is(false));
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi by strimzi.
the class KafkaConnectAssemblyOperatorMockTest method testPauseReconcileUnpause.
@Test
public void testPauseReconcileUnpause(VertxTestContext context) {
setConnectResource(new KafkaConnectBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(TestUtils.map("foo", "bar")).withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "true")).build()).withNewSpec().withReplicas(replicas).endSpec().build());
KafkaConnectApi mock = mock(KafkaConnectApi.class);
when(mock.list(anyString(), anyInt())).thenReturn(Future.succeededFuture(emptyList()));
when(mock.listConnectorPlugins(any(), anyString(), anyInt())).thenReturn(Future.succeededFuture(emptyList()));
Checkpoint async = context.checkpoint();
createConnectCluster(context, mock, true).onComplete(context.succeeding()).compose(v -> {
LOGGER.info("Reconciling again -> update");
return kco.reconcile(new Reconciliation("test-trigger", KafkaConnect.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}).onComplete(context.succeeding(v -> context.verify(() -> {
Resource<KafkaConnect> resource = Crds.kafkaConnectOperation(mockClient).inNamespace(NAMESPACE).withName(CLUSTER_NAME);
if (resource.get().getStatus() == null) {
fail();
}
List<Condition> conditions = resource.get().getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if ("ReconciliationPaused".equals(condition.getType())) {
conditionFound = true;
break;
}
}
}
assertTrue(conditionFound);
async.flag();
}))).compose(v -> {
setConnectResource(new KafkaConnectBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(TestUtils.map("foo", "bar")).withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "false")).build()).withNewSpec().withReplicas(replicas).endSpec().build());
LOGGER.info("Reconciling again -> update");
return kco.reconcile(new Reconciliation("test-trigger", KafkaConnect.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}).onComplete(context.succeeding(v -> context.verify(() -> {
Resource<KafkaConnect> resource = Crds.kafkaConnectOperation(mockClient).inNamespace(NAMESPACE).withName(CLUSTER_NAME);
if (resource.get().getStatus() == null) {
fail();
}
List<Condition> conditions = resource.get().getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if ("ReconciliationPaused".equals(condition.getType())) {
conditionFound = true;
break;
}
}
}
assertFalse(conditionFound);
async.flag();
})));
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNewWithMissingHardGoalsAndRefresh.
/**
* Tests the transition from 'New' to 'NotReady' due to "missing hard goals" error
* The KafkaRebalance resource is updated with "skip hard goals check" and refreshed; it then moves to the 'ProposalReady' state
*
* 1. A new KafkaRebalance resource is created with some specified not hard goals; it is in the New state
* 2. The operator requests a rebalance proposal through the Cruise Control REST API
* 3. The operator receives a "missing hard goals" error instead of a proposal
* 4. The KafkaRebalance resource moves to the 'NotReady' state
* 5. The rebalance is updated with the 'skip hard goals check' field to "true" and annotated with 'strimzi.io/rebalance=refresh'
* 6. The operator requests a rebalance proposal through the Cruise Control REST API
* 7. The rebalance proposal is ready on the first call
* 8. The KafkaRebalance resource moves to the 'ProposalReady' state
*/
@Test
public void testNewWithMissingHardGoalsAndRefresh(VertxTestContext context) throws IOException, URISyntaxException {
// Setup the rebalance endpoint to get error about hard goals
MockCruiseControl.setupCCRebalanceBadGoalsError(ccServer);
KafkaRebalanceSpec kafkaRebalanceSpec = new KafkaRebalanceSpecBuilder().withGoals("DiskCapacityGoal", "CpuCapacityGoal").build();
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, kafkaRebalanceSpec);
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).create(kr);
// the Kafka cluster isn't deployed in the namespace
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, kubernetesClient);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> context.verify(() -> {
// the resource moved from New to NotReady due to the error
KafkaRebalance kr1 = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
assertThat(kr1, StateMatchers.hasState());
Condition condition = kcrao.rebalanceStateCondition(kr1.getStatus());
assertThat(condition, StateMatchers.hasStateInCondition(KafkaRebalanceState.NotReady, CruiseControlRestException.class, "Error processing POST request '/rebalance' due to: " + "'java.lang.IllegalArgumentException: Missing hard goals [NetworkInboundCapacityGoal, DiskCapacityGoal, RackAwareGoal, NetworkOutboundCapacityGoal, CpuCapacityGoal, ReplicaCapacityGoal] " + "in the provided goals: [RackAwareGoal, ReplicaCapacityGoal]. " + "Add skip_hard_goal_check=true parameter to ignore this sanity check.'."));
}))).compose(v -> {
ccServer.reset();
try {
// Setup the rebalance endpoint with the number of pending calls before a response is received.
MockCruiseControl.setupCCRebalanceResponse(ccServer, 0);
} catch (IOException | URISyntaxException e) {
context.failNow(e);
}
// set the skip hard goals check flag
KafkaRebalance kr2 = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
KafkaRebalance patchedKr = new KafkaRebalanceBuilder(kr2).editSpec().withSkipHardGoalCheck(true).endSpec().build();
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).patch(patchedKr);
// apply the "refresh" annotation to the resource in the NotReady state
patchedKr = annotate(kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceAnnotation.refresh);
// trigger another reconcile to process the NotReady state
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), patchedKr);
}).onComplete(context.succeeding(v -> {
// the resource transitioned from 'NotReady' to 'ProposalReady'
assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.ProposalReady);
checkpoint.flag();
}));
}
Aggregations