Search in sources :

Example 6 with InvocationTargetException

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);
    }
}
Also used : Method(java.lang.reflect.Method) File(java.io.File) Credentials(org.apache.hadoop.security.Credentials) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with InvocationTargetException

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);
    }
}
Also used : GroovyRuntimeException(groovy.lang.GroovyRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with InvocationTargetException

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);
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with InvocationTargetException

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);
            }
        }
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) DefaultGroovyMethods(org.codehaus.groovy.runtime.DefaultGroovyMethods) Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException) File(java.io.File)

Example 10 with InvocationTargetException

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;
}
Also used : XORErasureCodec(org.apache.hadoop.io.erasurecode.codec.XORErasureCodec) HHXORErasureCodec(org.apache.hadoop.io.erasurecode.codec.HHXORErasureCodec) RSErasureCodec(org.apache.hadoop.io.erasurecode.codec.RSErasureCodec) ErasureCodec(org.apache.hadoop.io.erasurecode.codec.ErasureCodec) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1714 Method (java.lang.reflect.Method)784 IOException (java.io.IOException)193 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)146 ArrayList (java.util.ArrayList)136 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)130 Test (org.junit.Test)129 Constructor (java.lang.reflect.Constructor)116 File (java.io.File)97 HashMap (java.util.HashMap)75 Field (java.lang.reflect.Field)71 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)69 List (java.util.List)61 Map (java.util.Map)60 CoreException (org.eclipse.core.runtime.CoreException)60 IStatus (org.eclipse.core.runtime.IStatus)43 AccessibleObject (java.lang.reflect.AccessibleObject)34 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)34 URLClassLoader (java.net.URLClassLoader)32 Status (org.eclipse.core.runtime.Status)30