use of org.apache.hadoop.ipc.RemoteException in project hadoop by apache.
the class RPCUtil method unwrapAndThrowException.
/**
* Utility method that unwraps and returns appropriate exceptions.
*
* @param se
* ServiceException
* @return An instance of the actual exception, which will be a subclass of
* {@link YarnException} or {@link IOException}
*/
public static Void unwrapAndThrowException(ServiceException se) throws IOException, YarnException {
Throwable cause = se.getCause();
if (cause == null) {
// SE generated by the RPC layer itself.
throw new IOException(se);
} else {
if (cause instanceof RemoteException) {
RemoteException re = (RemoteException) cause;
Class<?> realClass = null;
try {
realClass = Class.forName(re.getClassName());
} catch (ClassNotFoundException cnf) {
// well.
throw instantiateYarnException(YarnException.class, re);
}
if (YarnException.class.isAssignableFrom(realClass)) {
throw instantiateYarnException(realClass.asSubclass(YarnException.class), re);
} else if (IOException.class.isAssignableFrom(realClass)) {
throw instantiateIOException(realClass.asSubclass(IOException.class), re);
} else if (RuntimeException.class.isAssignableFrom(realClass)) {
throw instantiateRuntimeException(realClass.asSubclass(RuntimeException.class), re);
} else {
throw re;
}
// RemoteException contains useful information as against the
// java.lang.reflect exceptions.
} else if (cause instanceof IOException) {
// RPC Client exception.
throw (IOException) cause;
} else if (cause instanceof RuntimeException) {
// RPC RuntimeException
throw (RuntimeException) cause;
} else {
// Should not be generated.
throw new IOException(se);
}
}
}
use of org.apache.hadoop.ipc.RemoteException in project hadoop by apache.
the class TestRPCUtil method verifyRemoteExceptionUnwrapping.
private void verifyRemoteExceptionUnwrapping(Class<? extends Throwable> expectedLocalException, String realExceptionClassName) {
String message = realExceptionClassName + "Message";
RemoteException re = new RemoteException(realExceptionClassName, message);
ServiceException se = new ServiceException(re);
Throwable t = null;
try {
RPCUtil.unwrapAndThrowException(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));
}
use of org.apache.hadoop.ipc.RemoteException in project SSM by Intel-bigdata.
the class SmartServer method checkAndMarkRunning.
private OutputStream checkAndMarkRunning() throws IOException {
try {
if (fs.exists(SSM_ID_PATH)) {
// try appending to it so that it will fail fast if another balancer is
// running.
IOUtils.closeStream(fs.append(SSM_ID_PATH));
fs.delete(SSM_ID_PATH, true);
}
final FSDataOutputStream fsout = fs.create(SSM_ID_PATH, false);
// mark balancer idPath to be deleted during filesystem closure
fs.deleteOnExit(SSM_ID_PATH);
fsout.writeBytes(InetAddress.getLocalHost().getHostName());
fsout.hflush();
return fsout;
} catch (RemoteException e) {
if (AlreadyBeingCreatedException.class.getName().equals(e.getClassName())) {
return null;
} else {
throw e;
}
}
}
use of org.apache.hadoop.ipc.RemoteException in project phoenix by apache.
the class MetaDataUtil method tableRegionsOnline.
/**
* This function checks if all regions of a table is online
* @param table
* @return true when all regions of a table are online
* @throws IOException
* @throws
*/
public static boolean tableRegionsOnline(Configuration conf, PTable table) {
HConnection hcon = null;
try {
hcon = HConnectionManager.getConnection(conf);
List<HRegionLocation> locations = hcon.locateRegions(org.apache.hadoop.hbase.TableName.valueOf(table.getTableName().getBytes()));
for (HRegionLocation loc : locations) {
try {
ServerName sn = loc.getServerName();
if (sn == null)
continue;
AdminService.BlockingInterface admin = hcon.getAdmin(sn);
GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(loc.getRegionInfo().getRegionName());
admin.getRegionInfo(null, request);
} catch (ServiceException e) {
IOException ie = ProtobufUtil.getRemoteException(e);
logger.debug("Region " + loc.getRegionInfo().getEncodedName() + " isn't online due to:" + ie);
return false;
} catch (RemoteException e) {
logger.debug("Cannot get region " + loc.getRegionInfo().getEncodedName() + " info due to error:" + e);
return false;
}
}
} catch (IOException ex) {
logger.warn("tableRegionsOnline failed due to:" + ex);
return false;
} finally {
if (hcon != null) {
try {
hcon.close();
} catch (IOException ignored) {
}
}
}
return true;
}
Aggregations