Search in sources :

Example 6 with Config

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

the class ConfigMgrImpl method getVersionListByAppEnv.

/**
     * 根据APPid获取其版本列表
     */
@Override
public List<String> getVersionListByAppEnv(Long appId, Long envId) {
    List<String> versionList = new ArrayList<String>();
    List<Config> configs = configDao.getConfByAppEnv(appId, envId);
    for (Config config : configs) {
        if (!versionList.contains(config.getVersion())) {
            versionList.add(config.getVersion());
        }
    }
    return versionList;
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) ArrayList(java.util.ArrayList)

Example 7 with Config

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

the class ConfigMgrImpl method updateItemValue.

/**
     * 更新 配置项/配置文件 的值
     */
@Override
public String updateItemValue(Long configId, String value) {
    Config config = getConfigById(configId);
    String oldValue = config.getValue();
    //
    // 配置数据库的值 encode to db
    //
    configDao.updateValue(configId, CodeUtils.utf8ToUnicode(value));
    configHistoryMgr.createOne(configId, oldValue, CodeUtils.utf8ToUnicode(value));
    //
    // 发送邮件通知
    //
    String toEmails = appMgr.getEmails(config.getAppId());
    if (applicationPropertyConfig.isEmailMonitorOn()) {
        boolean isSendSuccess = logMailBean.sendHtmlEmail(toEmails, " config update", DiffUtils.getDiff(CodeUtils.unicodeToUtf8(oldValue), value, config.toString(), getConfigUrlHtml(config)));
        if (isSendSuccess) {
            return "修改成功,邮件通知成功";
        } else {
            return "修改成功,邮件发送失败,请检查邮箱配置";
        }
    }
    return "修改成功";
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig)

Example 8 with Config

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

the class ConfigFetcherController method getFile.

/**
     * 获取配置文件
     *
     * @return
     */
@NoAuth
@RequestMapping(value = "/file", method = RequestMethod.GET)
@ResponseBody
public HttpEntity<byte[]> getFile(ConfForm confForm) {
    boolean hasError = false;
    //
    // 校验
    //
    ConfigFullModel configModel = null;
    try {
        configModel = configValidator4Fetch.verifyConfForm(confForm, false);
    } catch (Exception e) {
        LOG.error(e.toString());
        hasError = true;
    }
    if (hasError == false) {
        try {
            //
            Config config = configFetchMgr.getConfByParameter(configModel.getApp().getId(), configModel.getEnv().getId(), configModel.getVersion(), configModel.getKey(), DisConfigTypeEnum.FILE);
            if (config == null) {
                hasError = true;
                throw new DocumentNotFoundException(configModel.getKey());
            }
            //API获取节点内容也需要同样做格式转换
            return downloadDspBill(configModel.getKey(), config.getValue());
        } catch (Exception e) {
            LOG.error(e.toString());
        }
    }
    if (confForm.getKey() != null) {
        throw new DocumentNotFoundException(confForm.getKey());
    } else {
        throw new DocumentNotFoundException("");
    }
}
Also used : DocumentNotFoundException(com.baidu.dsp.common.exception.DocumentNotFoundException) Config(com.baidu.disconf.web.service.config.bo.Config) ConfigFullModel(com.baidu.disconf.web.web.config.dto.ConfigFullModel) DocumentNotFoundException(com.baidu.dsp.common.exception.DocumentNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoAuth(com.baidu.dsp.common.annotation.NoAuth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with Config

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

the class ConfigDaoTestCase method test.

@Test
public void test() {
    URL url = ClassLoader.getSystemResource("file2/confA.properties");
    byte[] btyes = readFileContent(url.getPath());
    try {
        // read data
        String str = new String(btyes, "UTF-8");
        // save to db
        Config config = configDao.get(1L);
        config.setValue(str);
        configDao.update(config);
        // read
        LOG.info(configDao.get(1L).getValue());
    } catch (UnsupportedEncodingException e) {
        Assert.assertTrue(false);
    }
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URL(java.net.URL) Test(org.junit.Test)

Example 10 with Config

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

the class ConfigFetcherController method getListImp.

private JsonObjectBase getListImp(ConfForm confForm, boolean hasValue) {
    LOG.info(confForm.toString());
    //
    // 校验
    //
    ConfigFullModel configModel = configValidator4Fetch.verifyConfForm(confForm, true);
    List<Config> configs = configFetchMgr.getConfListByParameter(configModel.getApp().getId(), configModel.getEnv().getId(), configModel.getVersion(), hasValue);
    return buildListSuccess(configs, configs.size());
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) ConfigFullModel(com.baidu.disconf.web.web.config.dto.ConfigFullModel)

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