This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b6febd  Fix NPE in DataProxyConfigRepository#reload (#1615)
9b6febd is described below

commit 9b6febd146e4c86c15538e20438390b059cae561
Author: Wenjun Ruan <[email protected]>
AuthorDate: Tue Oct 12 13:00:28 2021 +0800

    Fix NPE in DataProxyConfigRepository#reload (#1615)
---
 .../inlong/manager/common/util/JsonUtils.java      | 14 ++++----
 .../apache/inlong/manager/dao/HiveServerDao.java   | 38 +++++++++++-----------
 .../service/core/impl/AgentTaskServiceImpl.java    |  4 +--
 .../core/operationlog/OperationLogRecorder.java    |  7 ++--
 .../repository/DataProxyConfigRepository.java      | 21 ++++++------
 .../manager/web/auth/AuthenticationFilter.java     |  4 +--
 6 files changed, 43 insertions(+), 45 deletions(-)

diff --git 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/JsonUtils.java
 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/JsonUtils.java
index dd7c55f..1d0dbb2 100644
--- 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/JsonUtils.java
+++ 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/util/JsonUtils.java
@@ -63,7 +63,7 @@ public class JsonUtils {
         try {
             return MAPPER.writeValueAsString(obj);
         } catch (JsonProcessingException e) {
-            log.error("JSON transform error: " + obj, e);
+            log.error("JSON transform error: {}", obj, e);
             throw new JsonException("JSON transform error");
         }
     }
@@ -80,7 +80,7 @@ public class JsonUtils {
         try {
             return MAPPER.readValue(json, type);
         } catch (IOException e) {
-            log.error("JSON transform error: " + json, e);
+            log.error("JSON transform error: {}", json, e);
             throw new JsonException("JSON transform error");
         }
     }
@@ -98,7 +98,7 @@ public class JsonUtils {
         try {
             return MAPPER.readTree(json);
         } catch (IOException e) {
-            log.error("JSON transform error: " + json, e);
+            log.error("JSON transform error: {}", json, e);
             throw new JsonException("JSON transform error");
         }
     }
@@ -115,7 +115,7 @@ public class JsonUtils {
         try {
             return MAPPER.readValue(json, tClass);
         } catch (IOException e) {
-            log.error("JSON transform error: " + json, e);
+            log.error("JSON transform error: {}", json, e);
             throw new JsonException("JSON transform error");
         }
     }
@@ -124,7 +124,7 @@ public class JsonUtils {
         try {
             return MAPPER.readValue(json, javaType);
         } catch (IOException e) {
-            log.error("JSON transform error: " + json, e);
+            log.error("JSON transform error: {}", json, e);
             throw new JsonException("JSON transform error");
         }
     }
@@ -141,7 +141,7 @@ public class JsonUtils {
         try {
             return MAPPER.readValue(json, 
MAPPER.getTypeFactory().constructCollectionType(List.class, eClass));
         } catch (IOException e) {
-            log.error("JSON transform error: " + json, e);
+            log.error("JSON transform error: {}", json, e);
             throw new JsonException("JSON transform error");
         }
     }
@@ -160,7 +160,7 @@ public class JsonUtils {
         try {
             return MAPPER.readValue(json, 
MAPPER.getTypeFactory().constructMapType(Map.class, kClass, vClass));
         } catch (IOException e) {
-            log.error("JSON transform error: " + json, e);
+            log.error("JSON transform error: {}", json, e);
             throw new JsonException("JSON transform error");
         }
     }
