Skip to content

Commit

Permalink
[Improve][code style] Add spotless plugin to seatunnel web (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricJoy2048 authored May 16, 2023
1 parent e0b6e75 commit 21a195c
Show file tree
Hide file tree
Showing 177 changed files with 4,213 additions and 3,654 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
cache: 'maven'
- name: Check code style
run: ./mvnw --batch-mode --quiet --no-snapshot-updates clean checkstyle:check
run: ./mvnw --batch-mode --quiet --no-snapshot-updates clean spotless:check

dead-link:
if: github.repository == 'apache/incubator-seatunnel-web'
Expand Down
241 changes: 155 additions & 86 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.seatunnel.datasource;

import static com.google.common.base.Preconditions.checkNotNull;

import org.apache.seatunnel.api.configuration.util.OptionRule;
import org.apache.seatunnel.datasource.exception.DataSourceSDKException;
import org.apache.seatunnel.datasource.plugin.api.DataSourceChannel;
Expand All @@ -34,6 +32,8 @@
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicInteger;

import static com.google.common.base.Preconditions.checkNotNull;

public abstract class AbstractDataSourceClient implements DataSourceService {

private Map<String, DataSourcePluginInfo> supportedDataSourceInfo = new HashMap<>();
Expand All @@ -47,33 +47,33 @@ public abstract class AbstractDataSourceClient implements DataSourceService {
protected AbstractDataSourceClient() {
AtomicInteger dataSourceIndex = new AtomicInteger();
ServiceLoader.load(DataSourceFactory.class)
.forEach(
seaTunnelDataSourceFactory -> {
seaTunnelDataSourceFactory
.supportedDataSources()
.forEach(
dataSourceInfo -> {
supportedDataSourceInfo.put(
dataSourceInfo.getName().toUpperCase(),
dataSourceInfo);
supportedDataSourceIndex.put(
dataSourceInfo.getName().toUpperCase(),
dataSourceIndex.get());
supportedDataSources.add(dataSourceInfo);
});
dataSourceChannels.add(seaTunnelDataSourceFactory.createChannel());
dataSourceIndex.getAndIncrement();
});
.forEach(
seaTunnelDataSourceFactory -> {
seaTunnelDataSourceFactory
.supportedDataSources()
.forEach(
dataSourceInfo -> {
supportedDataSourceInfo.put(
dataSourceInfo.getName().toUpperCase(),
dataSourceInfo);
supportedDataSourceIndex.put(
dataSourceInfo.getName().toUpperCase(),
dataSourceIndex.get());
supportedDataSources.add(dataSourceInfo);
});
dataSourceChannels.add(seaTunnelDataSourceFactory.createChannel());
dataSourceIndex.getAndIncrement();
});
if (supportedDataSourceInfo.isEmpty()) {
throw new DataSourceSDKException("No supported data source found");
}
}

@Override
public Boolean checkDataSourceConnectivity(
String pluginName, Map<String, String> dataSourceParams) {
String pluginName, Map<String, String> dataSourceParams) {
return getDataSourceChannel(pluginName)
.checkDataSourceConnectivity(pluginName, dataSourceParams);
.checkDataSourceConnectivity(pluginName, dataSourceParams);
}

@Override
Expand All @@ -86,7 +86,7 @@ protected DataSourceChannel getDataSourceChannel(String pluginName) {
Integer index = supportedDataSourceIndex.get(pluginName.toUpperCase());
if (index == null) {
throw new DataSourceSDKException(
"The %s plugin is not supported or plugin not exist.", pluginName);
"The %s plugin is not supported or plugin not exist.", pluginName);
}
return dataSourceChannels.get(index);
}
Expand All @@ -99,12 +99,12 @@ public OptionRule queryDataSourceFieldByName(String pluginName) {
@Override
public OptionRule queryMetadataFieldByName(String pluginName) {
return getDataSourceChannel(pluginName)
.getDatasourceMetadataFieldsByDataSourceName(pluginName);
.getDatasourceMetadataFieldsByDataSourceName(pluginName);
}

@Override
public List<String> getTables(
String pluginName, String databaseName, Map<String, String> requestParams) {
String pluginName, String databaseName, Map<String, String> requestParams) {
return getDataSourceChannel(pluginName).getTables(pluginName, requestParams, databaseName);
}

Expand All @@ -115,21 +115,21 @@ public List<String> getDatabases(String pluginName, Map<String, String> requestP

@Override
public List<TableField> getTableFields(
String pluginName,
Map<String, String> requestParams,
String databaseName,
String tableName) {
String pluginName,
Map<String, String> requestParams,
String databaseName,
String tableName) {
return getDataSourceChannel(pluginName)
.getTableFields(pluginName, requestParams, databaseName, tableName);
.getTableFields(pluginName, requestParams, databaseName, tableName);
}

@Override
public Map<String, List<TableField>> getTableFields(
String pluginName,
Map<String, String> requestParams,
String databaseName,
List<String> tableNames) {
String pluginName,
Map<String, String> requestParams,
String databaseName,
List<String> tableNames) {
return getDataSourceChannel(pluginName)
.getTableFields(pluginName, requestParams, databaseName, tableNames);
.getTableFields(pluginName, requestParams, databaseName, tableNames);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ public interface DataSourceService {
/**
* get data source table names by database name
*
* @param pluginName plugin name
* @param databaseName database name
* @param pluginName plugin name
* @param databaseName database name
* @param requestParams connection params
* @return table names
*/
List<String> getTables(
String pluginName, String databaseName, Map<String, String> requestParams);
String pluginName, String databaseName, Map<String, String> requestParams);

/**
* get data source database names
*
* @param pluginName plugin name
* @param pluginName plugin name
* @param requestParams connection params
* @return database names
*/
Expand All @@ -87,30 +87,30 @@ List<String> getTables(
/**
* get data source table fields
*
* @param pluginName plugin name
* @param pluginName plugin name
* @param requestParams connection params
* @param databaseName database name
* @param tableName table name
* @param databaseName database name
* @param tableName table name
* @return table fields
*/
List<TableField> getTableFields(
String pluginName,
Map<String, String> requestParams,
String databaseName,
String tableName);
String pluginName,
Map<String, String> requestParams,
String databaseName,
String tableName);

/**
* get data source table fields
*
* @param pluginName plugin name
* @param pluginName plugin name
* @param requestParams connection params
* @param databaseName database name
* @param tableNames table names
* @param databaseName database name
* @param tableNames table names
* @return table fields
*/
Map<String, List<TableField>> getTableFields(
String pluginName,
Map<String, String> requestParams,
String databaseName,
List<String> tableNames);
String pluginName,
Map<String, String> requestParams,
String databaseName,
List<String> tableNames);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

import org.apache.seatunnel.datasource.plugin.s3.S3DatasourceChannel;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableMap;

import java.util.Map;

@Disabled
Expand All @@ -33,23 +34,23 @@ class S3DatasourceChannelTest {
@Test
void checkDataSourceConnectivity() {
Assertions.assertDoesNotThrow(
() -> {
S3_DATASOURCE_CHANNEL.checkDataSourceConnectivity("S3", createRequestParams());
});
() -> {
S3_DATASOURCE_CHANNEL.checkDataSourceConnectivity("S3", createRequestParams());
});
}

private Map<String, String> createRequestParams() {
Map<String, String> requestParams =
new ImmutableMap.Builder<String, String>()
.put("bucket", "s3a://poc-kuke")
.put("fs.s3a.endpoint", "s3.cn-north-1.amazonaws.com.cn")
.put(
"fs.s3a.aws.credentials.provider",
"org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider")
.put("access_key", "AKIAYYUV5DMXADXRBGTA")
.put("secret_key", "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")
.put("hadoop_s3_properties", "")
.build();
new ImmutableMap.Builder<String, String>()
.put("bucket", "s3a://poc-kuke")
.put("fs.s3a.endpoint", "s3.cn-north-1.amazonaws.com.cn")
.put(
"fs.s3a.aws.credentials.provider",
"org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider")
.put("access_key", "AKIAYYUV5DMXADXRBGTA")
.put("secret_key", "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")
.put("hadoop_s3_properties", "")
.build();
return requestParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.seatunnel.datasource;

import org.apache.commons.lang3.StringUtils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -27,22 +28,22 @@ class DataSourceClientTest {
@Test
public void listAllDataSources() {
Assertions.assertTrue(
DATA_SOURCE_CLIENT.listAllDataSources().stream()
.anyMatch(
dataSourcePluginInfo ->
StringUtils.equalsAnyIgnoreCase(
dataSourcePluginInfo.getName(), "jdbc-mysql")));
DATA_SOURCE_CLIENT.listAllDataSources().stream()
.anyMatch(
dataSourcePluginInfo ->
StringUtils.equalsAnyIgnoreCase(
dataSourcePluginInfo.getName(), "jdbc-mysql")));
Assertions.assertTrue(
DATA_SOURCE_CLIENT.listAllDataSources().stream()
.anyMatch(
dataSourcePluginInfo ->
StringUtils.equalsAnyIgnoreCase(
dataSourcePluginInfo.getName(), "kafka")));
DATA_SOURCE_CLIENT.listAllDataSources().stream()
.anyMatch(
dataSourcePluginInfo ->
StringUtils.equalsAnyIgnoreCase(
dataSourcePluginInfo.getName(), "kafka")));
Assertions.assertTrue(
DATA_SOURCE_CLIENT.listAllDataSources().stream()
.anyMatch(
dataSourcePluginInfo ->
StringUtils.equalsAnyIgnoreCase(
dataSourcePluginInfo.getName(), "elasticsearch")));
DATA_SOURCE_CLIENT.listAllDataSources().stream()
.anyMatch(
dataSourcePluginInfo ->
StringUtils.equalsAnyIgnoreCase(
dataSourcePluginInfo.getName(), "elasticsearch")));
}
}
Loading

0 comments on commit 21a195c

Please sign in to comment.