Index: metastore/src/test/org/apache/hadoop/hive/metastore/DummyEndFunctionListener.java =================================================================== --- metastore/src/test/org/apache/hadoop/hive/metastore/DummyEndFunctionListener.java (revision 0) +++ metastore/src/test/org/apache/hadoop/hive/metastore/DummyEndFunctionListener.java (working copy) @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.metastore; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.hadoop.conf.Configuration; + + +/** A dummy implementation for + * {@link org.apache.hadoop.hive.metastore.MetaStoreEndFunctionListener} + * for testing purposes. + */ +public class DummyEndFunctionListener extends MetaStoreEndFunctionListener{ + + public static final List funcNameList = new ArrayList(); + public static final List contextList = + new ArrayList(); + + public DummyEndFunctionListener(Configuration config) { + super(config); + } + + @Override + public void onEndFunction(String functionName, MetaStoreEndFunctionContext context) { + funcNameList.add(functionName); + contextList.add(context); + } + +} Index: metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java =================================================================== --- metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java (revision 0) +++ metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java (working copy) @@ -0,0 +1,154 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.metastore; + + + + +import junit.framework.TestCase; + +import org.apache.hadoop.hive.cli.CliSessionState; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; +import org.apache.hadoop.hive.ql.Driver; +import org.apache.hadoop.hive.ql.session.SessionState; +/** + * TestMetaStoreEventListener. Test case for + * {@link org.apache.hadoop.hive.metastore.MetaStoreEndFunctionListener} + */ +public class TestMetaStoreEndFunctionListener extends TestCase { + private static final String msPort = "20002"; + private HiveConf hiveConf; + private HiveMetaStoreClient msc; + private Driver driver; + + private static class RunMS implements Runnable { + + @Override + public void run() { + try { + HiveMetaStore.main(new String[]{msPort}); + } catch (Throwable e) { + e.printStackTrace(System.err); + assert false; + } + } + } + + @Override + protected void setUp() throws Exception { + + super.setUp(); + System.setProperty("hive.metastore.event.listeners", + DummyListener.class.getName()); + System.setProperty("hive.metastore.pre.event.listeners", + DummyPreListener.class.getName()); + System.setProperty("hive.metastore.end.function.listeners", + DummyEndFunctionListener.class.getName()); + Thread t = new Thread(new RunMS()); + t.start(); + Thread.sleep(40000); + hiveConf = new HiveConf(this.getClass()); + hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + msPort); + hiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTRETRIES, 3); + hiveConf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, ""); + hiveConf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, ""); + hiveConf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false"); + SessionState.start(new CliSessionState(hiveConf)); + msc = new HiveMetaStoreClient(hiveConf, null); + driver = new Driver(hiveConf); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testEndFunctionListener() throws Exception { + /* Objective here is to ensure that when exceptions are thrown in HiveMetaStore in API methods + * they bubble up and are stored in the MetaStoreEndFunctionContext objects + */ + String dbName = "tmpdb"; + String tblName = "tmptbl"; + int listSize = 0; + + driver.run("create database " + dbName); + + try { + msc.getDatabase("UnknownDB"); + } + catch (Exception e) { + } + listSize = DummyEndFunctionListener.funcNameList.size(); + String func_name = DummyEndFunctionListener.funcNameList.get(listSize-1); + MetaStoreEndFunctionContext context = DummyEndFunctionListener.contextList.get(listSize-1); + assertEquals(func_name,"get_database"); + assertFalse(context.isSuccess()); + Exception e = context.getException(); + assertTrue((e!=null)); + assertTrue((e instanceof NoSuchObjectException)); + + driver.run("use " + dbName); + driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName)); + + try { + msc.getTable(dbName, "Unknown"); + } + catch (Exception e1) { + } + listSize = DummyEndFunctionListener.funcNameList.size(); + func_name = DummyEndFunctionListener.funcNameList.get(listSize-1); + context = DummyEndFunctionListener.contextList.get(listSize-1); + assertEquals(func_name,"get_table"); + assertFalse(context.isSuccess()); + e = context.getException(); + assertTrue((e!=null)); + assertTrue((e instanceof NoSuchObjectException)); + + try { + msc.getPartition("tmpdb", "tmptbl", "b=2012"); + } + catch (Exception e2) { + } + listSize = DummyEndFunctionListener.funcNameList.size(); + func_name = DummyEndFunctionListener.funcNameList.get(listSize-1); + context = DummyEndFunctionListener.contextList.get(listSize-1); + assertEquals(func_name,"get_partition_by_name"); + assertFalse(context.isSuccess()); + e = context.getException(); + assertTrue((e!=null)); + assertTrue((e instanceof NoSuchObjectException)); + + try { + driver.run("drop table Unknown"); + } + catch (Exception e4) { + } + listSize = DummyEndFunctionListener.funcNameList.size(); + func_name = DummyEndFunctionListener.funcNameList.get(listSize-1); + context = DummyEndFunctionListener.contextList.get(listSize-1); + assertEquals(func_name,"get_table"); + assertFalse(context.isSuccess()); + e = context.getException(); + assertTrue((e!=null)); + assertTrue((e instanceof NoSuchObjectException)); + + } + +} Index: metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEndFunctionContext.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEndFunctionContext.java (revision 1390738) +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEndFunctionContext.java (working copy) @@ -28,11 +28,17 @@ * whether method was successful or not. */ private final boolean success; + private final Exception e; - public MetaStoreEndFunctionContext(boolean success) { + public MetaStoreEndFunctionContext(boolean success, Exception e) { this.success = success; + this.e = e; } + public MetaStoreEndFunctionContext(boolean success) { + this(success, null); + } + /** * @return whether or not the method succeeded. */ @@ -40,4 +46,8 @@ return success; } + public Exception getException() { + return e; + } + } Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (revision 1390738) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (working copy) @@ -455,8 +455,8 @@ return startFunction(function, " : db=" + db + " tbl=" + tbl + "partition=" + partName); } - public void endFunction(String function, boolean successful) { - endFunction(function, new MetaStoreEndFunctionContext(successful)); + public void endFunction(String function, boolean successful, Exception e) { + endFunction(function, new MetaStoreEndFunctionContext(successful, e)); } public void endFunction(String function, MetaStoreEndFunctionContext context) { @@ -562,6 +562,7 @@ throws AlreadyExistsException, InvalidObjectException, MetaException { startFunction("create_database", ": " + db.toString()); boolean success = false; + Exception ex = null; try { try { if (null != get_database(db.getName())) { @@ -573,8 +574,21 @@ create_database_core(getMS(), db); success = true; + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("create_database", success); + endFunction("create_database", success, ex); } } @@ -582,17 +596,21 @@ MetaException { startFunction("get_database", ": " + name); Database db = null; + Exception ex = null; try { db = getMS().getDatabase(name); } catch (MetaException e) { + ex = e; throw e; } catch (NoSuchObjectException e) { + ex = e; throw e; } catch (Exception e) { + ex = e; assert (e instanceof RuntimeException); throw (RuntimeException) e; } finally { - endFunction("get_database", db != null); + endFunction("get_database", db != null, ex); } return db; } @@ -601,11 +619,25 @@ throws NoSuchObjectException, TException, MetaException { startFunction("alter_database" + dbName); boolean success = false; + Exception ex = null; try { getMS().alterDatabase(dbName, db); success = true; + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("alter_database", success); + endFunction("alter_database", success, ex); } } @@ -735,18 +767,33 @@ startFunction("drop_database", ": " + dbName); if (DEFAULT_DATABASE_NAME.equalsIgnoreCase(dbName)) { - endFunction("drop_database", false); + endFunction("drop_database", false, null); throw new MetaException("Can not drop default database"); } boolean success = false; + Exception ex = null; try { drop_database_core(getMS(), dbName, deleteData, cascade); success = true; } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidOperationException) { + throw (InvalidOperationException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("drop_database", success); + endFunction("drop_database", success, ex); } } @@ -754,10 +801,20 @@ startFunction("get_databases", ": " + pattern); List ret = null; + Exception ex = null; try { ret = getMS().getDatabases(pattern); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_databases", ret != null); + endFunction("get_databases", ret != null, ex); } return ret; } @@ -766,10 +823,20 @@ startFunction("get_all_databases"); List ret = null; + Exception ex = null; try { ret = getMS().getAllDatabases(); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_all_databases", ret != null); + endFunction("get_all_databases", ret != null, ex); } return ret; } @@ -799,11 +866,25 @@ MetaException, InvalidObjectException { startFunction("create_type", ": " + type.toString()); boolean success = false; + Exception ex = null; try { create_type_core(getMS(), type); success = true; + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("create_type", success); + endFunction("create_type", success, ex); } return success; @@ -813,13 +894,25 @@ startFunction("get_type", ": " + name); Type ret = null; + Exception ex = null; try { ret = getMS().getType(name); if (null == ret) { throw new NoSuchObjectException("Type \"" + name + "\" not found."); } + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_type", ret != null); + endFunction("get_type", ret != null, ex); } return ret; } @@ -853,11 +946,23 @@ startFunction("drop_type", ": " + name); boolean success = false; + Exception ex = null; try { // TODO:pc validate that there are no types that refer to this success = getMS().dropType(name); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("drop_type", success); + endFunction("drop_type", success, ex); } return success; } @@ -865,7 +970,7 @@ public Map get_type_all(String name) throws MetaException { // TODO Auto-generated method stub startFunction("get_type_all", ": " + name); - endFunction("get_type_all", false); + endFunction("get_type_all", false, null); throw new MetaException("Not yet implemented"); } @@ -981,13 +1086,28 @@ MetaException, InvalidObjectException { startFunction("create_table", ": " + tbl.toString()); boolean success = false; + Exception ex = null; try { create_table_core(getMS(), tbl, envContext); success = true; } catch (NoSuchObjectException e) { + ex = e; throw new InvalidObjectException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("create_table", success); + endFunction("create_table", success, ex); } } @@ -1180,13 +1300,26 @@ startTableFunction("drop_table", dbname, name); boolean success = false; + Exception ex = null; try { drop_table_core(getMS(), dbname, name, deleteData); success = true; } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("drop_table", success); + endFunction("drop_table", success, ex); } } @@ -1210,14 +1343,26 @@ NoSuchObjectException { Table t = null; startTableFunction("get_table", dbname, name); + Exception ex = null; try { t = getMS().getTable(dbname, name); if (t == null) { throw new NoSuchObjectException(dbname + "." + name + " table not found"); } + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_table", t != null); + endFunction("get_table", t != null, ex); } return t; } @@ -1242,6 +1387,7 @@ throws MetaException, InvalidOperationException, UnknownDBException { List tables = null; startMultiTableFunction("get_multi_table", dbname, names); + Exception ex = null; try { if (dbname == null || dbname.isEmpty()) { @@ -1252,8 +1398,21 @@ throw new InvalidOperationException(dbname + " cannot find null tables"); } tables = getMS().getTableObjectsByName(dbname, names); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidOperationException) { + throw (InvalidOperationException) e; + } else if (e instanceof UnknownDBException) { + throw (UnknownDBException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_multi_table", tables != null); + endFunction("get_multi_table", tables != null, ex); } return tables; } @@ -1264,6 +1423,7 @@ throws MetaException, InvalidOperationException, UnknownDBException { List tables = null; startFunction("get_table_names_by_filter", ": db = " + dbName + ", filter = " + filter); + Exception ex = null; try { if (dbName == null || dbName.isEmpty()) { throw new UnknownDBException("DB name is null or empty"); @@ -1272,15 +1432,28 @@ throw new InvalidOperationException(filter + " cannot apply null filter"); } tables = getMS().listTableNamesByFilter(dbName, filter, maxTables); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidOperationException) { + throw (InvalidOperationException) e; + } else if (e instanceof UnknownDBException) { + throw (UnknownDBException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_table_names_by_filter", tables != null); + endFunction("get_table_names_by_filter", tables != null, ex); } return tables; } public boolean set_table_parameters(String dbname, String name, Map params) throws NoSuchObjectException, MetaException { - endFunction(startTableFunction("set_table_parameters", dbname, name), false); + endFunction(startTableFunction("set_table_parameters", dbname, name), false, null); // TODO Auto-generated method stub return false; } @@ -1364,10 +1537,24 @@ } Partition ret = null; + Exception ex = null; try { ret = append_partition_common(getMS(), dbName, tableName, part_vals); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("append_partition", ret != null); + endFunction("append_partition", ret != null, ex); } return ret; } @@ -1411,10 +1598,24 @@ } Integer ret = null; + Exception ex = null; try { ret = add_partitions_core(getMS(), parts); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("add_partition", ret != null); + endFunction("add_partition", ret != null, ex); } return ret; } @@ -1587,10 +1788,24 @@ startTableFunction("add_partition", part.getDbName(), part.getTableName()); Partition ret = null; + Exception ex = null; try { ret = add_partition_core(getMS(), part, envContext); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("add_partition", ret != null); + endFunction("add_partition", ret != null, ex); } return ret; } @@ -1676,12 +1891,27 @@ LOG.info("Partition values:" + part_vals); boolean ret = false; + Exception ex = null; try { ret = drop_partition_common(getMS(), db_name, tbl_name, part_vals, deleteData); } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("drop_partition", ret); + endFunction("drop_partition", ret, ex); } return ret; @@ -1692,10 +1922,22 @@ startPartitionFunction("get_partition", db_name, tbl_name, part_vals); Partition ret = null; + Exception ex = null; try { ret = getMS().getPartition(db_name, tbl_name, part_vals); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partition", ret != null); + endFunction("get_partition", ret != null, ex); } return ret; } @@ -1709,13 +1951,28 @@ part_vals); Partition ret = null; + Exception ex = null; try { ret = getMS().getPartitionWithAuth(db_name, tbl_name, part_vals, user_name, group_names); } catch (InvalidObjectException e) { + ex = e; throw new NoSuchObjectException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partition_with_auth", ret != null); + endFunction("get_partition_with_auth", ret != null, ex); } return ret; } @@ -1725,10 +1982,22 @@ startTableFunction("get_partitions", db_name, tbl_name); List ret = null; + Exception ex = null; try { ret = getMS().getPartitions(db_name, tbl_name, max_parts); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partitions", ret != null); + endFunction("get_partitions", ret != null, ex); } return ret; @@ -1742,13 +2011,28 @@ startTableFunction("get_partitions_with_auth", dbName, tblName); List ret = null; + Exception ex = null; try { ret = getMS().getPartitionsWithAuth(dbName, tblName, maxParts, userName, groupNames); } catch (InvalidObjectException e) { + ex = e; throw new NoSuchObjectException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partitions_with_auth", ret != null); + endFunction("get_partitions_with_auth", ret != null, ex); } return ret; @@ -1759,10 +2043,20 @@ startTableFunction("get_partition_names", db_name, tbl_name); List ret = null; + Exception ex = null; try { ret = getMS().listPartitionNames(db_name, tbl_name, max_parts); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partition_names", ret != null); + endFunction("get_partition_names", ret != null, ex); } return ret; } @@ -1807,6 +2101,7 @@ } Partition oldPart = null; + Exception ex = null; try { try { for (MetaStorePreEventListener listener : preListeners) { @@ -1826,11 +2121,26 @@ listener.onAlterPartition(alterPartitionEvent); } } catch (InvalidObjectException e) { + ex = e; throw new InvalidOperationException(e.getMessage()); } catch (AlreadyExistsException e) { + ex = e; throw new InvalidOperationException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidOperationException) { + throw (InvalidOperationException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("alter_partition", oldPart != null); + endFunction("alter_partition", oldPart != null, ex); } return; } @@ -1851,6 +2161,7 @@ // all partitions are altered atomically // all prehooks are fired together followed by all post hooks List oldParts = null; + Exception ex = null; try { for (Partition tmpPart: new_parts) { try { @@ -1880,18 +2191,33 @@ } } } catch (InvalidObjectException e) { + ex = e; throw new InvalidOperationException(e.getMessage()); } catch (AlreadyExistsException e) { + ex = e; throw new InvalidOperationException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidOperationException) { + throw (InvalidOperationException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("alter_partition", oldParts != null); + endFunction("alter_partition", oldParts != null, ex); } return; } public boolean create_index(Index index_def) throws IndexAlreadyExistsException, MetaException { - endFunction(startFunction("create_index"), false); + endFunction(startFunction("create_index"), false, null); // TODO Auto-generated method stub throw new MetaException("Not yet implemented"); } @@ -1905,19 +2231,32 @@ .currentTimeMillis() / 1000)); boolean success = false; + Exception ex = null; try { getMS().alterIndex(dbname, base_table_name, index_name, newIndex); success = true; } catch (InvalidObjectException e) { + ex = e; throw new InvalidOperationException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidOperationException) { + throw (InvalidOperationException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("alter_index", success); + endFunction("alter_index", success, ex); } return; } public String getVersion() throws TException { - endFunction(startFunction("getVersion"), true); + endFunction(startFunction("getVersion"), true, null); return "3.0"; } @@ -1950,15 +2289,11 @@ .currentTimeMillis() / 1000)); } boolean success = false; + Exception ex = null; try { Table oldt = get_table(dbname, name); - - try { - for (MetaStorePreEventListener listener : preListeners) { - listener.onEvent(new PreAlterTableEvent(oldt, newTable, this)); - } - } catch (NoSuchObjectException e) { - throw new MetaException(e.getMessage()); + for (MetaStorePreEventListener listener : preListeners) { + listener.onEvent(new PreAlterTableEvent(oldt, newTable, this)); } alterHandler.alterTable(getMS(), wh, dbname, name, newTable); success = true; @@ -1971,9 +2306,21 @@ } } catch (NoSuchObjectException e) { // thrown when the table to be altered does not exist + ex = e; throw new InvalidOperationException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof InvalidOperationException) { + throw (InvalidOperationException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("alter_table", success); + endFunction("alter_table", success, ex); } } @@ -1982,10 +2329,20 @@ startFunction("get_tables", ": db=" + dbname + " pat=" + pattern); List ret = null; + Exception ex = null; try { ret = getMS().getTables(dbname, pattern); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_tables", ret != null); + endFunction("get_tables", ret != null, ex); } return ret; } @@ -1994,10 +2351,20 @@ startFunction("get_all_tables", ": db=" + dbname); List ret = null; + Exception ex = null; try { ret = getMS().getAllTables(dbname); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_all_tables", ret != null); + endFunction("get_all_tables", ret != null, ex); } return ret; } @@ -2010,6 +2377,7 @@ Table tbl; List ret = null; + Exception ex = null; try { try { tbl = get_table(db, base_table_name); @@ -2029,8 +2397,21 @@ throw new MetaException(e.getMessage()); } } + } catch (Exception e) { + ex = e; + if (e instanceof UnknownDBException) { + throw (UnknownDBException) e; + } else if (e instanceof UnknownTableException) { + throw (UnknownTableException) e; + } else if (e instanceof MetaException) { + throw (MetaException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_fields", ret != null); + endFunction("get_fields", ret != null, ex); } return ret; @@ -2053,6 +2434,7 @@ throws MetaException, UnknownTableException, UnknownDBException { startFunction("get_schema", ": db=" + db + "tbl=" + tableName); boolean success = false; + Exception ex = null; try { String[] names = tableName.split("\\."); String base_table_name = names[0]; @@ -2076,8 +2458,21 @@ } success = true; return fieldSchemas; + } catch (Exception e) { + ex = e; + if (e instanceof UnknownDBException) { + throw (UnknownDBException) e; + } else if (e instanceof UnknownTableException) { + throw (UnknownTableException) e; + } else if (e instanceof MetaException) { + throw (MetaException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_schema", success); + endFunction("get_schema", success, ex); } } @@ -2096,6 +2491,7 @@ startFunction("get_config_value", ": name=" + name + " defaultValue=" + defaultValue); boolean success = false; + Exception ex = null; try { if (name == null) { success = true; @@ -2118,8 +2514,19 @@ } success = true; return toReturn; + } catch (Exception e) { + ex = e; + if (e instanceof ConfigValSecurityException) { + throw (ConfigValSecurityException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + TException te = new TException(e.toString()); + te.initCause(e); + throw te; + } } finally { - endFunction("get_config_value", success); + endFunction("get_config_value", success, ex); } } @@ -2173,11 +2580,24 @@ + tbl_name + " part=" + part_name); Partition ret = null; - + Exception ex = null; try { ret = get_partition_by_name_core(getMS(), db_name, tbl_name, part_name); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partition_by_name", ret != null); + endFunction("get_partition_by_name", ret != null, ex); } return ret; } @@ -2189,12 +2609,28 @@ + tbl_name + " part=" + part_name); Partition ret = null; + Exception ex = null; try { RawStore ms = getMS(); List partVals = getPartValsFromName(ms, db_name, tbl_name, part_name); ret = append_partition_common(ms, db_name, tbl_name, partVals); + } catch (Exception e) { + ex = e; + if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("append_partition_by_name", ret != null); + endFunction("append_partition_by_name", ret != null, ex); } return ret; } @@ -2222,13 +2658,28 @@ + tbl_name + " part=" + part_name); boolean ret = false; + Exception ex = null; try { ret = drop_partition_by_name_core(getMS(), db_name, tbl_name, part_name, deleteData); } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("drop_partition_by_name", ret); + endFunction("drop_partition_by_name", ret, ex); } return ret; @@ -2241,11 +2692,25 @@ startPartitionFunction("get_partitions_ps", db_name, tbl_name, part_vals); List ret = null; + Exception ex = null; try { ret = get_partitions_ps_with_auth(db_name, tbl_name, part_vals, max_parts, null, null); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partitions_ps", ret != null); + endFunction("get_partitions_ps", ret != null, ex); } return ret; @@ -2259,13 +2724,28 @@ startPartitionFunction("get_partitions_ps_with_auth", db_name, tbl_name, part_vals); List ret = null; + Exception ex = null; try { ret = getMS().listPartitionsPsWithAuth(db_name, tbl_name, part_vals, max_parts, userName, groupNames); } catch (InvalidObjectException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partitions_ps_with_auth", ret != null); + endFunction("get_partitions_ps_with_auth", ret != null, ex); } return ret; } @@ -2276,10 +2756,24 @@ throws MetaException, TException, NoSuchObjectException { startPartitionFunction("get_partitions_names_ps", db_name, tbl_name, part_vals); List ret = null; + Exception ex = null; try { ret = getMS().listPartitionNamesPs(db_name, tbl_name, part_vals, max_parts); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partitions_names_ps", ret != null); + endFunction("get_partitions_names_ps", ret != null, ex); } return ret; } @@ -2310,10 +2804,26 @@ throws InvalidObjectException, AlreadyExistsException, MetaException, TException { startFunction("add_index", ": " + newIndex.toString() + " " + indexTable.toString()); Index ret = null; + Exception ex = null; try { ret = add_index_core(getMS(), newIndex, indexTable); + } catch (Exception e) { + ex = e; + if (e instanceof InvalidObjectException) { + throw (InvalidObjectException) e; + } else if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException) e; + } else if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("add_index", ret != null); + endFunction("add_index", ret != null, ex); } return ret; } @@ -2383,13 +2893,28 @@ + tblName + " index=" + indexName); boolean ret = false; + Exception ex = null; try { ret = drop_index_by_name_core(getMS(), dbName, tblName, indexName, deleteData); } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("drop_index_by_name", ret); + endFunction("drop_index_by_name", ret, ex); } return ret; @@ -2462,11 +2987,24 @@ + tblName + " index=" + indexName); Index ret = null; - + Exception ex = null; try { ret = get_index_by_name_core(getMS(), dbName, tblName, indexName); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("drop_index_by_name", ret != null); + endFunction("drop_index_by_name", ret != null, ex); } return ret; } @@ -2489,10 +3027,22 @@ startTableFunction("get_index_names", dbName, tblName); List ret = null; + Exception ex = null; try { ret = getMS().listIndexNames(dbName, tblName, maxIndexes); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_index_names", ret != null); + endFunction("get_index_names", ret != null, ex); } return ret; } @@ -2504,10 +3054,24 @@ startTableFunction("get_indexes", dbName, tblName); List ret = null; + Exception ex = null; try { ret = getMS().getIndexes(dbName, tblName, maxIndexes); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_indexes", ret != null); + endFunction("get_indexes", ret != null, ex); } return ret; } @@ -2519,10 +3083,24 @@ startTableFunction("get_partitions_by_filter", dbName, tblName); List ret = null; + Exception ex = null; try { ret = getMS().getPartitionsByFilter(dbName, tblName, filter, maxParts); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partitions_by_filter", ret != null); + endFunction("get_partitions_by_filter", ret != null, ex); } return ret; } @@ -2535,10 +3113,24 @@ startTableFunction("get_partitions_by_names", dbName, tblName); List ret = null; + Exception ex = null; try { ret = getMS().getPartitionsByNames(dbName, tblName, partNames); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_partitions_by_names", ret != null); + endFunction("get_partitions_by_names", ret != null, ex); } return ret; } @@ -3047,13 +3639,26 @@ throws MetaException, TException { startFunction("cancel_delegation_token"); boolean success = false; + Exception ex = null; try { HiveMetaStore.cancelDelegationToken(token_str_form); success = true; } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("cancel_delegation_token", success); + endFunction("cancel_delegation_token", success, ex); } } @@ -3062,12 +3667,25 @@ throws MetaException, TException { startFunction("renew_delegation_token"); Long ret = null; + Exception ex = null; try { ret = HiveMetaStore.renewDelegationToken(token_str_form); } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("renew_delegation_token", ret != null); + endFunction("renew_delegation_token", ret != null, ex); } return ret; } @@ -3078,16 +3696,30 @@ throws MetaException, TException { startFunction("get_delegation_token"); String ret = null; + Exception ex = null; try { ret = HiveMetaStore.getDelegationToken(token_owner, renewer_kerberos_principal_name); } catch (IOException e) { + ex = e; throw new MetaException(e.getMessage()); } catch (InterruptedException e) { + ex = e; throw new MetaException(e.getMessage()); + } catch (Exception e) { + ex = e; + if (e instanceof MetaException) { + throw (MetaException) e; + } else if (e instanceof TException) { + throw (TException) e; + } else { + MetaException me = new MetaException(e.toString()); + me.initCause(e); + throw me; + } } finally { - endFunction("get_delegation_token", ret != null); + endFunction("get_delegation_token", ret != null, ex); } return ret; } @@ -3100,34 +3732,14 @@ InvalidPartitionException, UnknownPartitionException { Table tbl = null; + Exception ex = null; try { startPartitionFunction("markPartitionForEvent", db_name, tbl_name, partName); - try { - for(MetaStorePreEventListener listener : preListeners){ - listener.onEvent( - new PreLoadPartitionDoneEvent(this, db_name, tbl_name, partName)); - } - tbl = getMS().markPartitionForEvent(db_name, tbl_name, partName, evtType); - } catch (Exception original) { - LOG.error(original); - if (original instanceof NoSuchObjectException) { - throw (NoSuchObjectException) original; - } else if (original instanceof UnknownTableException) { - throw (UnknownTableException) original; - } else if (original instanceof UnknownDBException) { - throw (UnknownDBException) original; - } else if (original instanceof UnknownPartitionException) { - throw (UnknownPartitionException) original; - } else if (original instanceof InvalidPartitionException) { - throw (InvalidPartitionException) original; - } else if (original instanceof MetaException) { - throw (MetaException) original; - } else { - MetaException me = new MetaException(original.toString()); - me.initCause(original); - throw me; - } + for(MetaStorePreEventListener listener : preListeners){ + listener.onEvent( + new PreLoadPartitionDoneEvent(this, db_name, tbl_name, partName)); } + tbl = getMS().markPartitionForEvent(db_name, tbl_name, partName, evtType); if (null == tbl) { throw new UnknownTableException("Table: " + tbl_name + " not found."); } else { @@ -3135,8 +3747,28 @@ listener.onLoadPartitionDone(new LoadPartitionDoneEvent(true, this, tbl, partName)); } } + } catch (Exception original) { + ex = original; + LOG.error(original); + if (original instanceof NoSuchObjectException) { + throw (NoSuchObjectException) original; + } else if (original instanceof UnknownTableException) { + throw (UnknownTableException) original; + } else if (original instanceof UnknownDBException) { + throw (UnknownDBException) original; + } else if (original instanceof UnknownPartitionException) { + throw (UnknownPartitionException) original; + } else if (original instanceof InvalidPartitionException) { + throw (InvalidPartitionException) original; + } else if (original instanceof MetaException) { + throw (MetaException) original; + } else { + MetaException me = new MetaException(original.toString()); + me.initCause(original); + throw me; + } } finally { - endFunction("markPartitionForEvent", tbl != null); + endFunction("markPartitionForEvent", tbl != null, ex); } } @@ -3148,10 +3780,12 @@ startPartitionFunction("isPartitionMarkedForEvent", db_name, tbl_name, partName); Boolean ret = null; + Exception ex = null; try { ret = getMS().isPartitionMarkedForEvent(db_name, tbl_name, partName, evtType); } catch (Exception original) { LOG.error(original); + ex = original; if (original instanceof NoSuchObjectException) { throw (NoSuchObjectException) original; } else if (original instanceof UnknownTableException) { @@ -3170,7 +3804,7 @@ throw me; } } finally { - endFunction("isPartitionMarkedForEvent", ret != null); + endFunction("isPartitionMarkedForEvent", ret != null, ex); } return ret;