Search in sources :

Example 6 with KafkaConnectCluster

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

the class KafkaConnectAssemblyOperatorTest method testCreateCluster.

@Test
public void testCreateCluster(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);
    when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
    when(mockServiceOps.reconcile(anyString(), anyString(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
    when(mockDcOps.reconcile(anyString(), anyString(), dcCaptor.capture())).thenReturn(Future.succeededFuture());
    when(mockDcOps.scaleUp(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(42));
    when(mockDcOps.scaleDown(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(42));
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
    Async async = context.async();
    ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
        context.assertTrue(createResult.succeeded());
        // Vertify service
        List<Service> capturedServices = serviceCaptor.getAllValues();
        context.assertEquals(1, capturedServices.size());
        Service service = capturedServices.get(0);
        context.assertEquals(connect.getName(), service.getMetadata().getName());
        context.assertEquals(connect.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(connect.getName(), dc.getMetadata().getName());
        context.assertEquals(connect.generateDeployment(), dc, "Deployments are not equal");
        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 7 with KafkaConnectCluster

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

the class KafkaConnectAssemblyOperatorTest method testUpdateClusterNoDiff.

@Test
public void testUpdateClusterNoDiff(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);
    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());
        // Vertify service
        List<Service> capturedServices = serviceCaptor.getAllValues();
        context.assertEquals(1, capturedServices.size());
        // Verify Deployment Config
        List<Deployment> capturedDc = dcCaptor.getAllValues();
        context.assertEquals(1, capturedDc.size());
        // 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 8 with KafkaConnectCluster

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

the class KafkaConnectAssemblyOperator method createOrUpdate.

@Override
protected void createOrUpdate(Reconciliation reconciliation, ConfigMap assemblyCm, Handler<AsyncResult<Void>> handler) {
    String namespace = reconciliation.namespace();
    String name = reconciliation.assemblyName();
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(assemblyCm);
    log.info("{}: Updating Kafka Connect cluster", reconciliation, name, namespace);
    Future<Void> chainFuture = Future.future();
    deploymentOperations.scaleDown(namespace, connect.getName(), connect.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, connect.getName(), connect.generateService())).compose(i -> deploymentOperations.reconcile(namespace, connect.getName(), connect.generateDeployment())).compose(i -> deploymentOperations.scaleUp(namespace, connect.getName(), connect.getReplicas()).map((Void) null)).compose(chainFuture::complete, chainFuture);
    chainFuture.setHandler(handler);
}
Also used : AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Labels(io.strimzi.controller.cluster.model.Labels) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) Reconciliation(io.strimzi.controller.cluster.Reconciliation) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster)

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