kezhenxu94 commented on a change in pull request #5983:
URL: https://github.com/apache/dolphinscheduler/pull/5983#discussion_r693432776



##########
File path: 
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/AsyncStreamThread.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.dolphinscheduler.common.thread;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * StreamGobbler
+ */
+public class AsyncStreamThread extends Thread {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(AsyncStreamThread.class);
+
+    private final InputStream inputStream;
+
+    public AsyncStreamThread(InputStream inputStream) {
+        this.inputStream = inputStream;
+    }
+
+    @Override
+    public void run() {
+        InputStreamReader inputStreamReader = null;
+        BufferedReader inputBufferReader = null;
+
+        try {
+            inputStreamReader = new InputStreamReader(inputStream);
+            inputBufferReader = new BufferedReader(inputStreamReader);
+            String line;

Review comment:
       Use `try-with-resources` syntax

##########
File path: 
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/AsyncStreamThread.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.dolphinscheduler.common.thread;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * StreamGobbler
+ */
+public class AsyncStreamThread extends Thread {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(AsyncStreamThread.class);
+
+    private final InputStream inputStream;
+
+    public AsyncStreamThread(InputStream inputStream) {
+        this.inputStream = inputStream;
+    }
+
+    @Override
+    public void run() {
+        InputStreamReader inputStreamReader = null;
+        BufferedReader inputBufferReader = null;
+
+        try {
+            inputStreamReader = new InputStreamReader(inputStream);
+            inputBufferReader = new BufferedReader(inputStreamReader);
+            String line;
+            StringBuilder output = new StringBuilder();
+            while ((line = inputBufferReader.readLine()) != null) {
+                output.append(line);
+                output.append(System.getProperty("line.separator"));
+            }
+            if (output.length() > 0) {
+                logger.info("out put msg is{}", output);

Review comment:
       ```suggestion
                   logger.info("out put msg is {}", output);
   ```

##########
File path: 
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/log/LoggerRequestProcessor.java
##########
@@ -96,26 +99,26 @@ public void process(Channel channel, Command command) {
                 for (String line : lines) {
                     builder.append(line + "\r\n");
                 }
-                RollViewLogResponseCommand rollViewLogRequestResponse = new 
RollViewLogResponseCommand(builder.toString());
-                
channel.writeAndFlush(rollViewLogRequestResponse.convert2Command(command.getOpaque()));
+                RollViewLogResponseCommand rollViewLogRequestResponse = new 
RollViewLogResponseCommand(
+                        builder.toString());
+                channel
+                        
.writeAndFlush(rollViewLogRequestResponse.convert2Command(command.getOpaque()));
                 break;
             case REMOVE_TAK_LOG_REQUEST:
                 RemoveTaskLogRequestCommand removeTaskLogRequest = 
JSONUtils.parseObject(
                         command.getBody(), RemoveTaskLogRequestCommand.class);
-
-                String taskLogPath = removeTaskLogRequest.getPath();
-
-                File taskLogFile = new File(taskLogPath);
+                List<String> taskLogPaths = removeTaskLogRequest.getPath();
+                OsSystemNativeCommand os = new LinuxSystem();
+                String cmd = "";
+                for (String path : taskLogPaths) {
+                    cmd += os.deleteCmd() + path + ";";
+                }

Review comment:
       I personally don't think manipulating the command is better than JDK 
APIs, and you should know manipulating the strings to a system command is 
dangerous and can be injected malicious codes as well

##########
File path: 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
##########
@@ -304,17 +319,20 @@ public Result queryProcessInstanceList(User loginUser, 
String projectName, Integ
      * @throws IOException io exception
      */
     @Override
-    public Map<String, Object> queryTaskListByProcessId(User loginUser, String 
projectName, Integer processId) throws IOException {
+    public Map<String, Object> queryTaskListByProcessId(User loginUser, String 
projectName,
+                                                        Integer processId) 
throws IOException {
         Map<String, Object> result = new HashMap<>();
         Project project = projectMapper.queryByName(projectName);
 
-        Map<String, Object> checkResult = 
projectService.checkProjectAndAuth(loginUser, project, projectName);
+        Map<String, Object> checkResult = projectService
+                .checkProjectAndAuth(loginUser, project, projectName);

Review comment:
       This code style is not better than before

##########
File path: 
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/MapUtils.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.dolphinscheduler.common.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class MapUtils {
+
+    public static void putAll(Map<String, List<String>> originMap,
+                                  Map<String, List<String>> newMap) {
+        for (String key : newMap.keySet()) {
+            List<String> filePaths = originMap.get(key);
+            if (filePaths == null) {
+                filePaths = new ArrayList<>();
+                originMap.put(key, filePaths);
+            }
+            filePaths.addAll(newMap.get(key));
+        }
+    }
+}

Review comment:
       This is an overuse of util class in my opinion, it's just a one-line 
codes and not a common case, I don't know who else will use this util class 
because it seems that this function is only used in your case.
   
   ```java
   newMap.forEach((key, val) -> originMap.computeIfAbsent(key, __ -> new 
ArrayList<>()).addAll(val));
   ```




-- 
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]


Reply via email to