public Object getData(String path) { path = "/" + path; try { if(_curator.checkExists().forPath(path)!=null) { return _des.deserializeObject(_curator.getData().forPath(path)); } else { return null; } } catch(Exception e) { throw new RuntimeException(e); } }
public byte[] getData(CuratorFramework zk, String path, boolean watch) throws Exception { String npath = PathUtils.normalize_path(path); try { if (existsNode(zk, npath, watch)) { if (watch) { return zk.getData().watched().forPath(npath); } else { return zk.getData().forPath(npath); } } } catch (KeeperException e) { LOG.error("zookeeper getdata for path" + path, e); } return null; }
@Override public byte[] call() throws Exception { return zk.getData().forPath(buildZookeeperPath(pathSuffix)); } });
private void loadData(String path) throws Exception { GetDataBuilder getDataBuilder = client.getData(); String key = getKeyFromNodePath(path); byte[] data = getDataBuilder.forPath(path); String value = new String(data, Charsets.UTF_8); this.config.put(key, value); }
private static Participant participantForPath(CuratorFramework client, String path, boolean markAsLeader) throws Exception { byte[] bytes = client.getData().forPath(path); String thisId = new String(bytes, "UTF-8"); return new Participant(thisId, markAsLeader); }
public byte[] readBytes(String path) { try { if (!exists(path)) return null; return m_curator.getData().forPath(path); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public byte[] getData() throws Exception { return internals.getClient().getData().forPath(path); } };
/** * get /brokers/topics/distributedTopic/partitions/1/state * { "controller_epoch":4, "isr":[ 1, 0 ], "leader":1, "leader_epoch":1, "version":1 } * * @param partition * @return */ private int getLeaderFor(long partition) { try { String topicBrokersPath = partitionPath(); byte[] hostPortData = _curator.getData().forPath(topicBrokersPath + "/" + partition + "/state"); Map<Object, Object> value = (Map<Object, Object>) JSONValue.parse(new String(hostPortData, "UTF-8")); Integer leader = ((Number) value.get("leader")).intValue(); return leader; } catch (Exception e) { throw new RuntimeException(e); } }
public byte[] readBytes(String path) { try { if (_curator.checkExists().forPath(path) != null) { return _curator.getData().forPath(path); } else { return null; } } catch (Exception e) { throw new RuntimeException(e); } }
private void postDataChangeEvent(WatchedEvent event) throws Exception { byte[] data = client.getData().forPath(event.getPath()); String value = new String(data, Charsets.UTF_8); String key = event.getPath().replace("/", "."); postDataChangeKeyValue(key, value); }
public KafkaBroker getBroker(String zookeeperUri, String brokerId) { KafkaBroker kafkaBroker = null; // Get the updated status for the cluster from zookeeper CuratorFramework curatorClient = getCuratorClient(zookeeperUri); if (curatorClient != null) { try { byte[] brokerData = curatorClient.getData().forPath("/brokers/ids/" + brokerId); // Parse the broker data provided as a JSON string Map<String, Object> brokerObject = objectMapper.readValue(brokerData, Map.class); kafkaBroker = new KafkaBroker(); kafkaBroker.setId(brokerId); kafkaBroker.setHost((String) brokerObject.get("host")); kafkaBroker.setPort((Integer) brokerObject.get("port")); kafkaBroker.setJmxPort((Integer) brokerObject.get("jmx_port")); } catch (Exception ex) { ex.printStackTrace(); kafkaBroker = null; } } return kafkaBroker; }
@Override public HostConfiguration getManualFailoverConfiguration() { try { if (this.curator.checkExists().forPath(MANUAL_FAILOVER_PATH) != null) { byte[] data = this.curator.getData().forPath(MANUAL_FAILOVER_PATH); String host = new String(data, Charset.forName("UTF-8")); if (host.contains(":")) { String[] hostData = host.split(":"); return new HostConfiguration(hostData[0], Integer.valueOf(hostData[1])); } else { this.deleteManualFailoverConfiguration(); } } } catch (NumberFormatException e) { this.deleteManualFailoverConfiguration(); } catch (Exception e) { throw new ZooKeeperException(e); } return null; }
@Override public Map<String, Map<HostConfiguration, NodeState>> getNodeDatas() { Map<String, Map<HostConfiguration, NodeState>> states = new HashMap<String, Map<HostConfiguration, NodeState>>(); try { List<String> children = this.curator.getChildren().forPath(NODE_STATES_PATH); for (String path : children) { byte[] nodeData = this.curator.getData().forPath(PathUtils.toPath(NODE_STATES_PATH, path)); if (nodeData != null && nodeData.length > 0) { states.put(path, this.jsonBinder.toNodeState(nodeData)); } } } catch (Exception e) { log.error("Error trying to access node datas", e); throw new ZooKeeperException(e); } return states; }
byte[] brokerData = curatorClient.getData().forPath("/brokers/ids/" + brokerId);
@Override public ClusterStatus getClusterData() { try { byte[] data = this.curator.getData().forPath(CLUSTER_PATH); if (data != null && data.length != 0) { return this.jsonBinder.toClusterStatus(data); } else { return new ClusterStatus(null, Collections.EMPTY_LIST, Collections.EMPTY_LIST); } } catch (Exception e) { throw new ZooKeeperException(e); } }
/** * Get all partitions with their current leaders */ public GlobalPartitionInformation getBrokerInfo() { GlobalPartitionInformation globalPartitionInformation = new GlobalPartitionInformation(); try { int numPartitionsForTopic = getNumPartitions(); String brokerInfoPath = brokerPath(); for (int partition = 0; partition < numPartitionsForTopic; partition++) { int leader = getLeaderFor(partition); String path = brokerInfoPath + "/" + leader; try { byte[] brokerData = _curator.getData().forPath(path); Broker hp = getBrokerHost(brokerData); globalPartitionInformation.addPartition(partition, hp); } catch (org.apache.zookeeper.KeeperException.NoNodeException e) { LOG.error("Node {} does not exist ", path); } } } catch (Exception e) { throw new RuntimeException(e); } LOG.info("Read partition info from zookeeper: " + globalPartitionInformation); return globalPartitionInformation; }
try byte[] bytes = client.getData().forPath(thisPath); if ( removeIt )
Mod<byte[]> newVal = f.apply(zk.getData().forPath(path));
if ( type == ProcessType.NORMAL ) bytes = client.getData().forPath(itemPath); requeue = (processMessageBytes(itemNode, bytes) == ProcessMessageBytesCode.REQUEUE);