hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r1100035 - in /hive/trunk: common/src/java/org/apache/hadoop/hive/conf/ conf/ metastore/src/java/org/apache/hadoop/hive/metastore/ metastore/src/java/org/apache/hadoop/hive/metastore/events/ metastore/src/test/org/apache/hadoop/hive/metastore/
Date Fri, 06 May 2011 03:17:53 GMT
Author: cws
Date: Fri May  6 03:17:52 2011
New Revision: 1100035

URL: http://svn.apache.org/viewvc?rev=1100035&view=rev
Log:
HIVE-2038. Add MetaStoreListener interface (Ashutosh Chauhan via cws)

Added:
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEventListener.java
  (with props)
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java
  (with props)
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateDatabaseEvent.java
  (with props)
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateTableEvent.java
  (with props)
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropDatabaseEvent.java
  (with props)
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java
  (with props)
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropTableEvent.java
  (with props)
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/ListenerEvent.java
  (with props)
    hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyListener.java   (with
props)
    hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java
  (with props)
Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/conf/hive-default.xml
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1100035&r1=1100034&r2=1100035&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Fri May  6 03:17:52
2011
@@ -215,6 +215,7 @@ public class HiveConf extends Configurat
     METASTORE_IDENTIFIER_FACTORY("datanucleus.identifierFactory", "datanucleus"),
     METASTORE_PLUGIN_REGISTRY_BUNDLE_CHECK("datanucleus.plugin.pluginRegistryBundleCheck",
"LOG"),
     METASTORE_BATCH_RETRIEVE_MAX("hive.metastore.batch.retrieve.max", 300),
+    METASTORE_EVENT_LISTENERS("hive.metastore.event.listeners", ""),
     // should we do checks against the storage (usually hdfs) for operations like drop_partition
     METASTORE_AUTHORIZATION_STORAGE_AUTH_CHECKS("hive.metastore.authorization.storage.checks",
false),
 

Modified: hive/trunk/conf/hive-default.xml
URL: http://svn.apache.org/viewvc/hive/trunk/conf/hive-default.xml?rev=1100035&r1=1100034&r2=1100035&view=diff
==============================================================================
--- hive/trunk/conf/hive-default.xml (original)
+++ hive/trunk/conf/hive-default.xml Fri May  6 03:17:52 2011
@@ -227,6 +227,12 @@
 </property>
 
 <property>
+  <name>hive.metastore.event.listeners</name>
+  <value></value>
+  <description>list of comma seperated listeners for metastore events.</description>
+</property>
+
+<property>
   <name>hive.metastore.connect.retries</name>
   <value>5</value>
   <description>Number of retries while opening a connection to metastore</description>

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java?rev=1100035&r1=1100034&r2=1100035&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java Fri
May  6 03:17:52 2011
@@ -65,6 +65,12 @@ import org.apache.hadoop.hive.metastore.
 import org.apache.hadoop.hive.metastore.api.Type;
 import org.apache.hadoop.hive.metastore.api.UnknownDBException;
 import org.apache.hadoop.hive.metastore.api.UnknownTableException;
+import org.apache.hadoop.hive.metastore.events.AddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.CreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.DropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.DropPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.DropTableEvent;
 import org.apache.hadoop.hive.metastore.hooks.JDOConnectionURLHook;
 import org.apache.hadoop.hive.metastore.model.MDBPrivilege;
 import org.apache.hadoop.hive.metastore.model.MGlobalPrivilege;
@@ -201,6 +207,8 @@ public class HiveMetaStore extends Thrif
 
     private ClassLoader classLoader;
     private AlterHandler alterHandler;
+    private List<MetaStoreEventListener> listeners;
+
     {
       classLoader = Thread.currentThread().getContextClassLoader();
       if (classLoader == null) {
@@ -240,6 +248,7 @@ public class HiveMetaStore extends Thrif
 
         }
       }
+      listeners = MetaStoreUtils.getMetaStoreListener(hiveConf);
       return true;
     }
 
@@ -546,8 +555,11 @@ public class HiveMetaStore extends Thrif
         } else {
           wh.mkdirs(new Path(db.getLocationUri()));
         }
