@Test public void testIsSameHdfs() throws IOException { try { Class dfsUtilClazz = Class.forName("org.apache.hadoop.hdfs.DFSUtil"); dfsUtilClazz.getMethod("getNNServiceRpcAddresses", Configuration.class); } catch (Exception e) { LOG.info("Skip testIsSameHdfs test case because of the no-HA hadoop version."); return; } Configuration conf = HBaseConfiguration.create(); Path srcPath = new Path("hdfs: Path desPath = new Path("hdfs: FileSystem srcFs = srcPath.getFileSystem(conf); FileSystem desFs = desPath.getFileSystem(conf); assertTrue(FSHDFSUtils.isSameHdfs(conf, srcFs, desFs)); desPath = new Path("hdfs: desFs = desPath.getFileSystem(conf); assertTrue(!FSHDFSUtils.isSameHdfs(conf, srcFs, desFs)); desPath = new Path("hdfs: desFs = desPath.getFileSystem(conf); assertTrue(!FSHDFSUtils.isSameHdfs(conf, srcFs, desFs)); conf.set("fs.defaultFS", "hdfs: conf.set("dfs.nameservices", "haosong-hadoop"); conf.set("dfs.ha.namenodes.haosong-hadoop", "nn1,nn2"); conf.set("dfs.client.failover.proxy.provider.haosong-hadoop", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider"); conf.set("dfs.namenode.rpc-address.haosong-hadoop.nn1", "127.0.0.1:8020"); conf.set("dfs.namenode.rpc-address.haosong-hadoop.nn2", "127.10.2.1:8000"); desPath = new Path("/"); desFs = desPath.getFileSystem(conf); assertTrue(FSHDFSUtils.isSameHdfs(conf, srcFs, desFs)); conf.set("dfs.namenode.rpc-address.haosong-hadoop.nn1", "127.10.2.1:8020"); conf.set("dfs.namenode.rpc-address.haosong-hadoop.nn2", "127.0.0.1:8000"); desPath = new Path("/"); desFs = desPath.getFileSystem(conf); assertTrue(!FSHDFSUtils.isSameHdfs(conf, srcFs, desFs)); }
public static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs) { String srcServiceName = srcFs.getCanonicalServiceName(); String desServiceName = desFs.getCanonicalServiceName(); if (srcServiceName == null || desServiceName == null) { return false; } if (srcServiceName.equals(desServiceName)) { return true; } if (srcFs instanceof DistributedFileSystem && desFs instanceof DistributedFileSystem) { Set<InetSocketAddress> srcAddrs = getNNAddresses((DistributedFileSystem) srcFs, conf); Set<InetSocketAddress> desAddrs = getNNAddresses((DistributedFileSystem) desFs, conf); if (Sets.intersection(srcAddrs, desAddrs).size() > 0) { return true; } } return false; }
FSHDFSUtils extends FSUtils { public static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs) { String srcServiceName = srcFs.getCanonicalServiceName(); String desServiceName = desFs.getCanonicalServiceName(); if (srcServiceName == null || desServiceName == null) { return false; } if (srcServiceName.equals(desServiceName)) { return true; } if (srcFs instanceof DistributedFileSystem && desFs instanceof DistributedFileSystem) { Set<InetSocketAddress> srcAddrs = getNNAddresses((DistributedFileSystem) srcFs, conf); Set<InetSocketAddress> desAddrs = getNNAddresses((DistributedFileSystem) desFs, conf); if (Sets.intersection(srcAddrs, desAddrs).size() > 0) { return true; } } return false; } }
FSHDFSUtils extends FSUtils { public static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs) { String srcServiceName = srcFs.getCanonicalServiceName(); String desServiceName = desFs.getCanonicalServiceName(); if (srcServiceName == null || desServiceName == null) { return false; } if (srcServiceName.equals(desServiceName)) { return true; } if (srcFs instanceof DistributedFileSystem && desFs instanceof DistributedFileSystem) { Set<InetSocketAddress> srcAddrs = getNNAddresses((DistributedFileSystem) srcFs, conf); Set<InetSocketAddress> desAddrs = getNNAddresses((DistributedFileSystem) desFs, conf); if (Sets.intersection(srcAddrs, desAddrs).size() > 0) { return true; } } return false; }  }
FSHDFSUtils extends FSUtils { public static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs) { String srcServiceName = srcFs.getCanonicalServiceName(); String desServiceName = desFs.getCanonicalServiceName(); if (srcServiceName == null || desServiceName == null) { return false; } if (srcServiceName.equals(desServiceName)) { return true; } if (srcFs instanceof DistributedFileSystem && desFs instanceof DistributedFileSystem) { Set<InetSocketAddress> srcAddrs = getNNAddresses((DistributedFileSystem) srcFs, conf); Set<InetSocketAddress> desAddrs = getNNAddresses((DistributedFileSystem) desFs, conf); if (Sets.intersection(srcAddrs, desAddrs).size() > 0) { return true; } } return false; }  static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs); @Override void recoverFileLease(final FileSystem fs, final Path p,
      Configuration conf, CancelableProgressable reporter); }
FSHDFSUtils extends FSUtils { public static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs) { String srcServiceName = srcFs.getCanonicalServiceName(); String desServiceName = desFs.getCanonicalServiceName(); if (srcServiceName == null || desServiceName == null) { return false; } if (srcServiceName.equals(desServiceName)) { return true; } if (srcFs instanceof DistributedFileSystem && desFs instanceof DistributedFileSystem) { Set<InetSocketAddress> srcAddrs = getNNAddresses((DistributedFileSystem) srcFs, conf); Set<InetSocketAddress> desAddrs = getNNAddresses((DistributedFileSystem) desFs, conf); if (Sets.intersection(srcAddrs, desAddrs).size() > 0) { return true; } } return false; }  static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs); @Override void recoverFileLease(final FileSystem fs, final Path p,
      Configuration conf, CancelableProgressable reporter);  }