Skip to content

Commit

Permalink
[#12371] add history grayname & fix rollback type-tags-desc miss (#12947
Browse files Browse the repository at this point in the history
)

* fix type search on mysql model

* add column gray name  into his_config_info

* check style and pmd fix

* add colomn for mapper

* fix rollback history type miss

* testcase

* testcase
  • Loading branch information
shiyiyue1102 authored Dec 16, 2024
1 parent 08fac16 commit 98c9760
Show file tree
Hide file tree
Showing 31 changed files with 440 additions and 1,374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class ConfigHistoryInfo implements Serializable {

private String publishType;

private String grayName;

private String extInfo;

private Timestamp createdTime;
Expand Down Expand Up @@ -172,6 +174,14 @@ public void setLastModifiedTime(Timestamp lastModifiedTime) {
this.lastModifiedTime = new Timestamp(lastModifiedTime.getTime());
}

public String getGrayName() {
return grayName;
}

public void setGrayName(String grayName) {
this.grayName = grayName;
}

public String getAppName() {
return appName;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ public ConfigHistoryInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
configHistoryInfo.setSrcUser(rs.getString("src_user"));
configHistoryInfo.setOpType(rs.getString("op_type"));
configHistoryInfo.setPublishType(rs.getString("publish_type"));
configHistoryInfo.setGrayName(rs.getString("gray_name"));
configHistoryInfo.setExtInfo(rs.getString("ext_info"));
configHistoryInfo.setCreatedTime(rs.getTimestamp("gmt_create"));
configHistoryInfo.setLastModifiedTime(rs.getTimestamp("gmt_modified"));
Expand All @@ -573,6 +574,7 @@ public ConfigHistoryInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
configHistoryInfo.setSrcIp(rs.getString("src_ip"));
configHistoryInfo.setOpType(rs.getString("op_type"));
configHistoryInfo.setPublishType(rs.getString("publish_type"));
configHistoryInfo.setGrayName(rs.getString("gray_name"));
configHistoryInfo.setExtInfo(rs.getString("ext_info"));
configHistoryInfo.setCreatedTime(rs.getTimestamp("gmt_create"));
configHistoryInfo.setLastModifiedTime(rs.getTimestamp("gmt_modified"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ public interface HistoryConfigInfoPersistService {
/**
* Update change records; database atomic operations, minimal sql actions, no business encapsulation.
*
* @param id id
* @param configInfo config info
* @param srcIp ip
* @param srcUser user
* @param time time
* @param ops ops type
* @param publishType publish type
* @param extInfo extra config info
* @param id id
* @param configInfo config info
* @param srcIp ip
* @param srcUser user
* @param time time
* @param ops ops type
* @param publishType publish type
* @param grayName gray name
* @param extInfo extra config info
*/
void insertConfigHistoryAtomic(long id, ConfigInfo configInfo, String srcIp, String srcUser, final Timestamp time,
String ops, String publishType, String extInfo);
String ops, String publishType, String grayName, String extInfo);
//------------------------------------------delete---------------------------------------------//

/**
Expand All @@ -77,7 +78,8 @@ void insertConfigHistoryAtomic(long id, ConfigInfo configInfo, String srcIp, Str
* @param publishType publish type
* @return {@link ConfigInfoStateWrapper} list
*/
List<ConfigInfoStateWrapper> findDeletedConfig(final Timestamp startTime, final long startId, int size, String publishType);
List<ConfigInfoStateWrapper> findDeletedConfig(final Timestamp startTime, final long startId, int size,
String publishType);

/**
* List configuration history change record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public ConfigOperateResult addConfigInfo4Gray(ConfigInfo configInfo, String gray

Timestamp now = new Timestamp(System.currentTimeMillis());
historyConfigInfoPersistService.insertConfigHistoryAtomic(hisId, configInfo, srcIp, srcUser, now, "I",
Constants.GRAY, ConfigExtInfoUtil.getExtInfoFromGrayInfo(grayNameTmp, grayRuleTmp, srcUser));
Constants.GRAY, grayNameTmp,
ConfigExtInfoUtil.getExtInfoFromGrayInfo(grayNameTmp, grayRuleTmp, srcUser));

EmbeddedStorageContextUtils.onModifyConfigGrayInfo(configInfo, grayNameTmp, grayRuleTmp, srcIp, now);
databaseOperate.blockUpdate();
Expand Down Expand Up @@ -226,7 +227,7 @@ public void removeConfigInfoGray(final String dataId, final String group, final

Timestamp now = new Timestamp(System.currentTimeMillis());
historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(), oldConfigAllInfo4Gray,
srcIp, srcUser, now, "D", Constants.GRAY,
srcIp, srcUser, now, "D", Constants.GRAY, grayNameTmp,
ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));

Expand Down Expand Up @@ -272,7 +273,7 @@ public ConfigOperateResult updateConfigInfo4Gray(ConfigInfo configInfo, String g

Timestamp now = new Timestamp(System.currentTimeMillis());
historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(),
oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY,
oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY, grayNameTmp,
ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));

Expand Down Expand Up @@ -331,7 +332,7 @@ public ConfigOperateResult updateConfigInfo4GrayCas(ConfigInfo configInfo, Strin

Timestamp now = new Timestamp(System.currentTimeMillis());
historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(),
oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY,
oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY, grayNameTmp,
ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@ private ConfigOperateResult addConfigInfo(final String srcIp, final String srcUs

addConfigTagsRelation(configId, configTags, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());

Timestamp now = new Timestamp(System.currentTimeMillis());
historyConfigInfoPersistService.insertConfigHistoryAtomic(hisId, configInfo, srcIp, srcUser, now, "I",
Constants.FORMAL, ConfigExtInfoUtil.getExtraInfoFromAdvanceInfoMap(configAdvanceInfo, srcUser));
Constants.FORMAL, null,
ConfigExtInfoUtil.getExtraInfoFromAdvanceInfoMap(configAdvanceInfo, srcUser));

EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, now);
databaseOperate.blockUpdate(consumer);
Expand Down Expand Up @@ -273,9 +274,9 @@ public long addConfigInfoAtomic(final long id, final String srcIp, final String

final String sql = configInfoMapper.insert(
Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_ip",
"src_user", "gmt_create@NOW()", "gmt_modified@NOW()", "c_desc", "c_use", "effect",
"type", "c_schema", "encrypted_data_key"));
final Object[] args = new Object[]{id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp,
"src_user", "gmt_create@NOW()", "gmt_modified@NOW()", "c_desc", "c_use", "effect", "type",
"c_schema", "encrypted_data_key"));
final Object[] args = new Object[] {id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp,
configInfo.getContent(), md5Tmp, srcIp, srcUser, desc, use, effect, type, schema, encryptedDataKey};
EmbeddedStorageContextHolder.addSqlContext(sql, args);
return id;
Expand Down Expand Up @@ -411,8 +412,9 @@ public void removeConfigInfo(final String dataId, final String group, final Stri

removeConfigInfoAtomic(dataId, group, tenantTmp, srcIp, srcUser);
removeTagByIdAtomic(oldConfigAllInfo.getId());
historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo, srcIp,
srcUser, time, "D", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo,
srcIp, srcUser, time, "D", Constants.FORMAL, null,
ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));

EmbeddedStorageContextUtils.onDeleteConfigInfo(tenantTmp, group, dataId, srcIp, time);

Expand Down Expand Up @@ -441,7 +443,7 @@ public List<ConfigAllInfo> removeConfigInfoByIds(final List<Long> ids, final Str
for (ConfigAllInfo configAllInfo : oldConfigAllInfoList) {
removeTagByIdAtomic(configAllInfo.getId());
historyConfigInfoPersistService.insertConfigHistoryAtomic(configAllInfo.getId(), configAllInfo,
srcIp, srcUser, time, "D", Constants.FORMAL,
srcIp, srcUser, time, "D", Constants.FORMAL, null,
ConfigExtInfoUtil.getExtInfoFromAllInfo(configAllInfo));
}
}
Expand Down Expand Up @@ -529,13 +531,14 @@ public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final S
if (configTags != null) {
// Delete all tags and recreate them
removeTagByIdAtomic(oldConfigAllInfo.getId());
addConfigTagsRelation(oldConfigAllInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
addConfigTagsRelation(oldConfigAllInfo.getId(), configTags, configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant());
}

Timestamp time = new Timestamp(System.currentTimeMillis());
historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo, srcIp,
srcUser, time, "U", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
srcUser, time, "U", Constants.FORMAL, null,
ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
databaseOperate.blockUpdate();
return getConfigInfoOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);
Expand Down Expand Up @@ -575,13 +578,14 @@ public ConfigOperateResult updateConfigInfoCas(final ConfigInfo configInfo, fina
if (configTags != null) {
// Delete all tags and recreate them
removeTagByIdAtomic(oldConfigAllInfo.getId());
addConfigTagsRelation(oldConfigAllInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
addConfigTagsRelation(oldConfigAllInfo.getId(), configTags, configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant());
}

Timestamp time = new Timestamp(System.currentTimeMillis());
historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo, srcIp,
srcUser, time, "U", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
srcUser, time, "U", Constants.FORMAL, null,
ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
boolean success = databaseOperate.blockUpdate();
if (success) {
Expand Down Expand Up @@ -626,7 +630,8 @@ private ConfigOperateResult updateConfigInfoAtomicCas(final ConfigInfo configInf
context.putWhereParameter(FieldConstant.MD5, configInfo.getMd5());
MapperResult mapperResult = configInfoMapper.updateConfigInfoAtomicCas(context);

EmbeddedStorageContextHolder.addSqlContext(Boolean.TRUE, mapperResult.getSql(), mapperResult.getParamList().toArray());
EmbeddedStorageContextHolder.addSqlContext(Boolean.TRUE, mapperResult.getSql(),
mapperResult.getParamList().toArray());
return getConfigInfoOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);

}
Expand All @@ -648,13 +653,13 @@ public void updateConfigInfoAtomic(final ConfigInfo configInfo, final String src
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
final String sql = configInfoMapper.update(
Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified@NOW()", "app_name",
"c_desc", "c_use", "effect", "type", "c_schema", "encrypted_data_key"),
Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified@NOW()", "app_name", "c_desc",
"c_use", "effect", "type", "c_schema", "encrypted_data_key"),
Arrays.asList("data_id", "group_id", "tenant_id"));

final Object[] args = new Object[]{configInfo.getContent(), md5Tmp, srcIp, srcUser, appNameTmp, desc,
use, effect, type, schema, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};

final Object[] args = new Object[] {configInfo.getContent(), md5Tmp, srcIp, srcUser, appNameTmp, desc, use,
effect, type, schema, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}

Expand Down Expand Up @@ -820,7 +825,8 @@ public Page<ConfigInfo> findConfigInfoLike4Page(final int pageNo, final int page
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
final String appName = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("appName");
final String content = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("content");
final String types = Optional.ofNullable(configAdvanceInfo).map(e -> (String) e.get(ParametersField.TYPES)).orElse(null);
final String types = Optional.ofNullable(configAdvanceInfo).map(e -> (String) e.get(ParametersField.TYPES))
.orElse(null);
final String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
MapperResult sqlCountRows;
MapperResult sqlFetchRows;
Expand Down
Loading

0 comments on commit 98c9760

Please sign in to comment.