Skip to content

Commit

Permalink
Merge branch 'apache:dev' into connector-teradata
Browse files Browse the repository at this point in the history
  • Loading branch information
FWLamb authored Nov 16, 2022
2 parents cf6bc4f + ace219f commit 1a50663
Show file tree
Hide file tree
Showing 16 changed files with 854 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public OptionValidationException(String message) {
}

public OptionValidationException(String formatMessage, Object... args) {
super(String.format(formatMessage, args));
super(SeaTunnelAPIErrorCode.OPTION_VALIDATION_FAILED, String.format(formatMessage, args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public void testAbsolutelyRequiredOption() {

// absent
config.put(TEST_PORTS.key(), "[9090]");
assertEquals("There are unconfigured options, the options('password', 'username') are required.",
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('password', 'username') are required.",
assertThrows(OptionValidationException.class, executable).getMessage());

config.put(KEY_USERNAME.key(), "asuka");
assertEquals("There are unconfigured options, the options('password') are required.",
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('password') are required.",
assertThrows(OptionValidationException.class, executable).getMessage());

// all present
Expand All @@ -102,7 +102,7 @@ public void testBundledRequiredOptions() {

// case2: some present
config.put(KEY_USERNAME.key(), "asuka");
assertEquals("These options('password', 'username') are bundled, must be present or absent together." +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options('password', 'username') are bundled, must be present or absent together." +
" The options present are: 'username'. The options absent are 'password'.",
assertThrows(OptionValidationException.class, executable).getMessage());

Expand All @@ -120,7 +120,7 @@ public void testSimpleExclusiveRequiredOptions() {
Executable executable = () -> validate(config, rule);

// all absent
assertEquals("There are unconfigured options, these options(['option.topic-pattern'], ['option.topic']) are mutually exclusive," +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, these options(['option.topic-pattern'], ['option.topic']) are mutually exclusive," +
" allowing only one set(\"[] for a set\") of options to be configured.",
assertThrows(OptionValidationException.class, executable).getMessage());

Expand All @@ -130,7 +130,7 @@ public void testSimpleExclusiveRequiredOptions() {

// present > 1
config.put(TEST_TOPIC.key(), "[\"saitou\"]");
assertEquals("These options(['option.topic-pattern'], ['option.topic']) are mutually exclusive, " +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options(['option.topic-pattern'], ['option.topic']) are mutually exclusive, " +
"allowing only one set(\"[] for a set\") of options to be configured.",
assertThrows(OptionValidationException.class, executable).getMessage());
}
Expand All @@ -147,13 +147,13 @@ public void testComplexExclusiveRequiredOptions() {
Executable executable = () -> validate(config, rule);

// all absent
assertEquals("There are unconfigured options, these options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, these options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
" allowing only one set(\"[] for a set\") of options to be configured.",
assertThrows(OptionValidationException.class, executable).getMessage());

// bundled option some present
config.put(KEY_USERNAME.key(), "asuka");
assertEquals("These options('password', 'username') are bundled, must be present or absent together." +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options('password', 'username') are bundled, must be present or absent together." +
" The options present are: 'username'. The options absent are 'password'.",
assertThrows(OptionValidationException.class, executable).getMessage());

Expand All @@ -163,13 +163,13 @@ public void testComplexExclusiveRequiredOptions() {

// tow set options present
config.put(KEY_BEARER_TOKEN.key(), "ashulin");
assertEquals("These options(['password', 'username'], ['bearer-token']) are mutually exclusive," +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options(['password', 'username'], ['bearer-token']) are mutually exclusive," +
" allowing only one set(\"[] for a set\") of options to be configured.",
assertThrows(OptionValidationException.class, executable).getMessage());

// three set options present
config.put(KEY_KERBEROS_TICKET.key(), "zongwen");
assertEquals("These options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
" allowing only one set(\"[] for a set\") of options to be configured.",
assertThrows(OptionValidationException.class, executable).getMessage());
}
Expand All @@ -187,7 +187,7 @@ public void testSimpleConditionalRequiredOptionsWithDefaultValue() {

// Expression match, and required options absent
config.put(TEST_MODE.key(), "timestamp");
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
" because ['option.mode' == TIMESTAMP] is true.",
assertThrows(OptionValidationException.class, executable).getMessage());

Expand All @@ -213,7 +213,7 @@ public void testSimpleConditionalRequiredOptionsWithoutDefaultValue() {

// Expression match, and required options absent
config.put(KEY_USERNAME.key(), "ashulin");
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
" because ['username' == ashulin] is true.",
assertThrows(OptionValidationException.class, executable).getMessage());

Expand Down Expand Up @@ -242,7 +242,7 @@ public void testComplexConditionalRequiredOptions() {

// 'username' == ashulin, and required options absent
config.put(KEY_USERNAME.key(), "ashulin");
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
" because ['username' == ashulin || ('username' == asuka && 'password' == saito)] is true.",
assertThrows(OptionValidationException.class, executable).getMessage());

Expand All @@ -260,7 +260,7 @@ public void testComplexConditionalRequiredOptions() {

// 'username' == asuka && 'password' == saito, and required options absent
config.remove(TEST_TIMESTAMP.key());
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
" because ['username' == ashulin || ('username' == asuka && 'password' == saito)] is true.",
assertThrows(OptionValidationException.class, executable).getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.seatunnel.connectors.cdc.base.config;

import io.debezium.relational.RelationalDatabaseConnectorConfig;
import org.seatunnel.connectors.cdc.base.source.IncrementalSource;

import java.time.Duration;
import java.util.List;
import java.util.Properties;

/**
* A Source configuration which is used by {@link IncrementalSource} which used JDBC data source.
*/
public abstract class JdbcSourceConfig extends BaseSourceConfig {

protected final String driverClassName;
protected final String hostname;
protected final int port;
protected final String username;
protected final String password;
protected final List<String> databaseList;
protected final List<String> tableList;
protected final int fetchSize;
protected final String serverTimeZone;
protected final Duration connectTimeout;
protected final int connectMaxRetries;
protected final int connectionPoolSize;

public JdbcSourceConfig(
StartupConfig startupConfig,
StopConfig stopConfig,
List<String> databaseList,
List<String> tableList,
int splitSize,
double distributionFactorUpper,
double distributionFactorLower,
Properties dbzProperties,
String driverClassName,
String hostname,
int port,
String username,
String password,
int fetchSize,
String serverTimeZone,
Duration connectTimeout,
int connectMaxRetries,
int connectionPoolSize) {
super(
startupConfig,
stopConfig,
splitSize,
distributionFactorUpper,
distributionFactorLower,
dbzProperties);
this.driverClassName = driverClassName;
this.hostname = hostname;
this.port = port;
this.username = username;
this.password = password;
this.databaseList = databaseList;
this.tableList = tableList;
this.fetchSize = fetchSize;
this.serverTimeZone = serverTimeZone;
this.connectTimeout = connectTimeout;
this.connectMaxRetries = connectMaxRetries;
this.connectionPoolSize = connectionPoolSize;
}

public abstract RelationalDatabaseConnectorConfig getDbzConnectorConfig();

public String getDriverClassName() {
return driverClassName;
}

public String getHostname() {
return hostname;
}

public int getPort() {
return port;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public List<String> getDatabaseList() {
return databaseList;
}

public List<String> getTableList() {
return tableList;
}

public int getFetchSize() {
return fetchSize;
}

public String getServerTimeZone() {
return serverTimeZone;
}

public Duration getConnectTimeout() {
return connectTimeout;
}

public int getConnectMaxRetries() {
return connectMaxRetries;
}

public int getConnectionPoolSize() {
return connectionPoolSize;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.seatunnel.connectors.cdc.base.dialect;

import org.apache.seatunnel.common.utils.SeaTunnelException;

import io.debezium.jdbc.JdbcConnection;
import io.debezium.relational.TableId;
import org.seatunnel.connectors.cdc.base.config.JdbcSourceConfig;
import org.seatunnel.connectors.cdc.base.relational.connection.JdbcConnectionFactory;
import org.seatunnel.connectors.cdc.base.relational.connection.JdbcConnectionPoolFactory;
import org.seatunnel.connectors.cdc.base.source.reader.external.FetchTask;
import org.seatunnel.connectors.cdc.base.source.reader.external.JdbcSourceFetchTaskContext;
import org.seatunnel.connectors.cdc.base.source.split.SourceSplitBase;

import java.util.List;

public interface JdbcDataSourceDialect extends DataSourceDialect<JdbcSourceConfig> {

/** Discovers the list of table to capture. */
@Override
List<TableId> discoverDataCollections(JdbcSourceConfig sourceConfig);

/**
* Creates and opens a new {@link JdbcConnection} backing connection pool.
*
* @param sourceConfig a basic source configuration.
* @return a utility that simplifies using a JDBC connection.
*/
default JdbcConnection openJdbcConnection(JdbcSourceConfig sourceConfig) {
JdbcConnection jdbc =
new JdbcConnection(
sourceConfig.getDbzConfiguration(),
new JdbcConnectionFactory(sourceConfig, getPooledDataSourceFactory()));
try {
jdbc.connect();
} catch (Exception e) {
throw new SeaTunnelException(e);
}
return jdbc;
}

/** Get a connection pool factory to create connection pool. */
JdbcConnectionPoolFactory getPooledDataSourceFactory();

@Override
FetchTask<SourceSplitBase> createFetchTask(SourceSplitBase sourceSplitBase);

@Override
JdbcSourceFetchTaskContext createFetchTaskContext(
SourceSplitBase sourceSplitBase, JdbcSourceConfig taskSourceConfig);
}
Loading

0 comments on commit 1a50663

Please sign in to comment.