caishunfeng commented on code in PR #12736:
URL: 
https://github.com/apache/dolphinscheduler/pull/12736#discussion_r1021028685


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRemoteHostController.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.api.controller;
+
+import static 
org.apache.dolphinscheduler.api.enums.Status.CREATE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.DELETE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_REMOTE_HOST_PAGE_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.SUCCESS;
+import static org.apache.dolphinscheduler.api.enums.Status.TEST_CONNECT_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.UPDATE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.VARIFY_TASK_REMOTE_HOST_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.TaskRemoteHostDTO;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.TaskRemoteHostService;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.api.vo.TaskRemoteHostVO;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
+/**
+ * task remote host controller
+ */
+@Tag(name = "TASK_REMOTE_HOST_TAG")
+@RestController
+@RequestMapping("/remote_host")
+public class TaskRemoteHostController {
+
+    @Autowired
+    private TaskRemoteHostService taskRemoteHostService;
+
+    @Operation(summary = "createTaskRemoteHost", description = 
"CREATE_TASK_REMOTE_HOST_NOTES")
+    @PostMapping(value = "/create")

Review Comment:
   maybe it should remove the value dut to default PostMapping means `create`? 
cc @zhongjiajie 
   ```suggestion
       @PostMapping()
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRemoteHostController.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.api.controller;
+
+import static 
org.apache.dolphinscheduler.api.enums.Status.CREATE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.DELETE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_REMOTE_HOST_PAGE_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.SUCCESS;
+import static org.apache.dolphinscheduler.api.enums.Status.TEST_CONNECT_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.UPDATE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.VARIFY_TASK_REMOTE_HOST_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.TaskRemoteHostDTO;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.TaskRemoteHostService;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.api.vo.TaskRemoteHostVO;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
+/**
+ * task remote host controller
+ */
+@Tag(name = "TASK_REMOTE_HOST_TAG")
+@RestController
+@RequestMapping("/remote_host")
+public class TaskRemoteHostController {
+
+    @Autowired
+    private TaskRemoteHostService taskRemoteHostService;
+
+    @Operation(summary = "createTaskRemoteHost", description = 
"CREATE_TASK_REMOTE_HOST_NOTES")
+    @PostMapping(value = "/create")
+    @ResponseStatus(HttpStatus.CREATED)
+    @ApiException(CREATE_TASK_REMOTE_HOST_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result createTaskRemoteHost(@Parameter(hidden = true) 
@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                       @RequestBody TaskRemoteHostDTO 
taskRemoteHostDTO) {
+        int result = taskRemoteHostService.createTaskRemoteHost(loginUser, 
taskRemoteHostDTO);
+        return result > 0 ? Result.success() : 
Result.error(CREATE_TASK_REMOTE_HOST_ERROR);
+    }
+
+    @Operation(summary = "updateTaskRemoteHost", description = 
"UPDATE_TASK_REMOTE_HOST_NOTES")
+    @PutMapping(value = "/update/{code}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(UPDATE_TASK_REMOTE_HOST_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result updateTaskRemoteHost(@Parameter(hidden = true) 
@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                       @PathVariable("code") Long code,
+                                       @RequestBody TaskRemoteHostDTO 
taskRemoteHostDTO) {
+        int result = taskRemoteHostService.updateTaskRemoteHost(code, 
loginUser, taskRemoteHostDTO);
+        return result > 0 ? Result.success() : 
Result.error(UPDATE_TASK_REMOTE_HOST_ERROR);
+    }
+
+    @Operation(summary = "delete", description = 
"DELETE_TASK_REMOTE_HOST_NOTES")
+    @Parameters({
+            @Parameter(name = "code", description = "TASK_REMOTE_HOST_CODE", 
schema = @Schema(implementation = long.class, example = "123456", required = 
true))
+    })
+    @PostMapping(value = "/delete")

Review Comment:
   ```suggestion
       @DeleteMapping(value = "/delete")
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java:
##########
@@ -190,11 +220,105 @@ public TaskResponse run(String execCommand) throws 
IOException, InterruptedExcep
             return result;
         }
 
