List of usage examples for org.apache.hadoop.ipc RemoteException RemoteException
public RemoteException(String className, String msg)
From source file:com.alibaba.wasp.ipc.NettyTransceiver.java
License:Apache License
private Message processResponse(List<ByteBuffer> res, Class<? extends VersionedProtocol> protocol, RpcRequestBody param) throws IOException { ByteBufferInputStream in = new ByteBufferInputStream(res); try {//from w w w. j ava 2 s .c om // See NettyServer.prepareResponse for where we write out the response. // It writes the call.id (int), a boolean signifying any error (and if // so the exception name/trace), and the response bytes // Read the call id. RpcResponseHeader response = RpcResponseHeader.parseDelimitedFrom(in); if (response == null) { // When the stream is closed, protobuf doesn't raise an EOFException, // instead, it returns a null message object. throw new EOFException(); } Status status = response.getStatus(); if (status == Status.SUCCESS) { Message rpcResponseType; try { rpcResponseType = ProtobufRpcEngine.Invoker.getReturnProtoType( ProtobufRpcEngine.Server.getMethod(protocol, param.getMethodName())); } catch (Exception e) { throw new RuntimeException(e); // local exception } Builder builder = rpcResponseType.newBuilderForType(); builder.mergeDelimitedFrom(in); Message value = builder.build(); return value; } else if (status == Status.ERROR) { RpcException exceptionResponse = RpcException.parseDelimitedFrom(in); RemoteException remoteException = new RemoteException(exceptionResponse.getExceptionName(), exceptionResponse.getStackTrace()); throw remoteException.unwrapRemoteException(); } else if (status == Status.FATAL) { RpcException exceptionResponse = RpcException.parseDelimitedFrom(in); // Close the connection LOG.error("Fatal Exception.", exceptionResponse); RemoteException remoteException = new RemoteException(exceptionResponse.getExceptionName(), exceptionResponse.getStackTrace()); throw remoteException.unwrapRemoteException(); } else { throw new IOException("What happened?"); } } catch (Exception e) { if (e instanceof RemoteException) { ((RemoteException) e).unwrapRemoteException(); } if (e instanceof IOException) { throw (IOException) e; } else { throw new IOException(e); } } }
From source file:com.bigstep.datalake.DLFileSystem.java
License:Apache License
private static Map<?, ?> validateResponse(final HttpOpParam.Op op, final HttpURLConnection conn, boolean unwrapException) throws IOException { final int code = conn.getResponseCode(); // server is demanding an authentication we don't support if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { // match hdfs/rpc exception throw new AccessControlException(conn.getResponseMessage()); }// w w w. ja v a 2 s .c om if (code != op.getExpectedHttpResponseCode()) { final Map<?, ?> m; try { m = jsonParse(conn, true); } catch (Exception e) { throw new IOException( "Unexpected HTTP response: code=" + code + " != " + op.getExpectedHttpResponseCode() + ", " + op.toQueryString() + ", message=" + conn.getResponseMessage(), e); } if (m == null) { throw new IOException( "Unexpected HTTP response: code=" + code + " != " + op.getExpectedHttpResponseCode() + ", " + op.toQueryString() + ", message=" + conn.getResponseMessage()); } else if (m.get(RemoteException.class.getSimpleName()) == null) { return m; } IOException re = JsonUtil.toRemoteException(m); // extract UGI-related exceptions and unwrap InvalidToken // the NN mangles these exceptions but the DN does not and may need // to re-fetch a token if either report the token is expired if (re.getMessage() != null && re.getMessage().startsWith(SecurityUtil.FAILED_TO_GET_UGI_MSG_HEADER)) { String[] parts = re.getMessage().split(":\\s+", 3); re = new RemoteException(parts[1], parts[2]); re = ((RemoteException) re).unwrapRemoteException(SecretManager.InvalidToken.class); } throw unwrapException ? toIOException(re) : re; } return null; }
From source file:com.bigstep.datalake.JsonUtil.java
License:Apache License
/** * Convert an exception object to a Json string. * @param json the exception coded as json * @return the remote exception//from ww w . j a va 2s. c o m */ public static RemoteException toRemoteException(final Map<?, ?> json) { final Map<?, ?> m = (Map<?, ?>) json.get(RemoteException.class.getSimpleName()); final String message = (String) m.get("message"); final String javaClassName = (String) m.get("javaClassName"); return new RemoteException(javaClassName, message); }
From source file:com.splicemachine.derby.hbase.HPipelineExceptionFactory.java
License:Apache License
@Override public IOException fromErrorString(String s) { //everything up to the first : is the className int colIndeex = s.indexOf(":"); if (colIndeex < 0) return new IOException(s); String clazzName = s.substring(0, colIndeex).trim(); String message = s.substring(colIndeex + 1).trim(); return processRemoteException(new RemoteException(clazzName, message)); }
From source file:org.apache.beam.sdk.io.hadoop.format.HDFSSynchronizationTest.java
License:Apache License
@Test public void testCatchingRemoteException() throws IOException { FileSystem mockedFileSystem = Mockito.mock(FileSystem.class); RemoteException thrownException = new RemoteException(AlreadyBeingCreatedException.class.getName(), "Failed to CREATE_FILE"); Mockito.when(mockedFileSystem.createNewFile(Mockito.any())).thenThrow(thrownException); HDFSSynchronization synchronization = new HDFSSynchronization("someDir", (conf) -> mockedFileSystem); assertFalse(synchronization.tryAcquireJobLock(configuration)); }
From source file:org.apache.slider.server.appmaster.rpc.SliderClusterProtocolProxy.java
License:Apache License
private IOException convert(ServiceException se) { IOException ioe = ProtobufHelper.getRemoteException(se); if (ioe instanceof RemoteException) { RemoteException remoteException = (RemoteException) ioe; return new RemoteException(remoteException.getClassName(), address.toString() + ": " + remoteException.getMessage()); }/*ww w. jav a 2 s . co m*/ return ioe; }
From source file:org.apache.tez.common.TestRPCUtil.java
License:Apache License
private void verifyRemoteExceptionUnwrapping(Class<? extends Throwable> expectedLocalException, String realExceptionClassName, boolean allowIO) { String message = realExceptionClassName + "Message"; RemoteException re = new RemoteException(realExceptionClassName, message); ServiceException se = new ServiceException(re); Throwable t = null;//from www .ja va 2s .co m try { if (allowIO) { RPCUtil.unwrapAndThrowException(se); } else { RPCUtil.unwrapAndThrowNonIOException(se); } } catch (Throwable thrown) { t = thrown; } Assert.assertTrue("Expected exception [" + expectedLocalException + "] but found " + t, expectedLocalException.isInstance(t)); Assert.assertTrue("Expected message [" + message + "] but found " + t.getMessage(), t.getMessage().contains(message)); }