Search in sources :

Example 1 with 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 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;
}
Also used : ZkDisconfData(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData) ArrayList(java.util.ArrayList)

Example 2 with 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;
}
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 ZkDisconfData

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;
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) ZkDisconfData(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData) DisConfigTypeEnum(com.baidu.disconf.core.common.constants.DisConfigTypeEnum) Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) MachineListVo(com.baidu.disconf.web.service.config.vo.MachineListVo) Env(com.baidu.disconf.web.service.env.bo.Env)

Example 4 with ZkDisconfData

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;
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) ZkDisconfData(com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData) HashMap(java.util.HashMap) Config(com.baidu.disconf.web.service.config.bo.Config) ApplicationPropertyConfig(com.baidu.disconf.web.config.ApplicationPropertyConfig) ArrayList(java.util.ArrayList) Env(com.baidu.disconf.web.service.env.bo.Env) ConfListVo(com.baidu.disconf.web.service.config.vo.ConfListVo)

Aggregations

ZkDisconfData (com.baidu.disconf.web.service.zookeeper.dto.ZkDisconfData)4 ApplicationPropertyConfig (com.baidu.disconf.web.config.ApplicationPropertyConfig)2 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 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DisConfigTypeEnum (com.baidu.disconf.core.common.constants.DisConfigTypeEnum)1 ZookeeperMgr (com.baidu.disconf.core.common.zookeeper.ZookeeperMgr)1 ConfListVo (com.baidu.disconf.web.service.config.vo.ConfListVo)1 MachineListVo (com.baidu.disconf.web.service.config.vo.MachineListVo)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1