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 flink by apache.
the class RestartStrategyFactory method createRestartStrategyFactory.
/**
* Creates a {@link RestartStrategy} instance from the given {@link Configuration}.
*
* @return RestartStrategy instance
* @throws Exception which indicates that the RestartStrategy could not be instantiated.
*/
public static RestartStrategyFactory createRestartStrategyFactory(Configuration configuration) throws Exception {
String restartStrategyName = configuration.getString(ConfigConstants.RESTART_STRATEGY, "none");
switch(restartStrategyName.toLowerCase()) {
case "none":
// support deprecated ConfigConstants values
final int numberExecutionRetries = configuration.getInteger(ConfigConstants.EXECUTION_RETRIES_KEY, ConfigConstants.DEFAULT_EXECUTION_RETRIES);
String pauseString = configuration.getString(ConfigConstants.AKKA_WATCH_HEARTBEAT_PAUSE, ConfigConstants.DEFAULT_AKKA_ASK_TIMEOUT);
String delayString = configuration.getString(ConfigConstants.EXECUTION_RETRY_DELAY_KEY, pauseString);
long delay;
try {
delay = Duration.apply(delayString).toMillis();
} catch (NumberFormatException nfe) {
if (delayString.equals(pauseString)) {
throw new Exception("Invalid config value for " + ConfigConstants.AKKA_WATCH_HEARTBEAT_PAUSE + ": " + pauseString + ". Value must be a valid duration (such as '10 s' or '1 min')");
} else {
throw new Exception("Invalid config value for " + ConfigConstants.EXECUTION_RETRY_DELAY_KEY + ": " + delayString + ". Value must be a valid duration (such as '100 milli' or '10 s')");
}
}
if (numberExecutionRetries > 0 && delay >= 0) {
return new FixedDelayRestartStrategy.FixedDelayRestartStrategyFactory(numberExecutionRetries, delay);
} else {
return NoRestartStrategy.createFactory(configuration);
}
case "off":
case "disable":
return NoRestartStrategy.createFactory(configuration);
case "fixeddelay":
case "fixed-delay":
return FixedDelayRestartStrategy.createFactory(configuration);
case "failurerate":
case "failure-rate":
return FailureRateRestartStrategy.createFactory(configuration);
default:
try {
Class<?> clazz = Class.forName(restartStrategyName);
if (clazz != null) {
Method method = clazz.getMethod(CREATE_METHOD, Configuration.class);
if (method != null) {
Object result = method.invoke(null, configuration);
if (result != null) {
return (RestartStrategyFactory) result;
}
}
}
} catch (ClassNotFoundException cnfe) {
LOG.warn("Could not find restart strategy class {}.", restartStrategyName);
} catch (NoSuchMethodException nsme) {
LOG.warn("Class {} does not has static method {}.", restartStrategyName, CREATE_METHOD);
} catch (InvocationTargetException ite) {
LOG.warn("Cannot call static method {} from class {}.", CREATE_METHOD, restartStrategyName);
} catch (IllegalAccessException iae) {
LOG.warn("Illegal access while calling method {} from class {}.", CREATE_METHOD, restartStrategyName);
}
// fallback in case of an error
return NoRestartStrategy.createFactory(configuration);
}
}
use of java.lang.reflect.InvocationTargetException in project groovy by apache.
the class TestDgmConverter method testConverter.
public void testConverter() throws URISyntaxException {
File dgmClassDirectory = new File(TestDgmConverter.class.getResource(REFERENCE_CLASS).toURI()).getParentFile();
final File[] files = dgmClassDirectory.listFiles();
Arrays.sort(files, new Comparator<File>() {
public int compare(final File o1, final File o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
}
});
for (int i = 0; i < files.length; i++) {
File file = files[i];
final String name = file.getName();
if (name.startsWith("dgm$")) {
final String className = "org.codehaus.groovy.runtime." + name.substring(0, name.length() - ".class".length());
try {
Class cls = Class.forName(className, false, DefaultGroovyMethods.class.getClassLoader());
Constructor[] declaredConstructors = cls.getDeclaredConstructors();
assertEquals(1, declaredConstructors.length);
Constructor constructor = declaredConstructors[0];
final MetaMethod metaMethod = (MetaMethod) constructor.newInstance(null, null, null, null);
} catch (ClassNotFoundException e) {
fail("Failed to load " + className);
} catch (IllegalAccessException e) {
fail("Failed to instantiate " + className);
} catch (InstantiationException e) {
fail("Failed to instantiate " + className);
} catch (InvocationTargetException e) {
fail("Failed to instantiate " + className);
}
}
}
}
use of java.lang.reflect.InvocationTargetException in project hadoop by apache.
the class CodecUtil method createCodec.
private static ErasureCodec createCodec(Configuration conf, String codecClassName, ErasureCodecOptions options) {
ErasureCodec codec = null;
try {
Class<? extends ErasureCodec> codecClass = conf.getClassByName(codecClassName).asSubclass(ErasureCodec.class);
Constructor<? extends ErasureCodec> constructor = codecClass.getConstructor(Configuration.class, ErasureCodecOptions.class);
codec = constructor.newInstance(conf, options);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException("Failed to create erasure codec", e);
}
if (codec == null) {
throw new RuntimeException("Failed to create erasure codec");
}
return codec;
}
Aggregations