diff --git 
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/HiveServerDao.java
 
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/HiveServerDao.java
index 1b40025..b95fcbb 100644
--- 
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/HiveServerDao.java
+++ 
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/HiveServerDao.java
@@ -36,10 +36,10 @@ public class HiveServerDao {
     private static final Logger LOG = 
LoggerFactory.getLogger(HiveServerDao.class);
 
     public void executeDDL(String ddl, String hiveUrl, String user, String 
password) throws Exception {
-        Connection conn = this.getHiveConnection(hiveUrl, user, password);
-        Statement stmt = conn.createStatement();
-        stmt.execute(ddl);
-        conn.close();
+        try (Connection conn = this.getHiveConnection(hiveUrl, user, 
password)) {
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+        }
     }
 
     /**
@@ -47,23 +47,23 @@ public class HiveServerDao {
      */
     public List<ColumnInfoBean> queryStructure(String querySql, String jdbcUrl,
             String user, String password) throws Exception {
-        Connection conn = this.getHiveConnection(jdbcUrl, user, password);
-        Statement stmt = conn.createStatement();
-        ResultSet rs = stmt.executeQuery(querySql);
-        List<ColumnInfoBean> columnInfoBeans = new ArrayList<>();
-        try {
-            while (rs.next()) {
-                ColumnInfoBean columnInfoBean = new ColumnInfoBean();
-                columnInfoBean.setColumnName(rs.getString(1));
-                columnInfoBean.setColumnType(rs.getString(2));
-                columnInfoBean.setColumnDesc(rs.getString(3));
-                columnInfoBeans.add(columnInfoBean);
+        try (Connection conn = this.getHiveConnection(jdbcUrl, user, 
password)) {
+            Statement stmt = conn.createStatement();
+            ResultSet rs = stmt.executeQuery(querySql);
+            List<ColumnInfoBean> columnInfoBeans = new ArrayList<>();
+            try {
+                while (rs.next()) {
+                    ColumnInfoBean columnInfoBean = new ColumnInfoBean();
+                    columnInfoBean.setColumnName(rs.getString(1));
+                    columnInfoBean.setColumnType(rs.getString(2));
+                    columnInfoBean.setColumnDesc(rs.getString(3));
+                    columnInfoBeans.add(columnInfoBean);
+                }
+            } catch (Exception e) {
+                LOG.error("query table structure error", e);
             }
-        } catch (Exception e) {
-            LOG.error("query table structure error", e);
+            return columnInfoBeans;
         }
-        conn.close();
-        return columnInfoBeans;
     }
 
     /**
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentTaskServiceImpl.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentTaskServiceImpl.java
index 6601890..3aab799 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentTaskServiceImpl.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentTaskServiceImpl.java
@@ -125,7 +125,7 @@ public class AgentTaskServiceImpl implements 
AgentTaskService {
             if (currentStatus / 100 == 2) { // Modify status 20x -> 30x
                 int nextStatus = currentStatus % 100 + 300;
                 SourceFileDetailEntity update = new SourceFileDetailEntity();
-                update.setId(Integer.valueOf(config.getTaskId()));
+                update.setId(config.getTaskId());
                 update.setStatus(nextStatus);
                 update.setPreviousStatus(currentStatus);
                 
sourceFileDetailEntityMapper.updateByPrimaryKeySelective(update);
@@ -160,7 +160,7 @@ public class AgentTaskServiceImpl implements 
AgentTaskService {
                             continue;
                         }
                         int nextStatus = 101;
-                        if (current != null && current.getStatus() / 100 == 3) 
{ // Modify 30x -> 10x
+                        if (current.getStatus() != null && current.getStatus() 
/ 100 == 3) { // Modify 30x -> 10x
                             if (command.getCommandResult() == 0) { // 
Processed successfully
                                 if (current.getStatus() == 300 || 
current.getStatus() == 305) {
                                     nextStatus = 100;
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/operationlog/OperationLogRecorder.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/operationlog/OperationLogRecorder.java
index 03640fe..b8cc4fb 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/operationlog/OperationLogRecorder.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/operationlog/OperationLogRecorder.java
@@ -29,6 +29,7 @@ import org.apache.inlong.manager.common.util.LoginUserUtil;
 import org.apache.inlong.manager.common.util.NetworkUtils;
 import org.apache.inlong.manager.dao.entity.OperationLogEntity;
 import org.aspectj.lang.ProceedingJoinPoint;
+import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
@@ -44,12 +45,12 @@ public class OperationLogRecorder {
      * Save operation logs of all Controller
      */
     public static Object doAround(ProceedingJoinPoint joinPoint, OperationLog 
operationLog) throws Throwable {
-        if (RequestContextHolder.getRequestAttributes() == null) {
+        RequestAttributes requestAttributes = 
RequestContextHolder.getRequestAttributes();
+        if (requestAttributes == null) {
             return joinPoint.proceed();
         }
 
-        HttpServletRequest request = ((ServletRequestAttributes) 
RequestContextHolder.getRequestAttributes())
-                .getRequest();
+        HttpServletRequest request = ((ServletRequestAttributes) 
requestAttributes).getRequest();
 
         UserDetail userDetail = 
Optional.ofNullable(LoginUserUtil.getLoginUserDetail())
                 .orElseGet(UserDetail::new);
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/repository/DataProxyConfigRepository.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/repository/DataProxyConfigRepository.java
index 8e77e4d..c20ceef 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/repository/DataProxyConfigRepository.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/repository/DataProxyConfigRepository.java
@@ -17,6 +17,8 @@
 
 package org.apache.inlong.manager.service.repository;
 
+import com.google.common.base.Splitter;
+import com.google.gson.Gson;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -25,7 +27,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
-
+import javax.annotation.PostConstruct;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.inlong.commons.pojo.dataproxy.CacheClusterObject;
 import org.apache.inlong.commons.pojo.dataproxy.CacheClusterSetObject;
@@ -59,9 +61,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
 
-import com.google.common.base.Splitter;
-import com.google.gson.Gson;
-
 /**
  * DataProxyConfigRepository
  */
@@ -77,23 +76,23 @@ public class DataProxyConfigRepository implements 
IRepository {
     private Map<String, DataProxyClusterSet> clusterSets = new HashMap<>();
 
     // Map<proxyClusterName, ProxyClusterObject>
-    private Map<String, ProxyClusterObject> proxyClusterMap = new HashMap<>();
+    private final Map<String, ProxyClusterObject> proxyClusterMap = new 
HashMap<>();
     // Map<cacheClusterName, CacheClusterObject>
-    private Map<String, CacheClusterObject> cacheClusterMap = new HashMap<>();
+    private final Map<String, CacheClusterObject> cacheClusterMap = new 
HashMap<>();
 
-    private long reloadInterval;
-    private Timer reloadTimer;
+    private long  reloadInterval;
 
     private Gson gson = new Gson();
 
-    public DataProxyConfigRepository() {
+    @PostConstruct
+    public void initialize() {
         LOGGER.info("create repository for {}" + 
DataProxyConfigRepository.class.getSimpleName());
         try {
             this.reloadInterval = DEFAULT_HEARTBEAT_INTERVAL_MS;
             reload();
             setReloadTimer();
         } catch (Throwable t) {
-            LOGGER.error(t.getMessage(), t);
+            LOGGER.error("Initialize DataProxyConfigRepository error", t);
         }
     }
 
@@ -156,7 +155,7 @@ public class DataProxyConfigRepository implements 
IRepository {
      * setReloadTimer
      */
     private void setReloadTimer() {
-        reloadTimer = new Timer(true);
+        Timer reloadTimer = new Timer(true);
         TimerTask task = new 
RepositoryTimerTask<DataProxyConfigRepository>(this);
         reloadTimer.scheduleAtFixedRate(task, reloadInterval, reloadInterval);
     }
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/auth/AuthenticationFilter.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/auth/AuthenticationFilter.java
index 68fec6e..0235174 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/auth/AuthenticationFilter.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/auth/AuthenticationFilter.java
@@ -77,9 +77,7 @@ public class AuthenticationFilter implements Filter {
             ((HttpServletResponse) 
servletResponse).sendError(HttpServletResponse.SC_FORBIDDEN);
             return;
         }
-        LoginUserUtil.setUserLoginInfo((UserDetail) subject.getPrincipal());
-        filterChain.doFilter(servletRequest, servletResponse);
-        LoginUserUtil.removeUserLoginInfo();
+        doFilter(servletRequest, servletResponse, filterChain, (UserDetail) 
subject.getPrincipal());
     }
 
     private void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain filterChain,

Reply via email to