diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/ConfigController.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/ConfigController.java index ca819b7d..9a2305ba 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/ConfigController.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/ConfigController.java @@ -55,13 +55,16 @@ public String updateConfigsByTypeAndId(@Validated @RequestBody UpdateConfigDTO u public List getInstanceDetailConfigs(@Validated @RequestBody GetConfigsListDTO getConfigsListDTO) { List configEntityList = configService.selectToFront(getConfigsListDTO.getInstanceId(), getConfigsListDTO.getInstanceType(), getConfigsListDTO); - Map stringStringConcurrentHashMap = configService.selectDefaultConfig(getConfigsListDTO.getBusinessType(), - getConfigsListDTO.getInstanceId(), getConfigsListDTO.getInstanceType()); + Map stringStringConcurrentHashMap = configService.selectDefaultConfig(getConfigsListDTO.getBusinessType(), + getConfigsListDTO.getInstanceType()); ArrayList showDetailConfigsVOS = new ArrayList<>(); configEntityList.forEach(n -> { DetailConfigsVO showDetailConfigsVO = new DetailConfigsVO(); - showDetailConfigsVO.setDefaultValue(stringStringConcurrentHashMap.get(n.getConfigName())); - showDetailConfigsVO.setIsModify(n.getIsModify()); + ConfigEntity defaultConfig = stringStringConcurrentHashMap.get(n.getConfigName()); + if (defaultConfig != null) { + showDetailConfigsVO.setDefaultValue(defaultConfig.getConfigValue()); + showDetailConfigsVO.setIsModify(defaultConfig.getIsModify()); + } showDetailConfigsVO.setConfigName(n.getConfigName()); showDetailConfigsVO.setConfigValue(n.getConfigValue()); showDetailConfigsVO.setAlreadyUpdate(n.getAlreadyUpdate()); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java index 2a6c9a1c..a874ecd9 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/mapper/config/ConfigMapper.java @@ -66,14 +66,16 @@ public interface ConfigMapper { @Insert({ ""}) + "INSERT INTO config (cluster_id, business_type, instance_type, instance_id, config_name, config_value, start_version,", + "eventmesh_version, end_version, diff_type, description, edit, is_default, is_modify) VALUES ", + "", + "(#{c.clusterId}, #{c.businessType}, #{c.instanceType}, #{c.instanceId}, #{c.configName},", + "#{c.configValue}, #{c.startVersion}, #{c.eventmeshVersion}, #{c.endVersion}, #{c.diffType}, #{c.description},", + "#{c.edit}, #{c.isDefault}, #{c.isModify})", + "", + "ON DUPLICATE KEY UPDATE config_value = VALUES(config_value)", + "" + }) @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void batchInsert(List configEntityList); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/ConfigService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/ConfigService.java index 3be1c537..4e43be8a 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/ConfigService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/ConfigService.java @@ -51,7 +51,7 @@ public interface ConfigService { List selectByInstanceIdAndType(Long instanceId, Integer type); - Map selectDefaultConfig(String version, Long instanceId, Integer instanceType); + Map selectDefaultConfig(String version, Integer instanceType); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java index b3e06d65..010fdaf2 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/Impl/ConfigServiceImpl.java @@ -45,7 +45,7 @@ public class ConfigServiceImpl implements ConfigService { @Autowired ConfigMapper configMapper; - private Map defaultConfigCache = new HashMap<>(); + private Map defaultConfigCache = new HashMap<>(); @EmLog(OprTarget = "Runtime", OprType = "UpdateConfigs") @@ -209,17 +209,17 @@ public void addDefaultConfigToCache() { List configEntityList = configMapper.selectAllDefaultConfig(); configEntityList.forEach(n -> { DefaultConfigKey defaultConfigKey = new DefaultConfigKey(n.getBusinessType(), n.getConfigName()); - defaultConfigCache.putIfAbsent(defaultConfigKey, n.getConfigValue()); + defaultConfigCache.putIfAbsent(defaultConfigKey, n); }); } @Override - public Map selectDefaultConfig(String businessType, Long instanceId, Integer instanceType) { + public Map selectDefaultConfig(String businessType, Integer instanceType) { if (defaultConfigCache.size() == 0) { this.addDefaultConfigToCache(); } - ConcurrentHashMap stringStringConcurrentHashMap = new ConcurrentHashMap<>(); + ConcurrentHashMap stringStringConcurrentHashMap = new ConcurrentHashMap<>(); defaultConfigCache.forEach((k, v) -> { if (k.getBusinessType().equals(businessType)) { stringStringConcurrentHashMap.put(k.getConfigName(), v); @@ -228,4 +228,4 @@ public Map selectDefaultConfig(String businessType, Long instanc return stringStringConcurrentHashMap; } -} +} \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/remote/RemoteRuntimeService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/remote/RemoteRuntimeService.java new file mode 100644 index 00000000..69045d31 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/service/config/remote/RemoteRuntimeService.java @@ -0,0 +1,78 @@ +/* + * 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.remote; + + +import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; +import org.apache.eventmesh.dashboard.console.entity.runtime.RuntimeEntity; +import org.apache.eventmesh.dashboard.console.mapper.config.ConfigMapper; + +import java.util.ArrayList; +import java.util.Map.Entry; +import java.util.Set; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +@Service +public class RemoteRuntimeService { + + @Autowired + private ConfigMapper configMapper; + + public void getRuntimeConfigByCluster(RuntimeEntity runtimeEntity) { + RestTemplate restTemplate = new RestTemplate(); + String forEntity = + restTemplate.getForObject("http://" + runtimeEntity.getHost() + ":" + runtimeEntity.getPort() + "/v2/configuration?format=properties", String.class, (Object) null); + JSONObject jsonMap = JSON.parseObject(forEntity); + Set> entries = jsonMap.entrySet(); + ArrayList configEntities = new ArrayList<>(); + for (Entry entry : entries) { + if (!entry.getKey().equals("data")) { + continue; + } + JSONObject parse = JSON.parseObject(entry.getValue().toString()); + Set> configurationEntry = parse.entrySet(); + configurationEntry.forEach((configuration) -> { + JSONObject parse1 = JSON.parseObject(configuration.getValue().toString()); + Set> configureEntry = parse1.entrySet(); + configureEntry.forEach((configure) -> { + ConfigEntity config = this.createRuntimeConfigEntity(runtimeEntity, configure.getKey(), configure.getValue().toString()); + configEntities.add(config); + }); + }); + } + configMapper.batchInsert(configEntities); + } + + private ConfigEntity createRuntimeConfigEntity(RuntimeEntity runtimeEntity, String configName, String configValue) { + ConfigEntity config = new ConfigEntity(); + config.setConfigName(configName); + config.setConfigValue(configValue); + config.setBusinessType("runtime"); + config.setInstanceType(0); + config.setClusterId(runtimeEntity.getClusterId()); + config.setIsDefault(0); + config.setInstanceId(runtimeEntity.getId()); + return config; + } +} diff --git a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql index b8ed61b9..aa913194 100644 --- a/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql +++ b/eventmesh-dashboard-console/src/main/resources/eventmesh-dashboard.sql @@ -54,13 +54,13 @@ create table config instance_id bigint default -1 not null comment '实例ID,上面配置对应的(比如runtime)的id', config_name varchar(192) default '' not null comment '配置名称', config_value text null comment '配置值', - start_version varchar(64) default '' not null comment '配置开始使用的版本', - status int default 1 not null comment '0 关闭 1 开启 ', + start_version varchar(64) default '' null comment '配置开始使用的版本', + status int default 1 null comment '0 关闭 1 开启 ', is_default int default 1 null, - end_version varchar(64) default '' not null comment '配置结束使用的版本', - diff_type int default -1 not null comment '差异类型', - description varchar(1000) default '' not null comment '备注', - edit int default 1 not null comment '是否可以编辑 1 不可编辑(程序获取) 2 可编辑', + end_version varchar(64) default '' null comment '配置结束使用的版本', + diff_type int default -1 null comment '差异类型', + description varchar(1000) default '' null comment '备注', + edit int default 1 null comment '是否可以编辑 1 不可编辑(程序获取) 2 可编辑', create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间', update_time timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改时间', is_modify int default 0 not null,