Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #137] Add an API for the dashboard to read the runtime configurationConfig #138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ 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<>();
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 @@ -66,14 +66,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,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<Entry<String, Object>> entries = jsonMap.entrySet();
ArrayList<ConfigEntity> configEntities = new ArrayList<>();
Comment on lines +43 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RPC implements to EventMesh Runtime, Event Store and Meta should be put in the core module. The console module can call org.apache.eventmesh.dashboard.service.remoting.ConfigRemotingService.

This RemotingService interface needs to differentiate between methods based on the type of operation and the type of configuration, and abstract classes based on the target of the operation. I'll submit a PR for that.

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 @@ -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,
Expand Down
Loading