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/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new acf3b223dc [INLONG-9586][Manager] Provide installation agent framework 
(#9587)
acf3b223dc is described below

commit acf3b223dcba1a5ef728ec2a3f899132ca1b0f4f
Author: fuweng11 <[email protected]>
AuthorDate: Thu Jan 18 14:46:37 2024 +0800

    [INLONG-9586][Manager] Provide installation agent framework (#9587)
---
 .../manager/pojo/cluster/ClusterNodeRequest.java   |  3 +
 .../service/cluster/InlongClusterService.java      |  2 +
 .../service/cluster/InlongClusterServiceImpl.java  | 28 +++++++++-
 .../node/AgentClusterNodeInstallOperator.java      | 64 ++++++++++++++++++++++
 .../node/InlongClusterNodeInstallOperator.java     | 50 +++++++++++++++++
 .../InlongClusterNodeInstallOperatorFactory.java   | 48 ++++++++++++++++
 .../service/node/doris/DorisDataNodeOperator.java  |  1 -
 .../web/controller/InlongClusterController.java    | 10 +++-
 8 files changed, 203 insertions(+), 3 deletions(-)

diff --git 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterNodeRequest.java
 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterNodeRequest.java
index ac79ea2841..804e8ce068 100644
--- 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterNodeRequest.java
+++ 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterNodeRequest.java
@@ -77,4 +77,7 @@ public class ClusterNodeRequest {
     @NotNull(groups = UpdateValidation.class, message = "version cannot be 
null")
     private Integer version;
 
+    @ApiModelProperty(value = "Whether to proceed with installation")
+    private Boolean isInstall = false;
+
 }
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterService.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterService.java
index 5062e4e730..2696d76afb 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterService.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterService.java
@@ -389,6 +389,8 @@ public interface InlongClusterService {
      */
     Boolean deleteNode(Integer id, String operator);
 
+    Boolean unloadNode(Integer id, String operator);
+
     /**
      * Delete cluster node.
      *
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java
index 6fbc0a8163..2c62c5a35c 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java
@@ -73,6 +73,8 @@ import org.apache.inlong.manager.pojo.tenant.InlongTenantInfo;
 import org.apache.inlong.manager.pojo.user.InlongRoleInfo;
 import org.apache.inlong.manager.pojo.user.LoginUserUtils;
 import org.apache.inlong.manager.pojo.user.UserInfo;
+import 
org.apache.inlong.manager.service.cluster.node.InlongClusterNodeInstallOperator;
+import 
org.apache.inlong.manager.service.cluster.node.InlongClusterNodeInstallOperatorFactory;
 import 
org.apache.inlong.manager.service.cluster.node.InlongClusterNodeOperator;
 import 
org.apache.inlong.manager.service.cluster.node.InlongClusterNodeOperatorFactory;
 import org.apache.inlong.manager.service.repository.DataProxyConfigRepository;
@@ -139,6 +141,8 @@ public class InlongClusterServiceImpl implements 
InlongClusterService {
     private InlongRoleService inlongRoleService;
     @Autowired
     private TenantRoleService tenantRoleService;
+    @Autowired
+    private InlongClusterNodeInstallOperatorFactory 
clusterNodeInstallOperatorFactory;
 
     @Lazy
     @Autowired
@@ -866,7 +870,13 @@ public class InlongClusterServiceImpl implements 
InlongClusterService {
             throw new BusinessException(errMsg);
         }
         InlongClusterNodeOperator instance = 
clusterNodeOperatorFactory.getInstance(request.getType());
-        return instance.saveOpt(request, operator);
+        Integer id = instance.saveOpt(request, operator);
+        if (request.getIsInstall()) {
+            InlongClusterNodeInstallOperator clusterNodeInstallOperator = 
clusterNodeInstallOperatorFactory.getInstance(
+                    request.getType());
+            clusterNodeInstallOperator.install(request, operator);
+        }
+        return id;
     }
 
     @Override
@@ -1068,6 +1078,11 @@ public class InlongClusterServiceImpl implements 
InlongClusterService {
         // update record
         InlongClusterNodeOperator instance = 
clusterNodeOperatorFactory.getInstance(request.getType());
         instance.updateOpt(request, operator);
+        if (request.getIsInstall()) {
+            InlongClusterNodeInstallOperator clusterNodeInstallOperator = 
clusterNodeInstallOperatorFactory.getInstance(
+                    request.getType());
+            clusterNodeInstallOperator.install(request, operator);
+        }
         return true;
     }
 
@@ -1127,6 +1142,17 @@ public class InlongClusterServiceImpl implements 
InlongClusterService {
         return true;
     }
 
+    @Override
+    public Boolean unloadNode(Integer id, String operator) {
+        LOGGER.info("begin to unload inlong cluster node={}, operator={}", id, 
operator);
+        InlongClusterNodeEntity clusterNodeEntity = 
clusterNodeMapper.selectById(id);
+        InlongClusterNodeInstallOperator clusterNodeInstallOperator = 
clusterNodeInstallOperatorFactory.getInstance(
+                clusterNodeEntity.getType());
+        boolean isSuccess = 
clusterNodeInstallOperator.unload(clusterNodeEntity, operator);
+        LOGGER.info("success to unload inlong cluster node={}, operator={}", 
id, operator);
+        return isSuccess;
+    }
+
     @Override
     public Boolean deleteNode(Integer id, UserInfo opInfo) {
         InlongClusterNodeEntity entity = clusterNodeMapper.selectById(id);
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
new file mode 100644
index 0000000000..ae9615eedc
--- /dev/null
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/AgentClusterNodeInstallOperator.java
@@ -0,0 +1,64 @@
+/*
+ * 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.inlong.manager.service.cluster.node;
+
+import org.apache.inlong.manager.common.enums.ClusterType;
+import org.apache.inlong.manager.dao.entity.InlongClusterEntity;
+import org.apache.inlong.manager.dao.entity.InlongClusterNodeEntity;
+import org.apache.inlong.manager.dao.mapper.InlongClusterEntityMapper;
+import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest;
+import org.apache.inlong.manager.pojo.cluster.agent.AgentClusterNodeRequest;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AgentClusterNodeInstallOperator implements 
InlongClusterNodeInstallOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AgentClusterNodeInstallOperator.class);
+
+    @Autowired
+    private InlongClusterEntityMapper clusterEntityMapper;
+
+    @Override
+    public Boolean accept(String clusterType) {
+        return getClusterNodeType().equals(clusterType);
+    }
+
+    @Override
+    public String getClusterNodeType() {
+        return ClusterType.AGENT;
+    }
+
+    @Override
+    public boolean install(ClusterNodeRequest clusterNodeRequest, String 
operator) {
+        // todo Provide agent installation capability
+        AgentClusterNodeRequest agentNodeRequest = (AgentClusterNodeRequest) 
clusterNodeRequest;
+        InlongClusterEntity clusterEntity = 
clusterEntityMapper.selectById(clusterNodeRequest.getParentId());
+        return true;
+    }
+
+    @Override
+    public boolean unload(InlongClusterNodeEntity clusterNodeEntity, String 
operator) {
+        // todo Provide agent uninstallation capability
+        InlongClusterEntity clusterEntity = 
clusterEntityMapper.selectById(clusterNodeEntity.getParentId());
+        return true;
+    }
+}
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
new file mode 100644
index 0000000000..8fcb695bdf
--- /dev/null
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperator.java
@@ -0,0 +1,50 @@
+/*
+ * 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.inlong.manager.service.cluster.node;
+
+import org.apache.inlong.manager.dao.entity.InlongClusterNodeEntity;
+import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest;
+
+public interface InlongClusterNodeInstallOperator {
+
+    /**
+     * Determines whether the current instance matches the specified type.
+     *
+     * @param clusterType cluster type
+     */
+    Boolean accept(String clusterType);
+
+    String getClusterNodeType();
+
+    /**
+     * Installing cluster nodes.
+     *
+     * @param clusterNodeRequest cluster request
+     * @param operator operator
+     */
+    boolean install(ClusterNodeRequest clusterNodeRequest, String operator);
+
+    /**
+     * Uninstalling cluster nodes.
+     *
+     * @param clusterNodeEntity cluster entity
+     * @param operator operator
+     */
+    boolean unload(InlongClusterNodeEntity clusterNodeEntity, String operator);
+
+}
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperatorFactory.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperatorFactory.java
new file mode 100644
index 0000000000..e198e11db0
--- /dev/null
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/InlongClusterNodeInstallOperatorFactory.java
@@ -0,0 +1,48 @@
+/*
+ * 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.inlong.manager.service.cluster.node;
+
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * Factory for {@link InlongClusterNodeInstallOperator}.
+ */
+@Service
+public class InlongClusterNodeInstallOperatorFactory {
+
+    @Autowired
+    private List<InlongClusterNodeInstallOperator> operatorList;
+
+    /**
+     * Get a cluster node install operator instance.
+     *
+     * @param clusterType cluster type
+     */
+    public InlongClusterNodeInstallOperator getInstance(String clusterType) {
+        return operatorList.stream().filter(inst -> inst.accept(clusterType))
+                .findFirst()
+                .orElseThrow(() -> new 
BusinessException(ErrorCodeEnum.CLUSTER_TYPE_NOT_SUPPORTED,
+                        
String.format(ErrorCodeEnum.CLUSTER_TYPE_NOT_SUPPORTED.getMessage(), 
clusterType)));
+    }
+}
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/doris/DorisDataNodeOperator.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/doris/DorisDataNodeOperator.java
index 425f9f6592..e29e2483ef 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/doris/DorisDataNodeOperator.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/doris/DorisDataNodeOperator.java
@@ -46,7 +46,6 @@ public class DorisDataNodeOperator extends 
AbstractDataNodeOperator {
 
     @Override
     public Boolean accept(String dataNodeType) {
-        LOGGER.info("test data type {}, actual type={}", dataNodeType, 
getDataNodeType());
         return getDataNodeType().equals(dataNodeType);
     }
 
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
index 9293ff5ed7..bba545a3df 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
@@ -158,7 +158,7 @@ public class InlongClusterController {
     @PostMapping(value = "/cluster/save")
     @ApiOperation(value = "Save cluster")
     @OperationLog(operation = OperationType.CREATE, operationTarget = 
OperationTarget.CLUSTER)
-    @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+    @RequiresRoles(value = UserRoleCode.TENANT_ADMIN)
     public Response<Integer> save(@Validated(SaveValidation.class) 
@RequestBody ClusterRequest request) {
         String currentUser = LoginUserUtils.getLoginUser().getName();
         return Response.success(clusterService.save(request, currentUser));
@@ -283,6 +283,14 @@ public class InlongClusterController {
         return Response.success(clusterService.deleteNode(id, 
LoginUserUtils.getLoginUser().getName()));
     }
 
+    @RequestMapping(value = "/cluster/node/unload/{id}", method = 
RequestMethod.DELETE)
+    @ApiOperation(value = "Delete cluster node")
+    @OperationLog(operation = OperationType.DELETE, operationTarget = 
OperationTarget.CLUSTER)
+    @ApiImplicitParam(name = "id", value = "Cluster node ID", dataTypeClass = 
Integer.class, required = true)
+    public Response<Boolean> unloadNode(@PathVariable Integer id) {
+        return Response.success(clusterService.unloadNode(id, 
LoginUserUtils.getLoginUser().getName()));
+    }
+
     @PostMapping("/cluster/testConnection")
     @ApiOperation(value = "Test connection for inlong cluster")
     public Response<Boolean> testConnection(@Validated @RequestBody 
ClusterRequest request) {

Reply via email to