use of org.bf2.operator.resources.v1alpha1.ManagedKafkaList in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ControlPlane method getKafkaClusters.
/**
* Get the current list of ManagedKafka clusters from the control plane
* as a blocking call.
* Also updates the cache of desired state ManagedKafka instances. May include
* entries that have not yet been created locally.
*
* @see {@link #getDesiredStates()} to get the full cache, rather than making a
* remote call
*/
public List<ManagedKafka> getKafkaClusters() {
ManagedKafkaList result = controlPlaneClient.getKafkaClusters(id);
result.getItems().forEach((mk) -> addDesiredState(mk));
return result.getItems();
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaList in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class PollerTest method testAddDelete.
@Test
public void testAddDelete() {
ManagedKafka managedKafka = exampleManagedKafka();
List<ManagedKafka> items = lookup.getLocalManagedKafkas();
assertEquals(0, items.size());
assertNull(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)));
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Collections.singletonList(managedKafka)));
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
assertFalse(items.get(0).getSpec().isDeleted());
// should do nothing
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
// make sure the remote tracking is there and not marked as deleted
assertFalse(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)).getSpec().isDeleted());
// try another placement - this shouldn't actually happen, should reject first and the original won't be there
ManagedKafka nextPlacement = exampleManagedKafka();
nextPlacement.setPlacementId("xyz");
nextPlacement.getSpec().getVersions().setStrimzi("?");
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Arrays.asList(managedKafka, nextPlacement)));
managedKafkaSync.syncKafkaClusters();
// should still be a single placement, and it should be the old one
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
assertNotEquals("?", items.get(0).getSpec().getVersions().getStrimzi());
// try to remove before marked as deleted, should not be successful
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList());
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(1, items.size());
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Arrays.asList(managedKafka, nextPlacement)));
managedKafka.getSpec().setDeleted(true);
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertTrue(items.get(0).getSpec().isDeleted());
// now the remote tracking should be marked as deleted
assertTrue(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)).getSpec().isDeleted());
// final removal
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList());
managedKafkaSync.syncKafkaClusters();
items = lookup.getLocalManagedKafkas();
assertEquals(0, items.size());
// remote tracking should be gone
assertNull(controlPlane.getDesiredState(ControlPlane.managedKafkaKey(managedKafka)));
// if it shows up again need to inform the control plane delete is still needed
Mockito.when(controlPlaneRestClient.getKafkaClusters(CLUSTER_ID)).thenReturn(new ManagedKafkaList(Collections.singletonList(managedKafka)));
managedKafkaSync.syncKafkaClusters();
// expect there to be a status about the deletion
ArgumentCaptor<Map<String, ManagedKafkaStatus>> statusCaptor = ArgumentCaptor.forClass(Map.class);
Mockito.verify(controlPlaneRestClient).updateKafkaClustersStatus(Mockito.eq(CLUSTER_ID), statusCaptor.capture());
Map<String, ManagedKafkaStatus> status = statusCaptor.getValue();
assertEquals(1, status.size());
assertEquals(1, status.get(ID).getConditions().size());
}
Aggregations