Java 类org.apache.hadoop.hdfs.protocol.proto.DatanodeProtocolProtos 实例源码

项目:hops    文件:PBHelper.java   
private static DatanodeProtocolProtos.BlockReportBlockProto.BlockReportBlockStateProto convert(BlockReportBlockState
    state){
  switch (state){
    case FINALIZED:
      return DatanodeProtocolProtos.BlockReportBlockProto
          .BlockReportBlockStateProto.FINALIZED;
    case RBW:
      return DatanodeProtocolProtos.BlockReportBlockProto
          .BlockReportBlockStateProto.RBW;
    case RUR:
      return DatanodeProtocolProtos.BlockReportBlockProto
          .BlockReportBlockStateProto.RUR;
    case RWR:
      return DatanodeProtocolProtos.BlockReportBlockProto
          .BlockReportBlockStateProto.RWR;
    case TEMPORARY:
      return DatanodeProtocolProtos.BlockReportBlockProto
          .BlockReportBlockStateProto.TEMPORARY;
    default:
      throw new RuntimeException();

  }
}
项目:hops    文件:PBHelper.java   
private static BlockReportBlockState convert(
    DatanodeProtocolProtos.BlockReportBlockProto.BlockReportBlockStateProto state) {
  switch (state){
    case FINALIZED:
      return BlockReportBlockState.FINALIZED;
    case RBW:
      return BlockReportBlockState.RBW;
    case RUR:
      return BlockReportBlockState.RUR;
    case RWR:
      return BlockReportBlockState.RWR;
    case TEMPORARY:
      return BlockReportBlockState.TEMPORARY;
    default:
      throw new RuntimeException();
  }
}
项目:hops    文件:DatanodeProtocolClientSideTranslatorPB.java   
/**
 * Read the small file data
 *
 * @param id
 * @return data
 * @throws IOException
 */
@Override
public byte[] getSmallFileData(int id) throws IOException {
  DatanodeProtocolProtos.GetSmallFileDataProto.Builder request =
          DatanodeProtocolProtos.GetSmallFileDataProto.newBuilder();
  request.setId(id);
  try{
   DatanodeProtocolProtos.SmallFileDataResponseProto response = rpcProxy.getSmallFileData(NULL_CONTROLLER, request.build());
   return PBHelper.convert(response);

  } catch (ServiceException e) {
  throw ProtobufHelper.getRemoteException(e);
  }
}
项目:hops    文件:PBHelper.java   
public static DatanodeProtocolProtos.BlockReportProto convert(BlockReport report) {

  List<DatanodeProtocolProtos.BlockReportBucketProto> bucketProtos = new
      ArrayList<>();
  for (BlockReportBucket bucket : report.getBuckets()){

    DatanodeProtocolProtos.BlockReportBucketProto.Builder bucketBuilder =
        DatanodeProtocolProtos.BlockReportBucketProto.newBuilder();
    for (BlockReportBlock block : bucket.getBlocks()){
      bucketBuilder.addBlocks(
          DatanodeProtocolProtos.BlockReportBlockProto.newBuilder()
              .setBlockId(block.getBlockId())
              .setGenerationStamp(block.getGenerationStamp())
              .setLength(block.getLength())
              .setState(convert(block.getState())));
    }
    bucketProtos.add(bucketBuilder.build());
  }

  List<Long> hashes = new ArrayList<>();
  for (long hash : report.getHashes()){
    hashes.add(hash);
  }

  return DatanodeProtocolProtos.BlockReportProto.newBuilder()
      .addAllBuckets(bucketProtos)
      .addAllHashes(hashes)
      .build();
}
项目:hops    文件:PBHelper.java   
public static BlockReport convert(
    DatanodeProtocolProtos.BlockReportProto blockReportProto) {
  int numBuckets = blockReportProto.getBucketsCount();

  BlockReportBucket[] buckets = new BlockReportBucket[numBuckets];
  long[] hashes = new long[numBuckets];
  int numBlocks = 0;

  for(int i = 0; i < numBuckets ; i ++){
    DatanodeProtocolProtos.BlockReportBucketProto bucketProto = blockReportProto.getBuckets(i);
    int numBlocksInBucket = bucketProto.getBlocksCount();

    numBlocks += numBlocksInBucket;

    BlockReportBlock[] blocks = new BlockReportBlock[numBlocksInBucket];
    for (int j = 0; j < numBlocksInBucket; j++){
      DatanodeProtocolProtos.BlockReportBlockProto blockProto = bucketProto.getBlocks(j);
      blocks[j] = new BlockReportBlock(blockProto.getBlockId(), blockProto
          .getGenerationStamp(), blockProto.getLength(), convert(blockProto
          .getState()));
    }

    BlockReportBucket bucket = new BlockReportBucket();
    bucket.setBlocks(blocks);
    buckets[i] = bucket;
    hashes[i] = blockReportProto.getHashes(i);
  }

  return new BlockReport(buckets, hashes, numBlocks);
}
项目:hops    文件:DatanodeProtocolServerSideTranslatorPB.java   
@Override
public BlockReportResponseProto blockReport(RpcController controller,
    BlockReportRequestProto request) throws ServiceException {
  DatanodeCommand cmd = null;
  StorageBlockReport[] storageBlockReports =
      new StorageBlockReport[request.getReportsCount()];

  int index = 0;
  for (StorageBlockReportProto s : request.getReportsList()) {
    DatanodeProtocolProtos.BlockReportProto report = s.getReport();
    storageBlockReports[index++] =
        new StorageBlockReport(PBHelper.convert(s.getStorage()),
            PBHelper.convert(report));
  }
  try {
    cmd = impl.blockReport(PBHelper.convert(request.getRegistration()),
        request.getBlockPoolId(), storageBlockReports);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  BlockReportResponseProto.Builder builder =
      BlockReportResponseProto.newBuilder();
  if (cmd != null) {
    builder.setCmd(PBHelper.convert(cmd));
  }
  return builder.build();
}
项目:hops    文件:DatanodeProtocolServerSideTranslatorPB.java   
@Override
public DatanodeProtocolProtos.SmallFileDataResponseProto getSmallFileData(RpcController controller, DatanodeProtocolProtos.GetSmallFileDataProto request) throws ServiceException {
  try{
    byte[] data = impl.getSmallFileData(request.getId());
    return  PBHelper.convert(data);
  } catch (IOException e){
    throw new ServiceException(e);
  }
}
项目:hops    文件:PBHelper.java   
public static byte[] convert(DatanodeProtocolProtos.SmallFileDataResponseProto response){
  return  response.getData().toByteArray();
}
项目:hops    文件:PBHelper.java   
public static DatanodeProtocolProtos.SmallFileDataResponseProto convert(byte[] data){
  DatanodeProtocolProtos.SmallFileDataResponseProto.Builder responseProto = DatanodeProtocolProtos.SmallFileDataResponseProto.newBuilder();
  responseProto.setData(ByteString.copyFrom(data));
  return responseProto.build();
}