Class KafkaConnectController
- java.lang.Object
-
- io.debezium.testing.openshift.tools.kafka.KafkaConnectController
-
public class KafkaConnectController extends Object
This class provides control over Kafka Connect instance deployed in OpenShift- Author:
- Jakub Cechacek
-
-
Field Summary
Fields Modifier and Type Field Description private io.fabric8.openshift.api.model.RouteapiRouteprivate okhttp3.OkHttpClienthttpprivate HttpUtilshttpUtilsprivate io.strimzi.api.kafka.model.KafkaConnectkafkaConnectprivate static org.slf4j.LoggerLOGGERprivate static intMETRICS_PORTprivate io.fabric8.openshift.api.model.RoutemetricsRouteprivate io.fabric8.kubernetes.api.model.ServicemetricsServiceprivate Stringnameprivate io.fabric8.openshift.client.OpenShiftClientocpprivate OpenShiftUtilsocpUtilsprivate Stringprojectprivate booleanuseConnectorResources
-
Constructor Summary
Constructors Constructor Description KafkaConnectController(io.strimzi.api.kafka.model.KafkaConnect kafkaConnect, io.fabric8.openshift.client.OpenShiftClient ocp, okhttp3.OkHttpClient http, boolean useConnectorResources)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyallowServiceAccess()Creates network policy allowing access to ports exposed by Kafka ConnectvoiddeployConnector(String name, ConnectorConfigBuilder config)Deploys Kafka connector with given name and configuration via RESTprivate voiddeployConnectorCr(String name, ConnectorConfigBuilder config)private voiddeployConnectorJson(String name, ConnectorConfigBuilder config)voiddestroy()Crashes Kafka Connect by force deleting all pods.voiddisable()Disables Kafka Connect by scaling it to ZERO NOTICE: cluster operator needs to be disabled first!io.fabric8.openshift.api.model.RouteexposeApi()Exposes a route for kafka connect API associated with given KafkaConnect resourceio.fabric8.openshift.api.model.RouteexposeMetrics()Exposes a route for prometheus metrics for kafka connect associated with given KafkaConnect resourceokhttp3.HttpUrlgetApiURL()List<String>getConnectMetrics()okhttp3.HttpUrlgetMetricsURL()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()booleanundeployCluster()Undeploy this Kafka Connect cluster by deleted related KafkaConnect CRvoidundeployConnector(String name)Deletes Kafka connector with given nameprivate voidundeployConnectorCr(String name)private voidundeployConnectorJson(String name)io.strimzi.api.kafka.model.KafkaConnectwaitForConnectCluster()Wait until KafkaConnect instance is back and readyvoidwaitForDB2Snapshot(String connectorName)Waits until snapshot phase of given DB2 connector completesio.strimzi.api.kafka.model.KafkaConnectorwaitForKafkaConnector(String name)Waits until connector is properly deployed.voidwaitForMongoSnapshot(String connectorName)Waits until snapshot phase of given MongoDB connector completesvoidwaitForMySqlSnapshot(String connectorName)Waits until snapshot phase of given MySQL connector completesvoidwaitForPostgreSqlSnapshot(String connectorName)Waits until snapshot phase of given PostgreSQL connector completesvoidwaitForSnapshot(String connectorName, String metricName)Waits until Snapshot phase of given connector completesvoidwaitForSqlServerSnapshot(String connectorName)Waits until snapshot phase of given SQL Server connector completes
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
METRICS_PORT
private static final int METRICS_PORT
- See Also:
- Constant Field Values
-
ocp
private final io.fabric8.openshift.client.OpenShiftClient ocp
-
http
private final okhttp3.OkHttpClient http
-
project
private final String project
-
ocpUtils
private final OpenShiftUtils ocpUtils
-
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
-
-
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 callingdisable()NOTICE: cluster operator needs to be disabled first!
-
waitForConnectCluster
public io.strimzi.api.kafka.model.KafkaConnect waitForConnectCluster() throws InterruptedExceptionWait until KafkaConnect instance is back and ready- Returns:
KafkaConnectresource 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:
Routeobject
-
exposeMetrics
public io.fabric8.openshift.api.model.Route exposeMetrics()
Exposes a route for prometheus metrics for kafka connect associated with given KafkaConnect resource- Returns:
Routeobject
-
deployConnector
public void deployConnector(String name, ConnectorConfigBuilder config) throws IOException, InterruptedException
Deploys Kafka connector with given name and configuration via REST- Parameters:
name- connector nameconfig- connector config- Throws:
IOException- or request errorInterruptedException
-
deployConnectorJson
private void deployConnectorJson(String name, ConnectorConfigBuilder config) throws IOException
- Throws:
IOException
-
deployConnectorCr
private void deployConnectorCr(String name, ConnectorConfigBuilder config) throws InterruptedException
- Throws:
InterruptedException
-
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 errorIllegalArgumentException- 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
-
undeployConnectorJson
private void undeployConnectorJson(String name) throws IOException
- Throws:
IOException
-
undeployConnectorCr
private void undeployConnectorCr(String name)
-
getConnectMetrics
public List<String> getConnectMetrics() throws IOException
- Throws:
IOException
-
waitForSnapshot
public void waitForSnapshot(String connectorName, String metricName) throws IOException
Waits until Snapshot phase of given connector completes- Parameters:
connectorName- name of the connectmetricName- 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
-
-