Search in sources :

Example 1 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project storm by apache.

the class Grouping method tupleSchemeReadValue.

@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
    _Fields setField = _Fields.findByThriftId(fieldID);
    if (setField != null) {
        switch(setField) {
            case FIELDS:
                List<String> fields;
                {
                    org.apache.thrift.protocol.TList _list12 = iprot.readListBegin();
                    fields = new ArrayList<String>(_list12.size);
                    String _elem13;
                    for (int _i14 = 0; _i14 < _list12.size; ++_i14) {
                        _elem13 = iprot.readString();
                        fields.add(_elem13);
                    }
                    iprot.readListEnd();
                }
                return fields;
            case SHUFFLE:
                NullStruct shuffle;
                shuffle = new NullStruct();
                shuffle.read(iprot);
                return shuffle;
            case ALL:
                NullStruct all;
                all = new NullStruct();
                all.read(iprot);
                return all;
            case NONE:
                NullStruct none;
                none = new NullStruct();
                none.read(iprot);
                return none;
            case DIRECT:
                NullStruct direct;
                direct = new NullStruct();
                direct.read(iprot);
                return direct;
            case CUSTOM_OBJECT:
                JavaObject custom_object;
                custom_object = new JavaObject();
                custom_object.read(iprot);
                return custom_object;
            case CUSTOM_SERIALIZED:
                ByteBuffer custom_serialized;
                custom_serialized = iprot.readBinary();
                return custom_serialized;
            case LOCAL_OR_SHUFFLE:
                NullStruct local_or_shuffle;
                local_or_shuffle = new NullStruct();
                local_or_shuffle.read(iprot);
                return local_or_shuffle;
            default:
                throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
        }
    } else {
        throw new TProtocolException("Couldn't find a field with field id " + fieldID);
    }
}
Also used : TProtocolException(org.apache.thrift.protocol.TProtocolException) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Example 2 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project storm by apache.

the class JavaObjectArg method tupleSchemeReadValue.

@Override
protected Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException {
    _Fields setField = _Fields.findByThriftId(fieldID);
    if (setField != null) {
        switch(setField) {
            case INT_ARG:
                Integer int_arg;
                int_arg = iprot.readI32();
                return int_arg;
            case LONG_ARG:
                Long long_arg;
                long_arg = iprot.readI64();
                return long_arg;
            case STRING_ARG:
                String string_arg;
                string_arg = iprot.readString();
                return string_arg;
            case BOOL_ARG:
                Boolean bool_arg;
                bool_arg = iprot.readBool();
                return bool_arg;
            case BINARY_ARG:
                ByteBuffer binary_arg;
                binary_arg = iprot.readBinary();
                return binary_arg;
            case DOUBLE_ARG:
                Double double_arg;
                double_arg = iprot.readDouble();
                return double_arg;
            default:
                throw new IllegalStateException("setField wasn't null, but didn't match any of the case statements!");
        }
    } else {
        throw new TProtocolException("Couldn't find a field with field id " + fieldID);
    }
}
Also used : TProtocolException(org.apache.thrift.protocol.TProtocolException) ByteBuffer(java.nio.ByteBuffer)

Example 3 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException 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 4 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project hive by apache.

the class TUGIBasedProcessor method handleSetUGI.

private void handleSetUGI(TUGIContainingTransport ugiTrans, set_ugi<Iface> fn, TMessage msg, TProtocol iprot, TProtocol oprot) throws TException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    UserGroupInformation clientUgi = ugiTrans.getClientUGI();
    if (null != clientUgi) {
        throw new TException(new IllegalStateException("UGI is already set. Resetting is not " + "allowed. Current ugi is: " + clientUgi.getUserName()));
    }
    set_ugi_args args = fn.getEmptyArgsInstance();
    try {
        args.read(iprot);
    } catch (TProtocolException e) {
        iprot.readMessageEnd();
        TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage());
        oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
        x.write(oprot);
        oprot.writeMessageEnd();
        oprot.getTransport().flush();
        return;
    }
    iprot.readMessageEnd();
    set_ugi_result result = fn.getResult(iface, args);
    List<String> principals = result.getSuccess();
    // Store the ugi in transport and then continue as usual.
    ugiTrans.setClientUGI(UserGroupInformation.createRemoteUser(principals.remove(principals.size() - 1)));
    oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.REPLY, msg.seqid));
    result.write(oprot);
    oprot.writeMessageEnd();
    oprot.getTransport().flush();
}
Also used : TException(org.apache.thrift.TException) ThriftHiveMetastore.set_ugi_result(org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_result) TMessage(org.apache.thrift.protocol.TMessage) ThriftHiveMetastore.set_ugi_args(org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_args) TProtocolException(org.apache.thrift.protocol.TProtocolException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) TApplicationException(org.apache.thrift.TApplicationException)

Example 5 with TProtocolException

use of org.apache.thrift.protocol.TProtocolException in project pinpoint by naver.

the class ThriftRequestProperty method writeTraceHeader.

public void writeTraceHeader(ThriftHeader headerKey, TProtocol oprot) throws TException {
    Object headerValue = this.thriftHeaders.get(headerKey);
    if (headerValue == null) {
        return;
    }
    byte headerType = headerKey.getType();
    TField traceField = new TField(headerKey.name(), headerKey.getType(), headerKey.getId());
    oprot.writeFieldBegin(traceField);
    try {
        if (headerType == TType.STRING) {
            // these will be read as byte buffer although it's probably safe to just use writeString here.
            // see org.apache.thrift.protocol.TProtocolUtil.skip(TProtocol, byte, int)
            oprot.writeBinary(stringToByteBuffer((String) headerValue));
        } else if (headerType == TType.I64) {
            oprot.writeI64((Long) headerValue);
        } else if (headerType == TType.I16) {
            oprot.writeI16((Short) headerValue);
        } else if (headerType == TType.BOOL) {
            oprot.writeBool((Boolean) headerValue);
        } else {
            throw new TProtocolException("Invalid pinpoint header type - " + headerType);
        }
    } finally {
        oprot.writeFieldEnd();
    }
}
Also used : TField(org.apache.thrift.protocol.TField) TProtocolException(org.apache.thrift.protocol.TProtocolException)

Aggregations

TProtocolException (org.apache.thrift.protocol.TProtocolException)11 ByteBuffer (java.nio.ByteBuffer)8 ArrayList (java.util.ArrayList)2 TApplicationException (org.apache.thrift.TApplicationException)2 TException (org.apache.thrift.TException)2 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 NoReconnect (org.apache.hadoop.hive.metastore.annotation.NoReconnect)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 ThriftHiveMetastore.set_ugi_args (org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_args)1 ThriftHiveMetastore.set_ugi_result (org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_result)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 TField (org.apache.thrift.protocol.TField)1 TMessage (org.apache.thrift.protocol.TMessage)1 TTransportException (org.apache.thrift.transport.TTransportException)1