use of java.lang.reflect.InvocationTargetException in project hadoop by apache.
the class RecordFactoryPBImpl method newRecordInstance.
@SuppressWarnings("unchecked")
@Override
public <T> T newRecordInstance(Class<T> clazz) {
Constructor<?> constructor = cache.get(clazz);
if (constructor == null) {
Class<?> pbClazz = null;
try {
pbClazz = localConf.getClassByName(getPBImplClassName(clazz));
} catch (ClassNotFoundException e) {
throw new YarnRuntimeException("Failed to load class: [" + getPBImplClassName(clazz) + "]", e);
}
try {
constructor = pbClazz.getConstructor();
constructor.setAccessible(true);
cache.putIfAbsent(clazz, constructor);
} catch (NoSuchMethodException e) {
throw new YarnRuntimeException("Could not find 0 argument constructor", e);
}
}
try {
Object retObject = constructor.newInstance();
return (T) retObject;
} catch (InvocationTargetException e) {
throw new YarnRuntimeException(e);
} catch (IllegalAccessException e) {
throw new YarnRuntimeException(e);
} catch (InstantiationException e) {
throw new YarnRuntimeException(e);
}
}
use of java.lang.reflect.InvocationTargetException in project hadoop by apache.
the class RpcFactoryProvider method getFactoryClassInstance.
private static Object getFactoryClassInstance(String factoryClassName) {
try {
Class<?> clazz = Class.forName(factoryClassName);
Method method = clazz.getMethod("get");
method.setAccessible(true);
return method.invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new YarnRuntimeException(e);
}
}
use of java.lang.reflect.InvocationTargetException in project hbase by apache.
the class HBaseConfiguration method getPassword.
/**
* Get the password from the Configuration instance using the
* getPassword method if it exists. If not, then fall back to the
* general get method for configuration elements.
*
* @param conf configuration instance for accessing the passwords
* @param alias the name of the password element
* @param defPass the default password
* @return String password or default password
* @throws IOException
*/
public static String getPassword(Configuration conf, String alias, String defPass) throws IOException {
String passwd = null;
try {
Method m = Configuration.class.getMethod("getPassword", String.class);
char[] p = (char[]) m.invoke(conf, alias);
if (p != null) {
LOG.debug(String.format("Config option \"%s\" was found through" + " the Configuration getPassword method.", alias));
passwd = new String(p);
} else {
LOG.debug(String.format("Config option \"%s\" was not found. Using provided default value", alias));
passwd = defPass;
}
} catch (NoSuchMethodException e) {
// this is a version of Hadoop where the credential
//provider API doesn't exist yet
LOG.debug(String.format("Credential.getPassword method is not available." + " Falling back to configuration."));
passwd = conf.get(alias, defPass);
} catch (SecurityException e) {
throw new IOException(e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new IOException(e.getMessage(), e);
} catch (IllegalArgumentException e) {
throw new IOException(e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new IOException(e.getMessage(), e);
}
return passwd;
}
use of java.lang.reflect.InvocationTargetException in project hbase by apache.
the class FanOutOneBlockAsyncDFSOutputHelper method createChecksumCreater27.
private static ChecksumCreater createChecksumCreater27(Class<?> confClass) throws NoSuchMethodException {
Method createChecksumMethod = confClass.getDeclaredMethod("createChecksum");
createChecksumMethod.setAccessible(true);
return new ChecksumCreater() {
@Override
public DataChecksum createChecksum(Object conf) {
try {
return (DataChecksum) createChecksumMethod.invoke(conf);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
};
}
use of java.lang.reflect.InvocationTargetException in project hbase by apache.
the class FanOutOneBlockAsyncDFSOutputHelper method createPipelineAckStatusGetter27.
private static PipelineAckStatusGetter createPipelineAckStatusGetter27() throws NoSuchMethodException {
Method getFlagListMethod = PipelineAckProto.class.getMethod("getFlagList");
@SuppressWarnings("rawtypes") Class<? extends Enum> ecnClass;
try {
ecnClass = Class.forName("org.apache.hadoop.hdfs.protocol.datatransfer.PipelineAck$ECN").asSubclass(Enum.class);
} catch (ClassNotFoundException e) {
String msg = "Couldn't properly initialize the PipelineAck.ECN class. Please " + "update your WAL Provider to not make use of the 'asyncfs' provider. See " + "HBASE-16110 for more information.";
LOG.error(msg, e);
throw new Error(msg, e);
}
@SuppressWarnings("unchecked") Enum<?> disabledECN = Enum.valueOf(ecnClass, "DISABLED");
Method getReplyMethod = PipelineAckProto.class.getMethod("getReply", int.class);
Method combineHeaderMethod = PipelineAck.class.getMethod("combineHeader", ecnClass, Status.class);
Method getStatusFromHeaderMethod = PipelineAck.class.getMethod("getStatusFromHeader", int.class);
return new PipelineAckStatusGetter() {
@Override
public Status get(PipelineAckProto ack) {
try {
@SuppressWarnings("unchecked") List<Integer> flagList = (List<Integer>) getFlagListMethod.invoke(ack);
Integer headerFlag;
if (flagList.isEmpty()) {
Status reply = (Status) getReplyMethod.invoke(ack, 0);
headerFlag = (Integer) combineHeaderMethod.invoke(null, disabledECN, reply);
} else {
headerFlag = flagList.get(0);
}
return (Status) getStatusFromHeaderMethod.invoke(null, headerFlag);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
};
}
Aggregations