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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3e8afd7ce1 [INLONG-10907][Manager] Support reinstalling the installer 
(#10909)
3e8afd7ce1 is described below

commit 3e8afd7ce191cd7ef32c3b689e40e09216f79854
Author: fuweng11 <76141879+fuwen...@users.noreply.github.com>
AuthorDate: Tue Aug 27 12:32:21 2024 +0800

    [INLONG-10907][Manager] Support reinstalling the installer (#10909)
---
 .../node/AgentClusterNodeInstallOperator.java      | 91 +++++++++++++++-------
 .../node/InlongClusterNodeInstallOperator.java     |  8 ++
 .../manager/service/cmd/CommandExecutor.java       |  3 +
 .../manager/service/cmd/CommandExecutorImpl.java   |  5 ++
 4 files changed, 79 insertions(+), 28 deletions(-)

diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/AgentClusterNodeInstallOperator.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/AgentClusterNodeInstallOperator.java
index d9ace7ab90..77a848dbb6 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/AgentClusterNodeInstallOperator.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/AgentClusterNodeInstallOperator.java
@@ -21,6 +21,7 @@ import org.apache.inlong.manager.common.enums.ClusterType;
 import org.apache.inlong.manager.common.enums.ModuleType;
 import org.apache.inlong.manager.common.exceptions.BusinessException;
 import org.apache.inlong.manager.common.util.AESUtils;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
 import org.apache.inlong.manager.common.util.Preconditions;
 import org.apache.inlong.manager.dao.entity.InlongClusterEntity;
 import org.apache.inlong.manager.dao.entity.InlongClusterNodeEntity;
@@ -33,6 +34,7 @@ import 
org.apache.inlong.manager.dao.mapper.ModuleConfigEntityMapper;
 import org.apache.inlong.manager.dao.mapper.PackageConfigEntityMapper;
 import org.apache.inlong.manager.dao.mapper.UserEntityMapper;
 import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest;
+import org.apache.inlong.manager.pojo.cluster.agent.AgentClusterNodeDTO;
 import org.apache.inlong.manager.pojo.cluster.agent.AgentClusterNodeRequest;
 import org.apache.inlong.manager.service.cmd.CommandExecutor;
 
@@ -43,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
@@ -50,17 +53,17 @@ import java.util.Objects;
 @Service
 public class AgentClusterNodeInstallOperator implements 
InlongClusterNodeInstallOperator {
 
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(AgentClusterNodeInstallOperator.class);
-
     public static final String INSTALLER_CONF_PATH = 
"/conf/installer.properties";
     public static final String INSTALLER_START_CMD = "/bin/installer.sh start";
+    public static final String INSTALLER_RESTART_CMD = "/bin/installer.sh 
restart";
+    public static final String INSTALLER_STOP_CMD = "/bin/installer.sh 
restart";
     public static final String AGENT_MANAGER_AUTH_SECRET_ID = 
"agent.manager.auth.secretId";
     public static final String AGENT_MANAGER_AUTH_SECRET_KEY = 
"agent.manager.auth.secretKey";
     public static final String AGENT_MANAGER_ADDR = "agent.manager.addr";
     public static final String AGENT_CLUSTER_NAME = "agent.cluster.name";
     public static final String AGENT_CLUSTER_TAG = "agent.cluster.tag";
     public static final String AGENT_LOCAL_IP = "agent.local.ip";
-
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AgentClusterNodeInstallOperator.class);
     @Autowired
     private InlongClusterEntityMapper clusterEntityMapper;
     @Autowired
@@ -91,45 +94,55 @@ public class AgentClusterNodeInstallOperator implements 
InlongClusterNodeInstall
 
     @Override
     public boolean install(ClusterNodeRequest clusterNodeRequest, String 
operator) {
-        LOGGER.info("begin to insert agent inlong cluster node={}", 
clusterNodeRequest);
+        LOGGER.info("begin to insert agent cluster node={}", 
clusterNodeRequest);
         try {
-            InlongClusterEntity clusterEntity = 
clusterEntityMapper.selectById(clusterNodeRequest.getParentId());
             AgentClusterNodeRequest request = (AgentClusterNodeRequest) 
clusterNodeRequest;
-            commandExecutor.mkdir(request, agentInstallPath);
-            String downLoadUrl = getInstallerDownLoadUrl(request);
-            String fileName = 
downLoadUrl.substring(downLoadUrl.lastIndexOf('/') + 1);
-            commandExecutor.downLoadPackage(request, agentInstallPath, 
downLoadUrl);
-            commandExecutor.tarPackage(request, fileName, agentInstallPath);
-            String confFile = agentInstallPath + INSTALLER_CONF_PATH;
-            Map<String, String> configMap = new HashMap<>();
-            configMap.put(AGENT_LOCAL_IP, request.getIp());
-            configMap.put(AGENT_MANAGER_ADDR, managerUrl);
-            UserEntity userInfo = userEntityMapper.selectByName(operator);
-            Preconditions.expectNotNull(userInfo, "User doesn't exist");
-            String secretKey =
-                    new 
String(AESUtils.decryptAsString(userInfo.getSecretKey(), 
userInfo.getEncryptVersion()));
-            configMap.put(AGENT_MANAGER_AUTH_SECRET_ID, operator);
-            configMap.put(AGENT_MANAGER_AUTH_SECRET_KEY, secretKey);
-            configMap.put(AGENT_CLUSTER_TAG, clusterEntity.getClusterTags());
-            configMap.put(AGENT_CLUSTER_NAME, clusterEntity.getName());
-            commandExecutor.modifyConfig(request, configMap, confFile);
+            deployInstaller(request, operator);
+        } catch (Exception e) {
+            
clusterNodeEntityMapper.updateOperateLogById(clusterNodeRequest.getId(), 
e.getMessage());
+            String errMsg = String.format("install agent cluster node failed 
for ip=%s", clusterNodeRequest.getIp());
+            LOGGER.error(errMsg, e);
+            throw new BusinessException(errMsg);
+        }
+        LOGGER.info("success to install agent cluster node={}", 
clusterNodeRequest);
+        return true;
+    }
+
+    @Override
+    public boolean reInstall(ClusterNodeRequest clusterNodeRequest, String 
operator) {
+        LOGGER.info("begin to reInstall agent cluster node={}", 
clusterNodeRequest);
+        try {
+            AgentClusterNodeRequest request = (AgentClusterNodeRequest) 
clusterNodeRequest;
+            commandExecutor.rmDir(request, agentInstallPath.substring(0, 
agentInstallPath.lastIndexOf(File.separator)));
+            deployInstaller(request, operator);
             String startCmd = agentInstallPath + INSTALLER_START_CMD;
             commandExecutor.execRemote(request, startCmd);
-
         } catch (Exception e) {
             
clusterNodeEntityMapper.updateOperateLogById(clusterNodeRequest.getId(), 
e.getMessage());
-            String errMsg = String.format("install installer failed for 
ip=%s", clusterNodeRequest.getIp());
+            String errMsg = String.format("reInstall agent cluster node failed 
for ip=%s", clusterNodeRequest.getIp());
             LOGGER.error(errMsg, e);
             throw new BusinessException(errMsg);
         }
-        LOGGER.info("success to insert agent inlong cluster node={}", 
clusterNodeRequest);
+        LOGGER.info("success to re reInstall agent cluster node={}", 
clusterNodeRequest);
         return true;
     }
 
     @Override
     public boolean unload(InlongClusterNodeEntity clusterNodeEntity, String 
operator) {
-        // todo Provide agent uninstallation capability
-        InlongClusterEntity clusterEntity = 
clusterEntityMapper.selectById(clusterNodeEntity.getParentId());
+        try {
+            AgentClusterNodeRequest request = 
CommonBeanUtils.copyProperties(clusterNodeEntity,
+                    AgentClusterNodeRequest::new, true);
+            AgentClusterNodeDTO agentClusterNodeDTO = 
AgentClusterNodeDTO.getFromJson(clusterNodeEntity.getExtParams());
+            CommonBeanUtils.copyProperties(agentClusterNodeDTO, request, true);
+            String stopCmd = agentInstallPath + INSTALLER_STOP_CMD;
+            commandExecutor.execRemote(request, stopCmd);
+            commandExecutor.rmDir(request, agentInstallPath.substring(0, 
agentInstallPath.lastIndexOf(File.separator)));
+        } catch (Exception e) {
+            
clusterNodeEntityMapper.updateOperateLogById(clusterNodeEntity.getId(), 
e.getMessage());
+            String errMsg = String.format("unload agent cluster node failed 
for ip=%s", clusterNodeEntity.getIp());
+            LOGGER.error(errMsg, e);
+            throw new BusinessException(errMsg);
+        }
         return true;
     }
 
@@ -151,4 +164,26 @@ public class AgentClusterNodeInstallOperator implements 
InlongClusterNodeInstall
                 String.format("can't get installer download url for ip=%s, 
type=%s", request.getIp(),
                         request.getType()));
     }
+
+    private void deployInstaller(AgentClusterNodeRequest request, String 
operator) throws Exception {
+        InlongClusterEntity clusterEntity = 
clusterEntityMapper.selectById(request.getParentId());
+        commandExecutor.mkdir(request, agentInstallPath);
+        String downLoadUrl = getInstallerDownLoadUrl(request);
+        String fileName = downLoadUrl.substring(downLoadUrl.lastIndexOf('/') + 
1);
+        commandExecutor.downLoadPackage(request, agentInstallPath, 
downLoadUrl);
+        commandExecutor.tarPackage(request, fileName, agentInstallPath);
+        String confFile = agentInstallPath + INSTALLER_CONF_PATH;
+        Map<String, String> configMap = new HashMap<>();
+        configMap.put(AGENT_LOCAL_IP, request.getIp());
+        configMap.put(AGENT_MANAGER_ADDR, managerUrl);
+        UserEntity userInfo = userEntityMapper.selectByName(operator);
+        Preconditions.expectNotNull(userInfo, "User doesn't exist");
+        String secretKey =
+                new String(AESUtils.decryptAsString(userInfo.getSecretKey(), 
userInfo.getEncryptVersion()));
+        configMap.put(AGENT_MANAGER_AUTH_SECRET_ID, operator);
+        configMap.put(AGENT_MANAGER_AUTH_SECRET_KEY, secretKey);
+        configMap.put(AGENT_CLUSTER_TAG, clusterEntity.getClusterTags());
+        configMap.put(AGENT_CLUSTER_NAME, clusterEntity.getName());
+        commandExecutor.modifyConfig(request, configMap, confFile);
+    }
 }
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperator.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperator.java
index 8fcb695bdf..851d085eee 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperator.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperator.java
@@ -39,6 +39,14 @@ public interface InlongClusterNodeInstallOperator {
      */
     boolean install(ClusterNodeRequest clusterNodeRequest, String operator);
 
+    /**
+     * ReInstalling cluster nodes.
+     *
+     * @param clusterNodeRequest cluster request
+     * @param operator operator
+     */
+    boolean reInstall(ClusterNodeRequest clusterNodeRequest, String operator);
+
     /**
      * Uninstalling cluster nodes.
      *
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutor.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutor.java
index ef44719d7e..6a565fb1c5 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutor.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutor.java
@@ -39,4 +39,7 @@ public interface CommandExecutor {
             throws Exception;
 
     CommandResult mkdir(AgentClusterNodeRequest clusterNodeRequest, String 
path) throws Exception;
+
+    CommandResult rmDir(AgentClusterNodeRequest clusterNodeRequest, String 
path) throws Exception;
+
 }
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutorImpl.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutorImpl.java
index 1ce4069fe1..804d04e4b6 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutorImpl.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cmd/CommandExecutorImpl.java
@@ -139,4 +139,9 @@ public class CommandExecutorImpl implements CommandExecutor 
{
         return execRemote(clusterNodeRequest, "mkdir " + path);
     }
 
+    @Override
+    public CommandResult rmDir(AgentClusterNodeRequest clusterNodeRequest, 
String path) throws Exception {
+        return execRemote(clusterNodeRequest, "rm -rf " + path);
+    }
+
 }

Reply via email to