Search in sources :

Example 11 with Config

use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.

the class ConfigMgrImpl method newConfig.

/**
     * 新建配置
     */
@Override
public void newConfig(ConfNewItemForm confNewForm, DisConfigTypeEnum disConfigTypeEnum) {
    Config config = new Config();
    config.setAppId(confNewForm.getAppId());
    config.setEnvId(confNewForm.getEnvId());
    config.setName(confNewForm.getKey());
    config.setType(disConfigTypeEnum.getType());
    config.setVersion(confNewForm.getVersion());
    config.setValue(CodeUtils.utf8ToUnicode(confNewForm.getValue()));
    config.setStatus(Constants.STATUS_NORMAL);
    // 时间
    String curTime = DateUtils.format(new Date(), DataFormatConstants.COMMON_TIME_FORMAT);
    config.setCreateTime(curTime);
    config.setUpdateTime(curTime);
    configDao.create(config);
    configHistoryMgr.createOne(config.getId(), "", config.getValue());
    // 发送邮件通知
    //
    String toEmails = appMgr.getEmails(config.getAppId());
    if (applicationPropertyConfig.isEmailMonitorOn() == true) {
        logMailBean.sendHtmlEmail(toEmails, " config new", getNewValue(confNewForm.getValue(), config.toString(), getConfigUrlHtml(config)));
    }
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) Date(java.util.Date)

Example 12 with Config

use of com.baidu.disconf.web.service.config.bo.Config 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)

Example 13 with Config

use of com.baidu.disconf.web.service.config.bo.Config 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 14 with Config

use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.

the class ConfigMgrImpl method delete.

/**
     * 删除配置
     *
     * @param configId
     */
@Override
public void delete(Long configId) {
    Config config = configDao.get(configId);
    configHistoryMgr.createOne(configId, config.getValue(), "");
    configDao.deleteItem(configId);
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig)

Example 15 with Config

use of com.baidu.disconf.web.service.config.bo.Config in project disconf by knightliao.

the class ConfigFetchMgrImpl method getConfItemByParameter.

/**
     * 根据详细参数获取配置返回
     */
public ValueVo getConfItemByParameter(Long appId, Long envId, String version, String key) {
    Config config = configDao.getByParameter(appId, envId, version, key, DisConfigTypeEnum.ITEM);
    if (config == null) {
        return ConfigUtils.getErrorVo("cannot find this config");
    }
    ValueVo valueVo = new ValueVo();
    valueVo.setValue(config.getValue());
    valueVo.setStatus(Constants.OK);
    return valueVo;
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) ValueVo(com.baidu.disconf.core.common.json.ValueVo)

Aggregations

Config (com.baidu.disconf.web.service.config.bo.Config)15 ApplicationPropertyConfig (com.baidu.disconf.web.config.ApplicationPropertyConfig)8 App (com.baidu.disconf.web.service.app.bo.App)4 Env (com.baidu.disconf.web.service.env.bo.Env)4 FieldException (com.baidu.dsp.common.exception.FieldException)3 ArrayList (java.util.ArrayList)3 ZkDisconfData (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData)2 ConfigFullModel (com.baidu.disconf.web.web.config.dto.ConfigFullModel)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 DisConfigTypeEnum (com.baidu.disconf.core.common.constants.DisConfigTypeEnum)1 ValueVo (com.baidu.disconf.core.common.json.ValueVo)1 ConfListVo (com.baidu.disconf.web.service.config.vo.ConfListVo)1 MachineListVo (com.baidu.disconf.web.service.config.vo.MachineListVo)1 NoAuth (com.baidu.dsp.common.annotation.NoAuth)1 DocumentNotFoundException (com.baidu.dsp.common.exception.DocumentNotFoundException)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1