TerrapinAdmin { public void rollbackFileSet(String[] args) throws Exception { if (args.length > 1) { final String fileSet = args[1]; FileSetInfo fileSetInfo = lockFileSet(zkManager, fileSet); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { try { unlockFileSet(zkManager, fileSet); } catch (Exception e) { e.printStackTrace(); } } })); try { int versionIndex = selectFileSetRollbackVersion(fileSetInfo, System.in); if (confirmFileSetRollbackVersion(fileSet, fileSetInfo, versionIndex, System.in)) { rollbackFileSet(zkManager, fileSet, fileSetInfo, versionIndex); } else { System.out.println("exiting rollback..."); } } catch (IllegalArgumentException exception) { LOG.error(exception.getMessage()); } } else { System.err.println("missing file set argument"); } } 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 testRollbackFileSet() throws Exception { ZooKeeperManager mockZKManager = mock(ZooKeeperManager.class); FileSetInfo fileSetInfo = new FileSetInfo(); 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); String fileSet = "test_fileset"; when(mockZKManager.getFileSetInfo(eq(fileSet))).thenReturn(fileSetInfo); doNothing().when(mockZKManager).setFileSetInfo(anyString(), any(FileSetInfo.class)); TerrapinAdmin.rollbackFileSet(mockZKManager, fileSet, fileSetInfo, 1); ArgumentCaptor<String> fileSetCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<FileSetInfo> fileSetInfoCaptor = ArgumentCaptor.forClass(FileSetInfo.class); verify(mockZKManager).setFileSetInfo(fileSetCaptor.capture(), fileSetInfoCaptor.capture()); assertEquals(fileSet, fileSetCaptor.getValue()); assertEquals("/hdfs/path/2", fileSetInfoCaptor.getValue().servingInfo.hdfsPath); assertEquals(1, fileSetInfoCaptor.getValue().oldServingInfoList.size()); assertEquals("/hdfs/path/3", fileSetInfoCaptor.getValue().oldServingInfoList.get(0).hdfsPath); }
@Test(expected = IllegalArgumentException.class) public void testRollbackFileSetWithInvalidVersion() throws Exception { ZooKeeperManager mockZKManager = mock(ZooKeeperManager.class); FileSetInfo fileSetInfo = new FileSetInfo(); 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); String fileSet = "test_fileset"; when(mockZKManager.getFileSetInfo(eq(fileSet))).thenReturn(fileSetInfo); doNothing().when(mockZKManager).setFileSetInfo(anyString(), any(FileSetInfo.class)); TerrapinAdmin.rollbackFileSet(mockZKManager, fileSet, fileSetInfo, 3); }