use of com.alibaba.nacos.config.server.model.ConfigAdvanceInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method findConfigAdvanceInfo.
@Override
public ConfigAdvanceInfo findConfigAdvanceInfo(final String dataId, final String group, final String tenant) {
final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
List<String> configTagList = this.selectTagByConfig(dataId, group, tenant);
ConfigAdvanceInfo configAdvance = databaseOperate.queryOne("SELECT gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,type,c_schema FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=?", new Object[] { dataId, group, tenantTmp }, CONFIG_ADVANCE_INFO_ROW_MAPPER);
if (CollectionUtils.isNotEmpty(configTagList)) {
StringBuilder configTagsTmp = new StringBuilder();
for (String configTag : configTagList) {
if (configTagsTmp.length() == 0) {
configTagsTmp.append(configTag);
} else {
configTagsTmp.append(',').append(configTag);
}
}
configAdvance.setConfigTags(configTagsTmp.toString());
}
return configAdvance;
}
use of com.alibaba.nacos.config.server.model.ConfigAdvanceInfo in project nacos by alibaba.
the class ExternalStoragePersistServiceImpl method findConfigAdvanceInfo.
@Override
public ConfigAdvanceInfo findConfigAdvanceInfo(final String dataId, final String group, final String tenant) {
final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
try {
List<String> configTagList = this.selectTagByConfig(dataId, group, tenant);
ConfigAdvanceInfo configAdvance = this.jt.queryForObject("SELECT gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,type,c_schema FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=?", new Object[] { dataId, group, tenantTmp }, CONFIG_ADVANCE_INFO_ROW_MAPPER);
if (configTagList != null && !configTagList.isEmpty()) {
StringBuilder configTagsTmp = new StringBuilder();
for (String configTag : configTagList) {
if (configTagsTmp.length() == 0) {
configTagsTmp.append(configTag);
} else {
configTagsTmp.append(',').append(configTag);
}
}
configAdvance.setConfigTags(configTagsTmp.toString());
}
return configAdvance;
} catch (EmptyResultDataAccessException e) {
// Indicates that the data does not exist, returns null
return null;
} catch (CannotGetJdbcConnectionException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e);
throw e;
}
}
use of com.alibaba.nacos.config.server.model.ConfigAdvanceInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method batchInsertOrUpdate.
@Override
public Map<String, Object> batchInsertOrUpdate(List<ConfigAllInfo> configInfoList, String srcUser, String srcIp, Map<String, Object> configAdvanceInfo, Timestamp time, boolean notify, SameConfigPolicy policy) throws NacosException {
int succCount = 0;
int skipCount = 0;
List<Map<String, String>> failData = null;
List<Map<String, String>> skipData = null;
final BiConsumer<Boolean, Throwable> callFinally = (result, t) -> {
if (t != null) {
throw new NacosRuntimeException(0, t);
}
};
for (int i = 0; i < configInfoList.size(); i++) {
ConfigAllInfo configInfo = configInfoList.get(i);
try {
ParamUtils.checkParam(configInfo.getDataId(), configInfo.getGroup(), "datumId", configInfo.getContent());
} catch (Throwable e) {
DEFAULT_LOG.error("data verification failed", e);
throw e;
}
ConfigInfo configInfo2Save = new ConfigInfo(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(), configInfo.getAppName(), configInfo.getContent());
configInfo2Save.setEncryptedDataKey(configInfo.getEncryptedDataKey() == null ? "" : configInfo.getEncryptedDataKey());
String type = configInfo.getType();
if (StringUtils.isBlank(type)) {
// simple judgment of file type based on suffix
if (configInfo.getDataId().contains(SPOT)) {
String extName = configInfo.getDataId().substring(configInfo.getDataId().lastIndexOf(SPOT) + 1);
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(extName);
type = fileTypeEnum.getFileType();
} else {
type = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(null).getFileType();
}
}
if (configAdvanceInfo == null) {
configAdvanceInfo = new HashMap<>(16);
}
configAdvanceInfo.put("type", type);
configAdvanceInfo.put("desc", configInfo.getDesc());
try {
ConfigInfo foundCfg = findConfigInfo(configInfo2Save.getDataId(), configInfo2Save.getGroup(), configInfo2Save.getTenant());
if (foundCfg != null) {
throw new Throwable("DuplicateKeyException: config already exists, should be overridden");
}
addConfigInfo(srcIp, srcUser, configInfo2Save, time, configAdvanceInfo, notify, callFinally);
succCount++;
} catch (Throwable e) {
if (!StringUtils.contains(e.toString(), "DuplicateKeyException")) {
throw new NacosException(NacosException.SERVER_ERROR, e);
}
// uniqueness constraint conflict
if (SameConfigPolicy.ABORT.equals(policy)) {
failData = new ArrayList<>();
skipData = new ArrayList<>();
Map<String, String> faileditem = new HashMap<>(2);
faileditem.put("dataId", configInfo2Save.getDataId());
faileditem.put("group", configInfo2Save.getGroup());
failData.add(faileditem);
for (int j = (i + 1); j < configInfoList.size(); j++) {
ConfigInfo skipConfigInfo = configInfoList.get(j);
Map<String, String> skipitem = new HashMap<>(2);
skipitem.put("dataId", skipConfigInfo.getDataId());
skipitem.put("group", skipConfigInfo.getGroup());
skipData.add(skipitem);
}
break;
} else if (SameConfigPolicy.SKIP.equals(policy)) {
skipCount++;
if (skipData == null) {
skipData = new ArrayList<>();
}
Map<String, String> skipitem = new HashMap<>(2);
skipitem.put("dataId", configInfo2Save.getDataId());
skipitem.put("group", configInfo2Save.getGroup());
skipData.add(skipitem);
} else if (SameConfigPolicy.OVERWRITE.equals(policy)) {
succCount++;
updateConfigInfo(configInfo2Save, srcIp, srcUser, time, configAdvanceInfo, notify);
}
}
}
Map<String, Object> result = new HashMap<>(4);
result.put("succCount", succCount);
result.put("skipCount", skipCount);
if (failData != null && !failData.isEmpty()) {
result.put("failData", failData);
}
if (skipData != null && !skipData.isEmpty()) {
result.put("skipData", skipData);
}
return result;
}
use of com.alibaba.nacos.config.server.model.ConfigAdvanceInfo in project nacos by alibaba.
the class ConfigControllerTest method testGetConfigAdvanceInfo.
@Test
public void testGetConfigAdvanceInfo() throws Exception {
ConfigAdvanceInfo configAdvanceInfo = new ConfigAdvanceInfo();
configAdvanceInfo.setCreateIp("localhost");
configAdvanceInfo.setCreateUser("test");
configAdvanceInfo.setDesc("desc");
when(persistService.findConfigAdvanceInfo("test", "test", "")).thenReturn(configAdvanceInfo);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.CONFIG_CONTROLLER_PATH + "/catalog").param("dataId", "test").param("group", "test").param("tenant", "");
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
String code = JacksonUtils.toObj(actualValue).get("code").toString();
String data = JacksonUtils.toObj(actualValue).get("data").toString();
ConfigAdvanceInfo resConfigAdvanceInfo = JacksonUtils.toObj(data, ConfigAdvanceInfo.class);
Assert.assertEquals("200", code);
Assert.assertEquals(configAdvanceInfo.getCreateIp(), resConfigAdvanceInfo.getCreateIp());
Assert.assertEquals(configAdvanceInfo.getCreateUser(), resConfigAdvanceInfo.getCreateUser());
Assert.assertEquals(configAdvanceInfo.getDesc(), resConfigAdvanceInfo.getDesc());
}
Aggregations