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 flink by apache.
the class HadoopModule method install.
@Override
public void install(SecurityUtils.SecurityConfiguration securityConfig) throws SecurityInstallException {
UserGroupInformation.setConfiguration(securityConfig.getHadoopConfiguration());
try {
if (UserGroupInformation.isSecurityEnabled() && !StringUtils.isBlank(securityConfig.getKeytab()) && !StringUtils.isBlank(securityConfig.getPrincipal())) {
String keytabPath = (new File(securityConfig.getKeytab())).getAbsolutePath();
UserGroupInformation.loginUserFromKeytab(securityConfig.getPrincipal(), keytabPath);
loginUser = UserGroupInformation.getLoginUser();
// supplement with any available tokens
String fileLocation = System.getenv(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
if (fileLocation != null) {
/*
* Use reflection API since the API semantics are not available in Hadoop1 profile. Below APIs are
* used in the context of reading the stored tokens from UGI.
* Credentials cred = Credentials.readTokenStorageFile(new File(fileLocation), config.hadoopConf);
* loginUser.addCredentials(cred);
*/
try {
Method readTokenStorageFileMethod = Credentials.class.getMethod("readTokenStorageFile", File.class, org.apache.hadoop.conf.Configuration.class);
Credentials cred = (Credentials) readTokenStorageFileMethod.invoke(null, new File(fileLocation), securityConfig.getHadoopConfiguration());
Method addCredentialsMethod = UserGroupInformation.class.getMethod("addCredentials", Credentials.class);
addCredentialsMethod.invoke(loginUser, cred);
} catch (NoSuchMethodException e) {
LOG.warn("Could not find method implementations in the shaded jar. Exception: {}", e);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
} else {
// note that the stored tokens are read automatically
try {
//Use reflection API to get the login user object
//UserGroupInformation.loginUserFromSubject(null);
Method loginUserFromSubjectMethod = UserGroupInformation.class.getMethod("loginUserFromSubject", Subject.class);
loginUserFromSubjectMethod.invoke(null, (Subject) null);
} catch (NoSuchMethodException e) {
LOG.warn("Could not find method implementations in the shaded jar. Exception: {}", e);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
loginUser = UserGroupInformation.getLoginUser();
}
if (UserGroupInformation.isSecurityEnabled()) {
// so we check only in ticket cache scenario.
if (securityConfig.useTicketCache() && !loginUser.hasKerberosCredentials()) {
// a delegation token is an adequate substitute in most cases
if (!HadoopUtils.hasHDFSDelegationToken()) {
LOG.warn("Hadoop security is enabled but current login user does not have Kerberos credentials");
}
}
}
LOG.info("Hadoop user set to {}", loginUser);
} catch (Throwable ex) {
throw new SecurityInstallException("Unable to set the Hadoop login user", ex);
}
}
use of java.lang.reflect.InvocationTargetException in project groovy by apache.
the class PropertyBinding method updateTargetValue.
public void updateTargetValue(final Object newValue) {
Runnable runnable = new Runnable() {
public void run() {
Object sourceValue = getSourceValue();
// if (isNonChangeCheck()) {
if ((sourceValue == null && newValue == null) || DefaultTypeTransformation.compareEqual(sourceValue, newValue)) {
// not a change, don't fire it
return;
}
// }
setBeanProperty(newValue);
}
};
switch(updateStrategy) {
case MIXED:
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
SwingUtilities.invokeLater(runnable);
}
break;
case ASYNC:
SwingUtilities.invokeLater(runnable);
break;
case SYNC:
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
try {
SwingUtilities.invokeAndWait(runnable);
} catch (InterruptedException e) {
LOG.log(Level.WARNING, "Error notifying propertyChangeListener", e);
throw new GroovyRuntimeException(e);
} catch (InvocationTargetException e) {
LOG.log(Level.WARNING, "Error notifying propertyChangeListener", e.getTargetException());
throw new GroovyRuntimeException(e.getTargetException());
}
}
break;
case SAME:
runnable.run();
break;
case OUTSIDE:
if (SwingUtilities.isEventDispatchThread()) {
DEFAULT_EXECUTOR_SERVICE.submit(runnable);
} else {
runnable.run();
}
break;
case DEFER:
DEFAULT_EXECUTOR_SERVICE.submit(runnable);
}
}
use of java.lang.reflect.InvocationTargetException in project DeepLinkDispatch by airbnb.
the class DeepLinkDelegate method dispatchFrom.
public DeepLinkResult dispatchFrom(Activity activity, Intent sourceIntent) {
if (activity == null) {
throw new NullPointerException("activity == null");
}
if (sourceIntent == null) {
throw new NullPointerException("sourceIntent == null");
}
Uri uri = sourceIntent.getData();
if (uri == null) {
return createResultAndNotify(activity, false, null, "No Uri in given activity's intent.");
}
String uriString = uri.toString();
DeepLinkEntry entry = findEntry(uriString);
if (entry != null) {
DeepLinkUri deepLinkUri = DeepLinkUri.parse(uriString);
Map<String, String> parameterMap = entry.getParameters(uriString);
for (String queryParameter : deepLinkUri.queryParameterNames()) {
for (String queryParameterValue : deepLinkUri.queryParameterValues(queryParameter)) {
if (parameterMap.containsKey(queryParameter)) {
Log.w(TAG, "Duplicate parameter name in path and query param: " + queryParameter);
}
parameterMap.put(queryParameter, queryParameterValue);
}
}
parameterMap.put(DeepLink.URI, uri.toString());
Bundle parameters;
if (sourceIntent.getExtras() != null) {
parameters = new Bundle(sourceIntent.getExtras());
} else {
parameters = new Bundle();
}
for (Map.Entry<String, String> parameterEntry : parameterMap.entrySet()) {
parameters.putString(parameterEntry.getKey(), parameterEntry.getValue());
}
try {
Class<?> c = entry.getActivityClass();
Intent newIntent;
TaskStackBuilder taskStackBuilder = null;
if (entry.getType() == DeepLinkEntry.Type.CLASS) {
newIntent = new Intent(activity, c);
} else {
Method method;
try {
method = c.getMethod(entry.getMethod(), Context.class);
if (method.getReturnType().equals(TaskStackBuilder.class)) {
taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity);
if (taskStackBuilder.getIntentCount() == 0) {
return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
}
newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
} else {
newIntent = (Intent) method.invoke(c, activity);
}
} catch (NoSuchMethodException exception) {
method = c.getMethod(entry.getMethod(), Context.class, Bundle.class);
if (method.getReturnType().equals(TaskStackBuilder.class)) {
taskStackBuilder = (TaskStackBuilder) method.invoke(c, activity, parameters);
if (taskStackBuilder.getIntentCount() == 0) {
return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod() + " intents length == 0");
}
newIntent = taskStackBuilder.editIntentAt(taskStackBuilder.getIntentCount() - 1);
} else {
newIntent = (Intent) method.invoke(c, activity, parameters);
}
}
}
if (newIntent.getAction() == null) {
newIntent.setAction(sourceIntent.getAction());
}
if (newIntent.getData() == null) {
newIntent.setData(sourceIntent.getData());
}
newIntent.putExtras(parameters);
newIntent.putExtra(DeepLink.IS_DEEP_LINK, true);
newIntent.putExtra(DeepLink.REFERRER_URI, uri);
if (activity.getCallingActivity() != null) {
newIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
}
if (taskStackBuilder != null) {
taskStackBuilder.startActivities();
} else {
activity.startActivity(newIntent);
}
return createResultAndNotify(activity, true, uri, null);
} catch (NoSuchMethodException exception) {
return createResultAndNotify(activity, false, uri, "Deep link to non-existent method: " + entry.getMethod());
} catch (IllegalAccessException exception) {
return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
} catch (InvocationTargetException exception) {
return createResultAndNotify(activity, false, uri, "Could not deep link to method: " + entry.getMethod());
}
} else {
return createResultAndNotify(activity, false, uri, "No registered entity to handle deep link: " + uri.toString());
}
}
Aggregations