Search in sources :

Example 1 with ConfigFullModel

use of com.baidu.disconf.web.web.config.dto.ConfigFullModel 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 2 with ConfigFullModel

use of com.baidu.disconf.web.web.config.dto.ConfigFullModel in project disconf by knightliao.

the class ConfigValidator4Fetch method verifyConfForm.

/**
 * 此接口是客户的接口,非常 重要,目前没有权限的控制
 *
 * @param confForm
 */
public ConfigFullModel verifyConfForm(ConfForm confForm, boolean unCheckKey) {
    // 
    if (StringUtils.isEmpty(confForm.getApp())) {
        throw new FieldException("app", "app is empty", null);
    }
    App app = appMgr.getByName(confForm.getApp());
    if (app == null) {
        throw new FieldException("app", "app " + confForm.getApp() + " doesn't exist in db.", null);
    }
    // 
    if (StringUtils.isEmpty(confForm.getEnv())) {
        throw new FieldException("env", "env is empty", null);
    }
    Env env = envMgr.getByName(confForm.getEnv());
    if (env == null) {
        throw new FieldException("env", "env " + confForm.getEnv() + " doesn't exist in db.", null);
    }
    // 
    if (!unCheckKey && StringUtils.isEmpty(confForm.getKey())) {
        throw new FieldException("key", "key is empty", null);
    }
    // 
    if (StringUtils.isEmpty(confForm.getVersion())) {
        throw new FieldException("version", "version is empty", null);
    }
    return new ConfigFullModel(app, env, confForm.getVersion(), confForm.getKey());
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) FieldException(com.baidu.dsp.common.exception.FieldException) ConfigFullModel(com.baidu.disconf.web.web.config.dto.ConfigFullModel) Env(com.baidu.disconf.web.service.env.bo.Env)

Example 3 with ConfigFullModel

use of com.baidu.disconf.web.web.config.dto.ConfigFullModel in project disconf by knightliao.

the class ConfigFetcherController method getItem.

/**
 * 获取配置项 Item
 *
 * @param confForm
 *
 * @return
 */
@NoAuth
@RequestMapping(value = "/item", method = RequestMethod.GET)
@ResponseBody
public ValueVo getItem(ConfForm confForm) {
    LOG.info(confForm.toString());
    // 
    // 校验
    // 
    ConfigFullModel configModel = null;
    try {
        configModel = configValidator4Fetch.verifyConfForm(confForm, false);
    } catch (Exception e) {
        LOG.warn(e.toString());
        return ConfigUtils.getErrorVo(e.getMessage());
    }
    return configFetchMgr.getConfItemByParameter(configModel.getApp().getId(), configModel.getEnv().getId(), configModel.getVersion(), configModel.getKey());
}
Also used : 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 4 with ConfigFullModel

use of com.baidu.disconf.web.web.config.dto.ConfigFullModel 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)

Example 5 with ConfigFullModel

use of com.baidu.disconf.web.web.config.dto.ConfigFullModel in project disconf by knightliao.

the class ZkDeployValidator method verify.

/**
 * @param zkDeployForm
 *
 * @return
 */
public ConfigFullModel verify(ZkDeployForm zkDeployForm) {
    // 
    if (zkDeployForm.getAppId() == null) {
        throw new FieldException("app is empty", null);
    }
    App app = appMgr.getById(zkDeployForm.getAppId());
    if (app == null) {
        throw new FieldException("app " + zkDeployForm.getAppId() + " doesn't exist in db.", null);
    }
    // 
    if (zkDeployForm.getEnvId() == null) {
        throw new FieldException("app is empty", null);
    }
    Env env = envMgr.getById(zkDeployForm.getEnvId());
    if (env == null) {
        throw new FieldException("env " + zkDeployForm.getEnvId() + " doesn't exist in db.", null);
    }
    // 
    if (StringUtils.isEmpty(zkDeployForm.getVersion())) {
        throw new FieldException("version is empty", null);
    }
    return new ConfigFullModel(app, env, zkDeployForm.getVersion(), "");
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) FieldException(com.baidu.dsp.common.exception.FieldException) ConfigFullModel(com.baidu.disconf.web.web.config.dto.ConfigFullModel) Env(com.baidu.disconf.web.service.env.bo.Env)

Aggregations

ConfigFullModel (com.baidu.disconf.web.web.config.dto.ConfigFullModel)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 App (com.baidu.disconf.web.service.app.bo.App)2 Config (com.baidu.disconf.web.service.config.bo.Config)2 Env (com.baidu.disconf.web.service.env.bo.Env)2 NoAuth (com.baidu.dsp.common.annotation.NoAuth)2 DocumentNotFoundException (com.baidu.dsp.common.exception.DocumentNotFoundException)2 FieldException (com.baidu.dsp.common.exception.FieldException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2