Class KafkaConnectController


  • public class KafkaConnectController
    extends Object
    This class provides control over Kafka Connect instance deployed in OpenShift
    Author:
    Jakub Cechacek
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • ocp

        private final io.fabric8.openshift.client.OpenShiftClient ocp
      • http

        private final okhttp3.OkHttpClient http
      • project

        private final String project
      • httpUtils

        private final HttpUtils httpUtils
      • useConnectorResources

        private final boolean useConnectorResources
      • name

        private final String name
      • kafkaConnect

        private io.strimzi.api.kafka.model.KafkaConnect kafkaConnect
      • apiRoute

        private io.fabric8.openshift.api.model.Route apiRoute
      • metricsRoute

        private io.fabric8.openshift.api.model.Route metricsRoute
      • metricsService

        private io.fabric8.kubernetes.api.model.Service metricsService
    • Constructor Detail

      • KafkaConnectController

        public KafkaConnectController​(io.strimzi.api.kafka.model.KafkaConnect kafkaConnect,
                                      io.fabric8.openshift.client.OpenShiftClient ocp,
                                      okhttp3.OkHttpClient http,
                                      boolean useConnectorResources)
    • Method Detail

      • disable

        public void disable()
        Disables Kafka Connect by scaling it to ZERO NOTICE: cluster operator needs to be disabled first!
      • destroy

        public void destroy()
        Crashes Kafka Connect by force deleting all pods. Then it immediately scales its deployment to ZERO by calling disable() NOTICE: cluster operator needs to be disabled first!
      • waitForConnectCluster

        public io.strimzi.api.kafka.model.KafkaConnect waitForConnectCluster()
                                                                      throws InterruptedException
        Wait until KafkaConnect instance is back and ready
        Returns:
        KafkaConnect resource instance
        Throws:
        InterruptedException
      • allowServiceAccess

        public io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy allowServiceAccess()
        Creates network policy allowing access to ports exposed by Kafka Connect
        Returns:
      • exposeApi

        public io.fabric8.openshift.api.model.Route exposeApi()
        Exposes a route for kafka connect API associated with given KafkaConnect resource
        Returns:
        Route object
      • exposeMetrics

        public io.fabric8.openshift.api.model.Route exposeMetrics()
        Exposes a route for prometheus metrics for kafka connect associated with given KafkaConnect resource
        Returns:
        Route object
      • waitForKafkaConnector

        public io.strimzi.api.kafka.model.KafkaConnector waitForKafkaConnector​(String name)
                                                                        throws InterruptedException
        Waits until connector is properly deployed. Note: works only for CR deployment
        Parameters:
        name - name of the connector
        Throws:
        InterruptedException - on wait error
        IllegalArgumentException - when deployment doesn't use custom resources
      • kafkaConnectorOperation

        private io.fabric8.kubernetes.client.dsl.NonNamespaceOperation<io.strimzi.api.kafka.model.KafkaConnector,​io.strimzi.api.kafka.KafkaConnectorList,​io.fabric8.kubernetes.client.dsl.Resource<io.strimzi.api.kafka.model.KafkaConnector>> kafkaConnectorOperation()
      • undeployConnector

        public void undeployConnector​(String name)
                               throws IOException
        Deletes Kafka connector with given name
        Parameters:
        name - connector name
        Throws:
        IOException - on request error
      • undeployConnectorCr

        private void undeployConnectorCr​(String name)
      • waitForSnapshot

        public void waitForSnapshot​(String connectorName,
                                    String metricName)
                             throws IOException
        Waits until Snapshot phase of given connector completes
        Parameters:
        connectorName - name of the connect
        metricName - name of the metric used to determine the state
        Throws:
        IOException - on metric request error
      • waitForMySqlSnapshot

        public void waitForMySqlSnapshot​(String connectorName)
                                  throws IOException
        Waits until snapshot phase of given MySQL connector completes
        Parameters:
        connectorName - connector name
        Throws:
        IOException - on metric request error
      • waitForPostgreSqlSnapshot

        public void waitForPostgreSqlSnapshot​(String connectorName)
                                       throws IOException
        Waits until snapshot phase of given PostgreSQL connector completes
        Parameters:
        connectorName - connector name
        Throws:
        IOException - on metric request error
      • waitForSqlServerSnapshot

        public void waitForSqlServerSnapshot​(String connectorName)
                                      throws IOException
        Waits until snapshot phase of given SQL Server connector completes
        Parameters:
        connectorName - connector name
        Throws:
        IOException - on metric request error
      • waitForMongoSnapshot

        public void waitForMongoSnapshot​(String connectorName)
                                  throws IOException
        Waits until snapshot phase of given MongoDB connector completes
        Parameters:
        connectorName - connector name
        Throws:
        IOException - on metric request error
      • waitForDB2Snapshot

        public void waitForDB2Snapshot​(String connectorName)
                                throws IOException
        Waits until snapshot phase of given DB2 connector completes
        Parameters:
        connectorName - connector name
        Throws:
        IOException - on metric request error
      • getApiURL

        public okhttp3.HttpUrl getApiURL()
        Returns:
        URL of Connect API endpoint
      • getMetricsURL

        public okhttp3.HttpUrl getMetricsURL()
        Returns:
        URL of metrics endpoint
      • undeployCluster

        public boolean undeployCluster()
        Undeploy this Kafka Connect cluster by deleted related KafkaConnect CR
        Returns:
        true if the CR was found and deleted