mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-11-30 11:07:41 +08:00
fix: Fix merge
Merge branch 'master' of github.com:shuangzishuai/incubator-datacap into plugin-mongo
This commit is contained in:
commit
f920c8ab99
@ -1,10 +1,9 @@
|
||||
FROM java:8
|
||||
FROM eclipse-temurin:8-jdk-focal
|
||||
MAINTAINER qianmoQ "shicheng@ttxit.com"
|
||||
|
||||
# Add datacap
|
||||
RUN mkdir -p /opt/app
|
||||
COPY dist/datacap-release.tar.gz /opt/app/datacap-release.tar.gz
|
||||
RUN tar -xvzf /opt/app/datacap-release.tar.gz -C /opt/app/
|
||||
ADD dist/datacap-release.tar.gz /opt/app/
|
||||
WORKDIR /opt/app/datacap
|
||||
CMD sh ./bin/startup.sh
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
<name>DataCap plugin for jdbc (Kyuubi)</name>
|
||||
|
||||
<properties>
|
||||
<kyuubi-jdbc.version>1.5.2-incubating</kyuubi-jdbc.version>
|
||||
<kyuubi-jdbc.version>1.6.0-incubating</kyuubi-jdbc.version>
|
||||
<plugin.name>jdbc-kyuubi</plugin.name>
|
||||
</properties>
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
package io.edurt.datacap.server.common;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import io.edurt.datacap.spi.Plugin;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class PluginCommon
|
||||
{
|
||||
private PluginCommon() {}
|
||||
|
||||
public static Optional<Plugin> getPluginByName(Injector injector, String pluginName)
|
||||
{
|
||||
Optional<Plugin> pluginOptional = injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}))
|
||||
.stream()
|
||||
.filter(plugin -> plugin.name().equalsIgnoreCase(pluginName))
|
||||
.findFirst();
|
||||
return pluginOptional;
|
||||
}
|
||||
}
|
@ -78,6 +78,10 @@ public class SourceEntity
|
||||
@Column(name = "create_time", columnDefinition = "datetime default CURRENT_TIMESTAMP()")
|
||||
private Timestamp createTime;
|
||||
|
||||
// Add from 1.1.0.20221115
|
||||
@Column(name = "_ssl", columnDefinition = "boolean default false")
|
||||
private Boolean ssl;
|
||||
|
||||
@OneToMany(mappedBy = "plugin", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<PluginAuditEntity> pluginAudits;
|
||||
|
@ -1,9 +1,8 @@
|
||||
package io.edurt.datacap.server.service.impl;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import io.edurt.datacap.server.audit.AuditPlugin;
|
||||
import io.edurt.datacap.server.common.PluginCommon;
|
||||
import io.edurt.datacap.server.common.Response;
|
||||
import io.edurt.datacap.server.common.ServiceState;
|
||||
import io.edurt.datacap.server.entity.ExecuteEntity;
|
||||
@ -15,7 +14,6 @@ import io.edurt.datacap.spi.model.Configure;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class ExecuteServiceImpl
|
||||
@ -40,10 +38,7 @@ public class ExecuteServiceImpl
|
||||
}
|
||||
|
||||
SourceEntity entity = entityOptional.get();
|
||||
Optional<Plugin> pluginOptional = this.injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}))
|
||||
.stream()
|
||||
.filter(plugin -> plugin.name().equalsIgnoreCase(entity.getType()))
|
||||
.findFirst();
|
||||
Optional<Plugin> pluginOptional = PluginCommon.getPluginByName(this.injector, entity.getType());
|
||||
if (!pluginOptional.isPresent()) {
|
||||
return Response.failure(ServiceState.PLUGIN_NOT_FOUND);
|
||||
}
|
||||
@ -55,6 +50,7 @@ public class ExecuteServiceImpl
|
||||
_configure.setUsername(Optional.ofNullable(entity.getUsername()));
|
||||
_configure.setPassword(Optional.ofNullable(entity.getPassword()));
|
||||
_configure.setDatabase(Optional.ofNullable(entity.getDatabase()));
|
||||
_configure.setSsl(Optional.ofNullable(entity.getSsl()));
|
||||
_configure.setEnv(Optional.ofNullable(configure.getEnv()));
|
||||
_configure.setFormat(configure.getFormat());
|
||||
plugin.connect(_configure);
|
||||
|
@ -4,6 +4,7 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import io.edurt.datacap.server.adapter.PageRequestAdapter;
|
||||
import io.edurt.datacap.server.common.PluginCommon;
|
||||
import io.edurt.datacap.server.common.Response;
|
||||
import io.edurt.datacap.server.common.ServiceState;
|
||||
import io.edurt.datacap.server.entity.PageEntity;
|
||||
@ -59,10 +60,7 @@ public class SourceServiceImpl
|
||||
@Override
|
||||
public Response<Object> testConnection(SourceEntity configure)
|
||||
{
|
||||
Optional<Plugin> pluginOptional = this.injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}))
|
||||
.stream()
|
||||
.filter(plugin -> plugin.name().equalsIgnoreCase(configure.getType()))
|
||||
.findFirst();
|
||||
Optional<Plugin> pluginOptional = PluginCommon.getPluginByName(this.injector, configure.getType());
|
||||
if (!pluginOptional.isPresent()) {
|
||||
return Response.failure(ServiceState.PLUGIN_NOT_FOUND);
|
||||
}
|
||||
@ -75,6 +73,7 @@ public class SourceServiceImpl
|
||||
_configure.setPassword(Optional.ofNullable(configure.getPassword()));
|
||||
_configure.setDatabase(Optional.ofNullable(configure.getDatabase()));
|
||||
_configure.setEnv(Optional.empty());
|
||||
_configure.setSsl(Optional.ofNullable(configure.getSsl()));
|
||||
_configure.setFormat(FormatType.JSON);
|
||||
plugin.connect(_configure);
|
||||
io.edurt.datacap.spi.model.Response response = plugin.execute(plugin.validator());
|
||||
|
2
server/src/main/schema/update_1.1.0.20221115.sql
Normal file
2
server/src/main/schema/update_1.1.0.20221115.sql
Normal file
@ -0,0 +1,2 @@
|
||||
ALTER TABLE `datacap`.`source`
|
||||
ADD COLUMN `_ssl` boolean default false;
|
@ -11,13 +11,14 @@ import io.edurt.datacap.spi.model.Time;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@SuppressFBWarnings(value = {"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"},
|
||||
@ -46,30 +47,51 @@ public class JdbcAdapter
|
||||
Connection connection = (Connection) this.jdbcConnection.getConnection();
|
||||
JdbcConfigure configure = (JdbcConfigure) this.jdbcConnection.getConfigure();
|
||||
if (response.getIsConnected()) {
|
||||
try (Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(content)) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(content)) {
|
||||
List<String> headers = new ArrayList<>();
|
||||
List<String> types = new ArrayList<>();
|
||||
List<Object> columns = new ArrayList<>();
|
||||
boolean isPresent = true;
|
||||
JdbcColumn jdbcColumn = new JdbcColumn(resultSet);
|
||||
while (resultSet.next()) {
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
List<Object> _columns = new ArrayList<>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
if (isPresent) {
|
||||
headers.add(metaData.getColumnName(i));
|
||||
types.add(metaData.getColumnTypeName(i));
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
boolean isPresent = true;
|
||||
JdbcColumn jdbcColumn = new JdbcColumn(resultSet);
|
||||
while (resultSet.next()) {
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
List<Object> _columns = new ArrayList<>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
if (isPresent) {
|
||||
headers.add(metaData.getColumnName(i));
|
||||
types.add(metaData.getColumnTypeName(i));
|
||||
}
|
||||
_columns.add(jdbcColumn.convert(metaData.getColumnTypeName(i), i));
|
||||
}
|
||||
_columns.add(jdbcColumn.convert(metaData.getColumnTypeName(i), i));
|
||||
isPresent = false;
|
||||
columns.add(handlerFormatter(configure.getFormat(), headers, _columns));
|
||||
}
|
||||
isPresent = false;
|
||||
columns.add(handlerFormatter(configure.getFormat(), headers, _columns));
|
||||
}
|
||||
response.setHeaders(headers);
|
||||
response.setTypes(types);
|
||||
response.setColumns(columns);
|
||||
response.setIsSuccessful(Boolean.TRUE);
|
||||
catch (SQLException tryUpdateEx) {
|
||||
if (Objects.equals(tryUpdateEx.getSQLState(), "S1009")) {
|
||||
try {
|
||||
headers.add("result");
|
||||
types.add(Integer.class.getSimpleName());
|
||||
List<Object> _columns = new ArrayList<>();
|
||||
_columns.add(statement.executeUpdate());
|
||||
columns.add(handlerFormatter(configure.getFormat(), headers, _columns));
|
||||
}
|
||||
catch (SQLException updateEx) {
|
||||
throw new SQLException(updateEx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new SQLException(tryUpdateEx);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
response.setHeaders(headers);
|
||||
response.setTypes(types);
|
||||
response.setColumns(columns);
|
||||
response.setIsSuccessful(Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
log.error("Execute content failed content {} exception ", content, ex);
|
||||
|
@ -37,13 +37,21 @@ public class JdbcConnection
|
||||
buffer.append("/");
|
||||
buffer.append(this.jdbcConfigure.getDatabase().get());
|
||||
}
|
||||
if (this.jdbcConfigure.getSsl().isPresent()) {
|
||||
buffer.append(String.format("?ssl=%s", this.jdbcConfigure.getSsl().get()));
|
||||
}
|
||||
if (this.jdbcConfigure.getEnv().isPresent()) {
|
||||
Map<String, Object> env = this.jdbcConfigure.getEnv().get();
|
||||
List<String> flatEnv = env.entrySet()
|
||||
.stream()
|
||||
.map(value -> String.format("%s=%s", value.getKey(), value.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
buffer.append("?");
|
||||
if (!this.jdbcConfigure.getSsl().isPresent()) {
|
||||
buffer.append("?");
|
||||
}
|
||||
else {
|
||||
buffer.append("&");
|
||||
}
|
||||
buffer.append(String.join("&", flatEnv));
|
||||
}
|
||||
return buffer.toString();
|
||||
|
@ -21,5 +21,6 @@ public class Configure
|
||||
private Optional<String> password = Optional.empty();
|
||||
private Optional<String> database = Optional.empty();
|
||||
private Optional<Map<String, Object>> env = Optional.empty();
|
||||
private Optional<Boolean> ssl = Optional.empty();
|
||||
private FormatType format = FormatType.NONE;
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
package io.edurt.datacap.spi.connection;
|
||||
|
||||
import io.edurt.datacap.spi.model.Response;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class JdbcConnectionTest
|
||||
{
|
||||
private JdbcConfigure jdbcConfigure;
|
||||
private Response response;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
this.jdbcConfigure = new JdbcConfigure();
|
||||
this.jdbcConfigure.setJdbcType("datacap");
|
||||
this.jdbcConfigure.setJdbcDriver("io.edurt.datacap.DataCapDriver");
|
||||
this.jdbcConfigure.setHost("127.0.0.1");
|
||||
this.jdbcConfigure.setPort(9096);
|
||||
|
||||
this.response = new Response();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatJdbcUrl()
|
||||
{
|
||||
Connection connection = new JdbcConnection(this.jdbcConfigure, this.response);
|
||||
Assert.assertEquals(connection.formatJdbcUrl(), "jdbc:datacap://127.0.0.1:9096");
|
||||
|
||||
this.jdbcConfigure.setSsl(Optional.ofNullable(true));
|
||||
connection = new JdbcConnection(this.jdbcConfigure, this.response);
|
||||
Assert.assertEquals(connection.formatJdbcUrl(), "jdbc:datacap://127.0.0.1:9096?ssl=true");
|
||||
|
||||
Map<String, Object> env = new HashMap<>();
|
||||
env.put("useUnicode", "true");
|
||||
env.put("zeroDateTimeBehavior", "convertToNull");
|
||||
this.jdbcConfigure.setEnv(Optional.ofNullable(env));
|
||||
connection = new JdbcConnection(this.jdbcConfigure, this.response);
|
||||
Assert.assertEquals(connection.formatJdbcUrl(), "jdbc:datacap://127.0.0.1:9096?ssl=true&useUnicode=true&zeroDateTimeBehavior=convertToNull");
|
||||
}
|
||||
}
|
@ -12,4 +12,5 @@ export interface SourceModel
|
||||
database: string;
|
||||
type: string;
|
||||
createTime?: number;
|
||||
ssl?: boolean
|
||||
}
|
||||
|
@ -21,12 +21,12 @@
|
||||
<a-menu>
|
||||
<a-menu-item>
|
||||
<a target="_blank" href="https://github.com/EdurtIO/incubator-datacap/fork">
|
||||
<img alt="GitHub forks" src="https://img.shields.io/github/forks/EdurtIO/incubator-datacap">
|
||||
Forks <img alt="GitHub forks" src="https://img.shields.io/github/forks/EdurtIO/incubator-datacap?color=%20&label=%20&logo=%20&style=flat">
|
||||
</a>
|
||||
</a-menu-item>
|
||||
<a-menu-item>
|
||||
<a href="https://github.com/EdurtIO/incubator-datacap/stargazers">
|
||||
<img alt="GitHub stars" src="https://img.shields.io/github/stars/EdurtIO/incubator-datacap">
|
||||
Stars <img alt="GitHub forks" src="https://img.shields.io/github/stars/EdurtIO/incubator-datacap?color=%20&label=%20&logo=%20&style=flat">
|
||||
</a>
|
||||
</a-menu-item>
|
||||
<a-menu-item>
|
||||
|
@ -99,6 +99,16 @@
|
||||
<a-input v-model:value="formState.password"/>
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane :disabled="!formState.type" key="ssl">
|
||||
<template #tab>
|
||||
<span>
|
||||
<safety-outlined/> SSL
|
||||
</span>
|
||||
</template>
|
||||
<a-form-item :name="['ssl']" label="SSL">
|
||||
<a-switch v-model:checked="formState.ssl"/>
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane :disabled="!formState.type" key="advanced">
|
||||
<template #tab>
|
||||
<span>
|
||||
@ -176,7 +186,7 @@ export default defineComponent({
|
||||
return {
|
||||
title: '',
|
||||
isUpdate: false,
|
||||
formState: {},
|
||||
formState: {} as SourceModel,
|
||||
plugins: [],
|
||||
testInfo: {} as TestInfo,
|
||||
connectionLoading: false,
|
||||
|
Loading…
Reference in New Issue
Block a user