Search in sources :

Example 1 with ConfListVo

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ConfListVo(com.baidu.disconf.web.service.config.vo.ConfListVo) DocumentNotFoundException(com.baidu.dsp.common.exception.DocumentNotFoundException) HttpEntity(org.springframework.http.HttpEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ConfListVo

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;
}
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 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;
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) ZkDisconfData(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData) HashMap(java.util.HashMap) Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) ArrayList(java.util.ArrayList) Env(com.baidu.disconf.web.service.env.bo.Env) ConfListVo(com.baidu.disconf.web.service.config.vo.ConfListVo)

Example 4 with ConfListVo

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());
    }
}
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)

Example 5 with ConfListVo

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);
}
Also used : ConfListVo(com.baidu.disconf.web.service.config.vo.ConfListVo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ConfListVo (com.baidu.disconf.web.service.config.vo.ConfListVo)5 ZkDisconfDataItem (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData.ZkDisconfDataItem)2 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 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 ConfListForm (com.baidu.disconf.web.service.config.form.ConfListForm)1 MachineListVo (com.baidu.disconf.web.service.config.vo.MachineListVo)1 Env (com.baidu.disconf.web.service.env.bo.Env)1 ZkDisconfData (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData)1 DocumentNotFoundException (com.baidu.dsp.common.exception.DocumentNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1