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 7fdb4c89a4 [INLONG-9538][Manager] Fix the problem of unable to 
retrieve parameters from ext_params when obtaining dataproxy node information 
(#9539)
7fdb4c89a4 is described below

commit 7fdb4c89a41e37e65efd2e4e1bc8fa2f4e19a205
Author: fuweng11 <[email protected]>
AuthorDate: Thu Dec 28 14:51:24 2023 +0800

    [INLONG-9538][Manager] Fix the problem of unable to retrieve parameters 
from ext_params when obtaining dataproxy node information (#9539)
---
 .../cluster/dataproxy/DataProxyClusterNodeDTO.java | 15 ++--
 .../service/cluster/InlongClusterServiceImpl.java  |  5 +-
 .../cluster/node/DataProxyClusterNodeOperator.java | 93 ++++++++++++++++++++++
 .../service/cluster/InlongClusterServiceTest.java  | 16 +++-
 4 files changed, 119 insertions(+), 10 deletions(-)

diff --git 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/dataproxy/DataProxyClusterNodeDTO.java
 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/dataproxy/DataProxyClusterNodeDTO.java
index 03f7ad27fa..dd14116521 100644
--- 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/dataproxy/DataProxyClusterNodeDTO.java
+++ 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/dataproxy/DataProxyClusterNodeDTO.java
@@ -17,9 +17,9 @@
 
 package org.apache.inlong.manager.pojo.cluster.dataproxy;
 
-import org.apache.inlong.common.heartbeat.ReportResourceType;
 import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
 import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
 import org.apache.inlong.manager.common.util.JsonUtils;
 
 import io.swagger.annotations.ApiModel;
@@ -28,6 +28,7 @@ import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 
 import javax.validation.constraints.NotNull;
 
@@ -42,7 +43,7 @@ import javax.validation.constraints.NotNull;
 public class DataProxyClusterNodeDTO {
 
     @ApiModelProperty("Report source type")
-    private String reportSourceType = ReportResourceType.INLONG;
+    private String reportSourceType = "INLONG";
 
     @ApiModelProperty("Enabled")
     private Boolean enabledOnline = true;
@@ -50,11 +51,11 @@ public class DataProxyClusterNodeDTO {
     /**
      * Get the dto instance from the request
      */
-    public static DataProxyClusterNodeDTO 
getFromRequest(DataProxyClusterNodeRequest request) {
-        return DataProxyClusterNodeDTO.builder()
-                .reportSourceType(request.getReportSourceType())
-                .enabledOnline(request.getEnabledOnline())
-                .build();
+    public static DataProxyClusterNodeDTO 
getFromRequest(DataProxyClusterNodeRequest request, String extParams) {
+        DataProxyClusterNodeDTO dto = StringUtils.isNotBlank(extParams)
+                ? DataProxyClusterNodeDTO.getFromJson(extParams)
+                : new DataProxyClusterNodeDTO();
+        return CommonBeanUtils.copyProperties(request, dto, true);
     }
 
     /**
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 7f8ba98c00..6fbc0a8163 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
@@ -922,7 +922,10 @@ public class InlongClusterServiceImpl implements 
InlongClusterService {
         Page<InlongClusterNodeEntity> entityPage =
                 (Page<InlongClusterNodeEntity>) 
clusterNodeMapper.selectByCondition(request);
         PageResult<ClusterNodeResponse> pageResult = 
PageResult.fromPage(entityPage)
-                .map(entity -> CommonBeanUtils.copyProperties(entity, 
ClusterNodeResponse::new));
+                .map(entity -> {
+                    InlongClusterNodeOperator instance = 
clusterNodeOperatorFactory.getInstance(entity.getType());
+                    return instance.getFromEntity(entity);
+                });
 
         LOGGER.debug("success to list inlong cluster node by {}", request);
         return pageResult;
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/DataProxyClusterNodeOperator.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/DataProxyClusterNodeOperator.java
new file mode 100644
index 0000000000..b31b84d901
--- /dev/null
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/DataProxyClusterNodeOperator.java
@@ -0,0 +1,93 @@
+/*
+ * 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.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.InlongClusterNodeEntity;
+import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest;
+import org.apache.inlong.manager.pojo.cluster.ClusterNodeResponse;
+import 
org.apache.inlong.manager.pojo.cluster.dataproxy.DataProxyClusterNodeDTO;
+import 
org.apache.inlong.manager.pojo.cluster.dataproxy.DataProxyClusterNodeRequest;
+import 
org.apache.inlong.manager.pojo.cluster.dataproxy.DataProxyClusterNodeResponse;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Data proxy cluster node operator.
+ */
+@Slf4j
+@Service
+public class DataProxyClusterNodeOperator extends AbstractClusterNodeOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(DataProxyClusterNodeOperator.class);
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public Boolean accept(String clusterNodeType) {
+        return getClusterNodeType().equals(clusterNodeType);
+    }
+
+    @Override
+    public String getClusterNodeType() {
+        return ClusterType.DATAPROXY;
+    }
+
+    @Override
+    public ClusterNodeResponse getFromEntity(InlongClusterNodeEntity entity) {
+        if (entity == null) {
+            throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
+        }
+
+        DataProxyClusterNodeResponse dataProxyClusterNodeResponse = new 
DataProxyClusterNodeResponse();
+        CommonBeanUtils.copyProperties(entity, dataProxyClusterNodeResponse);
+        if (StringUtils.isNotBlank(entity.getExtParams())) {
+            DataProxyClusterNodeDTO dto = 
DataProxyClusterNodeDTO.getFromJson(entity.getExtParams());
+            CommonBeanUtils.copyProperties(dto, dataProxyClusterNodeResponse);
+        }
+
+        LOGGER.debug("success to get data proxy cluster node info from 
entity");
+        return dataProxyClusterNodeResponse;
+    }
+
+    @Override
+    protected void setTargetEntity(ClusterNodeRequest request, 
InlongClusterNodeEntity targetEntity) {
+        DataProxyClusterNodeRequest dataProxyClusterNodeRequest = 
(DataProxyClusterNodeRequest) request;
+        CommonBeanUtils.copyProperties(dataProxyClusterNodeRequest, 
targetEntity, true);
+        try {
+            DataProxyClusterNodeDTO dto = 
DataProxyClusterNodeDTO.getFromRequest(dataProxyClusterNodeRequest,
+                    targetEntity.getExtParams());
+            targetEntity.setExtParams(objectMapper.writeValueAsString(dto));
+            LOGGER.debug("success to set entity for data proxy cluster node");
+        } catch (Exception e) {
+            throw new BusinessException(ErrorCodeEnum.CLUSTER_INFO_INCORRECT,
+                    String.format("serialize extParams of Data proxy 
ClusterNode failure: %s", e.getMessage()));
+        }
+    }
+
+}
diff --git 
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceTest.java
 
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceTest.java
index 870b7e967e..d8c0224f36 100644
--- 
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceTest.java
+++ 
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceTest.java
@@ -29,6 +29,7 @@ import org.apache.inlong.manager.pojo.cluster.ClusterInfo;
 import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest;
 import org.apache.inlong.manager.pojo.cluster.ClusterNodeResponse;
 import org.apache.inlong.manager.pojo.cluster.ClusterPageRequest;
+import 
org.apache.inlong.manager.pojo.cluster.dataproxy.DataProxyClusterNodeRequest;
 import 
org.apache.inlong.manager.pojo.cluster.dataproxy.DataProxyClusterRequest;
 import org.apache.inlong.manager.pojo.cluster.pulsar.PulsarClusterInfo;
 import org.apache.inlong.manager.pojo.cluster.pulsar.PulsarClusterRequest;
@@ -159,6 +160,17 @@ public class InlongClusterServiceTest extends 
ServiceBaseTest {
         return clusterService.saveNode(request, GLOBAL_OPERATOR);
     }
 
+    public Integer saveDataProxyClusterNode(Integer parentId, String type, 
String ip, Integer port,
+            String protocolType) {
+        DataProxyClusterNodeRequest request = new 
DataProxyClusterNodeRequest();
+        request.setParentId(parentId);
+        request.setType(type);
+        request.setIp(ip);
+        request.setPort(port);
+        request.setProtocolType(protocolType);
+        return clusterService.saveNode(request, GLOBAL_OPERATOR);
+    }
+
     /**
      * List cluster nodes by page.
      */
@@ -348,11 +360,11 @@ public class InlongClusterServiceTest extends 
ServiceBaseTest {
         // save cluster node
         String ip = "127.0.0.1";
         Integer port1 = 46800;
-        Integer nodeId1 = this.saveClusterNode(id, ClusterType.DATAPROXY, ip, 
port1, ProtocolType.TCP);
+        Integer nodeId1 = this.saveDataProxyClusterNode(id, 
ClusterType.DATAPROXY, ip, port1, ProtocolType.TCP);
         Assertions.assertNotNull(nodeId1);
 
         Integer port2 = 46801;
-        Integer nodeId2 = this.saveClusterNode(id, ClusterType.DATAPROXY, ip, 
port2, ProtocolType.TCP);
+        Integer nodeId2 = this.saveDataProxyClusterNode(id, 
ClusterType.DATAPROXY, ip, port2, ProtocolType.TCP);
         Assertions.assertNotNull(nodeId2);
 
         // create an inlong group which use the clusterTag

Reply via email to