Search in sources :

Example 21 with InvocationTargetException

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);
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with InvocationTargetException

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);
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with InvocationTargetException

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

Example 24 with InvocationTargetException

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

Example 25 with InvocationTargetException

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);
            }
        }
    };
}
Also used : Status(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.Status) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) PipelineAckProto(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.PipelineAckProto) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) ArrayList(java.util.ArrayList)

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