Search in sources :

Example 1 with JsonException

use of com.bonree.brfs.common.utils.JsonUtils.JsonException in project BRFS by zhangnianli.

the class ReadMetaData method main.

public static void main(String[] args) throws JsonException {
    String path = "/brfs/test1/rebalance/changes/0";
    Map<String, List<ChangeSummary>> csMap = Maps.newHashMap();
    CuratorClient curatorClient = CuratorClient.getClientInstance("192.168.107.13");
    List<String> childNodeList = curatorClient.getChildren(path);
    Collections.sort(childNodeList);
    for (String node : childNodeList) {
        String nodePath = ZKPaths.makePath(path, node);
        ChangeSummary cs = JsonUtils.toObject(curatorClient.getData(nodePath), ChangeSummary.class);
        if (csMap.get(cs.getChangeServer()) == null) {
            List<ChangeSummary> csList = Lists.newArrayList();
            csList.add(cs);
            csMap.put(cs.getChangeServer(), csList);
        } else {
            csMap.get(cs.getChangeServer()).add(cs);
        }
    }
    for (Entry<String, List<ChangeSummary>> entry : csMap.entrySet()) {
        System.out.println(entry.getKey() + ":" + entry.getValue());
        System.out.println(entry.getKey() + ":" + entry.getValue().stream().map(x -> x.getChangeType()).collect(Collectors.toList()));
    }
    curatorClient.close();
}
Also used : Maps(org.apache.curator.shaded.com.google.common.collect.Maps) List(java.util.List) ZKPaths(org.apache.curator.utils.ZKPaths) JsonException(com.bonree.brfs.common.utils.JsonUtils.JsonException) Lists(com.google.common.collect.Lists) JsonUtils(com.bonree.brfs.common.utils.JsonUtils) Map(java.util.Map) Entry(java.util.Map.Entry) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) List(java.util.List)

Aggregations

JsonUtils (com.bonree.brfs.common.utils.JsonUtils)1 JsonException (com.bonree.brfs.common.utils.JsonUtils.JsonException)1 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)1 Lists (com.google.common.collect.Lists)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Maps (org.apache.curator.shaded.com.google.common.collect.Maps)1 ZKPaths (org.apache.curator.utils.ZKPaths)1