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