use of com.baidu.disconf.core.common.zookeeper.ZookeeperMgr in project disconf by knightliao.
the class ZookeeperDriverImpl method getDisconfData.
/**
* 获取分布式配置 Map
*
* @param app
* @param env
* @param version
*
* @return
*/
@Override
public ZkDisconfData getDisconfData(String app, String env, String version, DisConfigTypeEnum disConfigTypeEnum, String keyName) {
String baseUrl = ZooPathMgr.getZooBaseUrl(zooConfig.getZookeeperUrlPrefix(), app, env, version);
try {
ZookeeperMgr zooKeeperMgr = ZookeeperMgr.getInstance();
ZooKeeper zooKeeper = zooKeeperMgr.getZk();
if (disConfigTypeEnum.equals(DisConfigTypeEnum.FILE)) {
return getDisconfData(ZooPathMgr.getFileZooPath(baseUrl), keyName, zooKeeper);
} else if (disConfigTypeEnum.equals(DisConfigTypeEnum.ITEM)) {
return getDisconfData(ZooPathMgr.getItemZooPath(baseUrl), keyName, zooKeeper);
}
} catch (KeeperException e) {
LOG.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOG.error(e.getMessage(), e);
}
return null;
}
use of com.baidu.disconf.core.common.zookeeper.ZookeeperMgr 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.core.common.zookeeper.ZookeeperMgr in project disconf by knightliao.
the class ZookeeperDriverImpl method getConf.
/**
* 返回groupName结点向下的所有zookeeper信息
*
* @param
*/
@Override
public List<String> getConf(String groupName) {
ZookeeperMgr zooKeeperMgr = ZookeeperMgr.getInstance();
ZooKeeper zooKeeper = zooKeeperMgr.getZk();
List<String> retList = new ArrayList<String>();
try {
getConf(zooKeeper, groupName, groupName, retList);
} catch (KeeperException e) {
LOG.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOG.error(e.getMessage(), e);
}
return retList;
}
use of com.baidu.disconf.core.common.zookeeper.ZookeeperMgr in project disconf by knightliao.
the class ZookeeperMgrTest method testGetRootChildren.
/**
* 测试获取Root子节点
*/
@Test
public final void testGetRootChildren() {
final ZookeeperMgr obj = ZookeeperMgr.getInstance();
//
// 注入
//
new NonStrictExpectations(obj) {
{
ResilientActiveKeyValueStore store = new ResilientActiveKeyValueStoreMock();
this.setField(obj, "store", store);
}
};
List<String> list = ZookeeperMgr.getInstance().getRootChildren();
for (String item : list) {
System.out.println(item);
}
Assert.assertTrue(list.size() > 0);
}
Aggregations