Refine search
@Override public String doGetContent(String path) { try { byte[] dataBytes = client.getData().forPath(path); return (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, charset); } catch (NoNodeException e) { // ignore NoNode Exception. } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } return null; }
@Override public String doGetContent(String path) { try { byte[] dataBytes = client.getData().forPath(path); return (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, charset); } catch (NoNodeException e) { // ignore NoNode Exception. } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } return null; }
@Override public String readData(String statePath) { try { if (curatorFramework.checkExists().forPath(statePath) == null) { // do we want to throw an exception if path doesn't exist?? return null; } else { byte[] bytes = curatorFramework.getData().forPath(statePath); String data = new String(bytes); logger.info(String.format("data was retrieved. path: %s, data: %s.", statePath, data)); return data; } } catch (Exception e) { throw new RuntimeException(e); } } }
public List<TaskAnnouncement> getAnnouncements() throws Exception { final List<TaskAnnouncement> announcements = new ArrayList<>(); for (String id : curatorFramework.getChildren().forPath(getStatusPathForWorker())) { announcements.add( jsonMapper.readValue( curatorFramework.getData().forPath(getStatusPathForId(id)), TaskAnnouncement.class ) ); } return announcements; }
/** * Get the jobid for this tracking node * @throws IOException */ public String getJobID() throws IOException { try { return new String(zk.getData().forPath(makeTrackingJobZnode(trackingnode))); } catch (Exception e) { // It was deleted during the transaction throw new IOException("Node already deleted " + trackingnode, e); } }
@Override public String peekLock(String lockPath) { lockPath = norm(lockPath); try { byte[] bytes = curator.getData().forPath(lockPath); return new String(bytes, StandardCharsets.UTF_8); } catch (KeeperException.NoNodeException ex) { return null; } catch (Exception ex) { throw new IllegalStateException("Error while peeking at " + lockPath, ex); } }
private static Map<TopicPartition, OffsetAndMetadata> getOffsetsAtPath( CuratorFramework curator, ObjectMapper objectMapper, String partitionsRoot) throws Exception { Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>(); if (curator.checkExists().forPath(partitionsRoot) == null) { throw new RuntimeException("No such path " + partitionsRoot); } List<String> partitionPaths = curator.getChildren().forPath(partitionsRoot); for (String partitionPath : partitionPaths) { String absPartitionPath = partitionsRoot + "/" + partitionPath; LOG.info("Reading offset data from path {}", absPartitionPath); byte[] partitionBytes = curator.getData().forPath(absPartitionPath); Map<String, Object> partitionMetadata = objectMapper.readValue(partitionBytes, new TypeReference<Map<String, Object>>() { }); String topic = (String) partitionMetadata.get("topic"); int partition = ((Number) partitionMetadata.get("partition")).intValue(); long offset = ((Number) partitionMetadata.get("offset")).longValue(); offsets.put(new TopicPartition(topic, partition), new OffsetAndMetadata(offset)); } return offsets; }
Map<Object, Object> readState (String stream, String shardId) { try { String path = getZkPath(stream, shardId); Map<Object, Object> state = null; byte[] b = null; if (curatorFramework.checkExists().forPath(path) != null) { b = curatorFramework.getData().forPath(path); } if (b != null) { state = (Map<Object, Object>) JSONValue.parseWithException(new String(b, "UTF-8")); } return state; } catch (Exception e) { throw new RuntimeException(e); } }