Search in sources :

Example 1 with ZkDisconfDataItem

use of com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem in project disconf by knightliao.

the class ConfigMgrImpl method getZkData.

/**
     * 获取ZK data
     */
private MachineListVo getZkData(List<ZkDisconfDataItem> datalist, Config config) {
    int errorNum = 0;
    for (ZkDisconfDataItem zkDisconfDataItem : datalist) {
        if (config.getType().equals(DisConfigTypeEnum.FILE.getType())) {
            List<String> errorKeyList = compareConfig(zkDisconfDataItem.getValue(), config.getValue());
            if (errorKeyList.size() != 0) {
                zkDisconfDataItem.setErrorList(errorKeyList);
                errorNum++;
            }
        } else {
            if (zkDisconfDataItem.getValue().trim().equals(config.getValue().trim())) {
            } else {
                List<String> errorKeyList = new ArrayList<String>();
                errorKeyList.add(config.getValue().trim());
                zkDisconfDataItem.setErrorList(errorKeyList);
                errorNum++;
            }
        }
    }
    MachineListVo machineListVo = new MachineListVo();
    machineListVo.setDatalist(datalist);
    machineListVo.setErrorNum(errorNum);
    machineListVo.setMachineSize(datalist.size());
    return machineListVo;
}
Also used : ArrayList(java.util.ArrayList) MachineListVo(com.baidu.disconf.web.service.config.vo.MachineListVo) ZkDisconfDataItem(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem)

Example 2 with ZkDisconfDataItem

use of com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem 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;
}
Also used : ConfListVo(com.baidu.disconf.web.service.config.vo.ConfListVo) MachineListVo(com.baidu.disconf.web.service.config.vo.MachineListVo) ZkDisconfDataItem(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem)

Example 3 with ZkDisconfDataItem

use of com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem 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());
    }
}
Also used : ConfListVo(com.baidu.disconf.web.service.config.vo.ConfListVo) ConfListForm(com.baidu.disconf.web.service.config.form.ConfListForm) ArrayList(java.util.ArrayList) ZkDisconfDataItem(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem)

Aggregations

ZkDisconfDataItem (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem)3 ConfListVo (com.baidu.disconf.web.service.config.vo.ConfListVo)2 MachineListVo (com.baidu.disconf.web.service.config.vo.MachineListVo)2 ArrayList (java.util.ArrayList)2 ConfListForm (com.baidu.disconf.web.service.config.form.ConfListForm)1