Search in sources :

Example 11 with UndeclaredThrowableException

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

the class RpcRetryingCallerImpl method translateException.

/**
   * Get the good or the remote exception if any, throws the DoNotRetryIOException.
   * @param t the throwable to analyze
   * @return the translated exception, if it's not a DoNotRetryIOException
   * @throws DoNotRetryIOException - if we find it, we throw it instead of translating.
   */
static Throwable translateException(Throwable t) throws DoNotRetryIOException {
    if (t instanceof UndeclaredThrowableException) {
        if (t.getCause() != null) {
            t = t.getCause();
        }
    }
    if (t instanceof RemoteException) {
        t = ((RemoteException) t).unwrapRemoteException();
    }
    if (t instanceof LinkageError) {
        throw new DoNotRetryIOException(t);
    }
    if (t instanceof ServiceException) {
        ServiceException se = (ServiceException) t;
        Throwable cause = se.getCause();
        if (cause != null && cause instanceof DoNotRetryIOException) {
            throw (DoNotRetryIOException) cause;
        }
        // Don't let ServiceException out; its rpc specific.
        t = cause;
        // t could be a RemoteException so go around again.
        translateException(t);
    } else if (t instanceof DoNotRetryIOException) {
        throw (DoNotRetryIOException) t;
    }
    return t;
}
Also used : ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) RemoteException(org.apache.hadoop.ipc.RemoteException)

Example 12 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project hive by apache.

the class UgiMetaStoreClientFactory method createProxy.

