Search in sources :

Example 1 with Config

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

the class ConfigMgrImpl method getDisconfFileList.

/**
     * 配置文件的整合
     *
     * @param confListForm
     *
     * @return
     */
public List<File> getDisconfFileList(ConfListForm confListForm) {
    List<Config> configList = configDao.getConfigList(confListForm.getAppId(), confListForm.getEnvId(), confListForm.getVersion(), true);
    // 时间作为当前文件夹
    String curTime = DateUtils.format(new Date(), DataFormatConstants.COMMON_TIME_FORMAT);
    curTime = "tmp" + File.separator + curTime;
    OsUtil.makeDirs(curTime);
    List<File> files = new ArrayList<File>();
    for (Config config : configList) {
        if (config.getType().equals(DisConfigTypeEnum.FILE.getType())) {
            File file = new File(curTime, config.getName());
            try {
                FileUtils.writeByteArrayToFile(file, config.getValue().getBytes());
            } catch (IOException e) {
                LOG.warn(e.toString());
            }
            files.add(file);
        }
    }
    return files;
}
Also used : Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) Date(java.util.Date)

Example 2 with Config

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

the class ConfigMgrImpl method getConfVo.

/**
     * 根据 配置ID获取配置返回
     */
@Override
public ConfListVo getConfVo(Long configId) {
    Config config = configDao.get(configId);
    App app = appMgr.getById(config.getAppId());
    Env env = envMgr.getById(config.getEnvId());
    return convert(config, app.getName(), env.getName(), null);
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) Env(com.baidu.disconf.web.service.env.bo.Env)

Example 3 with Config

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

the class ConfigValidator method validateNew.

/**
     * 校验新建 配置
     *
     * @param confNewForm
     * @param disConfigTypeEnum
     */
public void validateNew(ConfNewItemForm confNewForm, DisConfigTypeEnum disConfigTypeEnum) {
    //
    // app
    //
    App app = appMgr.getById(confNewForm.getAppId());
    if (app == null) {
        throw new FieldException(ConfNewForm.APPID, "app.not.exist", null);
    }
    //
    validateAppAuth(app.getId());
    //
    // env
    //
    Env env = envMgr.getById(confNewForm.getEnvId());
    if (env == null) {
        throw new FieldException(ConfNewForm.ENVID, "env.not.exist", null);
    }
    //
    // key
    //
    Config config = configFetchMgr.getConfByParameter(app.getId(), env.getId(), confNewForm.getVersion(), confNewForm.getKey(), disConfigTypeEnum);
    if (config != null) {
        throw new FieldException(ConfNewItemForm.KEY, "key.exist", null);
    }
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) FieldException(com.baidu.dsp.common.exception.FieldException) Config(com.baidu.disconf.web.service.config.bo.Config) Env(com.baidu.disconf.web.service.env.bo.Env)

Example 4 with Config

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

the class ConfigValidator method validateDelete.

/**
     * 验证删除
     */
public void validateDelete(Long configId) {
    Config config = configMgr.getConfigById(configId);
    if (config == null) {
        throw new FieldException("configId", "config.not.exist", null);
    }
    //
    validateAppAuth(config.getAppId());
}
Also used : FieldException(com.baidu.dsp.common.exception.FieldException) Config(com.baidu.disconf.web.service.config.bo.Config)

Example 5 with Config

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

the class ConfigValidator method valideConfigExist.

/**
     * 校验
     *
     * @param id
     *
     * @return
     */
public Config valideConfigExist(Long id) {
    //
    // config
    //
    Config config = configMgr.getConfigById(id);
    if (config == null) {
        throw new FieldException("configId", "config.id.not.exist", null);
    }
    //
    // validate app
    //
    validateAppAuth(config.getAppId());
    return config;
}
Also used : FieldException(com.baidu.dsp.common.exception.FieldException) Config(com.baidu.disconf.web.service.config.bo.Config)

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