protected IOException unwrapException(IOException e) { if (e instanceof RemoteException) { e = ((RemoteException)e).unwrapRemoteException(); } return e; } }
private static IOException unwrapException(IOException e) { if (e instanceof RemoteException) { return ((RemoteException)e).unwrapRemoteException(); } return e; }
private boolean isHealthCheckFailedException(Throwable t) { return ((t instanceof HealthCheckFailedException) || (t instanceof RemoteException && ((RemoteException)t).unwrapRemoteException( HealthCheckFailedException.class) instanceof HealthCheckFailedException)); }
private static boolean isWrappedStandbyException(Exception e) { if (!(e instanceof RemoteException)) { return false; } Exception unwrapped = ((RemoteException)e).unwrapRemoteException( StandbyException.class); return unwrapped instanceof StandbyException; }
static RetriableException getWrappedRetriableException(Exception e) { if (!(e instanceof RemoteException)) { return null; } Exception unwrapped = ((RemoteException)e).unwrapRemoteException( RetriableException.class); return unwrapped instanceof RetriableException ? (RetriableException) unwrapped : null; } }
/** * Returns null if file already exists. throws if there was unexpected problem */ public static FSDataOutputStream tryCreateFile(FileSystem fs, Path file) throws IOException { try { FSDataOutputStream os = fs.create(file, false); return os; } catch (FileAlreadyExistsException e) { return null; } catch (RemoteException e) { if (e.unwrapRemoteException() instanceof AlreadyBeingCreatedException) { return null; } else { // unexpected error throw e; } } }
public Exception unwrapRemoteException() { final Throwable cause = getCause(); if (cause instanceof RemoteException) { return ((RemoteException)cause).unwrapRemoteException(); } if (cause instanceof Exception) { return (Exception)cause; } return new Exception(cause); }
static Throwable translateException(Throwable t) { if (t instanceof UndeclaredThrowableException && t.getCause() != null) { t = t.getCause(); } if (t instanceof RemoteException) { t = ((RemoteException) t).unwrapRemoteException(); } if (t instanceof ServiceException && t.getCause() != null) { t = translateException(t.getCause()); } return t; }
public static void monitorHealth(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.monitorHealth(); } catch (RemoteException e) { throw e.unwrapRemoteException(HealthCheckFailedException.class); } }
public static void transitionToActive(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.transitionToActive(reqInfo); } catch (RemoteException e) { throw e.unwrapRemoteException(ServiceFailedException.class); } }
public static void transitionToStandby(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.transitionToStandby(reqInfo); } catch (RemoteException e) { throw e.unwrapRemoteException(ServiceFailedException.class); } } }
private void shutdownWAL(final boolean close) { if (this.walFactory != null) { try { if (close) { walFactory.close(); } else { walFactory.shutdown(); } } catch (Throwable e) { e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e; LOG.error("Shutdown / close of WAL failed: " + e); LOG.debug("Shutdown / close exception details:", e); } } }
private Throwable cleanup(final Throwable t, final String msg) { // Don't log as error if NSRE; NSRE is 'normal' operation. if (t instanceof NotServingRegionException) { LOG.debug("NotServingRegionException; " + t.getMessage()); return t; } Throwable e = t instanceof RemoteException ? ((RemoteException) t).unwrapRemoteException() : t; if (msg == null) { LOG.error("", e); } else { LOG.error(msg, e); } if (!rpcServices.checkOOME(t)) { checkFileSystem(); } return t; }
private static IOException makeIOExceptionOfException(Exception e) { Throwable t = e; if (e instanceof ServiceException) { t = e.getCause(); } if (ExceptionUtil.isInterrupt(t)) { return ExceptionUtil.asInterrupt(t); } if (t instanceof RemoteException) { t = ((RemoteException)t).unwrapRemoteException(); } return t instanceof IOException? (IOException)t: new HBaseIOException(t); }
private static IOException makeIOExceptionOfException(Exception e) { Throwable t = e; if (e instanceof ServiceException || e instanceof org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) { t = e.getCause(); } if (ExceptionUtil.isInterrupt(t)) { return ExceptionUtil.asInterrupt(t); } if (t instanceof RemoteException) { t = ((RemoteException)t).unwrapRemoteException(); } return t instanceof IOException? (IOException)t: new HBaseIOException(t); }
@Override public List<SecurityCapability> getSecurityCapabilities() throws IOException { try { return executeCallable(new MasterCallable<List<SecurityCapability>>(getConnection(), getRpcControllerFactory()) { @Override protected List<SecurityCapability> rpcCall() throws Exception { SecurityCapabilitiesRequest req = SecurityCapabilitiesRequest.newBuilder().build(); return ProtobufUtil.toSecurityCapabilityList( master.getSecurityCapabilities(getRpcController(), req).getCapabilitiesList()); } }); } catch (IOException e) { if (e instanceof RemoteException) { e = ((RemoteException)e).unwrapRemoteException(); } throw e; } }
@Test public void testNotOverwrite() throws IOException { Path file = new Path("/" + name.getMethodName()); try (FSDataOutputStream out1 = FS.create(file)) { try { FS.create(file, false); fail("Should fail as there is a file with the same name which is being written"); } catch (RemoteException e) { // expected assertThat(e.unwrapRemoteException(), instanceOf(AlreadyBeingCreatedException.class)); } } }
@Test public void testDoubleCreateSemantics() throws Exception { //1 create an already existing open file w/o override flag Path file1 = new Path(dir.toString() + Path.SEPARATOR_CHAR + "file1"); try (FSDataOutputStream os1 = fs.create(file1, false)) { fs.create(file1, false); // should fail fail("Create did not throw an exception"); } catch (RemoteException e) { Assert.assertEquals(AlreadyBeingCreatedException.class, e.unwrapRemoteException().getClass()); } //2 close file and retry creation try { fs.create(file1, false); // should still fail fail("Create did not throw an exception"); } catch (FileAlreadyExistsException e) { // expecting this exception } //3 delete file and retry creation fs.delete(file1, false); try (FSDataOutputStream os2 = fs.create(file1, false)) { Assert.assertNotNull(os2); } }
@Test public void testAppendSemantics() throws Exception { //1 try to append to an open file Path file1 = new Path(dir.toString() + Path.SEPARATOR_CHAR + "file1"); try (FSDataOutputStream os1 = fs.create(file1, false)) { fs.append(file1); // should fail fail("Append did not throw an exception"); } catch (RemoteException e) { // expecting AlreadyBeingCreatedException inside RemoteException Assert.assertEquals(AlreadyBeingCreatedException.class, e.unwrapRemoteException().getClass()); } //2 try to append to a closed file try (FSDataOutputStream os2 = fs.append(file1)) { assertThat(os2, notNull()); } }
/** * This is important for fencing when recover from RS crash. */ @Test public void testCreateParentFailed() throws IOException { Path f = new Path("/" + name.getMethodName() + "/test"); EventLoop eventLoop = EVENT_LOOP_GROUP.next(); try { FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true, false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS); fail("should fail with parent does not exist"); } catch (RemoteException e) { LOG.info("expected exception caught", e); assertThat(e.unwrapRemoteException(), instanceOf(FileNotFoundException.class)); } }