+        for (MetaStoreEventListener listener : listeners) {
+          listener.onCreateDatabase(new CreateDatabaseEvent(db, success, this));
       }
     }
+    }
 
     public void create_database(final Database db)
         throws AlreadyExistsException, InvalidObjectException, MetaException {
@@ -661,8 +673,11 @@ public class HiveMetaStore extends Thrif
           wh.deleteDir(new Path(db.getLocationUri()), true);
           // it is not a terrible thing even if the data is not deleted
         }
+        for (MetaStoreEventListener listener : listeners) {
+          listener.onDropDatabase(new DropDatabaseEvent(db, success, this));
       }
     }
+    }
 
     public void drop_database(final String dbName, final boolean deleteData, final boolean
cascade)
         throws NoSuchObjectException, InvalidOperationException, MetaException {
@@ -936,8 +951,11 @@ public class HiveMetaStore extends Thrif
             wh.deleteDir(tblPath, true);
           }
         }
+        for (MetaStoreEventListener listener : listeners) {
+          listener.onCreateTable(new CreateTableEvent(tbl, success, this));
       }
     }
+    }
 
     public void create_table(final Table tbl) throws AlreadyExistsException,
         MetaException, InvalidObjectException {
@@ -1023,7 +1041,6 @@ public class HiveMetaStore extends Thrif
         if (!ms.dropTable(dbname, name)) {
           throw new MetaException("Unable to drop table");
         }
-        tbl = null; // table collections disappear after dropping
         success = ms.commitTransaction();
       } finally {
         if (!success) {
@@ -1032,8 +1049,11 @@ public class HiveMetaStore extends Thrif
           wh.deleteDir(tblPath, true);
           // ok even if the data is not deleted
         }
+        for(MetaStoreEventListener listener : listeners){
+          listener.onDropTable(new DropTableEvent(tbl, success, this));
       }
     }
+    }
 
     public void drop_table(final String dbname, final String name, final boolean deleteData)
         throws NoSuchObjectException, MetaException {
@@ -1341,6 +1361,9 @@ public class HiveMetaStore extends Thrif
             wh.deleteDir(partLocation, true);
           }
         }
+        for(MetaStoreEventListener listener : listeners){
+          listener.onAddPartition(new AddPartitionEvent(part, success, this));
+      }
       }
       return part;
     }
@@ -1432,6 +1455,9 @@ public class HiveMetaStore extends Thrif
             // ok even if the data is not deleted
           }
         }
+        for(MetaStoreEventListener listener : listeners){
+          listener.onDropPartition(new DropPartitionEvent(part, success, this));
+      }
       }
       return true;
     }

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEventListener.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEventListener.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEventListener.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEventListener.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,90 @@
+/**
+ * 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 org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.events.AddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.CreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.DropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.DropPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.DropTableEvent;
+
+/**
+ * This abstract class needs to be extended to  provide implementation of actions that needs
+ * to be performed when a particular event occurs on a metastore. These methods
+ * are called whenever an event occurs on metastore. Status of the event whether
+ * it was successful or not is contained in container event object.
+ */
+
+public abstract class MetaStoreEventListener implements Configurable {
+
+  private Configuration conf;
+
+  public MetaStoreEventListener(Configuration config){
+    this.conf = config;
+  }
+  /**
+   * @param create table event.
+   * @throws MetaException
+   */
+  public abstract void onCreateTable (CreateTableEvent tableEvent) throws MetaException;
+
+  /**
+   * @param drop table event.
+   * @throws MetaException
+   */
+  public abstract void onDropTable (DropTableEvent tableEvent)  throws MetaException;
+
+  /**
+   * @param add partition event
+   * @throws MetaException
+   */
+  public abstract void onAddPartition (AddPartitionEvent partitionEvent)  throws MetaException;
+
+  /**
+   * @param drop partition event
+   * @throws MetaException
+   */
+  public abstract void onDropPartition (DropPartitionEvent partitionEvent)  throws MetaException;
+
+  /**
+   * @param create database event
+   * @throws MetaException
+   */
+  public abstract void onCreateDatabase (CreateDatabaseEvent dbEvent) throws MetaException;
+
+  /**
+   * @param drop database event
+   * @throws MetaException
+   */
+  public abstract void onDropDatabase (DropDatabaseEvent dbEvent) throws MetaException;
+
+  @Override
+  public Configuration getConf() {
+    return this.conf;
+  }
+
+  @Override
+  public void setConf(Configuration config) {
+    this.conf = config;
+  }
+}

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java?rev=1100035&r1=1100034&r2=1100035&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java Fri
May  6 03:17:52 2011
@@ -37,6 +37,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.JavaUtils;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.api.Constants;
 import org.apache.hadoop.hive.metastore.api.FieldSchema;
