List<RSGroupInfo> retrieveGroupListFromZookeeper() throws IOException { String groupBasePath = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, rsGroupZNode); List<RSGroupInfo> RSGroupInfoList = Lists.newArrayList(); // Overwrite any info stored by table, this takes precedence try { if (ZKUtil.checkExists(watcher, groupBasePath) != -1) { List<String> children = ZKUtil.listChildrenAndWatchForNewChildren(watcher, groupBasePath); if (children == null) { return RSGroupInfoList; } for (String znode : children) { byte[] data = ZKUtil.getData(watcher, ZNodePaths.joinZNode(groupBasePath, znode)); if (data.length > 0) { ProtobufUtil.expectPBMagicPrefix(data); ByteArrayInputStream bis = new ByteArrayInputStream(data, ProtobufUtil.lengthOfPBMagic(), data.length); RSGroupInfoList .add(RSGroupProtobufUtil.toGroupInfo(RSGroupProtos.RSGroupInfo.parseFrom(bis))); } } LOG.debug("Read ZK GroupInfo count:" + RSGroupInfoList.size()); } } catch (KeeperException | DeserializationException | InterruptedException e) { throw new IOException("Failed to read rsGroupZNode", e); } return RSGroupInfoList; }
byte[] data = ZKUtil.getData(zkw, ZNodePaths.joinZNode(groupBasePath, znode)); if(data.length > 0) { ProtobufUtil.expectPBMagicPrefix(data); ByteArrayInputStream bis = new ByteArrayInputStream( data, ProtobufUtil.lengthOfPBMagic(), data.length);
List<RSGroupInfo> retrieveGroupListFromZookeeper() throws IOException { String groupBasePath = ZNodePaths.joinZNode(watcher.znodePaths.baseZNode, rsGroupZNode); List<RSGroupInfo> RSGroupInfoList = Lists.newArrayList(); //Overwrite any info stored by table, this takes precedence try { if(ZKUtil.checkExists(watcher, groupBasePath) != -1) { for(String znode: ZKUtil.listChildrenAndWatchForNewChildren(watcher, groupBasePath)) { byte[] data = ZKUtil.getData(watcher, ZNodePaths.joinZNode(groupBasePath, znode)); if(data.length > 0) { ProtobufUtil.expectPBMagicPrefix(data); ByteArrayInputStream bis = new ByteArrayInputStream( data, ProtobufUtil.lengthOfPBMagic(), data.length); RSGroupInfoList.add(RSGroupProtobufUtil.toGroupInfo( RSGroupProtos.RSGroupInfo.parseFrom(bis))); } } LOG.debug("Read ZK GroupInfo count:" + RSGroupInfoList.size()); } } catch (KeeperException|DeserializationException|InterruptedException e) { throw new IOException("Failed to read rsGroupZNode",e); } return RSGroupInfoList; }
List<RSGroupInfo> retrieveGroupListFromZookeeper() throws IOException { String groupBasePath = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, rsGroupZNode); List<RSGroupInfo> RSGroupInfoList = Lists.newArrayList(); //Overwrite any info stored by table, this takes precedence try { if(ZKUtil.checkExists(watcher, groupBasePath) != -1) { List<String> children = ZKUtil.listChildrenAndWatchForNewChildren(watcher, groupBasePath); if (children == null) { return RSGroupInfoList; } for(String znode: children) { byte[] data = ZKUtil.getData(watcher, ZNodePaths.joinZNode(groupBasePath, znode)); if(data.length > 0) { ProtobufUtil.expectPBMagicPrefix(data); ByteArrayInputStream bis = new ByteArrayInputStream( data, ProtobufUtil.lengthOfPBMagic(), data.length); RSGroupInfoList.add(RSGroupProtobufUtil.toGroupInfo( RSGroupProtos.RSGroupInfo.parseFrom(bis))); } } LOG.debug("Read ZK GroupInfo count:" + RSGroupInfoList.size()); } } catch (KeeperException|DeserializationException|InterruptedException e) { throw new IOException("Failed to read rsGroupZNode",e); } return RSGroupInfoList; }
private RegionNormalizerProtos.RegionNormalizerState parseFrom(byte [] pbBytes) throws DeserializationException { ProtobufUtil.expectPBMagicPrefix(pbBytes); RegionNormalizerProtos.RegionNormalizerState.Builder builder = RegionNormalizerProtos.RegionNormalizerState.newBuilder(); try { int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, pbBytes, magicLen, pbBytes.length - magicLen); } catch (IOException e) { throw new DeserializationException(e); } return builder.build(); } }
private LoadBalancerProtos.LoadBalancerState parseFrom(byte [] pbBytes) throws DeserializationException { ProtobufUtil.expectPBMagicPrefix(pbBytes); LoadBalancerProtos.LoadBalancerState.Builder builder = LoadBalancerProtos.LoadBalancerState.newBuilder(); try { int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, pbBytes, magicLen, pbBytes.length - magicLen); } catch (IOException e) { throw new DeserializationException(e); } return builder.build(); } }
/** * Parse the content of the ${HBASE_ROOTDIR}/hbase.version file. * @param bytes The byte content of the hbase.version file. * @return The version found in the file as a String. * @throws DeserializationException */ static String parseVersionFrom(final byte [] bytes) throws DeserializationException { ProtobufUtil.expectPBMagicPrefix(bytes); int pblen = ProtobufUtil.lengthOfPBMagic(); FSProtos.HBaseVersionFileContent.Builder builder = FSProtos.HBaseVersionFileContent.newBuilder(); try { ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen); return builder.getVersion(); } catch (IOException e) { // Convert throw new DeserializationException(e); } }
/** * @param data Serialized date to parse. * @return A RegionTransition instance made of the passed <code>data</code> * @throws DeserializationException * @see #toByteArray() */ public static RegionTransition parseFrom(final byte [] data) throws DeserializationException { ProtobufUtil.expectPBMagicPrefix(data); try { int prefixLen = ProtobufUtil.lengthOfPBMagic(); ZooKeeperProtos.RegionTransition.Builder builder = ZooKeeperProtos.RegionTransition.newBuilder(); ProtobufUtil.mergeFrom(builder, data, prefixLen, data.length - prefixLen); return new RegionTransition(builder.build()); } catch (IOException e) { throw new DeserializationException(e); } }
/** * @param bytes Content of a state znode. * @return State parsed from the passed bytes. * @throws DeserializationException */ private static ZooKeeperProtos.ReplicationState.State parseStateFrom(final byte[] bytes) throws DeserializationException { ProtobufUtil.expectPBMagicPrefix(bytes); int pblen = ProtobufUtil.lengthOfPBMagic(); ZooKeeperProtos.ReplicationState.Builder builder = ZooKeeperProtos.ReplicationState.newBuilder(); ZooKeeperProtos.ReplicationState state; try { ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen); state = builder.build(); return state.getState(); } catch (IOException e) { throw new DeserializationException(e); } }
/** * @param data Serialized date to parse. * @return An SplitLogTaskState instance made of the passed <code>data</code> * @throws DeserializationException * @see #toByteArray() */ public static SplitLogTask parseFrom(final byte [] data) throws DeserializationException { ProtobufUtil.expectPBMagicPrefix(data); try { int prefixLen = ProtobufUtil.lengthOfPBMagic(); ZooKeeperProtos.SplitLogTask.Builder builder = ZooKeeperProtos.SplitLogTask.newBuilder(); ProtobufUtil.mergeFrom(builder, data, prefixLen, data.length - prefixLen); return new SplitLogTask(builder.build()); } catch (IOException e) { throw new DeserializationException(Bytes.toStringBinary(data, 0, 64), e); } }
byte[] data = ZKUtil.getData(zkw, ZNodePaths.joinZNode(groupBasePath, znode)); if(data.length > 0) { ProtobufUtil.expectPBMagicPrefix(data); ByteArrayInputStream bis = new ByteArrayInputStream( data, ProtobufUtil.lengthOfPBMagic(), data.length);
/** * Gets table state from ZK. * @param zkw ZooKeeperWatcher instance to use * @param tableName table we're checking * @return Null or {@link ZooKeeperProtos.Table.State} found in znode. * @throws KeeperException */ private ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw, final TableName tableName) throws KeeperException, InterruptedException { String znode = ZKUtil.joinZNode(zkw.tableZNode, tableName.getNameAsString()); byte [] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) return null; try { ProtobufUtil.expectPBMagicPrefix(data); ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder(); int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, data, magicLen, data.length - magicLen); return builder.getState(); } catch (IOException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } catch (DeserializationException e) { throw ZKUtil.convert(e); } }
/** * @param zkw ZooKeeperWatcher instance to use * @param tableName table we're checking * @return Null or {@link ZooKeeperProtos.Table.State} found in znode. * @throws KeeperException */ static ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw, final TableName tableName) throws KeeperException, InterruptedException { String znode = ZKUtil.joinZNode(zkw.tableZNode, tableName.getNameAsString()); byte [] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) return null; try { ProtobufUtil.expectPBMagicPrefix(data); ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder(); int magicLen = ProtobufUtil.lengthOfPBMagic(); ProtobufUtil.mergeFrom(builder, data, magicLen, data.length - magicLen); return builder.getState(); } catch (IOException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } catch (DeserializationException e) { throw ZKUtil.convert(e); } } }