TerrapinAdmin { @VisibleForTesting protected static boolean confirmFileSetRollbackVersion(String fileSet, FileSetInfo fileSetInfo, int versionIndex, InputStream inputStream) { String rollbackHdfs = fileSetInfo.oldServingInfoList.get(versionIndex).hdfsPath; System.out.print(String.format("are you sure to rollback %s from %s to %s? [y/n]: ", fileSet, fileSetInfo.servingInfo.hdfsPath, rollbackHdfs)); Scanner scanner = new Scanner(inputStream); if (scanner.hasNextLine()) { String input = scanner.nextLine(); if (input.length() > 0 && input.equalsIgnoreCase("y")) { return true; } } return false; } TerrapinAdmin(PropertiesConfiguration configuration); void setNamenode(String[] args); void setDfsReplication(String[] args); void checkClusterHealth(String[] args); void rollbackFileSet(String[] args); void deleteFileSet(String[] args); static FileSetInfo lockFileSet(ZooKeeperManager zkManager,
                                        String fileSet,
                                        CreateMode mode); static FileSetInfo lockFileSet(ZooKeeperManager zkManager, String fileSet); static void unlockFileSet(ZooKeeperManager zkManager, String fileSet); static void rollbackFileSet(ZooKeeperManager zkManager, String fileSet,
                                     FileSetInfo fileSetInfo, int versionIndex); static void deleteFileSet(ZooKeeperManager zkManager, String fileSet); static void main(String[] args);  }
@Test public void testConfirmFileSetRollbackVersion() { FileSetInfo fileSetInfo = new FileSetInfo(); fileSetInfo.fileSetName = "test_fileset"; fileSetInfo.numVersionsToKeep = 4; fileSetInfo.oldServingInfoList = ImmutableList.of( new FileSetInfo.ServingInfo("/hdfs/path/1", "resource", 1000, PartitionerType.MODULUS), new FileSetInfo.ServingInfo("/hdfs/path/2", "resource", 1000, PartitionerType.MODULUS), new FileSetInfo.ServingInfo("/hdfs/path/3", "resource", 1000, PartitionerType.MODULUS) ); fileSetInfo.servingInfo = new FileSetInfo.ServingInfo("/hdfs/path/4", "resource", 1000, PartitionerType.MODULUS); ByteArrayInputStream inputStream = new ByteArrayInputStream("y\n".getBytes()); assertTrue(TerrapinAdmin.confirmFileSetRollbackVersion(fileSetInfo.fileSetName, fileSetInfo, 1, inputStream)); }
@Test public void testConfirmFileSetRollbackVersionWithEmptyInput() { FileSetInfo fileSetInfo = new FileSetInfo(); fileSetInfo.fileSetName = "test_fileset"; fileSetInfo.numVersionsToKeep = 4; fileSetInfo.oldServingInfoList = ImmutableList.of( new FileSetInfo.ServingInfo("/hdfs/path/1", "resource", 1000, PartitionerType.MODULUS), new FileSetInfo.ServingInfo("/hdfs/path/2", "resource", 1000, PartitionerType.MODULUS), new FileSetInfo.ServingInfo("/hdfs/path/3", "resource", 1000, PartitionerType.MODULUS) ); fileSetInfo.servingInfo = new FileSetInfo.ServingInfo("/hdfs/path/4", "resource", 1000, PartitionerType.MODULUS); ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]); assertFalse(TerrapinAdmin.confirmFileSetRollbackVersion(fileSetInfo.fileSetName, fileSetInfo, 1, inputStream)); }
@Test public void testConfirmFileSetRollbackVersionWithOtherInput() { FileSetInfo fileSetInfo = new FileSetInfo(); fileSetInfo.fileSetName = "test_fileset"; fileSetInfo.numVersionsToKeep = 4; fileSetInfo.oldServingInfoList = ImmutableList.of( new FileSetInfo.ServingInfo("/hdfs/path/1", "resource", 1000, PartitionerType.MODULUS), new FileSetInfo.ServingInfo("/hdfs/path/2", "resource", 1000, PartitionerType.MODULUS), new FileSetInfo.ServingInfo("/hdfs/path/3", "resource", 1000, PartitionerType.MODULUS) ); fileSetInfo.servingInfo = new FileSetInfo.ServingInfo("/hdfs/path/4", "resource", 1000, PartitionerType.MODULUS); ByteArrayInputStream inputStream = new ByteArrayInputStream("other input".getBytes()); assertFalse(TerrapinAdmin.confirmFileSetRollbackVersion(fileSetInfo.fileSetName, fileSetInfo, 1, inputStream)); }