@@ -944,4 +945,37 @@ public class MetaStoreUtils {
     }
     return filter.toString();
   }
+
+  /**
+   * create listener instances as per the configuration.
+   * @param conf
+   * @return
+   * @throws MetaException
+   */
+  static List<MetaStoreEventListener> getMetaStoreListener (HiveConf conf)
+  throws MetaException {
+
+    List<MetaStoreEventListener> listeners = new ArrayList<MetaStoreEventListener>();
+    String listenerImplList = conf.getVar(HiveConf.ConfVars.METASTORE_EVENT_LISTENERS);
+    listenerImplList = listenerImplList.trim();
+    if (listenerImplList.equals("")) {
+      return listeners;
+}
+
+    String[] listenerImpls = listenerImplList.split(",");
+    for (String listenerImpl : listenerImpls) {
+      try {
+        MetaStoreEventListener listener = (MetaStoreEventListener) Class.forName(
+            listenerImpl.trim(), true, JavaUtils.getClassLoader()).getConstructor(
+                Configuration.class).newInstance(conf);
+        listener.setConf(conf);
+        listeners.add(listener);
+      } catch (Exception e) {
+        throw new MetaException("Failed to instantiate listener named: "+
+            listenerImpl + e.toString());
+      }
+    }
+
+    return listeners;
+  }
 }

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java?rev=1100035&r1=1100034&r2=1100035&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java Fri May
 6 03:17:52 2011
@@ -26,9 +26,9 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
+import java.util.Map.Entry;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -86,9 +86,9 @@ import org.apache.hadoop.hive.metastore.
 import org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege;
 import org.apache.hadoop.hive.metastore.model.MTablePrivilege;
 import org.apache.hadoop.hive.metastore.model.MType;
-import org.apache.hadoop.hive.metastore.parser.ExpressionTree.ANTLRNoCaseStringStream;
 import org.apache.hadoop.hive.metastore.parser.FilterLexer;
 import org.apache.hadoop.hive.metastore.parser.FilterParser;
