use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.
the class ConfigMgrImpl method getVersionListByAppEnv.
/**
* 根据APPid获取其版本列表
*/
@Override
public List<String> getVersionListByAppEnv(Long appId, Long envId) {
List<String> versionList = new ArrayList<String>();
List<Config> configs = configDao.getConfByAppEnv(appId, envId);
for (Config config : configs) {
if (!versionList.contains(config.getVersion())) {
versionList.add(config.getVersion());
}
}
return versionList;
}
use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.
the class ConfigMgrImpl method updateItemValue.
/**
* 更新 配置项/配置文件 的值
*/
@Override
public String updateItemValue(Long configId, String value) {
Config config = getConfigById(configId);
String oldValue = config.getValue();
//
// 配置数据库的值 encode to db
//
configDao.updateValue(configId, CodeUtils.utf8ToUnicode(value));
configHistoryMgr.createOne(configId, oldValue, CodeUtils.utf8ToUnicode(value));
//
// 发送邮件通知
//
String toEmails = appMgr.getEmails(config.getAppId());
if (applicationPropertyConfig.isEmailMonitorOn()) {
boolean isSendSuccess = logMailBean.sendHtmlEmail(toEmails, " config update", DiffUtils.getDiff(CodeUtils.unicodeToUtf8(oldValue), value, config.toString(), getConfigUrlHtml(config)));
if (isSendSuccess) {
return "修改成功,邮件通知成功";
} else {
return "修改成功,邮件发送失败,请检查邮箱配置";
}
}
return "修改成功";
}
use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.
the class ConfigFetcherController method getFile.
/**
* 获取配置文件
*
* @return
*/
@NoAuth
@RequestMapping(value = "/file", method = RequestMethod.GET)
@ResponseBody
public HttpEntity<byte[]> getFile(ConfForm confForm) {
boolean hasError = false;
//
// 校验
//
ConfigFullModel configModel = null;
try {
configModel = configValidator4Fetch.verifyConfForm(confForm, false);
} catch (Exception e) {
LOG.error(e.toString());
hasError = true;
}
if (hasError == false) {
try {
//
Config config = configFetchMgr.getConfByParameter(configModel.getApp().getId(), configModel.getEnv().getId(), configModel.getVersion(), configModel.getKey(), DisConfigTypeEnum.FILE);
if (config == null) {
hasError = true;
throw new DocumentNotFoundException(configModel.getKey());
}
//API获取节点内容也需要同样做格式转换
return downloadDspBill(configModel.getKey(), config.getValue());
} catch (Exception e) {
LOG.error(e.toString());
}
}
if (confForm.getKey() != null) {
throw new DocumentNotFoundException(confForm.getKey());
} else {
throw new DocumentNotFoundException("");
}
}
use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.
the class ConfigDaoTestCase method test.
@Test
public void test() {
URL url = ClassLoader.getSystemResource("file2/confA.properties");
byte[] btyes = readFileContent(url.getPath());
try {
// read data
String str = new String(btyes, "UTF-8");
// save to db
Config config = configDao.get(1L);
config.setValue(str);
configDao.update(config);
// read
LOG.info(configDao.get(1L).getValue());
} catch (UnsupportedEncodingException e) {
Assert.assertTrue(false);
}
}
use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.
the class ConfigFetcherController method getListImp.
private JsonObjectBase getListImp(ConfForm confForm, boolean hasValue) {
LOG.info(confForm.toString());
//
// 校验
//
ConfigFullModel configModel = configValidator4Fetch.verifyConfForm(confForm, true);
List<Config> configs = configFetchMgr.getConfListByParameter(configModel.getApp().getId(), configModel.getEnv().getId(), configModel.getVersion(), hasValue);
return buildListSuccess(configs, configs.size());
}
Aggregations