Skip to content

Commit

Permalink
[ISSUES#137]Added an API for the dashboard to read the runtime config…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
“zzxxiansheng committed Apr 29, 2024
1 parent 6ca4640 commit 5f17c47
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ public String updateConfigsByTypeAndId(@Validated @RequestBody UpdateConfigDTO u
public List<DetailConfigsVO> getInstanceDetailConfigs(@Validated @RequestBody GetConfigsListDTO getConfigsListDTO) {
List<ConfigEntity> configEntityList = configService.selectToFront(getConfigsListDTO.getInstanceId(),
getConfigsListDTO.getInstanceType(), getConfigsListDTO);
Map<String, String> stringStringConcurrentHashMap = configService.selectDefaultConfig(getConfigsListDTO.getBusinessType(),
getConfigsListDTO.getInstanceId(), getConfigsListDTO.getInstanceType());
Map<String, ConfigEntity> stringStringConcurrentHashMap = configService.selectDefaultConfig(getConfigsListDTO.getBusinessType(),
getConfigsListDTO.getInstanceType());
ArrayList<DetailConfigsVO> showDetailConfigsVOS = new ArrayList<>();
System.out.println(stringStringConcurrentHashMap.get("eventMesh.server.global.scheduler"));
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ public interface ConfigMapper {

@Insert({
"<script>",
" 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 ",
" <foreach collection='list' item='c' index='index' separator=','>",
" (#{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})",
" </foreach>",
"</script>"})
"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 ",
"<foreach collection='list' item='c' index='index' separator=','>",
"(#{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})",
"</foreach>",
"ON DUPLICATE KEY UPDATE config_value = VALUES(config_value)",
"</script>"
})
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
void batchInsert(List<ConfigEntity> configEntityList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface ConfigService {

List<ConfigEntity> selectByInstanceIdAndType(Long instanceId, Integer type);

Map<String, String> selectDefaultConfig(String version, Long instanceId, Integer instanceType);
Map<String, ConfigEntity> selectDefaultConfig(String version, Integer instanceType);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ConfigServiceImpl implements ConfigService {
@Autowired
ConfigMapper configMapper;

private Map<DefaultConfigKey, String> defaultConfigCache = new HashMap<>();
private Map<DefaultConfigKey, ConfigEntity> defaultConfigCache = new HashMap<>();


@EmLog(OprTarget = "Runtime", OprType = "UpdateConfigs")
Expand Down Expand Up @@ -209,17 +209,17 @@ public void addDefaultConfigToCache() {
List<ConfigEntity> 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<String, String> selectDefaultConfig(String businessType, Long instanceId, Integer instanceType) {
public Map<String, ConfigEntity> selectDefaultConfig(String businessType, Integer instanceType) {
if (defaultConfigCache.size() == 0) {
this.addDefaultConfigToCache();
}
ConcurrentHashMap<String, String> stringStringConcurrentHashMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String, ConfigEntity> stringStringConcurrentHashMap = new ConcurrentHashMap<>();
defaultConfigCache.forEach((k, v) -> {
if (k.getBusinessType().equals(businessType)) {
stringStringConcurrentHashMap.put(k.getConfigName(), v);
Expand All @@ -228,4 +228,4 @@ public Map<String, String> selectDefaultConfig(String businessType, Long instanc
return stringStringConcurrentHashMap;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.HashMap;
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<Entry<String, Object>> entries = jsonMap.entrySet();
ArrayList<ConfigEntity> configEntities = new ArrayList<>();
for (Entry<String, Object> entry : entries) {
if (!entry.getKey().equals("data")) {
continue;
}
JSONObject parse = JSON.parseObject(entry.getValue().toString());
Set<Entry<String, Object>> configurationEntry = parse.entrySet();
configurationEntry.forEach((configuration) -> {
JSONObject parse1 = JSON.parseObject(configuration.getValue().toString());
Set<Entry<String, Object>> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ create table config
instance_type tinyint not null comment '实例类型 0:runtime,1:storage,2:connector,3:topic',
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 开启 ',
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 可编辑',
config_value text null comment '配置值',
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 '' 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,
Expand Down

0 comments on commit 5f17c47

Please sign in to comment.