use of org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations in project hadoop by apache.
the class TestPBHelper method getBlockWithLocations.
private static BlockWithLocations getBlockWithLocations(int bid, boolean isStriped) {
final String[] datanodeUuids = { "dn1", "dn2", "dn3" };
final String[] storageIDs = { "s1", "s2", "s3" };
final StorageType[] storageTypes = { StorageType.DISK, StorageType.DISK, StorageType.DISK };
final byte[] indices = { 0, 1, 2 };
final short dataBlkNum = 6;
BlockWithLocations blkLocs = new BlockWithLocations(new Block(bid, 0, 1), datanodeUuids, storageIDs, storageTypes);
if (isStriped) {
blkLocs = new StripedBlockWithLocations(blkLocs, indices, dataBlkNum, StripedFileTestUtil.getDefaultECPolicy().getCellSize());
}
return blkLocs;
}
use of org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations in project hadoop by apache.
the class TestPBHelper method testConvertBlocksWithLocations.
@Test
public void testConvertBlocksWithLocations() {
boolean[] testSuite = new boolean[] { false, true };
for (int i = 0; i < testSuite.length; i++) {
BlockWithLocations[] list = new BlockWithLocations[] { getBlockWithLocations(1, testSuite[i]), getBlockWithLocations(2, testSuite[i]) };
BlocksWithLocations locs = new BlocksWithLocations(list);
BlocksWithLocationsProto locsProto = PBHelper.convert(locs);
BlocksWithLocations locs2 = PBHelper.convert(locsProto);
BlockWithLocations[] blocks = locs.getBlocks();
BlockWithLocations[] blocks2 = locs2.getBlocks();
assertEquals(blocks.length, blocks2.length);
for (int j = 0; j < blocks.length; j++) {
compare(blocks[j], blocks2[j]);
}
}
}
use of org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations in project hadoop by apache.
the class PBHelper method convert.
public static BlockWithLocations convert(BlockWithLocationsProto b) {
final List<String> datanodeUuids = b.getDatanodeUuidsList();
final List<String> storageUuids = b.getStorageUuidsList();
final List<StorageTypeProto> storageTypes = b.getStorageTypesList();
BlockWithLocations blk = new BlockWithLocations(PBHelperClient.convert(b.getBlock()), datanodeUuids.toArray(new String[datanodeUuids.size()]), storageUuids.toArray(new String[storageUuids.size()]), PBHelperClient.convertStorageTypes(storageTypes, storageUuids.size()));
if (b.hasIndices()) {
blk = new StripedBlockWithLocations(blk, b.getIndices().toByteArray(), (short) b.getDataBlockNum(), b.getCellSize());
}
return blk;
}
Aggregations