use of com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData in project disconf by knightliao.
the class ZookeeperDriverImpl method getDisconfData.
/**
* 获取指定 配置数据
*
* @return
*
* @throws InterruptedException
* @throws KeeperException
*/
private ZkDisconfData getDisconfData(String path, String keyName, ZooKeeper zooKeeper) throws KeeperException, InterruptedException {
String curPath = path + "/" + keyName;
if (zooKeeper.exists(curPath, false) == null) {
return null;
}
ZkDisconfData zkDisconfData = new ZkDisconfData();
zkDisconfData.setKey(keyName);
List<String> secChiList = zooKeeper.getChildren(curPath, false);
List<ZkDisconfData.ZkDisconfDataItem> zkDisconfDataItems = new ArrayList<ZkDisconfData.ZkDisconfDataItem>();
// list
for (String secKey : secChiList) {
// machine
ZkDisconfData.ZkDisconfDataItem zkDisconfDataItem = new ZkDisconfData.ZkDisconfDataItem();
zkDisconfDataItem.setMachine(secKey);
String thirdPath = curPath + "/" + secKey;
// value
byte[] data = zooKeeper.getData(thirdPath, null, null);
if (data != null) {
zkDisconfDataItem.setValue(new String(data, CHARSET));
}
// add
zkDisconfDataItems.add(zkDisconfDataItem);
}
zkDisconfData.setData(zkDisconfDataItems);
return zkDisconfData;
}
use of com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData in project disconf by knightliao.
the class ZookeeperDriverImpl method getDisconfData.
/**
* 广度搜索法:搜索分布式配置对应的两层数据
*
* @return
*
* @throws InterruptedException
* @throws KeeperException
*/
private Map<String, ZkDisconfData> getDisconfData(String path) throws KeeperException, InterruptedException {
Map<String, ZkDisconfData> ret = new HashMap<String, ZkDisconfData>();
ZookeeperMgr zooKeeperMgr = ZookeeperMgr.getInstance();
ZooKeeper zooKeeper = zooKeeperMgr.getZk();
if (zooKeeper.exists(path, false) == null) {
return ret;
}
List<String> children = zooKeeper.getChildren(path, false);
for (String firstKey : children) {
ZkDisconfData zkDisconfData = getDisconfData(path, firstKey, zooKeeper);
if (zkDisconfData != null) {
ret.put(firstKey, zkDisconfData);
}
}
return ret;
}
use of com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData 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;
}
use of com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData 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;
}
Aggregations