use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method convertDeletedConfig.
@Override
public List<ConfigInfo> convertDeletedConfig(List<Map<String, Object>> list) {
List<ConfigInfo> configs = new ArrayList<ConfigInfo>();
for (Map<String, Object> map : list) {
String dataId = (String) map.get("data_id");
String group = (String) map.get("group_id");
String tenant = (String) map.get("tenant_id");
ConfigInfo config = new ConfigInfo();
config.setDataId(dataId);
config.setGroup(group);
config.setTenant(tenant);
configs.add(config);
}
return configs;
}
use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method findConfigInfo4Page.
@Override
public Page<ConfigInfo> findConfigInfo4Page(final int pageNo, final int pageSize, final String dataId, final String group, final String tenant, final Map<String, Object> configAdvanceInfo) {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
final String appName = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("appName");
final String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
String sqlCount = "SELECT count(*) FROM config_info";
String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
List<String> paramList = new ArrayList<String>();
paramList.add(tenantTmp);
if (StringUtils.isNotBlank(configTags)) {
sqlCount = "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id";
sql = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN " + "config_tags_relation b ON a.id=b.id";
where.append(" a.tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
paramList.add(dataId);
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
paramList.add(group);
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
paramList.add(appName);
}
where.append(" AND b.tag_name IN (");
String[] tagArr = configTags.split(",");
for (int i = 0; i < tagArr.length; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
paramList.add(tagArr[i]);
}
where.append(") ");
} else {
where.append(" tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
paramList.add(dataId);
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
paramList.add(group);
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
paramList.add(appName);
}
}
PaginationHelper<ConfigInfo> helper = createPaginationHelper();
Page<ConfigInfo> page = helper.fetchPage(sqlCount + where, sql + where, paramList.toArray(), pageNo, pageSize, CONFIG_INFO_ROW_MAPPER);
for (ConfigInfo configInfo : page.getPageItems()) {
Pair<String, String> pair = EncryptionHandler.decryptHandler(configInfo.getDataId(), configInfo.getEncryptedDataKey(), configInfo.getContent());
configInfo.setContent(pair.getSecond());
}
return page;
}
use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method removeConfigInfoByIds.
@Override
public List<ConfigInfo> removeConfigInfoByIds(final List<Long> ids, final String srcIp, final String srcUser) {
if (CollectionUtils.isEmpty(ids)) {
return null;
}
ids.removeAll(Collections.singleton(null));
final Timestamp time = new Timestamp(System.currentTimeMillis());
try {
String idsStr = StringUtils.join(ids, StringUtils.COMMA);
List<ConfigInfo> configInfoList = findConfigInfosByIds(idsStr);
if (CollectionUtils.isNotEmpty(configInfoList)) {
removeConfigInfoByIdsAtomic(idsStr);
for (ConfigInfo configInfo : configInfoList) {
removeTagByIdAtomic(configInfo.getId());
insertConfigHistoryAtomic(configInfo.getId(), configInfo, srcIp, srcUser, time, "D");
}
}
EmbeddedStorageContextUtils.onBatchDeleteConfigInfo(configInfoList);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Failed to config batch deletion");
}
return configInfoList;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
}
}
use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method removeConfigInfo4Beta.
@Override
public void removeConfigInfo4Beta(final String dataId, final String group, final String tenant) {
final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
ConfigInfo configInfo = findConfigInfo4Beta(dataId, group, tenant);
if (configInfo != null) {
try {
final String sql = "DELETE FROM config_info_beta WHERE data_id=? AND group_id=? AND tenant_id=?";
final Object[] args = new Object[] { dataId, group, tenantTmp };
EmbeddedStorageContextUtils.onDeleteConfigBetaInfo(tenantTmp, group, dataId, System.currentTimeMillis());
EmbeddedStorageContextUtils.addSqlContext(sql, args);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[Tag] Configuration deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
}
}
}
use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class ExternalStoragePersistServiceImpl method convertDeletedConfig.
@Override
public List<ConfigInfo> convertDeletedConfig(List<Map<String, Object>> list) {
List<ConfigInfo> configs = new ArrayList<ConfigInfo>();
for (Map<String, Object> map : list) {
String dataId = (String) map.get("data_id");
String group = (String) map.get("group_id");
String tenant = (String) map.get("tenant_id");
ConfigInfo config = new ConfigInfo();
config.setDataId(dataId);
config.setGroup(group);
config.setTenant(tenant);
configs.add(config);
}
return configs;
}
Aggregations