private IMetaStoreClient createProxy(final IMetaStoreClient delegate, final String user, final UserGroupInformation authenticatedUser) {
    InvocationHandler handler = new AbstractInvocationHandler() {

        @Override
        protected Object handleInvocation(Object proxy, final Method method, final Object[] args) throws Throwable {
            try {
                if (!I_META_STORE_CLIENT_METHODS.contains(method) || authenticatedUser == null) {
                    return method.invoke(delegate, args);
                }
                try {
                    return authenticatedUser.doAs(new PrivilegedExceptionAction<Object>() {

                        @Override
                        public Object run() throws Exception {
                            return method.invoke(delegate, args);
                        }
                    });
                } catch (IOException | InterruptedException e) {
                    throw new TException("PrivilegedExceptionAction failed as user '" + user + "'.", e);
                }
            } catch (UndeclaredThrowableException | InvocationTargetException e) {
                throw e.getCause();
            }
        }
    };
    ClassLoader classLoader = IMetaStoreClient.class.getClassLoader();
    Class<?>[] interfaces = new Class<?>[] { IMetaStoreClient.class };
    Object proxy = Proxy.newProxyInstance(classLoader, interfaces, handler);
    return IMetaStoreClient.class.cast(proxy);
}
Also used : TException(org.apache.thrift.TException) Method(java.lang.reflect.Method) IOException(java.io.IOException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) AbstractInvocationHandler(com.google.common.reflect.AbstractInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AbstractInvocationHandler(com.google.common.reflect.AbstractInvocationHandler)

Example 13 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project hive by apache.

the class RetryingMetaStoreClient method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Object ret = null;
    int retriesMade = 0;
    TException caughtException = null;
    boolean allowReconnect = !method.isAnnotationPresent(NoReconnect.class);
    boolean allowRetry = true;
    Annotation[] directives = method.getDeclaredAnnotations();
    if (directives != null) {
        for (Annotation a : directives) {
            if (a instanceof RetrySemantics.CannotRetry) {
                allowRetry = false;
            }
        }
    }
    while (true) {
        try {
            reloginExpiringKeytabUser();
            if (allowReconnect) {
                if (retriesMade > 0 || hasConnectionLifeTimeReached(method)) {
                    base.reconnect();
                    lastConnectionTime = System.currentTimeMillis();
                }
            }
            if (metaCallTimeMap == null) {
                ret = method.invoke(base, args);
            } else {
                // need to capture the timing
                long startTime = System.currentTimeMillis();
                ret = method.invoke(base, args);
                long timeTaken = System.currentTimeMillis() - startTime;
                addMethodTime(method, timeTaken);
            }
            break;
        } catch (UndeclaredThrowableException e) {
            throw e.getCause();
        } catch (InvocationTargetException e) {
            Throwable t = e.getCause();
            if (t instanceof TApplicationException) {
                TApplicationException tae = (TApplicationException) t;
                switch(tae.getType()) {
                    case TApplicationException.UNSUPPORTED_CLIENT_TYPE:
                    case TApplicationException.UNKNOWN_METHOD:
                    case TApplicationException.WRONG_METHOD_NAME:
                    case TApplicationException.INVALID_PROTOCOL:
                        throw t;
                    default:
                        // TODO: most other options are probably unrecoverable... throw?
                        caughtException = tae;
                }
            } else if ((t instanceof TProtocolException) || (t instanceof TTransportException)) {
                // TODO: most protocol exceptions are probably unrecoverable... throw?
                caughtException = (TException) t;
            } else if ((t instanceof MetaException) && t.getMessage().matches("(?s).*(JDO[a-zA-Z]*|TProtocol|TTransport)Exception.*") && !t.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
                caughtException = (MetaException) t;
            } else {
                throw t;
            }
        } catch (MetaException e) {
            if (e.getMessage().matches("(?s).*(IO|TTransport)Exception.*") && !e.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException")) {
                caughtException = e;
            } else {
                throw e;
            }
        }
        if (retriesMade >= retryLimit || base.isLocalMetaStore() || !allowRetry) {
            throw caughtException;
        }
        retriesMade++;
        LOG.warn("MetaStoreClient lost connection. Attempting to reconnect (" + retriesMade + " of " + retryLimit + ") after " + retryDelaySeconds + "s. " + method.getName(), caughtException);
        Thread.sleep(retryDelaySeconds * 1000);
    }
    return ret;
}
Also used : TException(org.apache.thrift.TException) TTransportException(org.apache.thrift.transport.TTransportException) NoReconnect(org.apache.hadoop.hive.metastore.annotation.NoReconnect) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException) TApplicationException(org.apache.thrift.TApplicationException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) TProtocolException(org.apache.thrift.protocol.TProtocolException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 14 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project mybatis-3 by mybatis.

the class ExceptionUtilTest method shouldUnwrapThrowable.

@Test
public void shouldUnwrapThrowable() {
    Exception exception = new Exception();
    assertEquals(exception, ExceptionUtil.unwrapThrowable(exception));
    assertEquals(exception, ExceptionUtil.unwrapThrowable(new InvocationTargetException(exception, "test")));
    assertEquals(exception, ExceptionUtil.unwrapThrowable(new UndeclaredThrowableException(exception, "test")));
    assertEquals(exception, ExceptionUtil.unwrapThrowable(new InvocationTargetException(new InvocationTargetException(exception, "test"), "test")));
    assertEquals(exception, ExceptionUtil.unwrapThrowable(new InvocationTargetException(new UndeclaredThrowableException(exception, "test"), "test")));
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 15 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.

the class AbstractHttpClient method execute.

// non-javadoc, see interface HttpClient
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException {
    if (responseHandler == null) {
        throw new IllegalArgumentException("Response handler must not be null.");
    }
    HttpResponse response = execute(target, request, context);
    T result;
    try {
        result = responseHandler.handleResponse(response);
    } catch (Throwable t) {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            try {
                entity.consumeContent();
            } catch (Throwable t2) {
                // Log this exception. The original exception is more
                // important and will be thrown to the caller.
                this.log.warn("Error consuming content after an exception.", t2);
            }
        }
        if (t instanceof Error) {
            throw (Error) t;
        }
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        }
        if (t instanceof IOException) {
            throw (IOException) t;
        }
        throw new UndeclaredThrowableException(t);
    }
    // Handling the response was successful. Ensure that the content has
    // been fully consumed.
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        // Let this exception go to the caller.
        entity.consumeContent();
    }
    return result;
}
Also used : HttpEntity(org.apache.http.HttpEntity) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)121 IOException (java.io.IOException)36 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PollStatus (org.opennms.netmgt.poller.PollStatus)9 HashMap (java.util.HashMap)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)7 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)7 Method (java.lang.reflect.Method)6 AccessControlException (java.security.AccessControlException)6 SQLException (java.sql.SQLException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6