Search in sources :

Example 16 with TApplicationException

use of org.apache.thrift.TApplicationException in project hive by apache.

the class TestForeignKey method addNoSuchCatalog.

@Test
public void addNoSuchCatalog() throws TException {
    Table parentTable = testTables[0];
    List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder().onTable(parentTable).addColumn("col1").build(metaStore.getConf());
    client.addPrimaryKey(pk);
    try {
        List<SQLForeignKey> fk = new SQLForeignKeyBuilder().setTableName(testTables[0].getTableName()).setDbName(testTables[0].getDbName()).setCatName("nosuch").fromPrimaryKey(pk).addColumn("col2").build(metaStore.getConf());
        client.addForeignKey(fk);
        Assert.fail();
    } catch (InvalidObjectException | TApplicationException e) {
    // NOP
    }
}
Also used : SQLPrimaryKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder) SQLForeignKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLForeignKeyBuilder) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) Table(org.apache.hadoop.hive.metastore.api.Table) SQLForeignKey(org.apache.hadoop.hive.metastore.api.SQLForeignKey) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TApplicationException(org.apache.thrift.TApplicationException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 17 with TApplicationException

use of org.apache.thrift.TApplicationException in project hive by apache.

the class TestNotNullConstraint method addNoSuchTable.

@Test
public void addNoSuchTable() throws TException {
    try {
        List<SQLNotNullConstraint> nn = new SQLNotNullConstraintBuilder().setTableName("nosuch").addColumn("col2").build(metaStore.getConf());
        client.addNotNullConstraint(nn);
        Assert.fail();
    } catch (InvalidObjectException | TApplicationException e) {
    // NOP
    }
}
Also used : SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) SQLNotNullConstraintBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLNotNullConstraintBuilder) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TApplicationException(org.apache.thrift.TApplicationException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 18 with TApplicationException

use of org.apache.thrift.TApplicationException in project hive by apache.

the class TestPrimaryKey method addNoSuchTable.

@Test
public void addNoSuchTable() throws TException {
    try {
        List<SQLPrimaryKey> pk = new SQLPrimaryKeyBuilder().setTableName("nosuch").addColumn("col2").build(metaStore.getConf());
        client.addPrimaryKey(pk);
        Assert.fail();
    } catch (InvalidObjectException | TApplicationException e) {
    // NOP
    }
}
Also used : SQLPrimaryKeyBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TApplicationException(org.apache.thrift.TApplicationException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 19 with TApplicationException

use of org.apache.thrift.TApplicationException in project hive by apache.

the class RetryingMetaStoreClient method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Object ret;
    int retriesMade = 0;
    TException caughtException;
    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 {
            SecurityUtils.reloginExpiringKeytabUser();
            if (allowReconnect) {
                if (retriesMade > 0 || hasConnectionLifeTimeReached(method)) {
                    if (this.ugi != null) {
                        // Perform reconnect with the proper user context
                        try {
                            LOG.info("RetryingMetaStoreClient trying reconnect as " + this.ugi);
                            this.ugi.doAs(new PrivilegedExceptionAction<Object>() {

                                @Override
                                public Object run() throws MetaException {
                                    base.reconnect();
                                    return null;
                                }
                            });
                        } catch (UndeclaredThrowableException e) {
                            Throwable te = e.getCause();
                            if (te instanceof PrivilegedActionException) {
                                throw te.getCause();
                            } else {
                                throw te;
                            }
                        }
                        lastConnectionTime = System.currentTimeMillis();
                    } else {
                        LOG.warn("RetryingMetaStoreClient unable to reconnect. No UGI information.");
                        throw new MetaException("UGI information unavailable. Will not attempt a reconnect.");
                    }
                }
            }
            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) && isRecoverableMetaException((MetaException) t)) {
                caughtException = (MetaException) t;
            } else {
                throw t;
            }
        } catch (MetaException e) {
            if (isRecoverableMetaException(e)) {
                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) PrivilegedActionException(java.security.PrivilegedActionException) 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 20 with TApplicationException

use of org.apache.thrift.TApplicationException in project hive by apache.

the class TestCheckConstraint method doubleAddUniqueConstraint.

@Test
public void doubleAddUniqueConstraint() throws TException {
    Table table = testTables[0];
    // Make sure get on a table with no key returns empty list
    CheckConstraintsRequest rqst = new CheckConstraintsRequest(table.getCatName(), table.getDbName(), table.getTableName());
    List<SQLCheckConstraint> fetched = client.getCheckConstraints(rqst);
    Assert.assertTrue(fetched.isEmpty());
    // Single column unnamed primary key in default catalog and database
    List<SQLCheckConstraint> cc = new SQLCheckConstraintBuilder().onTable(table).addColumn("col1").setCheckExpression("> 0").build(metaStore.getConf());
    client.addCheckConstraint(cc);
    try {
        cc = new SQLCheckConstraintBuilder().onTable(table).addColumn("col2").setCheckExpression("= 'this string intentionally left empty'").build(metaStore.getConf());
        client.addCheckConstraint(cc);
        Assert.fail();
    } catch (InvalidObjectException | TApplicationException e) {
    // NOP
    }
}
Also used : SQLCheckConstraintBuilder(org.apache.hadoop.hive.metastore.client.builder.SQLCheckConstraintBuilder) Table(org.apache.hadoop.hive.metastore.api.Table) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) CheckConstraintsRequest(org.apache.hadoop.hive.metastore.api.CheckConstraintsRequest) TApplicationException(org.apache.thrift.TApplicationException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

TApplicationException (org.apache.thrift.TApplicationException)38 TException (org.apache.thrift.TException)16 Test (org.junit.Test)14 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)12 TMessage (org.apache.thrift.protocol.TMessage)12 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)11 Table (org.apache.hadoop.hive.metastore.api.Table)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)6 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)6 Method (java.lang.reflect.Method)5 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)5 SQLPrimaryKey (org.apache.hadoop.hive.metastore.api.SQLPrimaryKey)5 SQLPrimaryKeyBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLPrimaryKeyBuilder)5 SQLForeignKey (org.apache.hadoop.hive.metastore.api.SQLForeignKey)4 SQLForeignKeyBuilder (org.apache.hadoop.hive.metastore.client.builder.SQLForeignKeyBuilder)4 TBase (org.apache.thrift.TBase)4 TFieldIdEnum (org.apache.thrift.TFieldIdEnum)4