Pil0tXia commented on code in PR #52:
URL: 
https://github.com/apache/eventmesh-dashboard/pull/52#discussion_r1516345052


##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/storage/StoreMapper.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.eventmesh.dashboard.console.mapper.storage;
+
+import org.apache.eventmesh.dashboard.console.entity.storage.StoreEntity;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Options;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import java.util.List;
+
+/**
+ * store table operation
+ */
+@Mapper
+public interface StoreMapper {
+
+    @Insert("insert into store (cluster_id, store_id, store_type, host, 
runtime_id, topic_list, diff_type"
+        + ", port, jmx_port, start_timestamp, rack, status, endpoint_map ) 
VALUES ("
+        + 
"#{clusterId},#{storeId},#{storeType},#{host},#{runtimeId},#{topicList},#{diffType},#{port},#{jmxPort}"
+        + ",#{startTimestamp},#{rack},#{status},#{endpointMap})")
+    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
+    void addStorage(StoreEntity storeEntity);
+
+    @Update("update store set is_delete=1 where cluster_id=#{clusterId} and 
store_id=#{storeId}")
+    void deleteStoreByUnique(StoreEntity storeEntity);
+
+    @Select("select * from store where cluster_id=#{clusterId} and 
is_delete=0")
+    List<StoreEntity> selectStoreByCluster(StoreEntity storeEntity);

Review Comment:
   Better unify with @Lambert-Rao's code and use upper case letters for 
operaions like `SELECT FROM` in SQL.



##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/connector/ConnectorDataService.java:
##########
@@ -17,9 +17,14 @@
 
 package org.apache.eventmesh.dashboard.console.service.connector;
 
+import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity;
+
+import java.util.List;
+
 /**
  * Service providing data of connectors.
  */

Review Comment:
   Could you please specify what type of data is processed in this service?



##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.eventmesh.dashboard.console.service.config.Impl;
+
+import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity;
+import org.apache.eventmesh.dashboard.console.mapper.config.ConfigMapper;
+import org.apache.eventmesh.dashboard.console.service.config.ConfigService;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.yaml.snakeyaml.Yaml;
+
+@Service
+public class ConfigServiceImpl implements ConfigService {
+
+
+    @Autowired
+    ConfigMapper configMapper;
+
+    @Override
+    public String mapToYaml(Map<String, String> stringMap) {
+        Yaml yaml = new Yaml();
+        return yaml.dumpAsMap(stringMap);
+    }
+
+    @Override
+    public String mapToProperties(Map<String, String> stringMap) {
+        Properties properties = new Properties();
+        stringMap.forEach((key, value) -> {
+            properties.setProperty(key, value);
+        });
+        return properties.toString().replace(",", ",\n");
+    }
+
+    @Override
+    public Integer addConfig(ConfigEntity configEntity) {
+        return configMapper.addConfig(configEntity);
+    }
+
+    @Override
+    public Integer deleteConfig(ConfigEntity configEntity) {
+        return configMapper.deleteConfig(configEntity);
+    }
+
+    @Override
+    public List<ConfigEntity> selectByInstanceId(ConfigEntity configEntity) {
+        return configMapper.selectByInstanceId(configEntity);
+    }
+
+    @Override
+    public List<ConfigEntity> selectDefaultConfig(ConfigEntity configEntity) {
+        return configMapper.selectDefaultConfig(configEntity);
+    }
+
+    @Override
+    public void updateConfig(ConfigEntity configEntity) {
+        configMapper.updateConfig(configEntity);
+    }

Review Comment:
   When will we update a config instead of creating a new one?



##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/instanceoperation/ConnectorConfigController.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.eventmesh.dashboard.console.service.config.instanceoperation;
+
+
+import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity;
+
+import java.util.List;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class ConnectorConfigController {
+
+    public List<ConfigEntity> getConnectorConfigFromInstance(Long clusterId, 
Long id) {
+        return null;
+    }
+}

Review Comment:
   Do you want to RPC a specific connector instance for its configuration in 
this class?
   
   A `Controller` class annotated with `@Service` seems incongruous.



##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SynchronousConnectorConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.eventmesh.dashboard.console.service.config.synchronous;
+
+import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity;
+import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity;
+import org.apache.eventmesh.dashboard.console.service.config.ConfigService;
+import 
org.apache.eventmesh.dashboard.console.service.config.instanceoperation.ConnectorConfigController;
+import 
org.apache.eventmesh.dashboard.console.service.connector.ConnectorDataService;
+
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SynchronousConnectorConfigTask {
+
+    @Autowired

Review Comment:
   If this task emphasizes the process of transferring data from one end to the 
other, then `Sync...Task` is better. Otherwise, it conveys the idea that 
operations will be performed serially.



##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/store/Impl/StoreServiceImpl.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.eventmesh.dashboard.console.service.store.Impl;
+
+import org.apache.eventmesh.dashboard.console.entity.storage.StoreEntity;
+import org.apache.eventmesh.dashboard.console.mapper.storage.StoreMapper;
+import org.apache.eventmesh.dashboard.console.service.store.StoreService;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class StoreServiceImpl implements StoreService {
+
+    @Autowired
+    private StoreMapper storeMapper;
+
+    @Override
+    public void addStorage(StoreEntity storeEntity) {
+        storeMapper.addStorage(storeEntity);
+    }

Review Comment:
   Event Store is a specific conception and it should be unified here.



##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/synchronous/SynchronousConnectorConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.eventmesh.dashboard.console.service.config.synchronous;
+
+import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity;
+import org.apache.eventmesh.dashboard.console.entity.connector.ConnectorEntity;
+import org.apache.eventmesh.dashboard.console.service.config.ConfigService;
+import 
org.apache.eventmesh.dashboard.console.service.config.instanceoperation.ConnectorConfigController;
+import 
org.apache.eventmesh.dashboard.console.service.connector.ConnectorDataService;
+
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SynchronousConnectorConfigTask {
+
+    @Autowired
+    private ConnectorDataService connectorDataService;
+
+    @Autowired
+    private ConnectorConfigController connectorConfigController;
+    @Autowired
+    private ConfigService configService;
+
+    public void synchronousConnectorConfig(Long clusterId) {
+        List<ConnectorEntity> connectorEntities = 
connectorDataService.selectConnectorByCluster(clusterId);
+        for (ConnectorEntity connectorEntity : connectorEntities) {
+
+            ConcurrentHashMap<String, String> connectorConfigMapFromInstance = 
this.configListToMap(
+                
connectorConfigController.getConnectorConfigFromInstance(clusterId, 
connectorEntity.getId()));
+
+            ConfigEntity configEntity = 
this.getConfigEntityBelongInstance(clusterId, connectorEntity.getId());
+
+            ConcurrentHashMap<String, String> connectorConfigMapFromDb = 
this.configListToMap(configService.selectByInstanceId(configEntity));
+
+            ConcurrentHashMap<String, String> updateConfigMap = new 
ConcurrentHashMap<>();
+
+            connectorConfigMapFromInstance.entrySet().forEach(n -> {
+                if (connectorConfigMapFromDb.remove(n.getKey(), n.getValue())) 
{
+                    connectorConfigMapFromInstance.remove(n.getKey());
+                }
+                if (connectorConfigMapFromDb.get(n.getKey()) != null) {
+                    updateConfigMap.put(n.getKey(), 
connectorConfigMapFromDb.get(n.getKey()));
+                    connectorConfigMapFromInstance.remove(n.getKey());
+                    connectorConfigMapFromDb.remove(n.getKey());
+                }
+            });
+            //add  connectorConfigMapFromDb
+
+            //update  updateConfigMap
+
+            //delete connectorConfigMapFromInstance
+        }
+    }
+
+    public ConcurrentHashMap<String, String> 
configListToMap(List<ConfigEntity> configEntityList) {
+        ConcurrentHashMap<String, String> connectorConfigMap = new 
ConcurrentHashMap<>();
+        configEntityList.forEach(n -> {
+                connectorConfigMap.put(n.getConfigName(), n.getConfigValue());
+            }
+        );
+        return connectorConfigMap;
+    }
+

Review Comment:
   Utility methods should be decorated with `private` namespace or moved to 
util class.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to