Search in sources :

Example 1 with MachineListVo

use of com.baidu.disconf.web.service.config.vo.MachineListVo in project disconf by knightliao.

the class ConfigReadController method getZkInfo.

/**
     * 获取 zk
     *
     * @param configId
     *
     * @return
     */
@RequestMapping(value = "/zk/{configId}", method = RequestMethod.GET)
@ResponseBody
public JsonObjectBase getZkInfo(@PathVariable long configId) {
    // 业务校验
    configValidator.valideConfigExist(configId);
    MachineListVo machineListVo = configMgr.getConfVoWithZk(configId);
    return buildSuccess(machineListVo);
}
Also used : MachineListVo(com.baidu.disconf.web.service.config.vo.MachineListVo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with MachineListVo

use of com.baidu.disconf.web.service.config.vo.MachineListVo 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 3 with MachineListVo

use of com.baidu.disconf.web.service.config.vo.MachineListVo 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 4 with MachineListVo

use of com.baidu.disconf.web.service.config.vo.MachineListVo in project disconf by knightliao.

the class ConfigMgrImpl method getConfVoWithZk.

/**
     * 根据 配置ID获取ZK对比数据
     */
@Override
public MachineListVo getConfVoWithZk(Long configId) {
    Config config = configDao.get(configId);
    App app = appMgr.getById(config.getAppId());
    Env env = envMgr.getById(config.getEnvId());
    //
    //
    //
    DisConfigTypeEnum disConfigTypeEnum = DisConfigTypeEnum.FILE;
    if (config.getType().equals(DisConfigTypeEnum.ITEM.getType())) {
        disConfigTypeEnum = DisConfigTypeEnum.ITEM;
    }
    ZkDisconfData zkDisconfData = zkDeployMgr.getZkDisconfData(app.getName(), env.getName(), config.getVersion(), disConfigTypeEnum, config.getName());
    if (zkDisconfData == null) {
        return new MachineListVo();
    }
    MachineListVo machineListVo = getZkData(zkDisconfData.getData(), config);
    return machineListVo;
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) ZkDisconfData(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData) DisConfigTypeEnum(com.baidu.disconf.core.common.constants.DisConfigTypeEnum) Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) MachineListVo(com.baidu.disconf.web.service.config.vo.MachineListVo) Env(com.baidu.disconf.web.service.env.bo.Env)

Aggregations

MachineListVo (com.baidu.disconf.web.service.config.vo.MachineListVo)4 ZkDisconfDataItem (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem)2 DisConfigTypeEnum (com.baidu.disconf.core.common.constants.DisConfigTypeEnum)1 ApplicationPropertyConfig (com.baidu.disconf.web.config.ApplicationPropertyConfig)1 App (com.baidu.disconf.web.service.app.bo.App)1 Config (com.baidu.disconf.web.service.config.bo.Config)1 ConfListVo (com.baidu.disconf.web.service.config.vo.ConfListVo)1 Env (com.baidu.disconf.web.service.env.bo.Env)1 ZkDisconfData (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1