/** * Helper method for testing async snapshot operations. Just waits for the * given snapshot to complete on the server by repeatedly checking the master. * * @param master: the master running the snapshot * @param snapshot: the snapshot to check * @param sleep: amount to sleep between checks to see if the snapshot is done * @throws ServiceException if the snapshot fails */ public static void waitForSnapshotToComplete(HMaster master, SnapshotDescription snapshot, long sleep) throws ServiceException { final IsSnapshotDoneRequest request = IsSnapshotDoneRequest.newBuilder() .setSnapshot(snapshot).build(); IsSnapshotDoneResponse done = IsSnapshotDoneResponse.newBuilder() .buildPartial(); while (!done.getDone()) { done = master.getMasterRpcServices().isSnapshotDone(null, request); try { Thread.sleep(sleep); } catch (InterruptedException e) { throw new ServiceException(e); } } }
/** * Expect the snapshot to throw an error when checking if the snapshot is * complete * * @param master master to check * @param snapshot the {@link SnapshotDescription} request to pass to the master * @param clazz expected exception from the master */ public static void expectSnapshotDoneException(HMaster master, IsSnapshotDoneRequest snapshot, Class<? extends HBaseSnapshotException> clazz) { try { master.getMasterRpcServices().isSnapshotDone(null, snapshot); Assert.fail("didn't fail to lookup a snapshot"); } catch (ServiceException se) { try { throw ProtobufUtil.getRemoteException(se); } catch (HBaseSnapshotException e) { assertEquals("Threw wrong snapshot exception!", clazz, e.getClass()); } catch (Throwable t) { Assert.fail("Threw an unexpected exception:" + t); } } }
/** * Checks if the specified snapshot is done. * @return true if the snapshot is in file system ready to use, * false if the snapshot is in the process of completing * @throws ServiceException wrapping UnknownSnapshotException if invalid snapshot, or * a wrapped HBaseSnapshotException with progress failure reason. */ @Override public IsSnapshotDoneResponse isSnapshotDone(RpcController controller, IsSnapshotDoneRequest request) throws ServiceException { LOG.debug("Checking to see if snapshot from request:" + ClientSnapshotDescriptionUtils.toString(request.getSnapshot()) + " is done"); try { master.checkInitialized(); IsSnapshotDoneResponse.Builder builder = IsSnapshotDoneResponse.newBuilder(); boolean done = master.snapshotManager.isSnapshotDone(request.getSnapshot()); builder.setDone(done); return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
/** * Helper method for testing async snapshot operations. Just waits for the * given snapshot to complete on the server by repeatedly checking the master. * * @param master: the master running the snapshot * @param snapshot: the snapshot to check * @param sleep: amount to sleep between checks to see if the snapshot is done * @throws ServiceException if the snapshot fails */ public static void waitForSnapshotToComplete(HMaster master, SnapshotDescription snapshot, long sleep) throws ServiceException { final IsSnapshotDoneRequest request = IsSnapshotDoneRequest.newBuilder() .setSnapshot(snapshot).build(); IsSnapshotDoneResponse done = IsSnapshotDoneResponse.newBuilder() .buildPartial(); while (!done.getDone()) { done = master.isSnapshotDone(null, request); try { Thread.sleep(sleep); } catch (InterruptedException e) { throw new ServiceException(e); } } }
/** * Expect the snapshot to throw an error when checking if the snapshot is * complete * * @param master master to check * @param snapshot the {@link SnapshotDescription} request to pass to the master * @param clazz expected exception from the master */ public static void expectSnapshotDoneException(HMaster master, IsSnapshotDoneRequest snapshot, Class<? extends HBaseSnapshotException> clazz) { try { master.isSnapshotDone(null, snapshot); Assert.fail("didn't fail to lookup a snapshot"); } catch (ServiceException se) { try { throw ProtobufUtil.getRemoteException(se); } catch (HBaseSnapshotException e) { assertEquals("Threw wrong snapshot exception!", clazz, e.getClass()); } catch (Throwable t) { Assert.fail("Threw an unexpected exception:" + t); } } }
/** * Make sure that we validate the snapshot name and the table name before we pass anything across * the wire * @throws Exception on failure */ @Test public void testValidateSnapshotName() throws Exception { ConnectionManager.HConnectionImplementation mockConnection = Mockito .mock(ConnectionManager.HConnectionImplementation.class); Configuration conf = HBaseConfiguration.create(); Mockito.when(mockConnection.getConfiguration()).thenReturn(conf); Admin admin = new HBaseAdmin(mockConnection); SnapshotDescription.Builder builder = SnapshotDescription.newBuilder(); // check that invalid snapshot names fail failSnapshotStart(admin, builder.setName(HConstants.SNAPSHOT_DIR_NAME).build()); failSnapshotStart(admin, builder.setName("-snapshot").build()); failSnapshotStart(admin, builder.setName("snapshot fails").build()); failSnapshotStart(admin, builder.setName("snap$hot").build()); failSnapshotStart(admin, builder.setName("snap:hot").build()); // check the table name also get verified failSnapshotStart(admin, builder.setName("snapshot").setTable(".table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("-table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("table fails").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("tab%le").build()); // mock the master connection MasterKeepAliveConnection master = Mockito.mock(MasterKeepAliveConnection.class); Mockito.when(mockConnection.getKeepAliveMasterService()).thenReturn(master); SnapshotResponse response = SnapshotResponse.newBuilder().setExpectedTimeout(0).build(); Mockito.when( master.snapshot((RpcController) Mockito.isNull(), Mockito.any(SnapshotRequest.class))) .thenReturn(response); IsSnapshotDoneResponse doneResponse = IsSnapshotDoneResponse.newBuilder().setDone(true).build(); Mockito.when( master.isSnapshotDone((RpcController) Mockito.isNull(), Mockito.any(IsSnapshotDoneRequest.class))).thenReturn(doneResponse); // make sure that we can use valid names admin.snapshot(builder.setName("snapshot").setTable("table").build()); }
/** * Checks if the specified snapshot is done. * @return true if the snapshot is in file system ready to use, * false if the snapshot is in the process of completing * @throws ServiceException wrapping UnknownSnapshotException if invalid snapshot, or * a wrapped HBaseSnapshotException with progress failure reason. */ @Override public IsSnapshotDoneResponse isSnapshotDone(RpcController controller, IsSnapshotDoneRequest request) throws ServiceException { LOG.debug("Checking to see if snapshot from request:" + ClientSnapshotDescriptionUtils.toString(request.getSnapshot()) + " is done"); try { IsSnapshotDoneResponse.Builder builder = IsSnapshotDoneResponse.newBuilder(); boolean done = snapshotManager.isSnapshotDone(request.getSnapshot()); builder.setDone(done); return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
/** * Make sure that we validate the snapshot name and the table name before we pass anything across * the wire * @throws Exception on failure */ @Test public void testValidateSnapshotName() throws Exception { HConnectionManager.HConnectionImplementation mockConnection = Mockito .mock(HConnectionManager.HConnectionImplementation.class); Configuration conf = HBaseConfiguration.create(); Mockito.when(mockConnection.getConfiguration()).thenReturn(conf); HBaseAdmin admin = new HBaseAdmin(mockConnection); SnapshotDescription.Builder builder = SnapshotDescription.newBuilder(); // check that invalid snapshot names fail failSnapshotStart(admin, builder.setName(HConstants.SNAPSHOT_DIR_NAME).build()); failSnapshotStart(admin, builder.setName("-snapshot").build()); failSnapshotStart(admin, builder.setName("snapshot fails").build()); failSnapshotStart(admin, builder.setName("snap$hot").build()); failSnapshotStart(admin, builder.setName("snap:hot").build()); // check the table name also get verified failSnapshotStart(admin, builder.setName("snapshot").setTable(".table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("-table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("table fails").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("tab%le").build()); // mock the master connection MasterKeepAliveConnection master = Mockito.mock(MasterKeepAliveConnection.class); Mockito.when(mockConnection.getKeepAliveMasterService()).thenReturn(master); SnapshotResponse response = SnapshotResponse.newBuilder().setExpectedTimeout(0).build(); Mockito.when( master.snapshot((RpcController) Mockito.isNull(), Mockito.any(SnapshotRequest.class))) .thenReturn(response); IsSnapshotDoneResponse doneResponse = IsSnapshotDoneResponse.newBuilder().setDone(true).build(); Mockito.when( master.isSnapshotDone((RpcController) Mockito.isNull(), Mockito.any(IsSnapshotDoneRequest.class))).thenReturn(doneResponse); // make sure that we can use valid names admin.snapshot(builder.setName("snapshot").setTable("table").build()); }
/** * Make sure that we validate the snapshot name and the table name before we pass anything across * the wire * @throws Exception on failure */ @Test public void testValidateSnapshotName() throws Exception { ConnectionManager.HConnectionImplementation mockConnection = Mockito .mock(ConnectionManager.HConnectionImplementation.class); Configuration conf = HBaseConfiguration.create(); Mockito.when(mockConnection.getConfiguration()).thenReturn(conf); HBaseAdmin admin = new HBaseAdmin(mockConnection); SnapshotDescription.Builder builder = SnapshotDescription.newBuilder(); // check that invalid snapshot names fail failSnapshotStart(admin, builder.setName(HConstants.SNAPSHOT_DIR_NAME).build()); failSnapshotStart(admin, builder.setName("-snapshot").build()); failSnapshotStart(admin, builder.setName("snapshot fails").build()); failSnapshotStart(admin, builder.setName("snap$hot").build()); failSnapshotStart(admin, builder.setName("snap:hot").build()); // check the table name also get verified failSnapshotStart(admin, builder.setName("snapshot").setTable(".table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("-table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("table fails").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("tab%le").build()); // mock the master connection MasterKeepAliveConnection master = Mockito.mock(MasterKeepAliveConnection.class); Mockito.when(mockConnection.getKeepAliveMasterService()).thenReturn(master); SnapshotResponse response = SnapshotResponse.newBuilder().setExpectedTimeout(0).build(); Mockito.when( master.snapshot((RpcController) Mockito.isNull(), Mockito.any(SnapshotRequest.class))) .thenReturn(response); IsSnapshotDoneResponse doneResponse = IsSnapshotDoneResponse.newBuilder().setDone(true).build(); Mockito.when( master.isSnapshotDone((RpcController) Mockito.isNull(), Mockito.any(IsSnapshotDoneRequest.class))).thenReturn(doneResponse); // make sure that we can use valid names admin.snapshot(builder.setName("snapshot").setTable("table").build()); }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 300000) public void testIsDoneContract() throws Exception { IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder(); String snapshotName = "asyncExpectedFailureTest"; // check that we get an exception when looking up snapshot where one hasn't happened SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // and that we get the same issue, even if we specify a name SnapshotDescription desc = SnapshotDescription.newBuilder() .setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build(); builder.setSnapshot(desc); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // set a mock handler to simulate a snapshot DisabledTableSnapshotHandler mockHandler = Mockito.mock(DisabledTableSnapshotHandler.class); Mockito.when(mockHandler.getException()).thenReturn(null); Mockito.when(mockHandler.getSnapshot()).thenReturn(desc); Mockito.when(mockHandler.isFinished()).thenReturn(new Boolean(true)); Mockito.when(mockHandler.getCompletionTimestamp()) .thenReturn(EnvironmentEdgeManager.currentTime()); master.getSnapshotManagerForTesting() .setSnapshotHandlerForTesting(TABLE_NAME, mockHandler); // if we do a lookup without a snapshot name, we should fail - you should always know your name builder = IsSnapshotDoneRequest.newBuilder(); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then do the lookup for the snapshot that it is done builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then create a snapshot to the fs and make sure that we can find it when checking done snapshotName = "completed"; Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir); desc = desc.toBuilder().setName(snapshotName).build(); SnapshotDescriptionUtils.writeSnapshotInfo(desc, snapshotDir, fs); builder.setSnapshot(desc); response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone()); }
/** * Make sure that we validate the snapshot name and the table name before we pass anything across * the wire * @throws Exception on failure */ @Test public void testValidateSnapshotName() throws Exception { ConnectionManager.HConnectionImplementation mockConnection = Mockito .mock(ConnectionManager.HConnectionImplementation.class); Configuration conf = HBaseConfiguration.create(); Mockito.when(mockConnection.getConfiguration()).thenReturn(conf); // we need a real retrying caller RpcRetryingCallerFactory callerFactory = new RpcRetryingCallerFactory(conf); RpcControllerFactory controllerFactory = Mockito.mock(RpcControllerFactory.class); Mockito.when(controllerFactory.newController()).thenReturn( Mockito.mock(PayloadCarryingRpcController.class)); Mockito.when(mockConnection.getRpcRetryingCallerFactory()).thenReturn(callerFactory); Mockito.when(mockConnection.getRpcControllerFactory()).thenReturn(controllerFactory); Admin admin = new HBaseAdmin(mockConnection); SnapshotDescription.Builder builder = SnapshotDescription.newBuilder(); // check that invalid snapshot names fail failSnapshotStart(admin, builder.setName(HConstants.SNAPSHOT_DIR_NAME).build()); failSnapshotStart(admin, builder.setName("-snapshot").build()); failSnapshotStart(admin, builder.setName("snapshot fails").build()); failSnapshotStart(admin, builder.setName("snap$hot").build()); failSnapshotStart(admin, builder.setName("snap:hot").build()); // check the table name also get verified failSnapshotStart(admin, builder.setName("snapshot").setTable(".table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("-table").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("table fails").build()); failSnapshotStart(admin, builder.setName("snapshot").setTable("tab%le").build()); // mock the master connection MasterKeepAliveConnection master = Mockito.mock(MasterKeepAliveConnection.class); Mockito.when(mockConnection.getKeepAliveMasterService()).thenReturn(master); SnapshotResponse response = SnapshotResponse.newBuilder().setExpectedTimeout(0).build(); Mockito.when( master.snapshot((RpcController) Mockito.any(), Mockito.any(SnapshotRequest.class))) .thenReturn(response); IsSnapshotDoneResponse doneResponse = IsSnapshotDoneResponse.newBuilder().setDone(true).build(); Mockito.when( master.isSnapshotDone((RpcController) Mockito.any(), Mockito.any(IsSnapshotDoneRequest.class))).thenReturn(doneResponse); // make sure that we can use valid names admin.snapshot(builder.setName("snapshot").setTable("table").build()); }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 300000) public void testIsDoneContract() throws Exception { IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder(); String snapshotName = "asyncExpectedFailureTest"; // check that we get an exception when looking up snapshot where one hasn't happened SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // and that we get the same issue, even if we specify a name SnapshotDescription desc = SnapshotDescription.newBuilder() .setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build(); builder.setSnapshot(desc); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // set a mock handler to simulate a snapshot DisabledTableSnapshotHandler mockHandler = Mockito.mock(DisabledTableSnapshotHandler.class); Mockito.when(mockHandler.getException()).thenReturn(null); Mockito.when(mockHandler.getSnapshot()).thenReturn(desc); Mockito.when(mockHandler.isFinished()).thenReturn(new Boolean(true)); Mockito.when(mockHandler.getCompletionTimestamp()) .thenReturn(EnvironmentEdgeManager.currentTimeMillis()); master.getSnapshotManagerForTesting() .setSnapshotHandlerForTesting(TABLE_NAME, mockHandler); // if we do a lookup without a snapshot name, we should fail - you should always know your name builder = IsSnapshotDoneRequest.newBuilder(); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then do the lookup for the snapshot that it is done builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then create a snapshot to the fs and make sure that we can find it when checking done snapshotName = "completed"; Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir); desc = desc.toBuilder().setName(snapshotName).build(); SnapshotDescriptionUtils.writeSnapshotInfo(desc, snapshotDir, fs); builder.setSnapshot(desc); response = master.isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone()); }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 300000) public void testIsDoneContract() throws Exception { IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder(); String snapshotName = "asyncExpectedFailureTest"; // check that we get an exception when looking up snapshot where one hasn't happened SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // and that we get the same issue, even if we specify a name SnapshotDescription desc = SnapshotDescription.newBuilder() .setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build(); builder.setSnapshot(desc); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // set a mock handler to simulate a snapshot DisabledTableSnapshotHandler mockHandler = Mockito.mock(DisabledTableSnapshotHandler.class); Mockito.when(mockHandler.getException()).thenReturn(null); Mockito.when(mockHandler.getSnapshot()).thenReturn(desc); Mockito.when(mockHandler.isFinished()).thenReturn(new Boolean(true)); Mockito.when(mockHandler.getCompletionTimestamp()) .thenReturn(EnvironmentEdgeManager.currentTimeMillis()); master.getSnapshotManagerForTesting() .setSnapshotHandlerForTesting(TABLE_NAME, mockHandler); // if we do a lookup without a snapshot name, we should fail - you should always know your name builder = IsSnapshotDoneRequest.newBuilder(); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then do the lookup for the snapshot that it is done builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then create a snapshot to the fs and make sure that we can find it when checking done snapshotName = "completed"; Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir); desc = desc.toBuilder().setName(snapshotName).build(); SnapshotDescriptionUtils.writeSnapshotInfo(desc, snapshotDir, fs); builder.setSnapshot(desc); response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone()); }
/** * Check the current state of the passed snapshot. * <p> * There are three possible states: * <ol> * <li>running - returns <tt>false</tt></li> * <li>finished - returns <tt>true</tt></li> * <li>finished with error - throws the exception that caused the snapshot to fail</li> * </ol> * <p> * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been * run/started since the snapshot your are checking, you will recieve an * {@link UnknownSnapshotException}. * @param snapshot description of the snapshot to check * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still * running * @throws IOException if we have a network issue * @throws HBaseSnapshotException if the snapshot failed * @throws UnknownSnapshotException if the requested snapshot is unknown */ @Override public boolean isSnapshotFinished(final SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException { return executeCallable(new MasterCallable<IsSnapshotDoneResponse>(getConnection()) { @Override public IsSnapshotDoneResponse call(int callTimeout) throws ServiceException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); return master.isSnapshotDone(controller, IsSnapshotDoneRequest.newBuilder().setSnapshot(snapshot).build()); } }).getDone(); }
/** * Check the current state of the passed snapshot. * <p> * There are three possible states: * <ol> * <li>running - returns <tt>false</tt></li> * <li>finished - returns <tt>true</tt></li> * <li>finished with error - throws the exception that caused the snapshot to fail</li> * </ol> * <p> * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been * run/started since the snapshot your are checking, you will recieve an * {@link UnknownSnapshotException}. * @param snapshot description of the snapshot to check * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still * running * @throws IOException if we have a network issue * @throws HBaseSnapshotException if the snapshot failed * @throws UnknownSnapshotException if the requested snapshot is unknown */ @Override public boolean isSnapshotFinished(final SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException { return executeCallable(new MasterCallable<IsSnapshotDoneResponse>(getConnection()) { @Override public IsSnapshotDoneResponse call(int callTimeout) throws ServiceException { return master.isSnapshotDone(null, IsSnapshotDoneRequest.newBuilder().setSnapshot(snapshot).build()); } }).getDone(); }
/** * Check the current state of the passed snapshot. * <p> * There are three possible states: * <ol> * <li>running - returns <tt>false</tt></li> * <li>finished - returns <tt>true</tt></li> * <li>finished with error - throws the exception that caused the snapshot to fail</li> * </ol> * <p> * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been * run/started since the snapshot your are checking, you will recieve an * {@link UnknownSnapshotException}. * @param snapshot description of the snapshot to check * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still * running * @throws IOException if we have a network issue * @throws HBaseSnapshotException if the snapshot failed * @throws UnknownSnapshotException if the requested snapshot is unknown */ public boolean isSnapshotFinished(final SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException { return executeCallable(new MasterCallable<IsSnapshotDoneResponse>(getConnection()) { @Override public IsSnapshotDoneResponse call() throws ServiceException { return master.isSnapshotDone(null, IsSnapshotDoneRequest.newBuilder().setSnapshot(snapshot).build()); } }).getDone(); }
/** * Check the current state of the passed snapshot. * <p> * There are three possible states: * <ol> * <li>running - returns <tt>false</tt></li> * <li>finished - returns <tt>true</tt></li> * <li>finished with error - throws the exception that caused the snapshot to fail</li> * </ol> * <p> * The cluster only knows about the most recent snapshot. Therefore, if another snapshot has been * run/started since the snapshot your are checking, you will recieve an * {@link UnknownSnapshotException}. * @param snapshot description of the snapshot to check * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still * running * @throws IOException if we have a network issue * @throws HBaseSnapshotException if the snapshot failed * @throws UnknownSnapshotException if the requested snapshot is unknown */ public boolean isSnapshotFinished(final SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException { return executeCallable(new MasterCallable<IsSnapshotDoneResponse>(getConnection()) { @Override public IsSnapshotDoneResponse call(int callTimeout) throws ServiceException { return master.isSnapshotDone(null, IsSnapshotDoneRequest.newBuilder().setSnapshot(snapshot).build()); } }).getDone(); }