+        if (bashTaskExecutionContext.getSessionHost() != null) {
+            runningOnSSH = true;
+        }
+
+        if (runningOnSSH && SystemUtils.IS_OS_WINDOWS) {
+            logger.error("SSH does not support Windows systems");
+            
TaskExecutionContextCacheManager.removeByTaskInstanceId(taskInstanceId);
+            return result;
+        }
+
         String commandFilePath = buildCommandFilePath();
 
         // create command file if not exists
         createCommandFileIfNotExists(execCommand, commandFilePath);
 
+        result = runCommandFile(commandFilePath);
+
+        return result;
+    }
+
+    private TaskResponse runCommandFile(String commandFilePath) throws 
IOException, InterruptedException {
+        return runningOnSSH ? runOnSSH(commandFilePath) : 
runOnLocalProcess(commandFilePath);
+    }
+
+    private TaskResponse runOnSSH(String commandFilePath) {
+        TaskResponse result = new TaskResponse();
+        SSHSessionHolder sessionHolder = null;
+        this.sessionHost = bashTaskExecutionContext.getSessionHost();
+        try {
+            sessionHolder = SSHSessionPool.getSessionHolder(sessionHost);
+            sessionHolder.setSftpConfig(SSHSessionPool.getSftpConfig());
+            logger.info("borrow session:{} success", sessionHolder);
+
+            boolean uploadRes =
+                    sessionHolder.sftpDir(taskRequest.getExecutePath(), 
taskRequest.getExecutePath(), logger);
+            if (!uploadRes) {
+                logger.error("upload task {} execute path to remote session {} 
failed", taskRequest.getExecutePath(),
+                        sessionHost.toString());
+                result.setExitStatusCode(EXIT_CODE_FAILURE);
+                return result;
+            }
+
+            if (taskRequest.getEnvFile() != null) {
+                boolean uploadEnvRes =
+                        sessionHolder.sftpDir(taskRequest.getEnvFile(), 
taskRequest.getExecutePath(), logger);
+                if (!uploadEnvRes) {
+                    logger.error("upload task {} execute path to remote 
session {} failed", taskRequest.getEnvFile(),
+                            sessionHost.toString());
+                    result.setExitStatusCode(EXIT_CODE_FAILURE);
+                    return result;
+                }
+            }
+
+            // because JSch .chmod is not stable, so use the 'chmod -R' instead
+            logger.info("update remote path's permission:{} on session:{} to 
755", taskRequest.getExecutePath(),
+                    sessionHost.toString());
+            String chmodCommand = "chmod -R 755 " + 
taskRequest.getExecutePath();

Review Comment:
   Why it should chmod 755? I'm not sure whether it will cause some CVE? cc 
@ruanwenjun 



##########
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql:
##########
@@ -2032,3 +2032,24 @@ CREATE TABLE t_ds_fav_task
     user_id   int         NOT NULL,
     PRIMARY KEY (id)
 );
+
+--
+-- Table structure for t_ds_task_remote_host
+--
+
+DROP TABLE IF EXISTS t_ds_task_remote_host CASCADE;
+CREATE TABLE t_ds_task_remote_host
+(
+    id                   int      NOT NULL   AUTO_INCREMENT,
+    code                 bigint(20)          NOT NULL ,
+    name        varchar(100)    NOT NULL ,
+    ip          varchar(100)    NOT NULL ,
+    port        int             NOT NULL ,
+    account        varchar(100)    NOT NULL ,
+    password    varchar(64)     NOT NULL ,
+    operator             int             DEFAULT NULL ,
+    description          text,
+    create_time          timestamp       DEFAULT NULL ,
+    update_time          timestamp       DEFAULT NULL ,
+    PRIMARY KEY (id)

Review Comment:
   format



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/ssh/PooledSSHSessionFactory.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.plugin.task.api.ssh;
+
+import org.apache.dolphinscheduler.plugin.task.api.model.SSHSessionHost;
+
+import org.apache.commons.pool2.BaseKeyedPooledObjectFactory;
+import org.apache.commons.pool2.DestroyMode;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ACP SSH Session factory
+ */
+public class PooledSSHSessionFactory extends 
BaseKeyedPooledObjectFactory<SSHSessionHost, SSHSessionHolder> {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(PooledSSHSessionFactory.class);
+
+    @Override
+    public SSHSessionHolder create(SSHSessionHost sshSessionHost) throws 
Exception {
+        SSHSessionHolder pooledObject = new SSHSessionHolder(sshSessionHost);
+        pooledObject.connect();
+        return pooledObject;
+    }
+
+    @Override
+    public PooledObject<SSHSessionHolder> wrap(SSHSessionHolder 
sshSessionHolder) {
+        return new DefaultPooledObject<>(sshSessionHolder);
+    }
+
+    @Override
+    public void destroyObject(SSHSessionHost key, 
PooledObject<SSHSessionHolder> p,
+                              DestroyMode destroyMode) throws Exception {
+        logger.info("destroy session {}", p.getObject().toString());
+        p.getObject().disconnect();
+    }
+
+    @Override
+    public boolean validateObject(SSHSessionHost key, 
PooledObject<SSHSessionHolder> p) {
+        if (p.getObject().isConnected()) {
+            try {
+                p.getObject().keepAlive();
+                return true;
+            } catch (Exception e) {
+                logger.error("Cannot send alive msg to session of {}", 
p.getObject().toString(), e);

Review Comment:
   ```suggestion
                   logger.error("Cannot send alive msg to session of {}", 
p.getObject(), e);
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskRemoteHostController.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.api.controller;
+
+import static 
org.apache.dolphinscheduler.api.enums.Status.CREATE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.DELETE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_REMOTE_HOST_PAGE_ERROR;
+import static org.apache.dolphinscheduler.api.enums.Status.SUCCESS;
+import static org.apache.dolphinscheduler.api.enums.Status.TEST_CONNECT_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.UPDATE_TASK_REMOTE_HOST_ERROR;
+import static 
org.apache.dolphinscheduler.api.enums.Status.VARIFY_TASK_REMOTE_HOST_ERROR;
+
+import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
+import org.apache.dolphinscheduler.api.dto.TaskRemoteHostDTO;
+import org.apache.dolphinscheduler.api.exceptions.ApiException;
+import org.apache.dolphinscheduler.api.service.TaskRemoteHostService;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.api.vo.TaskRemoteHostVO;
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
+/**
+ * task remote host controller
+ */
+@Tag(name = "TASK_REMOTE_HOST_TAG")
+@RestController
+@RequestMapping("/remote_host")
+public class TaskRemoteHostController {
+
+    @Autowired
+    private TaskRemoteHostService taskRemoteHostService;
+
+    @Operation(summary = "createTaskRemoteHost", description = 
"CREATE_TASK_REMOTE_HOST_NOTES")
+    @PostMapping(value = "/create")
+    @ResponseStatus(HttpStatus.CREATED)
+    @ApiException(CREATE_TASK_REMOTE_HOST_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result createTaskRemoteHost(@Parameter(hidden = true) 
@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                                       @RequestBody TaskRemoteHostDTO 
taskRemoteHostDTO) {
+        int result = taskRemoteHostService.createTaskRemoteHost(loginUser, 
taskRemoteHostDTO);
+        return result > 0 ? Result.success() : 
Result.error(CREATE_TASK_REMOTE_HOST_ERROR);
+    }
+
+    @Operation(summary = "updateTaskRemoteHost", description = 
"UPDATE_TASK_REMOTE_HOST_NOTES")
+    @PutMapping(value = "/update/{code}")

Review Comment:
   same here, the PutMapping is update action defaultly.
   ```suggestion
       @PutMapping(value = "/{code}")
   ```



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskRemoteHostServiceImpl.java:
##########
@@ -0,0 +1,281 @@
+/*
+ * 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.api.service.impl;
+
+import static 
org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_REMOTE_HOST_CREATE;
+import static 
org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_REMOTE_HOST_DELETE;
+import static 
org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_REMOTE_HOST_EDIT;
+
+import org.apache.dolphinscheduler.api.dto.TaskRemoteHostDTO;
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ServiceException;
+import org.apache.dolphinscheduler.api.service.TaskRemoteHostService;
+import org.apache.dolphinscheduler.api.utils.PageInfo;
+import org.apache.dolphinscheduler.api.vo.TaskRemoteHostVO;
+import org.apache.dolphinscheduler.common.enums.AuthorizationType;
+import org.apache.dolphinscheduler.common.enums.UserType;
+import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
+import 
org.apache.dolphinscheduler.common.utils.CodeGenerateUtils.CodeGenerateException;
+import org.apache.dolphinscheduler.common.utils.NetUtils;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.dao.entity.TaskRemoteHost;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
+import org.apache.dolphinscheduler.dao.mapper.TaskRemoteHostMapper;
+import org.apache.dolphinscheduler.plugin.task.api.model.SSHSessionHost;
+import 
org.apache.dolphinscheduler.plugin.task.api.ssh.DSSessionAbandonedConfig;
+import org.apache.dolphinscheduler.plugin.task.api.ssh.DSSessionPoolConfig;
+import org.apache.dolphinscheduler.plugin.task.api.ssh.SSHResponse;
+import org.apache.dolphinscheduler.plugin.task.api.ssh.SSHSessionHolder;
+import org.apache.dolphinscheduler.plugin.task.api.ssh.SSHSessionPool;
+import org.apache.dolphinscheduler.service.utils.Constants;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+@Service
+public class TaskRemoteHostServiceImpl extends BaseServiceImpl implements 
TaskRemoteHostService {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(TaskRemoteHostServiceImpl.class);
+
+    @Autowired
+    private TaskRemoteHostMapper taskRemoteHostMapper;
+
+    @Autowired
+    private TaskInstanceMapper taskInstanceMapper;
+
+    @Override
+    @Transactional
+    public int createTaskRemoteHost(User loginUser, TaskRemoteHostDTO 
taskRemoteHostDTO) {
+        checkTaskRemoteHostDTO(taskRemoteHostDTO);
+
+        checkOperatorPermissions(loginUser, null, 
AuthorizationType.TASK_REMOTE_TASK, TASK_REMOTE_HOST_CREATE);
+
+        if (isExistSameName(taskRemoteHostDTO.getName())) {
+            throw new ServiceException(Status.TASK_REMOTE_HOST_EXIST, 
taskRemoteHostDTO.getName());
+        }
+
+        TaskRemoteHost remoteHost = new TaskRemoteHost();
+        BeanUtils.copyProperties(taskRemoteHostDTO, remoteHost);
+        long remoteHostCode;
+        try {
+            remoteHostCode = CodeGenerateUtils.getInstance().genCode();
+        } catch (CodeGenerateException e) {
+            throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
+        }
+        remoteHost.setCode(remoteHostCode);
+        remoteHost.setOperator(loginUser.getId());
+        remoteHost.setCreateTime(new Date());
+        remoteHost.setUpdateTime(new Date());
+
+        int result = taskRemoteHostMapper.insert(remoteHost);
+        if (result > 0) {
+            permissionPostHandle(AuthorizationType.TASK_REMOTE_TASK, 
loginUser.getId(),
+                    Collections.singletonList(remoteHost.getId()), logger);
+            logger.info("Create remote host successes, host name {}.", 
remoteHost.getName());
+        }

Review Comment:
   In this case, I think checking result > 0 is meanless, due to not multi db 
write operations after inserting. Defaultly, it will success if no exception. 
WDYT?
   ```suggestion
           taskRemoteHostMapper.insert(remoteHost);
           permissionPostHandle(AuthorizationType.TASK_REMOTE_TASK, 
loginUser.getId(),
                     Collections.singletonList(remoteHost.getId()), logger);
           logger.info("Create remote host successes, host name {}.", 
remoteHost.getName());
           
   ```



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