@Test public void testSwitchVolumesDifferentSourceDepths() { List<Pair<Path,Path>> replacements = new ArrayList<>(); replacements.add(new Pair<>(new Path("hdfs: replacements.add(new Pair<>(new Path("hdfs: replacements.add(new Pair<>(new Path("hdfs: assertEquals(new Path("viewfs:/a/tables/t-00000/C000.rf"), VolumeUtil .switchVolume("hdfs: assertEquals(new Path("viewfs:/a/tables/t-00000/C000.rf"), VolumeUtil.switchVolume( "hdfs: assertEquals(new Path("viewfs:/b/tables/t-00000/C000.rf"), VolumeUtil .switchVolume("hdfs: assertNull( VolumeUtil.switchVolume("viewfs:/a/tables/t-00000/C000.rf", FileType.TABLE, replacements)); assertNull(VolumeUtil.switchVolume("file:/nn1/a/accumulo/tables/t-00000/C000.rf", FileType.TABLE, replacements)); replacements.clear(); replacements.add(new Pair<>(new Path("hdfs: replacements.add(new Pair<>(new Path("hdfs: replacements.add(new Pair<>(new Path("hdfs: assertEquals(new Path("viewfs:/a/tables/t-00000/C000.rf"), VolumeUtil.switchVolume( "hdfs: assertEquals(new Path("viewfs:/a/tables/t-00000/C000.rf"), VolumeUtil.switchVolume( "hdfs: assertEquals(new Path("viewfs:/b/tables/t-00000/C000.rf"), VolumeUtil.switchVolume( "hdfs: assertNull( VolumeUtil.switchVolume("viewfs:/a/tables/t-00000/C000.rf", FileType.TABLE, replacements)); assertNull(VolumeUtil.switchVolume("file:/nn1/a/accumulo/tables/t-00000/C000.rf", FileType.TABLE, replacements)); assertNull(VolumeUtil.switchVolume("hdfs: replacements)); }
public static Path switchVolume(String path, FileType ft, List<Pair<Path,Path>> replacements) { if (replacements.isEmpty()) { log.trace("Not switching volume because there are no replacements"); return null; } Path p = new Path(path); Path volume = removeTrailingSlash(ft.getVolume(p)); for (Pair<Path,Path> pair : replacements) { Path key = removeTrailingSlash(pair.getFirst()); if (key.equals(volume)) { Path replacement = new Path(pair.getSecond(), ft.removeVolume(p)); log.trace("Replacing {} with {}", path, replacement); return replacement; } } log.trace("Could not find replacement for {} at {}", ft, path); return null; }
VolumeUtil { public static Path switchVolume(String path, FileType ft, List<Pair<Path,Path>> replacements) { if (replacements.isEmpty()) { log.trace("Not switching volume because there are no replacements"); return null; } Path p = new Path(path); Path volume = removeTrailingSlash(ft.getVolume(p)); for (Pair<Path,Path> pair : replacements) { Path key = removeTrailingSlash(pair.getFirst()); if (key.equals(volume)) { Path replacement = new Path(pair.getSecond(), ft.removeVolume(p)); log.trace("Replacing {} with {}", path, replacement); return replacement; } } log.trace("Could not find replacement for {} at {}", ft, path); return null; } }
VolumeUtil { public static Path switchVolume(String path, FileType ft, List<Pair<Path,Path>> replacements) { if (replacements.isEmpty()) { log.trace("Not switching volume because there are no replacements"); return null; } Path p = new Path(path); Path volume = removeTrailingSlash(ft.getVolume(p)); for (Pair<Path,Path> pair : replacements) { Path key = removeTrailingSlash(pair.getFirst()); if (key.equals(volume)) { Path replacement = new Path(pair.getSecond(), ft.removeVolume(p)); log.trace("Replacing {} with {}", path, replacement); return replacement; } } log.trace("Could not find replacement for {} at {}", ft, path); return null; }  }
VolumeUtil { public static Path switchVolume(String path, FileType ft, List<Pair<Path,Path>> replacements) { if (replacements.isEmpty()) { log.trace("Not switching volume because there are no replacements"); return null; } Path p = new Path(path); Path volume = removeTrailingSlash(ft.getVolume(p)); for (Pair<Path,Path> pair : replacements) { Path key = removeTrailingSlash(pair.getFirst()); if (key.equals(volume)) { Path replacement = new Path(pair.getSecond(), ft.removeVolume(p)); log.trace("Replacing {} with {}", path, replacement); return replacement; } } log.trace("Could not find replacement for {} at {}", ft, path); return null; }  static String removeTrailingSlash(String path); static Path removeTrailingSlash(Path path); static Path switchVolume(String path, FileType ft, List<Pair<Path,Path>> replacements); static TabletFiles updateTabletVolumes(ServerContext context, ZooLock zooLock,
      KeyExtent extent, TabletFiles tabletFiles, boolean replicate); }
VolumeUtil { public static Path switchVolume(String path, FileType ft, List<Pair<Path,Path>> replacements) { if (replacements.isEmpty()) { log.trace("Not switching volume because there are no replacements"); return null; } Path p = new Path(path); Path volume = removeTrailingSlash(ft.getVolume(p)); for (Pair<Path,Path> pair : replacements) { Path key = removeTrailingSlash(pair.getFirst()); if (key.equals(volume)) { Path replacement = new Path(pair.getSecond(), ft.removeVolume(p)); log.trace("Replacing {} with {}", path, replacement); return replacement; } } log.trace("Could not find replacement for {} at {}", ft, path); return null; }  static String removeTrailingSlash(String path); static Path removeTrailingSlash(Path path); static Path switchVolume(String path, FileType ft, List<Pair<Path,Path>> replacements); static TabletFiles updateTabletVolumes(ServerContext context, ZooLock zooLock,
      KeyExtent extent, TabletFiles tabletFiles, boolean replicate);  }