List of usage examples for java.lang.reflect UndeclaredThrowableException UndeclaredThrowableException
public UndeclaredThrowableException(Throwable undeclaredThrowable, String s)
From source file:com.bol.crazypigs.HBaseStorage15.java
/** * Get delegation token from hbase and add it to the Job * */// w w w .ja v a 2s . c o m @SuppressWarnings({ "rawtypes", "unchecked" }) private void addHBaseDelegationToken(Configuration hbaseConf, Job job) { if (!UDFContext.getUDFContext().isFrontend()) { return; } if ("kerberos".equalsIgnoreCase(hbaseConf.get(HBASE_SECURITY_CONF_KEY))) { // Will not be entering this block for 0.20.2 as it has no security. try { // getCurrentUser method is not public in 0.20.2 Method m1 = UserGroupInformation.class.getMethod("getCurrentUser"); UserGroupInformation currentUser = (UserGroupInformation) m1.invoke(null, (Object[]) null); // hasKerberosCredentials method not available in 0.20.2 Method m2 = UserGroupInformation.class.getMethod("hasKerberosCredentials"); boolean hasKerberosCredentials = (Boolean) m2.invoke(currentUser, (Object[]) null); if (hasKerberosCredentials) { // Class and method are available only from 0.92 security release Class tokenUtilClass = Class.forName("org.apache.hadoop.hbase.security.token.TokenUtil"); Method m3 = tokenUtilClass.getMethod("obtainTokenForJob", new Class[] { Configuration.class, UserGroupInformation.class, Job.class }); m3.invoke(null, new Object[] { hbaseConf, currentUser, job }); } else { LOG.info("Not fetching hbase delegation token as no Kerberos TGT is available"); } } catch (ClassNotFoundException cnfe) { throw new RuntimeException("Failure loading TokenUtil class, " + "is secure RPC available?", cnfe); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new UndeclaredThrowableException(e, "Unexpected error calling TokenUtil.obtainTokenForJob()"); } } }
From source file:org.apache.hadoop.security.UserGroupInformation.java
/** * Run the given action as the user, potentially throwing an exception. * @param <T> the return type of the run method * @param action the method to execute//w w w . j av a2 s. c om * @return the value from the run method * @throws IOException if the action throws an IOException * @throws Error if the action throws an Error * @throws RuntimeException if the action throws a RuntimeException * @throws InterruptedException if the action throws an InterruptedException * @throws UndeclaredThrowableException if the action throws something else */ public <T> T doAs(PrivilegedExceptionAction<T> action) throws IOException, InterruptedException { try { logPriviledgedAction(subject, action); return Subject.doAs(subject, action); } catch (PrivilegedActionException pae) { Throwable cause = pae.getCause(); LOG.error("PriviledgedActionException as:" + this + " cause:" + cause); if (cause instanceof IOException) { throw (IOException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof InterruptedException) { throw (InterruptedException) cause; } else { throw new UndeclaredThrowableException(pae, "Unknown exception in doAs"); } } }