use of com.baidu.disconf.web.service.config.vo.ConfListVo in project disconf by knightliao.
the class ConfigReadController method downloadDspBill.
/**
* 下载
*
* @param configId
*
* @return
*/
@RequestMapping(value = "/download/{configId}", method = RequestMethod.GET)
public HttpEntity<byte[]> downloadDspBill(@PathVariable long configId) {
// 业务校验
configValidator.valideConfigExist(configId);
ConfListVo config = configMgr.getConfVo(configId);
HttpHeaders header = new HttpHeaders();
byte[] res = config.getValue().getBytes();
if (res == null) {
throw new DocumentNotFoundException(config.getKey());
}
String name = null;
try {
name = URLEncoder.encode(config.getKey(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
header.set("Content-Disposition", "attachment; filename=" + name);
header.setContentLength(res.length);
return new HttpEntity<byte[]>(res, header);
}
use of com.baidu.disconf.web.service.config.vo.ConfListVo in project disconf by knightliao.
the class ConfigMgrImpl method convert.
/**
* 转换成配置返回
*
* @param config
*
* @return
*/
private ConfListVo convert(Config config, String appNameString, String envName, ZkDisconfData zkDisconfData) {
ConfListVo confListVo = new ConfListVo();
confListVo.setConfigId(config.getId());
confListVo.setAppId(config.getAppId());
confListVo.setAppName(appNameString);
confListVo.setEnvName(envName);
confListVo.setEnvId(config.getEnvId());
confListVo.setCreateTime(config.getCreateTime());
confListVo.setModifyTime(config.getUpdateTime().substring(0, 12));
confListVo.setKey(config.getName());
// StringEscapeUtils.escapeHtml escape
confListVo.setValue(CodeUtils.unicodeToUtf8(config.getValue()));
confListVo.setVersion(config.getVersion());
confListVo.setType(DisConfigTypeEnum.getByType(config.getType()).getModelName());
confListVo.setTypeId(config.getType());
//
if (zkDisconfData != null) {
confListVo.setMachineSize(zkDisconfData.getData().size());
List<ZkDisconfDataItem> datalist = zkDisconfData.getData();
MachineListVo machineListVo = getZkData(datalist, config);
confListVo.setErrorNum(machineListVo.getErrorNum());
confListVo.setMachineList(machineListVo.getDatalist());
confListVo.setMachineSize(machineListVo.getMachineSize());
}
return confListVo;
}
use of com.baidu.disconf.web.service.config.vo.ConfListVo in project disconf by knightliao.
the class ConfigMgrImpl method getConfigList.
/**
* 配置列表
*/
@Override
public DaoPageResult<ConfListVo> getConfigList(ConfListForm confListForm, boolean fetchZk, final boolean getErrorMessage) {
//
// 数据据结果
//
DaoPageResult<Config> configList = configDao.getConfigList(confListForm.getAppId(), confListForm.getEnvId(), confListForm.getVersion(), confListForm.getPage());
//
//
//
final App app = appMgr.getById(confListForm.getAppId());
final Env env = envMgr.getById(confListForm.getEnvId());
//
//
//
final boolean myFetchZk = fetchZk;
Map<String, ZkDisconfData> zkDataMap = new HashMap<String, ZkDisconfData>();
if (myFetchZk) {
zkDataMap = zkDeployMgr.getZkDisconfDataMap(app.getName(), env.getName(), confListForm.getVersion());
}
final Map<String, ZkDisconfData> myzkDataMap = zkDataMap;
//
// 进行转换
//
DaoPageResult<ConfListVo> configListVo = ServiceUtil.getResult(configList, new DataTransfer<Config, ConfListVo>() {
@Override
public ConfListVo transfer(Config input) {
String appNameString = app.getName();
String envName = env.getName();
ZkDisconfData zkDisconfData = null;
if (myzkDataMap != null && myzkDataMap.keySet().contains(input.getName())) {
zkDisconfData = myzkDataMap.get(input.getName());
}
ConfListVo configListVo = convert(input, appNameString, envName, zkDisconfData);
// 列表操作不要显示值, 为了前端显示快速(只是内存里操作)
if (!myFetchZk && !getErrorMessage) {
// 列表 value 设置为 ""
configListVo.setValue("");
configListVo.setMachineList(new ArrayList<ZkDisconfData.ZkDisconfDataItem>());
}
return configListVo;
}
});
return configListVo;
}
use of com.baidu.disconf.web.service.config.vo.ConfListVo in project disconf by knightliao.
the class ConfigConsistencyMonitorServiceImpl method checkAppEnvVersionConfigConsistency.
/**
* 校验APP/ENV/VERSION 一致性
*/
private void checkAppEnvVersionConfigConsistency(App app, Env env, String version) {
String monitorInfo = "monitor " + app.getName() + "\t" + env.getName() + "\t" + version;
LOG.info(monitorInfo);
//
//
//
ConfListForm confiConfListForm = new ConfListForm();
confiConfListForm.setAppId(app.getId());
confiConfListForm.setEnvId(env.getId());
confiConfListForm.setVersion(version);
//
//
//
DaoPageResult<ConfListVo> daoPageResult = configMgr.getConfigList(confiConfListForm, true, true);
// 准备发送邮件通知
String toEmails = appMgr.getEmails(app.getId());
List<ConfListVo> confListVos = daoPageResult.getResult();
List<String> errorList = new ArrayList<String>();
for (ConfListVo confListVo : confListVos) {
if (confListVo.getErrorNum() != 0) {
List<ZkDisconfDataItem> zkDisconfDataItems = confListVo.getMachineList();
for (ZkDisconfDataItem zkDisconfDataItem : zkDisconfDataItems) {
if (zkDisconfDataItem.getErrorList().size() != 0) {
String data = zkDisconfDataItem.toString() + "<br/><br/><br/><br/><br/><br/>original:" + confListVo.getValue();
LOG.warn(data);
errorList.add(data + "<br/><br/><br/>");
}
}
}
}
if (errorList.size() != 0) {
logMailBean.sendHtmlEmail(toEmails, " monitor ConfigConsistency ", monitorInfo + "<br/><br/><br/>" + errorList.toString());
}
}
use of com.baidu.disconf.web.service.config.vo.ConfListVo in project disconf by knightliao.
the class ConfigReadController method getConfig.
/**
* 获取某个
*
* @param configId
*
* @return
*/
@RequestMapping(value = "/{configId}", method = RequestMethod.GET)
@ResponseBody
public JsonObjectBase getConfig(@PathVariable long configId) {
// 业务校验
configValidator.valideConfigExist(configId);
ConfListVo config = configMgr.getConfVo(configId);
return buildSuccess(config);
}
Aggregations