-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Seatunnel-web] Add FakeSource and Console data sources into…
… seatunnel-web
- Loading branch information
1 parent
475b799
commit 353ba14
Showing
26 changed files
with
674 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
seatunnel-datasource/seatunnel-datasource-plugins/datasource-console/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-datasource-plugins</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>datasource-console</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>datasource-plugins-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
72 changes: 72 additions & 0 deletions
72
...rc/main/java/org/apache/seatunnel/datasource/plugin/console/ConsoleDataSourceChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.apache.seatunnel.datasource.plugin.console; | ||
|
||
import org.apache.seatunnel.api.configuration.util.OptionRule; | ||
import org.apache.seatunnel.datasource.plugin.api.DataSourceChannel; | ||
import org.apache.seatunnel.datasource.plugin.api.model.TableField; | ||
|
||
import lombok.NonNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ConsoleDataSourceChannel implements DataSourceChannel { | ||
|
||
@Override | ||
public OptionRule getDataSourceOptions(@NonNull String pluginName) { | ||
return ConsoleDataSourceConfig.OPTION_RULE; | ||
} | ||
|
||
@Override | ||
public OptionRule getDatasourceMetadataFieldsByDataSourceName(@NonNull String pluginName) { | ||
return ConsoleDataSourceConfig.METADATA_RULE; | ||
} | ||
|
||
@Override | ||
public List<String> getTables( | ||
@NonNull String pluginName, | ||
Map<String, String> requestParams, | ||
String database, | ||
Map<String, String> options) { | ||
return Arrays.asList("console_fake_table"); | ||
} | ||
|
||
@Override | ||
public List<String> getDatabases( | ||
@NonNull String pluginName, @NonNull Map<String, String> requestParams) { | ||
return Arrays.asList("console_fake_database"); | ||
} | ||
|
||
@Override | ||
public boolean checkDataSourceConnectivity( | ||
@NonNull String pluginName, @NonNull Map<String, String> requestParams) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<TableField> getTableFields( | ||
@NonNull String pluginName, | ||
@NonNull Map<String, String> requestParams, | ||
@NonNull String database, | ||
@NonNull String table) { | ||
return Collections.emptyList(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...src/main/java/org/apache/seatunnel/datasource/plugin/console/ConsoleDataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.apache.seatunnel.datasource.plugin.console; | ||
|
||
import org.apache.seatunnel.api.configuration.Option; | ||
import org.apache.seatunnel.api.configuration.Options; | ||
import org.apache.seatunnel.api.configuration.util.OptionRule; | ||
import org.apache.seatunnel.datasource.plugin.api.DataSourcePluginInfo; | ||
import org.apache.seatunnel.datasource.plugin.api.DatasourcePluginTypeEnum; | ||
|
||
public class ConsoleDataSourceConfig { | ||
|
||
public static final String PLUGIN_NAME = "Console"; | ||
|
||
public static final DataSourcePluginInfo CONSOLE_DATASOURCE_PLUGIN_INFO = | ||
DataSourcePluginInfo.builder() | ||
.name(PLUGIN_NAME) | ||
.icon(PLUGIN_NAME) | ||
.version("1.0.0") | ||
.type(DatasourcePluginTypeEnum.FAKE_CONNECTION.getCode()) | ||
.build(); | ||
|
||
public static final Option<String> URL = | ||
Options.key("url") | ||
.stringType() | ||
.defaultValue("dummy://URL") | ||
.withDescription( | ||
"This is required to meet the design constraints, however, it won't be utilized during execution."); | ||
|
||
public static final OptionRule OPTION_RULE = OptionRule.builder().required(URL).build(); | ||
public static final OptionRule METADATA_RULE = OptionRule.builder().build(); | ||
} |
48 changes: 48 additions & 0 deletions
48
...rc/main/java/org/apache/seatunnel/datasource/plugin/console/ConsoleDataSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.apache.seatunnel.datasource.plugin.console; | ||
|
||
import org.apache.seatunnel.datasource.plugin.api.DataSourceChannel; | ||
import org.apache.seatunnel.datasource.plugin.api.DataSourceFactory; | ||
import org.apache.seatunnel.datasource.plugin.api.DataSourcePluginInfo; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.common.collect.Sets; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Set; | ||
|
||
@Slf4j | ||
@AutoService(DataSourceFactory.class) | ||
public class ConsoleDataSourceFactory implements DataSourceFactory { | ||
|
||
@Override | ||
public String factoryIdentifier() { | ||
return ConsoleDataSourceConfig.PLUGIN_NAME; | ||
} | ||
|
||
@Override | ||
public Set<DataSourcePluginInfo> supportedDataSources() { | ||
return Sets.newHashSet(ConsoleDataSourceConfig.CONSOLE_DATASOURCE_PLUGIN_INFO); | ||
} | ||
|
||
@Override | ||
public DataSourceChannel createChannel() { | ||
return new ConsoleDataSourceChannel(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
seatunnel-datasource/seatunnel-datasource-plugins/datasource-fakesource/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-datasource-plugins</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>datasource-fakesource</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>datasource-plugins-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
94 changes: 94 additions & 0 deletions
94
...n/java/org/apache/seatunnel/datasource/plugin/fakesource/FakeSourceDataSourceChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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.apache.seatunnel.datasource.plugin.fakesource; | ||
|
||
import org.apache.seatunnel.api.configuration.util.OptionRule; | ||
import org.apache.seatunnel.common.utils.JsonUtils; | ||
import org.apache.seatunnel.datasource.plugin.api.DataSourceChannel; | ||
import org.apache.seatunnel.datasource.plugin.api.DataSourcePluginException; | ||
import org.apache.seatunnel.datasource.plugin.api.model.TableField; | ||
|
||
import lombok.NonNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class FakeSourceDataSourceChannel implements DataSourceChannel { | ||
|
||
@Override | ||
public OptionRule getDataSourceOptions(@NonNull String pluginName) { | ||
return FakeSourceDataSourceConfig.OPTION_RULE; | ||
} | ||
|
||
@Override | ||
public OptionRule getDatasourceMetadataFieldsByDataSourceName(@NonNull String pluginName) { | ||
return FakeSourceDataSourceConfig.METADATA_RULE; | ||
} | ||
|
||
@Override | ||
public List<String> getTables( | ||
@NonNull String pluginName, | ||
Map<String, String> requestParams, | ||
String database, | ||
Map<String, String> options) { | ||
return Arrays.asList("fake_table"); | ||
} | ||
|
||
@Override | ||
public List<String> getDatabases( | ||
@NonNull String pluginName, @NonNull Map<String, String> requestParams) { | ||
return Arrays.asList("fake_database"); | ||
} | ||
|
||
@Override | ||
public boolean checkDataSourceConnectivity( | ||
@NonNull String pluginName, @NonNull Map<String, String> requestParams) { | ||
try { | ||
JsonUtils.toMap(requestParams.get("fields")); | ||
} catch (RuntimeException ex) { | ||
throw new DataSourcePluginException( | ||
"Failed to parse field parameter. " + ex.getMessage(), ex); | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<TableField> getTableFields( | ||
@NonNull String pluginName, | ||
@NonNull Map<String, String> requestParams, | ||
@NonNull String database, | ||
@NonNull String table) { | ||
String fieldsJson = requestParams.get("fields"); | ||
if (fieldsJson == null) { | ||
return Collections.emptyList(); | ||
} | ||
Map<String, String> fields = JsonUtils.toMap(fieldsJson); | ||
return fields.entrySet().stream() | ||
.map( | ||
entry -> { | ||
TableField tableField = new TableField(); | ||
tableField.setName(entry.getKey()); | ||
tableField.setType(entry.getValue()); | ||
return tableField; | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
Oops, something went wrong.