healchow commented on code in PR #6501:
URL: https://github.com/apache/inlong/pull/6501#discussion_r1027063819


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/ElasticsearchClusterOperator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+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.InlongClusterEntity;
+import org.apache.inlong.manager.pojo.cluster.ClusterInfo;
+import org.apache.inlong.manager.pojo.cluster.ClusterRequest;
+import org.apache.inlong.manager.pojo.cluster.es.ElasticsearchClusterInfo;
+import org.apache.inlong.manager.pojo.cluster.es.ElasticsearchClusterRequest;
+import org.apache.inlong.manager.pojo.cluster.es.ElasticsearchClusterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Elasticsearch cluster operator.
+ */
+@Service
+public class ElasticsearchClusterOperator extends AbstractClusterOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ElasticsearchClusterOperator.class);
+
+    @Autowired
+    private ObjectMapper mapper;
+
+    @Override
+    public Boolean accept(String clusterType) {
+        return getClusterType().equals(clusterType);
+    }
+
+    @Override
+    public String getClusterType() {
+        return ClusterType.ELASTICSEARCH;
+    }
+
+    @Override
+    protected void setTargetEntity(ClusterRequest request, InlongClusterEntity 
targetEntity) {
+        ElasticsearchClusterRequest esRequest = (ElasticsearchClusterRequest) 
request;
+        CommonBeanUtils.copyProperties(esRequest, targetEntity, true);
+        try {
+            ElasticsearchClusterDTO dto = 
ElasticsearchClusterDTO.getFromRequest(esRequest);
+            targetEntity.setExtParams(mapper.writeValueAsString(dto));
+            LOGGER.info("success to set entity for es cluster");
+        } catch (Exception e) {
+            throw new 
BusinessException(ErrorCodeEnum.SOURCE_INFO_INCORRECT.getMessage() + ": " + 
e.getMessage());
+        }
+    }
+
+    @Override
+    public ClusterInfo getFromEntity(InlongClusterEntity entity) {
+        if (entity == null) {
+            throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
+        }
+        ElasticsearchClusterInfo info = new ElasticsearchClusterInfo();
+        CommonBeanUtils.copyProperties(entity, info);
+        if (StringUtils.isNotBlank(entity.getExtParams())) {
+            ElasticsearchClusterDTO dto = 
ElasticsearchClusterDTO.getFromJson(entity.getExtParams());
+            CommonBeanUtils.copyProperties(dto, info);
+        }
+        LOGGER.info("success to get es cluster info from entity");

Review Comment:
   Ditto.



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/ElasticsearchClusterOperator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+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.InlongClusterEntity;
+import org.apache.inlong.manager.pojo.cluster.ClusterInfo;
+import org.apache.inlong.manager.pojo.cluster.ClusterRequest;
+import org.apache.inlong.manager.pojo.cluster.es.ElasticsearchClusterInfo;
+import org.apache.inlong.manager.pojo.cluster.es.ElasticsearchClusterRequest;
+import org.apache.inlong.manager.pojo.cluster.es.ElasticsearchClusterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Elasticsearch cluster operator.
+ */
+@Service
+public class ElasticsearchClusterOperator extends AbstractClusterOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ElasticsearchClusterOperator.class);
+
+    @Autowired
+    private ObjectMapper mapper;
+
+    @Override
+    public Boolean accept(String clusterType) {
+        return getClusterType().equals(clusterType);
+    }
+
+    @Override
+    public String getClusterType() {
+        return ClusterType.ELASTICSEARCH;
+    }
+
+    @Override
+    protected void setTargetEntity(ClusterRequest request, InlongClusterEntity 
targetEntity) {
+        ElasticsearchClusterRequest esRequest = (ElasticsearchClusterRequest) 
request;
+        CommonBeanUtils.copyProperties(esRequest, targetEntity, true);
+        try {
+            ElasticsearchClusterDTO dto = 
ElasticsearchClusterDTO.getFromRequest(esRequest);
+            targetEntity.setExtParams(mapper.writeValueAsString(dto));
+            LOGGER.info("success to set entity for es cluster");

Review Comment:
   This is a high-frequency method and is not prone to errors. Even if errors 
occur, there will be exception information. Therefore, it is not recommended to 
print operation logs.



-- 
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: commits-unsubscr...@inlong.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to