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

项目:aliyun-oss-hadoop-fs    文件:PBHelper.java   
public static RecoveringBlockProto convert(RecoveringBlock b) {
  if (b == null) {
    return null;
  }
  LocatedBlockProto lb = PBHelperClient.convertLocatedBlock(b);
  RecoveringBlockProto.Builder builder = RecoveringBlockProto.newBuilder();
  builder.setBlock(lb).setNewGenStamp(b.getNewGenerationStamp());
  if(b.getNewBlock() != null)
    builder.setTruncateBlock(PBHelperClient.convert(b.getNewBlock()));
  if (b instanceof RecoveringStripedBlock) {
    RecoveringStripedBlock sb = (RecoveringStripedBlock) b;
    builder.setEcPolicy(PBHelperClient.convertErasureCodingPolicy(
        sb.getErasureCodingPolicy()));
    builder.setBlockIndices(PBHelperClient.getByteString(sb.getBlockIndices()));
  }
  return builder.build();
}
项目:hops    文件:PBHelper.java   
public static LocatedBlockProto convert(LocatedBlock b) {
  if (b == null) {
    return null;
  }
  Builder builder = LocatedBlockProto.newBuilder();
  DatanodeInfo[] locs = b.getLocations();
  for (int i = 0; i < locs.length; i++) {
    builder.addLocs(i, PBHelper.convert(locs[i]));
    //For compatability with newer clients
    builder.addStorageIDs("HopsFS_Hack_Storage_ID" );
    builder.addStorageTypes(HdfsProtos.StorageTypeProto.DISK);
    builder.addIsCached(false);
  }

  builder = builder.setB(PBHelper.convert(b.getBlock()))
      .setBlockToken(PBHelper.convert(b.getBlockToken()))
      .setCorrupt(b.isCorrupt()).setOffset(b.getStartOffset());
  if(b.isPhantomBlock() && b.isDataSet()){
    builder.setData(ByteString.copyFrom(b.getData()));
  }
  return builder.build();
}
项目:hops    文件:PBHelper.java   
public static LocatedBlock convert(LocatedBlockProto proto) {
  if (proto == null) {
    return null;
  }
  List<DatanodeInfoProto> locs = proto.getLocsList();
  DatanodeInfo[] targets = new DatanodeInfo[locs.size()];
  for (int i = 0; i < locs.size(); i++) {
    targets[i] = PBHelper.convert(locs.get(i));
  }
  LocatedBlock lb = new LocatedBlock(PBHelper.convert(proto.getB()), targets,
      proto.getOffset(), proto.getCorrupt());
  lb.setBlockToken(PBHelper.convert(proto.getBlockToken()));
  if(proto.getData().size() > 0){
    lb.setData(proto.getData().toByteArray());
  }
  return lb;
}
项目:hadoop    文件:PBHelper.java   
public static RecoveringBlockProto convert(RecoveringBlock b) {
  if (b == null) {
    return null;
  }
  LocatedBlockProto lb = PBHelper.convert((LocatedBlock)b);
  RecoveringBlockProto.Builder builder = RecoveringBlockProto.newBuilder();
  builder.setBlock(lb).setNewGenStamp(b.getNewGenerationStamp());
  if(b.getNewBlock() != null)
    builder.setTruncateBlock(PBHelper.convert(b.getNewBlock()));
  return builder.build();
}
项目:hadoop    文件:PBHelper.java   
public static LocatedBlockProto convert(LocatedBlock b) {
  if (b == null) return null;
  Builder builder = LocatedBlockProto.newBuilder();
  DatanodeInfo[] locs = b.getLocations();
  List<DatanodeInfo> cachedLocs =
      Lists.newLinkedList(Arrays.asList(b.getCachedLocations()));
  for (int i = 0; i < locs.length; i++) {
    DatanodeInfo loc = locs[i];
    builder.addLocs(i, PBHelper.convert(loc));
    boolean locIsCached = cachedLocs.contains(loc);
    builder.addIsCached(locIsCached);
    if (locIsCached) {
      cachedLocs.remove(loc);
    }
  }
  Preconditions.checkArgument(cachedLocs.size() == 0,
      "Found additional cached replica locations that are not in the set of"
      + " storage-backed locations!");

  StorageType[] storageTypes = b.getStorageTypes();
  if (storageTypes != null) {
    for (int i = 0; i < storageTypes.length; ++i) {
      builder.addStorageTypes(PBHelper.convertStorageType(storageTypes[i]));
    }
  }
  final String[] storageIDs = b.getStorageIDs();
  if (storageIDs != null) {
    builder.addAllStorageIDs(Arrays.asList(storageIDs));
  }

  return builder.setB(PBHelper.convert(b.getBlock()))
      .setBlockToken(PBHelper.convert(b.getBlockToken()))
      .setCorrupt(b.isCorrupt()).setOffset(b.getStartOffset()).build();
}
项目:hadoop    文件:PBHelper.java   
public static LocatedBlock convert(LocatedBlockProto proto) {
  if (proto == null) return null;
  List<DatanodeInfoProto> locs = proto.getLocsList();
  DatanodeInfo[] targets = new DatanodeInfo[locs.size()];
  for (int i = 0; i < locs.size(); i++) {
    targets[i] = PBHelper.convert(locs.get(i));
  }

  final StorageType[] storageTypes = convertStorageTypes(
      proto.getStorageTypesList(), locs.size());

  final int storageIDsCount = proto.getStorageIDsCount();
  final String[] storageIDs;
  if (storageIDsCount == 0) {
    storageIDs = null;
  } else {
    Preconditions.checkState(storageIDsCount == locs.size());
    storageIDs = proto.getStorageIDsList().toArray(new String[storageIDsCount]);
  }

  // Set values from the isCached list, re-using references from loc
  List<DatanodeInfo> cachedLocs = new ArrayList<DatanodeInfo>(locs.size());
  List<Boolean> isCachedList = proto.getIsCachedList();
  for (int i=0; i<isCachedList.size(); i++) {
    if (isCachedList.get(i)) {
      cachedLocs.add(targets[i]);
    }
  }

  LocatedBlock lb = new LocatedBlock(PBHelper.convert(proto.getB()), targets,
      storageIDs, storageTypes, proto.getOffset(), proto.getCorrupt(),
      cachedLocs.toArray(new DatanodeInfo[0]));
  lb.setBlockToken(PBHelper.convert(proto.getBlockToken()));

  return lb;
}
项目:hadoop    文件:PBHelper.java   
public static List<LocatedBlock> convertLocatedBlock(
    List<LocatedBlockProto> lb) {
  if (lb == null) return null;
  final int len = lb.size();
  List<LocatedBlock> result = 
      new ArrayList<LocatedBlock>(len);
  for (int i = 0; i < len; ++i) {
    result.add(PBHelper.convert(lb.get(i)));
  }
  return result;
}
项目:hadoop    文件:PBHelper.java   
public static List<LocatedBlockProto> convertLocatedBlock2(List<LocatedBlock> lb) {
  if (lb == null) return null;
  final int len = lb.size();
  List<LocatedBlockProto> result = new ArrayList<LocatedBlockProto>(len);
  for (int i = 0; i < len; ++i) {
    result.add(PBHelper.convert(lb.get(i)));
  }
  return result;
}
项目:hadoop    文件:DatanodeProtocolServerSideTranslatorPB.java   
@Override
public ReportBadBlocksResponseProto reportBadBlocks(RpcController controller,
    ReportBadBlocksRequestProto request) throws ServiceException {
  List<LocatedBlockProto> lbps = request.getBlocksList();
  LocatedBlock [] blocks = new LocatedBlock [lbps.size()];
  for(int i=0; i<lbps.size(); i++) {
    blocks[i] = PBHelper.convert(lbps.get(i));
  }
  try {
    impl.reportBadBlocks(blocks);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REPORT_BAD_BLOCK_RESPONSE;
}
项目:hadoop    文件:ClientNamenodeProtocolServerSideTranslatorPB.java   
@Override
public ReportBadBlocksResponseProto reportBadBlocks(RpcController controller,
    ReportBadBlocksRequestProto req) throws ServiceException {
  try {
    List<LocatedBlockProto> bl = req.getBlocksList();
    server.reportBadBlocks(PBHelper.convertLocatedBlock(
            bl.toArray(new LocatedBlockProto[bl.size()])));
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REP_BAD_BLOCK_RESPONSE;
}
项目:hadoop    文件:ClientNamenodeProtocolServerSideTranslatorPB.java   
@Override
public UpdateBlockForPipelineResponseProto updateBlockForPipeline(
    RpcController controller, UpdateBlockForPipelineRequestProto req)
    throws ServiceException {
  try {
    LocatedBlockProto result = PBHelper.convert(server
        .updateBlockForPipeline(PBHelper.convert(req.getBlock()),
            req.getClientName()));
    return UpdateBlockForPipelineResponseProto.newBuilder().setBlock(result)
        .build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
项目:hadoop    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlock() {
  LocatedBlock lb = createLocatedBlock();
  LocatedBlockProto lbProto = PBHelper.convert(lb);
  LocatedBlock lb2 = PBHelper.convert(lbProto);
  compare(lb,lb2);
}
项目:hadoop    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockNoStorageMedia() {
  LocatedBlock lb = createLocatedBlockNoStorageMedia();
  LocatedBlockProto lbProto = PBHelper.convert(lb);
  LocatedBlock lb2 = PBHelper.convert(lbProto);
  compare(lb,lb2);
}
项目:hadoop    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockList() {
  ArrayList<LocatedBlock> lbl = new ArrayList<LocatedBlock>();
  for (int i=0;i<3;i++) {
    lbl.add(createLocatedBlock());
  }
  List<LocatedBlockProto> lbpl = PBHelper.convertLocatedBlock2(lbl);
  List<LocatedBlock> lbl2 = PBHelper.convertLocatedBlock(lbpl);
  assertEquals(lbl.size(), lbl2.size());
  for (int i=0;i<lbl.size();i++) {
    compare(lbl.get(i), lbl2.get(2));
  }
}
项目:hadoop    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockArray() {
  LocatedBlock [] lbl = new LocatedBlock[3];
  for (int i=0;i<3;i++) {
    lbl[i] = createLocatedBlock();
  }
  LocatedBlockProto [] lbpl = PBHelper.convertLocatedBlock(lbl);
  LocatedBlock [] lbl2 = PBHelper.convertLocatedBlock(lbpl);
  assertEquals(lbl.length, lbl2.length);
  for (int i=0;i<lbl.length;i++) {
    compare(lbl[i], lbl2[i]);
  }
}
项目:aliyun-oss-hadoop-fs    文件:PBHelperClient.java   
public static List<LocatedBlock> convertLocatedBlocks(
    List<LocatedBlockProto> lb) {
  if (lb == null) return null;
  final int len = lb.size();
  List<LocatedBlock> result = new ArrayList<>(len);
  for (LocatedBlockProto aLb : lb) {
    result.add(convertLocatedBlockProto(aLb));
  }
  return result;
}
项目:aliyun-oss-hadoop-fs    文件:PBHelperClient.java   
public static List<LocatedBlockProto> convertLocatedBlocks2(
    List<LocatedBlock> lb) {
  if (lb == null) return null;
  final int len = lb.size();
  List<LocatedBlockProto> result = new ArrayList<>(len);
  for (LocatedBlock aLb : lb) {
    result.add(convertLocatedBlock(aLb));
  }
  return result;
}
项目:aliyun-oss-hadoop-fs    文件:PBHelperClient.java   
public static List<LocatedBlock> convertLocatedBlock(
    List<LocatedBlockProto> lb) {
  if (lb == null) return null;
  final int len = lb.size();
  List<LocatedBlock> result = new ArrayList<>(len);
  for (LocatedBlockProto aLb : lb) {
    result.add(convertLocatedBlockProto(aLb));
  }
  return result;
}
项目:aliyun-oss-hadoop-fs    文件:DatanodeProtocolServerSideTranslatorPB.java   
@Override
public ReportBadBlocksResponseProto reportBadBlocks(RpcController controller,
    ReportBadBlocksRequestProto request) throws ServiceException {
  List<LocatedBlockProto> lbps = request.getBlocksList();
  LocatedBlock [] blocks = new LocatedBlock [lbps.size()];
  for(int i=0; i<lbps.size(); i++) {
    blocks[i] = PBHelperClient.convertLocatedBlockProto(lbps.get(i));
  }
  try {
    impl.reportBadBlocks(blocks);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REPORT_BAD_BLOCK_RESPONSE;
}
项目:aliyun-oss-hadoop-fs    文件:ClientNamenodeProtocolServerSideTranslatorPB.java   
@Override
public ReportBadBlocksResponseProto reportBadBlocks(RpcController controller,
    ReportBadBlocksRequestProto req) throws ServiceException {
  try {
    List<LocatedBlockProto> bl = req.getBlocksList();
    server.reportBadBlocks(PBHelperClient.convertLocatedBlocks(
        bl.toArray(new LocatedBlockProto[bl.size()])));
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REP_BAD_BLOCK_RESPONSE;
}
项目:aliyun-oss-hadoop-fs    文件:ClientNamenodeProtocolServerSideTranslatorPB.java   
@Override
public UpdateBlockForPipelineResponseProto updateBlockForPipeline(
    RpcController controller, UpdateBlockForPipelineRequestProto req)
    throws ServiceException {
  try {
    LocatedBlockProto result = PBHelperClient.convertLocatedBlock(
        server.updateBlockForPipeline(PBHelperClient.convert(req.getBlock()),
            req.getClientName()));
    return UpdateBlockForPipelineResponseProto.newBuilder().setBlock(result)
        .build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlock() {
  LocatedBlock lb = createLocatedBlock();
  LocatedBlockProto lbProto = PBHelperClient.convertLocatedBlock(lb);
  LocatedBlock lb2 = PBHelperClient.convertLocatedBlockProto(lbProto);
  compare(lb,lb2);
}
项目:aliyun-oss-hadoop-fs    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockNoStorageMedia() {
  LocatedBlock lb = createLocatedBlockNoStorageMedia();
  LocatedBlockProto lbProto = PBHelperClient.convertLocatedBlock(lb);
  LocatedBlock lb2 = PBHelperClient.convertLocatedBlockProto(lbProto);
  compare(lb,lb2);
}
项目:aliyun-oss-hadoop-fs    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockList() {
  ArrayList<LocatedBlock> lbl = new ArrayList<LocatedBlock>();
  for (int i=0;i<3;i++) {
    lbl.add(createLocatedBlock());
  }
  List<LocatedBlockProto> lbpl = PBHelperClient.convertLocatedBlocks2(lbl);
  List<LocatedBlock> lbl2 = PBHelperClient.convertLocatedBlocks(lbpl);
  assertEquals(lbl.size(), lbl2.size());
  for (int i=0;i<lbl.size();i++) {
    compare(lbl.get(i), lbl2.get(2));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockArray() {
  LocatedBlock [] lbl = new LocatedBlock[3];
  for (int i=0;i<3;i++) {
    lbl[i] = createLocatedBlock();
  }
  LocatedBlockProto [] lbpl = PBHelperClient.convertLocatedBlocks(lbl);
  LocatedBlock [] lbl2 = PBHelperClient.convertLocatedBlocks(lbpl);
  assertEquals(lbl.length, lbl2.length);
  for (int i=0;i<lbl.length;i++) {
    compare(lbl[i], lbl2[i]);
  }
}
项目:big-c    文件:PBHelper.java   
public static RecoveringBlockProto convert(RecoveringBlock b) {
  if (b == null) {
    return null;
  }
  LocatedBlockProto lb = PBHelper.convert((LocatedBlock)b);
  RecoveringBlockProto.Builder builder = RecoveringBlockProto.newBuilder();
  builder.setBlock(lb).setNewGenStamp(b.getNewGenerationStamp());
  if(b.getNewBlock() != null)
    builder.setTruncateBlock(PBHelper.convert(b.getNewBlock()));
  return builder.build();
}
项目:big-c    文件:PBHelper.java   
public static LocatedBlockProto convert(LocatedBlock b) {
  if (b == null) return null;
  Builder builder = LocatedBlockProto.newBuilder();
  DatanodeInfo[] locs = b.getLocations();
  List<DatanodeInfo> cachedLocs =
      Lists.newLinkedList(Arrays.asList(b.getCachedLocations()));
  for (int i = 0; i < locs.length; i++) {
    DatanodeInfo loc = locs[i];
    builder.addLocs(i, PBHelper.convert(loc));
    boolean locIsCached = cachedLocs.contains(loc);
    builder.addIsCached(locIsCached);
    if (locIsCached) {
      cachedLocs.remove(loc);
    }
  }
  Preconditions.checkArgument(cachedLocs.size() == 0,
      "Found additional cached replica locations that are not in the set of"
      + " storage-backed locations!");

  StorageType[] storageTypes = b.getStorageTypes();
  if (storageTypes != null) {
    for (int i = 0; i < storageTypes.length; ++i) {
      builder.addStorageTypes(PBHelper.convertStorageType(storageTypes[i]));
    }
  }
  final String[] storageIDs = b.getStorageIDs();
  if (storageIDs != null) {
    builder.addAllStorageIDs(Arrays.asList(storageIDs));
  }

  return builder.setB(PBHelper.convert(b.getBlock()))
      .setBlockToken(PBHelper.convert(b.getBlockToken()))
      .setCorrupt(b.isCorrupt()).setOffset(b.getStartOffset()).build();
}
项目:big-c    文件:PBHelper.java   
public static LocatedBlock convert(LocatedBlockProto proto) {
  if (proto == null) return null;
  List<DatanodeInfoProto> locs = proto.getLocsList();
  DatanodeInfo[] targets = new DatanodeInfo[locs.size()];
  for (int i = 0; i < locs.size(); i++) {
    targets[i] = PBHelper.convert(locs.get(i));
  }

  final StorageType[] storageTypes = convertStorageTypes(
      proto.getStorageTypesList(), locs.size());

  final int storageIDsCount = proto.getStorageIDsCount();
  final String[] storageIDs;
  if (storageIDsCount == 0) {
    storageIDs = null;
  } else {
    Preconditions.checkState(storageIDsCount == locs.size());
    storageIDs = proto.getStorageIDsList().toArray(new String[storageIDsCount]);
  }

  // Set values from the isCached list, re-using references from loc
  List<DatanodeInfo> cachedLocs = new ArrayList<DatanodeInfo>(locs.size());
  List<Boolean> isCachedList = proto.getIsCachedList();
  for (int i=0; i<isCachedList.size(); i++) {
    if (isCachedList.get(i)) {
      cachedLocs.add(targets[i]);
    }
  }

  LocatedBlock lb = new LocatedBlock(PBHelper.convert(proto.getB()), targets,
      storageIDs, storageTypes, proto.getOffset(), proto.getCorrupt(),
      cachedLocs.toArray(new DatanodeInfo[0]));
  lb.setBlockToken(PBHelper.convert(proto.getBlockToken()));

  return lb;
}
项目:big-c    文件:PBHelper.java   
public static List<LocatedBlock> convertLocatedBlock(
    List<LocatedBlockProto> lb) {
  if (lb == null) return null;
  final int len = lb.size();
  List<LocatedBlock> result = 
      new ArrayList<LocatedBlock>(len);
  for (int i = 0; i < len; ++i) {
    result.add(PBHelper.convert(lb.get(i)));
  }
  return result;
}
项目:big-c    文件:PBHelper.java   
public static List<LocatedBlockProto> convertLocatedBlock2(List<LocatedBlock> lb) {
  if (lb == null) return null;
  final int len = lb.size();
  List<LocatedBlockProto> result = new ArrayList<LocatedBlockProto>(len);
  for (int i = 0; i < len; ++i) {
    result.add(PBHelper.convert(lb.get(i)));
  }
  return result;
}
项目:big-c    文件:DatanodeProtocolServerSideTranslatorPB.java   
@Override
public ReportBadBlocksResponseProto reportBadBlocks(RpcController controller,
    ReportBadBlocksRequestProto request) throws ServiceException {
  List<LocatedBlockProto> lbps = request.getBlocksList();
  LocatedBlock [] blocks = new LocatedBlock [lbps.size()];
  for(int i=0; i<lbps.size(); i++) {
    blocks[i] = PBHelper.convert(lbps.get(i));
  }
  try {
    impl.reportBadBlocks(blocks);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REPORT_BAD_BLOCK_RESPONSE;
}
项目:big-c    文件:ClientNamenodeProtocolServerSideTranslatorPB.java   
@Override
public ReportBadBlocksResponseProto reportBadBlocks(RpcController controller,
    ReportBadBlocksRequestProto req) throws ServiceException {
  try {
    List<LocatedBlockProto> bl = req.getBlocksList();
    server.reportBadBlocks(PBHelper.convertLocatedBlock(
            bl.toArray(new LocatedBlockProto[bl.size()])));
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REP_BAD_BLOCK_RESPONSE;
}
项目:big-c    文件:ClientNamenodeProtocolServerSideTranslatorPB.java   
@Override
public UpdateBlockForPipelineResponseProto updateBlockForPipeline(
    RpcController controller, UpdateBlockForPipelineRequestProto req)
    throws ServiceException {
  try {
    LocatedBlockProto result = PBHelper.convert(server
        .updateBlockForPipeline(PBHelper.convert(req.getBlock()),
            req.getClientName()));
    return UpdateBlockForPipelineResponseProto.newBuilder().setBlock(result)
        .build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
项目:big-c    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlock() {
  LocatedBlock lb = createLocatedBlock();
  LocatedBlockProto lbProto = PBHelper.convert(lb);
  LocatedBlock lb2 = PBHelper.convert(lbProto);
  compare(lb,lb2);
}
项目:big-c    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockNoStorageMedia() {
  LocatedBlock lb = createLocatedBlockNoStorageMedia();
  LocatedBlockProto lbProto = PBHelper.convert(lb);
  LocatedBlock lb2 = PBHelper.convert(lbProto);
  compare(lb,lb2);
}
项目:big-c    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockList() {
  ArrayList<LocatedBlock> lbl = new ArrayList<LocatedBlock>();
  for (int i=0;i<3;i++) {
    lbl.add(createLocatedBlock());
  }
  List<LocatedBlockProto> lbpl = PBHelper.convertLocatedBlock2(lbl);
  List<LocatedBlock> lbl2 = PBHelper.convertLocatedBlock(lbpl);
  assertEquals(lbl.size(), lbl2.size());
  for (int i=0;i<lbl.size();i++) {
    compare(lbl.get(i), lbl2.get(2));
  }
}
项目:big-c    文件:TestPBHelper.java   
@Test
public void testConvertLocatedBlockArray() {
  LocatedBlock [] lbl = new LocatedBlock[3];
  for (int i=0;i<3;i++) {
    lbl[i] = createLocatedBlock();
  }
  LocatedBlockProto [] lbpl = PBHelper.convertLocatedBlock(lbl);
  LocatedBlock [] lbl2 = PBHelper.convertLocatedBlock(lbpl);
  assertEquals(lbl.length, lbl2.length);
  for (int i=0;i<lbl.length;i++) {
    compare(lbl[i], lbl2[i]);
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:PBHelper.java   
public static RecoveringBlockProto convert(RecoveringBlock b) {
  if (b == null) {
    return null;
  }
  LocatedBlockProto lb = PBHelper.convert((LocatedBlock)b);
  return RecoveringBlockProto.newBuilder().setBlock(lb)
      .setNewGenStamp(b.getNewGenerationStamp()).build();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:PBHelper.java   
public static LocatedBlockProto convert(LocatedBlock b) {
  if (b == null) return null;
  Builder builder = LocatedBlockProto.newBuilder();
  DatanodeInfo[] locs = b.getLocations();
  List<DatanodeInfo> cachedLocs =
      Lists.newLinkedList(Arrays.asList(b.getCachedLocations()));
  for (int i = 0; i < locs.length; i++) {
    DatanodeInfo loc = locs[i];
    builder.addLocs(i, PBHelper.convert(loc));
    boolean locIsCached = cachedLocs.contains(loc);
    builder.addIsCached(locIsCached);
    if (locIsCached) {
      cachedLocs.remove(loc);
    }
  }
  Preconditions.checkArgument(cachedLocs.size() == 0,
      "Found additional cached replica locations that are not in the set of"
      + " storage-backed locations!");

  StorageType[] storageTypes = b.getStorageTypes();
  if (storageTypes != null) {
    for (int i = 0; i < storageTypes.length; ++i) {
      builder.addStorageTypes(PBHelper.convertStorageType(storageTypes[i]));
    }
  }
  final String[] storageIDs = b.getStorageIDs();
  if (storageIDs != null) {
    builder.addAllStorageIDs(Arrays.asList(storageIDs));
  }

  return builder.setB(PBHelper.convert(b.getBlock()))
      .setBlockToken(PBHelper.convert(b.getBlockToken()))
      .setCorrupt(b.isCorrupt()).setOffset(b.getStartOffset()).build();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:PBHelper.java   
public static LocatedBlock convert(LocatedBlockProto proto) {
  if (proto == null) return null;
  List<DatanodeInfoProto> locs = proto.getLocsList();
  DatanodeInfo[] targets = new DatanodeInfo[locs.size()];
  for (int i = 0; i < locs.size(); i++) {
    targets[i] = PBHelper.convert(locs.get(i));
  }

  final StorageType[] storageTypes = convertStorageTypes(
      proto.getStorageTypesList(), locs.size());

  final int storageIDsCount = proto.getStorageIDsCount();
  final String[] storageIDs;
  if (storageIDsCount == 0) {
    storageIDs = null;
  } else {
    Preconditions.checkState(storageIDsCount == locs.size());
    storageIDs = proto.getStorageIDsList().toArray(new String[storageIDsCount]);
  }

  // Set values from the isCached list, re-using references from loc
  List<DatanodeInfo> cachedLocs = new ArrayList<DatanodeInfo>(locs.size());
  List<Boolean> isCachedList = proto.getIsCachedList();
  for (int i=0; i<isCachedList.size(); i++) {
    if (isCachedList.get(i)) {
      cachedLocs.add(targets[i]);
    }
  }

  LocatedBlock lb = new LocatedBlock(PBHelper.convert(proto.getB()), targets,
      storageIDs, storageTypes, proto.getOffset(), proto.getCorrupt(),
      cachedLocs.toArray(new DatanodeInfo[0]));
  lb.setBlockToken(PBHelper.convert(proto.getBlockToken()));

  return lb;
}