+import org.apache.hadoop.hive.metastore.parser.ExpressionTree.ANTLRNoCaseStringStream;
 import org.apache.hadoop.util.StringUtils;
 
 /**
@@ -1000,6 +1000,7 @@ public class ObjectStore implements RawS
       throw new NoSuchObjectException("partition values="
           + part_vals.toString());
     }
+    part.setValues(part_vals);
     return part;
   }
 

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,40 @@
+/**
+ * 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.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Partition;
+
+public class AddPartitionEvent extends ListenerEvent {
+
+  private final Partition partition;
+
+  public AddPartitionEvent (Partition partition, boolean status, HMSHandler handler) {
+
+    super (status, handler);
+    this.partition = partition;
+  }
+
+  /**
+   * @return the partition
+   */
+  public Partition getPartition() {
+    return partition;
+  }
+}
\ No newline at end of file

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateDatabaseEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateDatabaseEvent.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateDatabaseEvent.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateDatabaseEvent.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,40 @@
+/**
+ * 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.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Database;
+
+public class CreateDatabaseEvent extends ListenerEvent {
+
+  private final Database db;
+
+  public CreateDatabaseEvent (Database db, boolean status, HMSHandler handler) {
+
+    super (status, handler);
+    this.db = db;
+  }
+
+  /**
+   * @return the db
+   */
+  public Database getDatabase () {
+    return db;
+  }
+}

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateDatabaseEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateTableEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateTableEvent.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateTableEvent.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateTableEvent.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,40 @@
+/**
+ * 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.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Table;
+
+public class CreateTableEvent extends ListenerEvent {
+
+  private final Table table;
+
+  public CreateTableEvent (Table table, boolean status, HMSHandler handler) {
+
+    super (status, handler);
+    this.table = table;
+  }
+
+  /**
+   * @return the table
+   */
+  public Table getTable () {
+    return table;
+  }
+}

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/CreateTableEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropDatabaseEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropDatabaseEvent.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropDatabaseEvent.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropDatabaseEvent.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,40 @@
+/**
+ * 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.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Database;
+
+public class DropDatabaseEvent extends ListenerEvent {
+
+  private final Database db;
+
+  public DropDatabaseEvent(Database db, boolean status, HMSHandler handler) {
+
+    super (status, handler);
+    this.db = db;
+  }
+
+  /**
+   * @return the db
+   */
+  public Database getDatabase() {
+    return db;
+  }
+}

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropDatabaseEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,41 @@
+/**
+ * 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.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Partition;
+
+public class DropPartitionEvent extends ListenerEvent {
+
+  private final Partition partition;
+
+  public DropPartitionEvent (Partition partition, boolean status, HMSHandler handler) {
+
+    super (status, handler);
+    this.partition = partition;
+  }
+
+  /**
+   * @return the partition
+   */
+  public Partition getPartition() {
+
+    return partition;
+  }
+}

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropTableEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropTableEvent.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropTableEvent.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropTableEvent.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,40 @@
+/**
+ * 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.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Table;
+
+public class DropTableEvent extends ListenerEvent{
+
+  private final Table table;
+
+  public DropTableEvent (Table table, boolean status, HMSHandler handler) {
+
+    super (status, handler);
+    this.table = table;
+  }
+
+  /**
+   * @return the table
+   */
+  public Table getTable () {
+    return table;
+  }
+}

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropTableEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/ListenerEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/ListenerEvent.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/ListenerEvent.java
(added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/ListenerEvent.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,55 @@
+/**
+ * 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.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+
+/**
+ * Base class for all the events which are defined for metastore.
+ */
+
+public abstract class ListenerEvent {
+
+  /**
+   * status of the event, whether event was successful or not.
+   */
+  private final boolean status;
+  private final HMSHandler handler;
+
+  public ListenerEvent(boolean status, HMSHandler handler) {
+    super();
+    this.status = status;
+    this.handler = handler;
+  }
+
+  /**
+   * @return the handler
+   */
+  public HMSHandler getHandler() {
+    return handler;
+  }
+
+  /**
+   * @return the status of event.
+   */
+  public boolean getStatus() {
+    return status;
+  }
+
+}

Propchange: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/ListenerEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyListener.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyListener.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyListener.java (added)
+++ hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyListener.java Fri
May  6 03:17:52 2011
@@ -0,0 +1,75 @@
+/**
+ * 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;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.events.AddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.CreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.DropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.DropPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.DropTableEvent;
+import org.apache.hadoop.hive.metastore.events.ListenerEvent;
+
+/** A dummy implementation for
+ * {@link org.apache.hadoop.hive.metastore.hadooorg.apache.hadoop.hive.metastore.MetaStoreEventListener}
+ * for testing purposes.
+ */
+public class DummyListener extends MetaStoreEventListener{
+
+  public static final List<ListenerEvent> notifyList = new ArrayList<ListenerEvent>();
+
+  public DummyListener(Configuration config) {
+    super(config);
+  }
+
+  @Override
+  public void onAddPartition(AddPartitionEvent partition) throws MetaException {
+    notifyList.add(partition);
+  }
+
+  @Override
+  public void onCreateDatabase(CreateDatabaseEvent db) throws MetaException {
+    notifyList.add(db);
+  }
+
+  @Override
+  public void onCreateTable(CreateTableEvent table) throws MetaException {
+    notifyList.add(table);
+  }
+
+  @Override
+  public void onDropDatabase(DropDatabaseEvent db) throws MetaException {
+    notifyList.add(db);
+  }
+
+  @Override
+  public void onDropPartition(DropPartitionEvent partition) throws MetaException {
+    notifyList.add(partition);
+  }
+
+  @Override
+  public void onDropTable(DropTableEvent table) throws MetaException {
+    notifyList.add(table);
+  }
+}

Propchange: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java?rev=1100035&view=auto
==============================================================================
--- hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java
(added)
+++ hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java
Fri May  6 03:17:52 2011
@@ -0,0 +1,140 @@
+/**
+ * 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.List;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.hive.cli.CliSessionState;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.events.AddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.CreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.DropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.DropPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.DropTableEvent;
+import org.apache.hadoop.hive.metastore.events.ListenerEvent;
+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.hadooorg.apache.hadoop.hive.metastore.MetaStoreEventListener}
+ */
+public class TestMetaStoreEventListener extends TestCase {
+
+  private static final String msPort = "20001";
+  private HiveConf hiveConf;
+  private HiveMetaStoreClient msc;
+  private Driver driver;
+
+  private static class RunMS implements Runnable {
+
+    @Override
+    public void run() {
+      HiveMetaStore.main(new String[]{msPort});
+    }
+
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+
+    super.setUp();
+    System.setProperty(ConfVars.METASTORE_EVENT_LISTENERS.varname,
+        DummyListener.class.getName());
+    Thread t = new Thread(new RunMS());
+    t.start();
+    Thread.sleep(40000);
+    hiveConf = new HiveConf(this.getClass());
+    hiveConf.set("hive.metastore.local", "false");
+    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 testListener() throws Exception {
+
+    List<ListenerEvent> notifyList = DummyListener.notifyList;
+    assertEquals(notifyList.size(), 0);
+
+    driver.run("create database tmpdb");
+    Database db = msc.getDatabase("tmpdb");
+    assertEquals(1, notifyList.size());
+    CreateDatabaseEvent dbEvent = (CreateDatabaseEvent)(notifyList.get(0));
+    assert dbEvent.getStatus();
+    assertEquals(db.getName(), dbEvent.getDatabase().getName());
+    assertEquals(db.getLocationUri(), dbEvent.getDatabase().getLocationUri());
+
+    driver.run("use tmpdb");
+    driver.run("create table tmptbl (a string) partitioned by (b string)");
+    Table tbl = msc.getTable("tmpdb", "tmptbl");
+    assertEquals(notifyList.size(), 2);
+    CreateTableEvent tblEvent = (CreateTableEvent)(notifyList.get(1));
+    assert tblEvent.getStatus();
+    assertEquals(tbl.getTableName(), tblEvent.getTable().getTableName());
+    assertEquals(tbl.getDbName(), tblEvent.getTable().getDbName());
+    assertEquals(tbl.getSd().getLocation(), tblEvent.getTable().getSd().getLocation());
+
+    driver.run("alter table tmptbl add partition (b='2011')");
+    Partition part = msc.getPartition("tmpdb", "tmptbl", "b=2011");
+    assertEquals(notifyList.size(), 3);
+    AddPartitionEvent partEvent = (AddPartitionEvent)(notifyList.get(2));
+    assert partEvent.getStatus();
+    assertEquals(part, partEvent.getPartition());
+
+    driver.run("alter table tmptbl drop partition (b='2011')");
+    assertEquals(notifyList.size(), 4);
+    DropPartitionEvent dropPart = (DropPartitionEvent)notifyList.get(3);
+    assert dropPart.getStatus();
+    assertEquals(part.getValues(), dropPart.getPartition().getValues());
+    assertEquals(part.getDbName(), dropPart.getPartition().getDbName());
+    assertEquals(part.getTableName(), dropPart.getPartition().getTableName());
+
+    driver.run("drop table tmptbl");
+    assertEquals(notifyList.size(), 5);
+    DropTableEvent dropTbl = (DropTableEvent)notifyList.get(4);
+    assert dropTbl.getStatus();
+    assertEquals(tbl.getTableName(), dropTbl.getTable().getTableName());
+    assertEquals(tbl.getDbName(), dropTbl.getTable().getDbName());
+    assertEquals(tbl.getSd().getLocation(), dropTbl.getTable().getSd().getLocation());
+
+
+    driver.run("drop database tmpdb");
+    assertEquals(notifyList.size(), 6);
+    DropDatabaseEvent dropDB = (DropDatabaseEvent)notifyList.get(5);
+    assert dropDB.getStatus();
+    assertEquals(db, dropDB.getDatabase());
+  }
+}

Propchange: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message