Search in sources :

Example 1 with KafkaConnectCluster

use of io.strimzi.controller.cluster.model.KafkaConnectCluster in project strimzi by strimzi.

the class KafkaConnectAssemblyOperatorTest method testUpdateCluster.

@Test
public void testUpdateCluster(TestContext context) {
    ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
    ServiceOperator mockServiceOps = mock(ServiceOperator.class);
    DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
    String clusterCmName = "foo";
    String clusterCmNamespace = "test";
    ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
    // Change the image to generate some diff
    clusterCm.getData().put("image", "some/different:image");
    when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
    when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
    when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
    ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
    when(mockServiceOps.reconcile(eq(clusterCmNamespace), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
    when(mockDcOps.reconcile(eq(clusterCmNamespace), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
    when(mockDcOps.scaleUp(eq(clusterCmNamespace), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
    when(mockDcOps.scaleDown(eq(clusterCmNamespace), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
    Async async = context.async();
    ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
        context.assertTrue(createResult.succeeded());
        KafkaConnectCluster compareTo = KafkaConnectCluster.fromConfigMap(clusterCm);
        // Vertify service
        List<Service> capturedServices = serviceCaptor.getAllValues();
        context.assertEquals(1, capturedServices.size());
        Service service = capturedServices.get(0);
        context.assertEquals(compareTo.getName(), service.getMetadata().getName());
        context.assertEquals(compareTo.generateService(), service, "Services are not equal");
        // Verify Deployment
        List<Deployment> capturedDc = dcCaptor.getAllValues();
        context.assertEquals(1, capturedDc.size());
        Deployment dc = capturedDc.get(0);
        context.assertEquals(compareTo.getName(), dc.getMetadata().getName());
        context.assertEquals(compareTo.generateDeployment(), dc, "Deployments are not equal");
        // Verify scaleDown / scaleUp were not called
        context.assertEquals(1, dcScaleDownNameCaptor.getAllValues().size());
        context.assertEquals(1, dcScaleUpNameCaptor.getAllValues().size());
        async.complete();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) Test(org.junit.Test)

Example 2 with KafkaConnectCluster

use of io.strimzi.controller.cluster.model.KafkaConnectCluster in project strimzi by strimzi.

the class KafkaConnectAssemblyOperatorTest method testUpdateClusterScaleDown.

@Test
public void testUpdateClusterScaleDown(TestContext context) {
    int scaleTo = 2;
    String newReplicas = String.valueOf(scaleTo);
    ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
    ServiceOperator mockServiceOps = mock(ServiceOperator.class);
    DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
    String clusterCmName = "foo";
    String clusterCmNamespace = "test";
    ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
    // Change replicas to create ScaleDown
    clusterCm.getData().put(KafkaConnectCluster.KEY_REPLICAS, newReplicas);
    when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
    when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
    when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
    when(mockServiceOps.reconcile(eq(clusterCmNamespace), any(), any())).thenReturn(Future.succeededFuture());
    when(mockDcOps.reconcile(eq(clusterCmNamespace), any(), any())).thenReturn(Future.succeededFuture());
    doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
    doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleDown(clusterCmNamespace, connect.getName(), scaleTo);
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
    Async async = context.async();
    ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
        context.assertTrue(createResult.succeeded());
        verify(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
        async.complete();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Test(org.junit.Test)

Example 3 with KafkaConnectCluster

use of io.strimzi.controller.cluster.model.KafkaConnectCluster in project strimzi by strimzi.

the class KafkaConnectAssemblyOperatorTest method testUpdateClusterFailure.

@Test
public void testUpdateClusterFailure(TestContext context) {
    ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
    ServiceOperator mockServiceOps = mock(ServiceOperator.class);
    DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
    String clusterCmName = "foo";
    String clusterCmNamespace = "test";
    ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
    // Change the image to generate some diff
    clusterCm.getData().put("image", "some/different:image");
    when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
    when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
    when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
    ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
    when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
    when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.failedFuture("Failed"));
    ArgumentCaptor<String> dcScaleUpNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
    when(mockDcOps.scaleUp(dcScaleUpNamespaceCaptor.capture(), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcScaleDownNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
    when(mockDcOps.scaleDown(dcScaleDownNamespaceCaptor.capture(), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
    Async async = context.async();
    ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
        context.assertFalse(createResult.succeeded());
        async.complete();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) Test(org.junit.Test)

Example 4 with KafkaConnectCluster

use of io.strimzi.controller.cluster.model.KafkaConnectCluster in project strimzi by strimzi.

the class KafkaConnectAssemblyOperatorTest method testDeleteCluster.

@Test
public void testDeleteCluster(TestContext context) {
    ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
    ServiceOperator mockServiceOps = mock(ServiceOperator.class);
    DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
    String clusterCmName = "foo";
    String clusterCmNamespace = "test";
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName));
    when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
    ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
    when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
    when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
    Async async = context.async();
    ops.delete(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), createResult -> {
        context.assertTrue(createResult.succeeded());
        // Vertify service
        context.assertEquals(1, serviceNameCaptor.getAllValues().size());
        context.assertEquals(clusterCmNamespace, serviceNamespaceCaptor.getValue());
        context.assertEquals(connect.getName(), serviceNameCaptor.getValue());
        // Vertify Deployment
        context.assertEquals(1, dcNameCaptor.getAllValues().size());
        context.assertEquals(clusterCmNamespace, dcNamespaceCaptor.getValue());
        context.assertEquals(connect.getName(), dcNameCaptor.getValue());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Test(org.junit.Test)

Example 5 with KafkaConnectCluster

use of io.strimzi.controller.cluster.model.KafkaConnectCluster in project strimzi by strimzi.

the class KafkaConnectAssemblyOperatorTest method testUpdateClusterScaleUp.

@Test
public void testUpdateClusterScaleUp(TestContext context) {
    int scaleTo = 4;
    String newReplicas = String.valueOf(scaleTo);
    ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
    ServiceOperator mockServiceOps = mock(ServiceOperator.class);
    DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
    String clusterCmName = "foo";
    String clusterCmNamespace = "test";
    ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
    // Change replicas to create ScaleUp
    clusterCm.getData().put(KafkaConnectCluster.KEY_REPLICAS, newReplicas);
    when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
    when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
    when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
    when(mockServiceOps.reconcile(eq(clusterCmNamespace), any(), any())).thenReturn(Future.succeededFuture());
    when(mockDcOps.reconcile(eq(clusterCmNamespace), any(), any())).thenReturn(Future.succeededFuture());
    doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
    doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleDown(clusterCmNamespace, connect.getName(), scaleTo);
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
    Async async = context.async();
    ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
        context.assertTrue(createResult.succeeded());
        verify(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
        async.complete();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Test(org.junit.Test)

Aggregations

Reconciliation (io.strimzi.controller.cluster.Reconciliation)8 KafkaConnectCluster (io.strimzi.controller.cluster.model.KafkaConnectCluster)8 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)8 DeploymentOperator (io.strimzi.controller.cluster.operator.resource.DeploymentOperator)8 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 Async (io.vertx.ext.unit.Async)7 Test (org.junit.Test)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Service (io.fabric8.kubernetes.api.model.Service)4 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 AssemblyType (io.strimzi.controller.cluster.model.AssemblyType)1 Labels (io.strimzi.controller.cluster.model.Labels)1 AsyncResult (io.vertx.core.AsyncResult)1 CompositeFuture (io.vertx.core.CompositeFuture)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 ArrayList (java.util.ArrayList)1