Java Code Examples for org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil#expectPBMagicPrefix()

The following examples show how to use org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil#expectPBMagicPrefix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SplitLogTask.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
  }
}
 
Example 2
Source File: SplitOrMergeTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
private SwitchState parseFrom(byte [] bytes)
  throws DeserializationException {
  ProtobufUtil.expectPBMagicPrefix(bytes);
  SwitchState.Builder builder = SwitchState.newBuilder();
  try {
    int magicLen = ProtobufUtil.lengthOfPBMagic();
    ProtobufUtil.mergeFrom(builder, bytes, magicLen, bytes.length - magicLen);
  } catch (IOException e) {
    throw new DeserializationException(e);
  }
  return builder.build();
}
 
Example 3
Source File: RSGroupInfoManagerImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
private List<RSGroupInfo> retrieveGroupListFromZookeeper() throws IOException {
  String groupBasePath = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, RS_GROUP_ZNODE);
  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(ProtobufUtil.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;
}
 
Example 4
Source File: FSUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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 if the version data cannot be translated into a version
 */
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);
  }
}
 
Example 5
Source File: SnapshotCleanupTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
private SnapshotCleanupProtos.SnapshotCleanupState parseFrom(final byte[] pbBytes)
    throws DeserializationException {
  ProtobufUtil.expectPBMagicPrefix(pbBytes);
  SnapshotCleanupProtos.SnapshotCleanupState.Builder builder =
      SnapshotCleanupProtos.SnapshotCleanupState.newBuilder();
  try {
    int magicLen = ProtobufUtil.lengthOfPBMagic();
    ProtobufUtil.mergeFrom(builder, pbBytes, magicLen, pbBytes.length - magicLen);
  } catch (IOException e) {
    throw new DeserializationException(e);
  }
  return builder.build();
}
 
Example 6
Source File: LoadBalancerTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: RegionNormalizerTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
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();
}