Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.github.shyiko.mysql.binlog.event.EventData;
import com.github.shyiko.mysql.binlog.event.EventHeaderV4;
import com.github.shyiko.mysql.binlog.event.RotateEventData;
import com.github.shyiko.mysql.binlog.network.SSLMode;
import io.debezium.config.Configuration;
import io.debezium.connector.mysql.MySqlConnection;
import io.debezium.connector.mysql.MySqlConnectorConfig;
Expand Down Expand Up @@ -242,12 +243,23 @@ private static Map<String, String> querySystemVariables(
return variables;
}

static SSLMode sslModeFor(MySqlConnectorConfig.SecureConnectionMode mode) {
try {
return mode == null ? null : SSLMode.valueOf(mode.name());
} catch (IllegalArgumentException e) {
LOG.error("Invalid SecureConnectionMode provided %s", mode.name(), e);
}
return null;
}

public static BinlogOffset findBinlogOffset(
long targetMs, MySqlConnection connection, MySqlSourceConfig mySqlSourceConfig) {
MySqlConnection.MySqlConnectionConfiguration config = connection.connectionConfig();
BinaryLogClient client =
new BinaryLogClient(
config.hostname(), config.port(), config.username(), config.password());
client.setSSLMode(sslModeFor(config.sslMode()));

if (mySqlSourceConfig.getServerIdRange() != null) {
client.setServerId(mySqlSourceConfig.getServerIdRange().getStartServerId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
import org.apache.flink.cdc.connectors.mysql.source.config.MySqlSourceConfigFactory;
import org.apache.flink.cdc.connectors.mysql.table.StartupOptions;

import com.github.shyiko.mysql.binlog.network.SSLMode;
import io.debezium.connector.mysql.MySqlConnection;
import io.debezium.connector.mysql.MySqlConnectorConfig;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.time.Duration;
import java.time.ZoneId;
import java.util.Properties;
import java.util.stream.Stream;

/** Tests for {@link org.apache.flink.cdc.connectors.mysql.debezium.DebeziumUtils}. */
class DebeziumUtilsTest {
Expand Down Expand Up @@ -83,6 +89,26 @@ private MySqlSourceConfig getConfig(Properties jdbcProperties) {
.createConfig(0);
}

@ParameterizedTest
@MethodSource("sslModeProvider")
void testSslModeConversion(MySqlConnectorConfig.SecureConnectionMode input, SSLMode expected) {
SSLMode actual = DebeziumUtils.sslModeFor(input);
Assertions.assertThat(actual).isEqualTo(expected);
}

static Stream<Arguments> sslModeProvider() {
return Stream.of(
Arguments.of(MySqlConnectorConfig.SecureConnectionMode.DISABLED, SSLMode.DISABLED),
Arguments.of(
MySqlConnectorConfig.SecureConnectionMode.PREFERRED, SSLMode.PREFERRED),
Arguments.of(MySqlConnectorConfig.SecureConnectionMode.REQUIRED, SSLMode.REQUIRED),
Arguments.of(
MySqlConnectorConfig.SecureConnectionMode.VERIFY_CA, SSLMode.VERIFY_CA),
Arguments.of(
MySqlConnectorConfig.SecureConnectionMode.VERIFY_IDENTITY,
SSLMode.VERIFY_IDENTITY));
}

private void assertJdbcUrl(String expected, String actual) {
// Compare after splitting to avoid the orderless jdbc parameters in jdbc url at Java 11
String[] expectedParam = expected.split("&");
Expand Down
Loading