}
public boolean verifyBlockLocations(String src, String destination,
NameNode srcNameNode, NameNode dstNameNode, boolean hardlink)
throws IOException {
LocatedBlocksWithMetaInfo srcLocatedBlocks =
srcNameNode.openAndFetchMetaInfo(src, 0,Long.MAX_VALUE);
List<LocatedBlock> srcblocks = srcLocatedBlocks.getLocatedBlocks();
LocatedBlocksWithMetaInfo dstLocatedBlocks =
dstNameNode.openAndFetchMetaInfo(destination, 0, Long.MAX_VALUE);
List<LocatedBlock> dstblocks = dstLocatedBlocks.getLocatedBlocks();
assertEquals(srcblocks.size(), dstblocks.size());
Iterator<LocatedBlock> srcIt = srcblocks.iterator();
Iterator<LocatedBlock> dstIt = dstblocks.iterator();
while (srcIt.hasNext()) {
LocatedBlock srcBlock = srcIt.next();
LocatedBlock dstBlock = dstIt.next();
List<DatanodeInfo> srcLocations = Arrays.asList(srcBlock.getLocations());
List<DatanodeInfo> dstLocations = Arrays.asList(dstBlock.getLocations());
System.out.println("Locations for src block : " + srcBlock.getBlock()
+ " file : " + src);
for (DatanodeInfo info : srcLocations) {
System.out.println("Datanode : " + info.toString());
}
System.out.println("Locations for dst block : " + dstBlock.getBlock()
+ " file : " + destination);
for (DatanodeInfo info : dstLocations) {
System.out.println("Datanode : " + info.toString());
}
assertEquals(srcLocations.size(), dstLocations.size());
if (srcNameNode.getNameNodeAddress().equals(
dstNameNode.getNameNodeAddress())) {
// Same FS copy, verify blocks are machine local.
assertTrue(srcLocations.containsAll(dstLocations));
assertTrue(dstLocations.containsAll(srcLocations));
} else {
// Verify blocks are rack local.
Iterator<DatanodeInfo> sit = srcLocations.iterator();
while (sit.hasNext()) {
DatanodeInfo srcInfo = sit.next();
// Verify location.
Iterator<DatanodeInfo> dit = dstLocations.iterator();
boolean flag = false;
while (dit.hasNext() && !flag) {
DatanodeInfo dstInfo = dit.next();
if (dstInfo.getHostName().equals(srcInfo.getHostName())) {
verifyHardLinks(srcInfo, dstInfo,
srcLocatedBlocks.getNamespaceID(), srcBlock.getBlock(),
dstLocatedBlocks.getNamespaceID(), dstBlock.getBlock(),
hardlink);
}
flag = srcInfo.getNetworkLocation().equals(
dstInfo.getNetworkLocation());
}