fuweng11 commented on code in PR #8424:
URL: https://github.com/apache/inlong/pull/8424#discussion_r1253849911
##########
inlong-manager/manager-web/sql/changes-1.8.0.sql:
##########
@@ -84,6 +84,21 @@ UPDATE inlong_cluster SET ext_params = replace(ext_params,
'"tenant"', '"pulsarT
ALTER TABLE `inlong_stream` MODIFY COLUMN `name` varchar(256) DEFAULT NULL
COMMENT 'The name of the inlong stream page display, can be Chinese';
+
+CREATE TABLE IF NOT EXISTS `audit_query_source_config`
+(
+ `audit_query_source` varchar(256) NOT NULL COMMENT 'MYSQL,
ELASTICSEARCH, CLICKHOUSE' ,
+ `hosts` varchar(256) NOT NULL COMMENT 'If source is ck:
jdbcUrl, if source is es: hostname' ,
+ `user_name` varchar(256) NOT NULL COMMENT 'user name' ,
Review Comment:
username
##########
inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/AuditController.java:
##########
@@ -59,4 +62,20 @@ public Response<Boolean> refreshCache() {
return Response.success(auditService.refreshBaseItemCache());
}
+ @ApiOperation(value = "insert a source and connect to the source")
+ @PostMapping(value = "/audit/updateSource")
+ public Response<Boolean> updateAuditQuerySource(@RequestParam(value =
"oldHosts", required = false) String oldHosts,
Review Comment:
Suggest use DTO.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
+ private static volatile String currentUserName = null;
+ private static volatile String currentPassword = null;
- private static String jdbcUrl;
-
- private static String username;
-
- private static String password;
-
- @Value("${audit.ck.jdbcUrl}")
- public void setUrl(String jdbcUrl) {
- ClickHouseConfig.jdbcUrl = jdbcUrl;
- }
-
- @Value("${audit.ck.username}")
- public void setUsername(String username) {
- ClickHouseConfig.username = username;
- }
-
- @Value("${audit.ck.password}")
- public void setPassword(String password) {
- ClickHouseConfig.password = password;
- }
+ public void updateCkSource() {
+ try {
+ if (querySourceConfigEntityMapper == null) {
+ log.warn("querySourceConfigEntityMapper is null");
+ }
+ AuditQuerySourceConfigEntity querySourceConfigEntity =
querySourceConfigEntityMapper.findByStatus();
+ String jdbcUrl = querySourceConfigEntity.getHosts();
+ String username = querySourceConfigEntity.getUserName();
+ String password = querySourceConfigEntity.getPassword();
+ String pwd = (password == null) ? "" : password;
+ log.info("current jdbc is: {}", currentJdbcUrl);
+ log.info("jdbc in db is: {}", jdbcUrl);
Review Comment:
Redundant log information.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
+ private static volatile String currentUserName = null;
+ private static volatile String currentPassword = null;
- private static String jdbcUrl;
-
- private static String username;
-
- private static String password;
-
- @Value("${audit.ck.jdbcUrl}")
- public void setUrl(String jdbcUrl) {
- ClickHouseConfig.jdbcUrl = jdbcUrl;
- }
-
- @Value("${audit.ck.username}")
- public void setUsername(String username) {
- ClickHouseConfig.username = username;
- }
-
- @Value("${audit.ck.password}")
- public void setPassword(String password) {
- ClickHouseConfig.password = password;
- }
+ public void updateCkSource() {
+ try {
+ if (querySourceConfigEntityMapper == null) {
+ log.warn("querySourceConfigEntityMapper is null");
+ }
+ AuditQuerySourceConfigEntity querySourceConfigEntity =
querySourceConfigEntityMapper.findByStatus();
+ String jdbcUrl = querySourceConfigEntity.getHosts();
+ String username = querySourceConfigEntity.getUserName();
+ String password = querySourceConfigEntity.getPassword();
+ String pwd = (password == null) ? "" : password;
+ log.info("current jdbc is: {}", currentJdbcUrl);
+ log.info("jdbc in db is: {}", jdbcUrl);
+ if (currentJdbcUrl == null || currentUserName == null ||
currentPassword == null
+ || !(currentJdbcUrl.equals(jdbcUrl) &&
currentUserName.equals(username)
+ && currentPassword.equals(pwd))) {
+ synchronized (ClickHouseConfig.class) {
+ currentJdbcUrl = jdbcUrl;
+ currentUserName = username;
+ currentPassword = pwd;
- /**
- * Get ClickHouse connection from data source
- */
- public static Connection getCkConnection() throws Exception {
- if (source == null) {
- synchronized (ClickHouseConfig.class) {
- if (source == null) {
Properties pros = new Properties();
pros.put("url", jdbcUrl);
pros.put("username", username);
- pros.put("password", password);
- source = DruidDataSourceFactory.createDataSource(pros);
+ pros.put("password", pwd);
+ try {
+ source = DruidDataSourceFactory.createDataSource(pros);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ log.info("Connected to {}", jdbcUrl);
}
}
+ } catch (Exception e) {
+ log.error("Error occurred while reading CK source: {}",
e.getCause());
+ }
+ }
+
+ /**
+ * Get ClickHouse connection from data source
+ */
+ public Connection getCkConnection() throws Exception {
+ log.info("Start to get connection to CLICKHOUSE...");
+ while (source == null) {
Review Comment:
Why use `while (source == null)`, may result in unlimited retries.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
+ private static volatile String currentUserName = null;
+ private static volatile String currentPassword = null;
- private static String jdbcUrl;
-
- private static String username;
-
- private static String password;
-
- @Value("${audit.ck.jdbcUrl}")
- public void setUrl(String jdbcUrl) {
- ClickHouseConfig.jdbcUrl = jdbcUrl;
- }
-
- @Value("${audit.ck.username}")
- public void setUsername(String username) {
- ClickHouseConfig.username = username;
- }
-
- @Value("${audit.ck.password}")
- public void setPassword(String password) {
- ClickHouseConfig.password = password;
- }
+ public void updateCkSource() {
+ try {
+ if (querySourceConfigEntityMapper == null) {
+ log.warn("querySourceConfigEntityMapper is null");
+ }
+ AuditQuerySourceConfigEntity querySourceConfigEntity =
querySourceConfigEntityMapper.findByStatus();
+ String jdbcUrl = querySourceConfigEntity.getHosts();
+ String username = querySourceConfigEntity.getUserName();
+ String password = querySourceConfigEntity.getPassword();
+ String pwd = (password == null) ? "" : password;
+ log.info("current jdbc is: {}", currentJdbcUrl);
+ log.info("jdbc in db is: {}", jdbcUrl);
+ if (currentJdbcUrl == null || currentUserName == null ||
currentPassword == null
Review Comment:
`StringUtils.isBlank(currentJdbcUrl)`、`StringUtils.isBlank(currentUserName)`、`StringUtils.isBlank(currentPassword)`、
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
+ private static volatile String currentUserName = null;
+ private static volatile String currentPassword = null;
Review Comment:
ditto
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
+ private static volatile String currentUserName = null;
Review Comment:
ditto
##########
inlong-manager/manager-dao/src/main/resources/mappers/AuditQuerySourceConfigEntityMapper.xml:
##########
@@ -0,0 +1,64 @@
+<?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.
+-->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper
namespace="org.apache.inlong.manager.dao.mapper.AuditQuerySourceConfigEntityMapper">
+ <resultMap id="BaseResultMap"
type="org.apache.inlong.manager.dao.entity.AuditQuerySourceConfigEntity">
+ <result column="audit_query_source" jdbcType="VARCHAR"
property="auditQuerySource"/>
+ <result column="hosts" jdbcType="VARCHAR" property="hosts"/>
+ <result column="user_name" jdbcType="VARCHAR" property="userName"/>
+ <result column="password" jdbcType="VARCHAR" property="password"/>
+ <result column="auth_enable" jdbcType="TINYINT" property="authEnable"/>
+ <result column="status" jdbcType="TINYINT" property="status"/>
+ <result column="create_time" jdbcType="TIMESTAMP"
property="createTime"/>
+ <result column="update_time" jdbcType="TIMESTAMP"
property="updateTime"/>
+ </resultMap>
+
+ <sql id="Base_Column_List">
+ audit_query_source, hosts, user_name, password, auth_enable, status,
create_time, update_time
+ </sql>
+
+ <select id="findByStatus"
resultType="org.apache.inlong.manager.dao.entity.AuditQuerySourceConfigEntity"
Review Comment:
Please fix code style.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
+ private static volatile String currentUserName = null;
+ private static volatile String currentPassword = null;
- private static String jdbcUrl;
-
- private static String username;
-
- private static String password;
-
- @Value("${audit.ck.jdbcUrl}")
- public void setUrl(String jdbcUrl) {
- ClickHouseConfig.jdbcUrl = jdbcUrl;
- }
-
- @Value("${audit.ck.username}")
- public void setUsername(String username) {
- ClickHouseConfig.username = username;
- }
-
- @Value("${audit.ck.password}")
- public void setPassword(String password) {
- ClickHouseConfig.password = password;
- }
+ public void updateCkSource() {
+ try {
+ if (querySourceConfigEntityMapper == null) {
+ log.warn("querySourceConfigEntityMapper is null");
+ }
+ AuditQuerySourceConfigEntity querySourceConfigEntity =
querySourceConfigEntityMapper.findByStatus();
+ String jdbcUrl = querySourceConfigEntity.getHosts();
+ String username = querySourceConfigEntity.getUserName();
+ String password = querySourceConfigEntity.getPassword();
+ String pwd = (password == null) ? "" : password;
Review Comment:
String password =
StringUritls.isBlank(querySourceConfigEntity.getPassword()) ? "",
querySourceConfigEntity.getPassword();
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
Review Comment:
Suggest just jdbcUrl
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/sink/ck/ClickHouseConfig.java:
##########
@@ -30,45 +35,61 @@
* Clickhouse config information, including url, user, etc.
*/
@Component
+@Service
+@Slf4j
public class ClickHouseConfig {
+ @Autowired
+ private AuditQuerySourceConfigEntityMapper querySourceConfigEntityMapper;
private static volatile DataSource source;
+ private static volatile String currentJdbcUrl = null;
+ private static volatile String currentUserName = null;
+ private static volatile String currentPassword = null;
- private static String jdbcUrl;
-
- private static String username;
-
- private static String password;
-
- @Value("${audit.ck.jdbcUrl}")
- public void setUrl(String jdbcUrl) {
- ClickHouseConfig.jdbcUrl = jdbcUrl;
- }
-
- @Value("${audit.ck.username}")
- public void setUsername(String username) {
- ClickHouseConfig.username = username;
- }
-
- @Value("${audit.ck.password}")
- public void setPassword(String password) {
- ClickHouseConfig.password = password;
- }
+ public void updateCkSource() {
+ try {
+ if (querySourceConfigEntityMapper == null) {
+ log.warn("querySourceConfigEntityMapper is null");
+ }
+ AuditQuerySourceConfigEntity querySourceConfigEntity =
querySourceConfigEntityMapper.findByStatus();
+ String jdbcUrl = querySourceConfigEntity.getHosts();
+ String username = querySourceConfigEntity.getUserName();
+ String password = querySourceConfigEntity.getPassword();
+ String pwd = (password == null) ? "" : password;
+ log.info("current jdbc is: {}", currentJdbcUrl);
+ log.info("jdbc in db is: {}", jdbcUrl);
+ if (currentJdbcUrl == null || currentUserName == null ||
currentPassword == null
+ || !(currentJdbcUrl.equals(jdbcUrl) &&
currentUserName.equals(username)
+ && currentPassword.equals(pwd))) {
+ synchronized (ClickHouseConfig.class) {
+ currentJdbcUrl = jdbcUrl;
+ currentUserName = username;
+ currentPassword = pwd;
- /**
- * Get ClickHouse connection from data source
- */
- public static Connection getCkConnection() throws Exception {
- if (source == null) {
- synchronized (ClickHouseConfig.class) {
- if (source == null) {
Properties pros = new Properties();
pros.put("url", jdbcUrl);
pros.put("username", username);
- pros.put("password", password);
- source = DruidDataSourceFactory.createDataSource(pros);
+ pros.put("password", pwd);
+ try {
+ source = DruidDataSourceFactory.createDataSource(pros);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ log.info("Connected to {}", jdbcUrl);
}
}
+ } catch (Exception e) {
+ log.error("Error occurred while reading CK source: {}",
e.getCause());
+ }
+ }
+
+ /**
+ * Get ClickHouse connection from data source
+ */
+ public Connection getCkConnection() throws Exception {
+ log.info("Start to get connection to CLICKHOUSE...");
Review Comment:
start to get connection to CLICKHOUSE
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]