Search in sources :

Example 26 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hbase by apache.

the class FanOutOneBlockAsyncDFSOutputSaslHelper method createTransparentCryptoHelper.

private static TransparentCryptoHelper createTransparentCryptoHelper() throws NoSuchMethodException {
    Method decryptEncryptedDataEncryptionKeyMethod = DFSClient.class.getDeclaredMethod("decryptEncryptedDataEncryptionKey", FileEncryptionInfo.class);
    decryptEncryptedDataEncryptionKeyMethod.setAccessible(true);
    return new TransparentCryptoHelper() {

        @Override
        public Encryptor createEncryptor(Configuration conf, FileEncryptionInfo feInfo, DFSClient client) throws IOException {
            try {
                KeyVersion decryptedKey = (KeyVersion) decryptEncryptedDataEncryptionKeyMethod.invoke(client, feInfo);
                CryptoCodec cryptoCodec = CryptoCodec.getInstance(conf, feInfo.getCipherSuite());
                Encryptor encryptor = cryptoCodec.createEncryptor();
                encryptor.init(decryptedKey.getMaterial(), feInfo.getIV());
                return encryptor;
            } catch (InvocationTargetException e) {
                Throwables.propagateIfPossible(e.getTargetException(), IOException.class);
                throw new RuntimeException(e.getTargetException());
            } catch (GeneralSecurityException e) {
                throw new IOException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) Configuration(org.apache.hadoop.conf.Configuration) KeyVersion(org.apache.hadoop.crypto.key.KeyProvider.KeyVersion) GeneralSecurityException(java.security.GeneralSecurityException) Encryptor(org.apache.hadoop.crypto.Encryptor) Method(java.lang.reflect.Method) IOException(java.io.IOException) FileEncryptionInfo(org.apache.hadoop.fs.FileEncryptionInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) CryptoCodec(org.apache.hadoop.crypto.CryptoCodec)

Example 27 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hbase by apache.

the class FanOutOneBlockAsyncDFSOutputHelper method createLeaseManager.

private static LeaseManager createLeaseManager() throws NoSuchMethodException {
    Method beginFileLeaseMethod = DFSClient.class.getDeclaredMethod("beginFileLease", long.class, DFSOutputStream.class);
    beginFileLeaseMethod.setAccessible(true);
    Method endFileLeaseMethod = DFSClient.class.getDeclaredMethod("endFileLease", long.class);
    endFileLeaseMethod.setAccessible(true);
    return new LeaseManager() {

        @Override
        public void begin(DFSClient client, long inodeId) {
            try {
                beginFileLeaseMethod.invoke(client, inodeId, null);
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void end(DFSClient client, long inodeId) {
            try {
                endFileLeaseMethod.invoke(client, inodeId);
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 28 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hbase by apache.

the class FanOutOneBlockAsyncDFSOutputHelper method createStorageTypeSetter.

private static StorageTypeSetter createStorageTypeSetter() throws NoSuchMethodException {
    Method setStorageTypeMethod = OpWriteBlockProto.Builder.class.getMethod("setStorageType", StorageTypeProto.class);
    ImmutableMap.Builder<String, StorageTypeProto> builder = ImmutableMap.builder();
    for (StorageTypeProto storageTypeProto : StorageTypeProto.values()) {
        builder.put(storageTypeProto.name(), storageTypeProto);
    }
    ImmutableMap<String, StorageTypeProto> name2ProtoEnum = builder.build();
    return new StorageTypeSetter() {

        @Override
        public OpWriteBlockProto.Builder set(OpWriteBlockProto.Builder builder, Enum<?> storageType) {
            Object protoEnum = name2ProtoEnum.get(storageType.name());
            try {
                setStorageTypeMethod.invoke(builder, protoEnum);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw new RuntimeException(e);
            }
            return builder;
        }
    };
}
Also used : StorageTypeProto(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.StorageTypeProto) Method(java.lang.reflect.Method) OpWriteBlockProto(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.OpWriteBlockProto) ImmutableMap(com.google.common.collect.ImmutableMap) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 29 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hbase by apache.

the class ParseFilter method parseSimpleFilterExpression.

/**
 * Constructs a filter object given a simple filter expression
 * <p>
 * @param filterStringAsByteArray filter string given by the user
 * @return filter object we constructed
 */
public Filter parseSimpleFilterExpression(byte[] filterStringAsByteArray) throws CharacterCodingException {
    String filterName = Bytes.toString(getFilterName(filterStringAsByteArray));
    ArrayList<byte[]> filterArguments = getFilterArguments(filterStringAsByteArray);
    if (!filterHashMap.containsKey(filterName)) {
        throw new IllegalArgumentException("Filter Name " + filterName + " not supported");
    }
    try {
        filterName = filterHashMap.get(filterName);
        Class<?> c = Class.forName(filterName);
        Class<?>[] argTypes = new Class[] { ArrayList.class };
        Method m = c.getDeclaredMethod("createFilterFromArguments", argTypes);
        return (Filter) m.invoke(null, filterArguments);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    throw new IllegalArgumentException("Incorrect filter string " + new String(filterStringAsByteArray));
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 30 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project hbase by apache.

the class BaseRowProcessorEndpoint method constructRowProcessorFromRequest.

@SuppressWarnings("unchecked")
RowProcessor<S, T> constructRowProcessorFromRequest(ProcessRequest request) throws IOException {
    String className = request.getRowProcessorClassName();
    Class<?> cls;
    try {
        cls = Class.forName(className);
        RowProcessor<S, T> ci = (RowProcessor<S, T>) cls.newInstance();
        if (request.hasRowProcessorInitializerMessageName()) {
            Class<?> imn = Class.forName(request.getRowProcessorInitializerMessageName()).asSubclass(Message.class);
            Method m;
            try {
                m = imn.getMethod("parseFrom", ByteString.class);
            } catch (SecurityException e) {
                throw new IOException(e);
            } catch (NoSuchMethodException e) {
                throw new IOException(e);
            }
            S s;
            try {
                s = (S) m.invoke(null, request.getRowProcessorInitializerMessage());
            } catch (IllegalArgumentException e) {
                throw new IOException(e);
            } catch (InvocationTargetException e) {
                throw new IOException(e);
            }
            ci.initialize(s);
        }
        return ci;
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } catch (InstantiationException e) {
        throw new IOException(e);
    } catch (IllegalAccessException e) {
        throw new IOException(e);
    }
}
Also used : ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RowProcessor(org.apache.hadoop.hbase.regionserver.RowProcessor)

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