Search in sources :

Example 1 with ZookeeperMgr

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;
}
Also used : ZookeeperMgr(com.baidu.disconf.core.common.zookeeper.ZookeeperMgr) ZooKeeper(org.apache.zookeeper.ZooKeeper) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with ZookeeperMgr

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;
}
Also used : ZkDisconfData(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData) ZookeeperMgr(com.baidu.disconf.core.common.zookeeper.ZookeeperMgr) ZooKeeper(org.apache.zookeeper.ZooKeeper) HashMap(java.util.HashMap)

Example 3 with ZookeeperMgr

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;
}
Also used : ZookeeperMgr(com.baidu.disconf.core.common.zookeeper.ZookeeperMgr) ZooKeeper(org.apache.zookeeper.ZooKeeper) ArrayList(java.util.ArrayList) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with ZookeeperMgr

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);
}
Also used : ZookeeperMgr(com.baidu.disconf.core.common.zookeeper.ZookeeperMgr) ResilientActiveKeyValueStore(com.baidu.disconf.core.common.zookeeper.inner.ResilientActiveKeyValueStore) NonStrictExpectations(mockit.NonStrictExpectations) ResilientActiveKeyValueStoreMock(com.baidu.disconf.core.test.zookeeper.mock.ResilientActiveKeyValueStoreMock) Test(org.junit.Test)

Aggregations

ZookeeperMgr (com.baidu.disconf.core.common.zookeeper.ZookeeperMgr)4 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 KeeperException (org.apache.zookeeper.KeeperException)2 ResilientActiveKeyValueStore (com.baidu.disconf.core.common.zookeeper.inner.ResilientActiveKeyValueStore)1 ResilientActiveKeyValueStoreMock (com.baidu.disconf.core.test.zookeeper.mock.ResilientActiveKeyValueStoreMock)1 ZkDisconfData (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NonStrictExpectations (mockit.NonStrictExpectations)1 Test (org.junit.Test)1