falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat...@apache.org
Subject [1/4] git commit: FALCON-96 Hive client to talk to the metastore. Contributed by Venkatesh Seetharam
Date Mon, 23 Sep 2013 22:53:17 GMT
Updated Branches:
  refs/heads/FALCON-85-new 408ebd7c7 -> 6ff80e6ea


FALCON-96 Hive client to talk to the metastore. Contributed by Venkatesh Seetharam


Project: http://git-wip-us.apache.org/repos/asf/incubator-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-falcon/commit/f84ed0c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-falcon/tree/f84ed0c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-falcon/diff/f84ed0c4

Branch: refs/heads/FALCON-85-new
Commit: f84ed0c4c1f10e96c6ee3e9aff09cc91d57d0fae
Parents: 408ebd7
Author: srikanth.sundarrajan <srikanth.sundarrajan@inmobi.com>
Authored: Wed Sep 11 08:22:39 2013 +0530
Committer: Venkatesh Seetharam <venkatesh@apache.org>
Committed: Mon Sep 23 15:47:22 2013 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |   5 +-
 common/pom.xml                                  |  10 ++
 .../falcon/catalog/AbstractCatalogService.java  |  25 +++
 .../falcon/catalog/HiveCatalogService.java      | 112 +++++++++----
 .../falcon/catalog/WebHCatCatalogService.java   | 104 ++++++++++++
 pom.xml                                         |  37 +++++
 webapp/src/conf/oozie/conf/action-conf/hive.xml |  30 ++--
 .../falcon/catalog/HiveCatalogServiceIT.java    | 157 +++++++++++++++++++
 webapp/src/test/resources/cluster-template.xml  |   2 +-
 9 files changed, 441 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b379021..f31cf95 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,7 +6,8 @@ Trunk (Unreleased)
 
   NEW FEATURES
 
-    FALCON-107 Adding extensions. (Shwetha GS)
+    FALCON-96 Hive client to talk to the metastore. (Venkatesh 
+    Seetharam via Srikanth Sundarrajan)
 
     FALCON-87 Hive table integration with feed entity. (Venkatesh
     Seetharam via Srikanth Sundarrajan)
@@ -17,6 +18,8 @@ Trunk (Unreleased)
     FALCON-88 Add embedded hive and webhcat for integration tests. 
     (Venkatesh Seetharam via Srikanth Sundarrajan)
 
+    FALCON-107 Adding extensions. (Shwetha GS)
+
     FALCON-62 Falcon compilation with hadoop 2.0 libs. (Shwetha GS
     via Srikanth Sundarrajan)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/common/pom.xml
----------------------------------------------------------------------
diff --git a/common/pom.xml b/common/pom.xml
index 0e192fc..4a8d446 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -153,6 +153,16 @@
             <groupId>javax.jms</groupId>
             <artifactId>jms</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.hive</groupId>
+            <artifactId>hive-common</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.hcatalog</groupId>
+            <artifactId>webhcat-java-client</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/common/src/main/java/org/apache/falcon/catalog/AbstractCatalogService.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/falcon/catalog/AbstractCatalogService.java b/common/src/main/java/org/apache/falcon/catalog/AbstractCatalogService.java
index a4b6cfd..be9773d 100644
--- a/common/src/main/java/org/apache/falcon/catalog/AbstractCatalogService.java
+++ b/common/src/main/java/org/apache/falcon/catalog/AbstractCatalogService.java
@@ -20,6 +20,8 @@ package org.apache.falcon.catalog;
 
 import org.apache.falcon.FalconException;
 
+import java.util.Map;
+
 /**
  * Interface definition for a catalog registry service
  * such as Hive or HCatalog.
@@ -36,6 +38,29 @@ public abstract class AbstractCatalogService {
      */
     public abstract boolean isAlive(String catalogBaseUrl) throws FalconException;
 
+    /**
+     * This method checks if the given table exists in the catalog.
+     *
+     * @param catalogUrl url for the catalog service
+     * @param database database the table belongs to
+     * @param tableName tableName to check if it exists
+     * @return if the table exists
+     * @throws FalconException exception
+     */
     public abstract boolean tableExists(String catalogUrl, String database, String tableName)
         throws FalconException;
+
+    /**
+     * Returns a list of table properties. Most important here are:
+     * 1. Table type: external table or a managed table
+     * 2. Location on HDFS
+     *
+     * @param catalogUrl url for the catalog service
+     * @param database database the table belongs to
+     * @param tableName tableName to check if it exists
+     * @return Bag of property name and associated value
+     * @throws FalconException
+     */
+    public abstract Map<String, String> listTableProperties(String catalogUrl, String
database,
+                                                            String tableName) throws FalconException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/common/src/main/java/org/apache/falcon/catalog/HiveCatalogService.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/falcon/catalog/HiveCatalogService.java b/common/src/main/java/org/apache/falcon/catalog/HiveCatalogService.java
index 67d14af..f9e7bee 100644
--- a/common/src/main/java/org/apache/falcon/catalog/HiveCatalogService.java
+++ b/common/src/main/java/org/apache/falcon/catalog/HiveCatalogService.java
@@ -18,14 +18,21 @@
 
 package org.apache.falcon.catalog;
 
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
 import org.apache.falcon.FalconException;
-import org.apache.falcon.security.CurrentUser;
+import org.apache.falcon.entity.ClusterHelper;
+import org.apache.falcon.entity.v0.cluster.Cluster;
+import org.apache.falcon.entity.v0.cluster.Interfacetype;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hcatalog.api.HCatClient;
+import org.apache.hcatalog.api.HCatDatabase;
+import org.apache.hcatalog.api.HCatTable;
+import org.apache.hcatalog.cli.SemanticAnalysis.HCatSemanticAnalyzer;
+import org.apache.hcatalog.common.HCatException;
 import org.apache.log4j.Logger;
 
-import javax.ws.rs.core.MediaType;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * An implementation of CatalogService that uses Hive Meta Store (HCatalog)
@@ -35,22 +42,58 @@ public class HiveCatalogService extends AbstractCatalogService {
 
     private static final Logger LOG = Logger.getLogger(HiveCatalogService.class);
 
+    private static final ConcurrentHashMap<String, HCatClient> CACHE = new ConcurrentHashMap<String,
HCatClient>();
+
+    public static HCatClient get(Cluster cluster) throws FalconException {
+        assert cluster != null : "Cluster cant be null";
+
+        String metastoreUrl = ClusterHelper.getInterface(cluster, Interfacetype.REGISTRY).getEndpoint();
+        return get(metastoreUrl);
+    }
+
+    public static synchronized HCatClient get(String metastoreUrl) throws FalconException
{
+
+        if (!CACHE.containsKey(metastoreUrl)) {
+            HCatClient hCatClient = getHCatClient(metastoreUrl);
+            LOG.info("Caching HCatalog client object for " + metastoreUrl);
+            CACHE.putIfAbsent(metastoreUrl, hCatClient);
+        }
+
+        return CACHE.get(metastoreUrl);
+    }
+
+    private static HCatClient getHCatClient(String metastoreUrl) throws FalconException {
+        try {
+            HiveConf hcatConf = new HiveConf();
+            hcatConf.set("hive.metastore.local", "false");
+            hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, metastoreUrl);
+            hcatConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3);
+            hcatConf.set(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK.varname,
+                    HCatSemanticAnalyzer.class.getName());
+            hcatConf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false");
+
+            hcatConf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, "");
+            hcatConf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, "");
+
+            return HCatClient.create(hcatConf);
+        } catch (HCatException e) {
+            throw new FalconException(e);
+        }
+    }
+
+
     @Override
     public boolean isAlive(String catalogBaseUrl) throws FalconException {
         LOG.info("Checking if the service is alive for: " + catalogBaseUrl);
 
-        Client client = Client.create();
-        WebResource service = client.resource(catalogBaseUrl);
-        ClientResponse response = service.path("status")
-                .accept(MediaType.APPLICATION_JSON)
-                .head();
-                // .get(ClientResponse.class);    // todo this isnt working
-
-        if (LOG.isDebugEnabled() && response.getStatus() != 200) {
-            LOG.debug("Output from Server .... \n" + response.getEntity(String.class));
+        try {
+            HCatClient client = get(catalogBaseUrl);
+            client.close();
+            HCatDatabase database = client.getDatabase("default");
+            return database != null;
+        } catch (HCatException e) {
+            throw new FalconException(e);
         }
-
-        return response.getStatus() == 200;
     }
 
     @Override
@@ -58,19 +101,34 @@ public class HiveCatalogService extends AbstractCatalogService {
         throws FalconException {
         LOG.info("Checking if the table exists: " + tableName);
 
-        Client client = Client.create();
-        WebResource service = client.resource(catalogUrl);
+        try {
+            HCatClient client = get(catalogUrl);
+            HCatTable table = client.getTable(database, tableName);
+            return table != null;
+        } catch (HCatException e) {
+            throw new FalconException(e);
+        }
+    }
 
-        ClientResponse response = service.path("ddl/database/").path(database)
-                .path("/table").path(tableName)
-                .queryParam("user.name", CurrentUser.getUser())
-                .accept(MediaType.APPLICATION_JSON)
-                .get(ClientResponse.class);
+    @Override
+    public Map<String, String> listTableProperties(String catalogUrl, String database,
+                                                   String tableName) throws FalconException
{
+        LOG.info("Returns a list of table properties for:" + tableName);
 
-        if (LOG.isDebugEnabled() && response.getStatus() != 200) {
-            LOG.debug("Output from Server .... \n" + response.getEntity(String.class));
-        }
+        try {
+            HCatClient client = get(catalogUrl);
+            HCatTable table = client.getTable(database, tableName);
 
-        return response.getStatus() == 200;
+            Map<String, String> tableProperties = new HashMap<String, String>();
+            tableProperties.put("database", table.getDbName());
+            tableProperties.put("tableName", table.getTableName());
+            tableProperties.put("tabletype", table.getTabletype());
+            tableProperties.put("location", table.getLocation());
+            // tableProperties.putAll(table.getTblProps());
+
+            return tableProperties;
+        } catch (HCatException e) {
+            throw new FalconException(e);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/common/src/main/java/org/apache/falcon/catalog/WebHCatCatalogService.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/falcon/catalog/WebHCatCatalogService.java b/common/src/main/java/org/apache/falcon/catalog/WebHCatCatalogService.java
new file mode 100644
index 0000000..49f97d1
--- /dev/null
+++ b/common/src/main/java/org/apache/falcon/catalog/WebHCatCatalogService.java
@@ -0,0 +1,104 @@
+/**
+ * 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.falcon.catalog;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.falcon.FalconException;
+import org.apache.falcon.security.CurrentUser;
+import org.apache.log4j.Logger;
+
+import javax.ws.rs.core.MediaType;
+import java.util.Map;
+
+/**
+ * An implementation of CatalogService that uses HTTP RESTful API to
+ * talk to the Hive Meta Store (HCatalog) as the backing Catalog registry.
+ */
+public class WebHCatCatalogService extends AbstractCatalogService {
+
+    private static final Logger LOG = Logger.getLogger(WebHCatCatalogService.class);
+
+    @Override
+    public boolean isAlive(String catalogBaseUrl) throws FalconException {
+        LOG.info("Checking if the service is alive for: " + catalogBaseUrl);
+
+        Client client = Client.create();
+        WebResource service = client.resource(catalogBaseUrl);
+        ClientResponse response = service.path("status")
+                .accept(MediaType.APPLICATION_JSON)
+                .get(ClientResponse.class);
+
+        if (LOG.isDebugEnabled() && response.getStatus() != 200) {
+            LOG.debug("Output from Server .... \n" + response.getEntity(String.class));
+        }
+
+        return response.getStatus() == 200;
+    }
+
+    @Override
+    public boolean tableExists(String catalogUrl, String database, String tableName)
+        throws FalconException {
+        LOG.info("Checking if the table exists: " + tableName);
+
+        Client client = Client.create();
+        WebResource service = client.resource(catalogUrl);
+
+        ClientResponse response = service.path("ddl/database").path(database)
+                .path("table").path(tableName)
+                .queryParam("user.name", CurrentUser.getUser())
+                .accept(MediaType.APPLICATION_JSON)
+                .get(ClientResponse.class);
+
+        if (LOG.isDebugEnabled() && response.getStatus() != 200) {
+            LOG.debug("Output from Server .... \n" + response.getEntity(String.class));
+        }
+
+        return response.getStatus() == 200;
+    }
+
+    @Override
+    public Map listTableProperties(String catalogUrl, String database,
+                                   String tableName) throws FalconException {
+        LOG.info("Returns a list of table properties for:" + tableName);
+
+        Client client = Client.create();
+        WebResource service = client.resource(catalogUrl);
+
+        ClientResponse response = service.path("ddl/database/").path(database)
+                .path("table").path(tableName)
+                .path("property")
+//                .queryParam("format", "extended")
+                .queryParam("user.name", CurrentUser.getUser())
+                .accept(MediaType.APPLICATION_JSON)
+                .get(ClientResponse.class);
+
+        if (LOG.isDebugEnabled() && response.getStatus() != 200) {
+            LOG.debug("Output from Server .... \n" + response.getEntity(String.class));
+        }
+
+        if (response.getStatus() != 200) {
+            throw new FalconException("There was an error in this request: "
+                    + response.getEntity(String.class));
+        }
+
+        return response.getEntity(Map.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2b51131..e1b8fa4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,6 +103,7 @@
         <activemq.version>5.4.3</activemq.version>
         <hadoop-distcp.version>0.9</hadoop-distcp.version>
         <hive.version>0.11.0</hive.version>
+        <hcatalog.version>0.11.0</hcatalog.version>
         <jetty.version>6.1.26</jetty.version>
         <internal.maven.repo>file:///tmp/falcontemprepo</internal.maven.repo>
         <skipCheck>false</skipCheck>
@@ -728,6 +729,42 @@
             </dependency>
 
             <dependency>
+                <groupId>org.apache.hive</groupId>
+                <artifactId>hive-common</artifactId>
+                <version>${hive.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.hive</groupId>
+                <artifactId>hive-metastore</artifactId>
+                <version>${hive.version}</version>
+                <exclusions>
+                    <exclusion> <!--Oozie already imports this-->
+                        <groupId>org.apache.derby</groupId>
+                        <artifactId>derby</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.hcatalog</groupId>
+                <artifactId>webhcat</artifactId>
+                <version>${hcatalog.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>xerces</groupId>
+                        <artifactId>xercesImpl</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.hcatalog</groupId>
+                <artifactId>webhcat-java-client</artifactId>
+                <version>${hcatalog.version}</version>
+            </dependency>
+
+            <dependency>
                 <groupId>net.sourceforge.findbugs</groupId>
                 <artifactId>annotations</artifactId>
                 <version>1.3.2</version>

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/webapp/src/conf/oozie/conf/action-conf/hive.xml
----------------------------------------------------------------------
diff --git a/webapp/src/conf/oozie/conf/action-conf/hive.xml b/webapp/src/conf/oozie/conf/action-conf/hive.xml
index 2076bd4..e5aef7d 100644
--- a/webapp/src/conf/oozie/conf/action-conf/hive.xml
+++ b/webapp/src/conf/oozie/conf/action-conf/hive.xml
@@ -18,18 +18,24 @@
   limitations under the License.
 -->
 <configuration>
-   <!-- An example of setting default properties for Hive action.
-        This could be useful with Hadoop versions that have deprecated
-        HADOOP_HOME that Hive still relies on.
+    <property>
+        <name>hive.metastore.uris</name>
+        <value>thrift://localhost:49083</value>
+    </property>
 
-   <property>
-      <name>hadoop.bin.path</name>
-      <value>/usr/bin/hadoop</value>
-   </property>
+    <property>
+        <name>hive.metastore.local</name>
+        <value>false</value>
+    </property>
 
-   <property>
-      <name>hadoop.config.dir</name>
-      <value>/etc/hadoop/conf</value>
-   </property>
-   -->
+    <property>
+        <name>fs.default.name</name>
+        <value>hdfs://localhost:41020</value>
+    </property>
+
+    <!-- Forcing the creation of the db dir under target so mvn clean will clean up -->
+    <property>
+        <name>javax.jdo.option.ConnectionURL</name>
+        <value>jdbc:derby:;databaseName=./target/metastore_db;create=true</value>
+    </property>
 </configuration>

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/webapp/src/test/java/org/apache/falcon/catalog/HiveCatalogServiceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/falcon/catalog/HiveCatalogServiceIT.java b/webapp/src/test/java/org/apache/falcon/catalog/HiveCatalogServiceIT.java
new file mode 100644
index 0000000..94d14ff
--- /dev/null
+++ b/webapp/src/test/java/org/apache/falcon/catalog/HiveCatalogServiceIT.java
@@ -0,0 +1,157 @@
+/**
+ * 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.falcon.catalog;
+
+import org.apache.falcon.FalconException;
+import org.apache.hcatalog.api.HCatAddPartitionDesc;
+import org.apache.hcatalog.api.HCatClient;
+import org.apache.hcatalog.api.HCatCreateDBDesc;
+import org.apache.hcatalog.api.HCatCreateTableDesc;
+import org.apache.hcatalog.data.schema.HCatFieldSchema;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests Hive Meta Store service.
+ */
+public class HiveCatalogServiceIT {
+
+    private static final String DATABASE_NAME = "falcondb";
+    private static final String TABLE_NAME = "foobar";
+    private static final String METASTORE_URL = "thrift://localhost:49083";
+
+    private HiveCatalogService hiveCatalogService;
+    private HCatClient client;
+
+    @BeforeClass
+    public void setUp() throws Exception {
+        hiveCatalogService = new HiveCatalogService();
+        client = HiveCatalogService.get(METASTORE_URL);
+
+        createDatabase();
+        createTable();
+        addPartition();
+    }
+
+    private void createDatabase() throws Exception {
+        HCatCreateDBDesc dbDesc = HCatCreateDBDesc.create(DATABASE_NAME)
+                .ifNotExists(true).build();
+        client.createDatabase(dbDesc);
+    }
+
+    public void createTable() throws Exception {
+        ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
+        cols.add(new HCatFieldSchema("id", HCatFieldSchema.Type.INT, "id comment"));
+        cols.add(new HCatFieldSchema("value", HCatFieldSchema.Type.STRING, "value comment"));
+
+        List<HCatFieldSchema> partitionSchema = Arrays.asList(
+            new HCatFieldSchema("ds", HCatFieldSchema.Type.STRING, ""),
+            new HCatFieldSchema("region", HCatFieldSchema.Type.STRING, "")
+        );
+
+        HCatCreateTableDesc tableDesc = HCatCreateTableDesc
+                .create(DATABASE_NAME, TABLE_NAME, cols)
+                .fileFormat("rcfile")
+                .ifNotExists(true)
+                .comments("falcon integration test")
+                .partCols(new ArrayList<HCatFieldSchema>(partitionSchema))
+                .build();
+        client.createTable(tableDesc);
+    }
+
+    private void addPartition() throws Exception {
+        Map<String, String> firstPtn = new HashMap<String, String>();
+        firstPtn.put("ds", "09/03/2013");
+        firstPtn.put("region", "usa");
+        HCatAddPartitionDesc addPtn = HCatAddPartitionDesc.create(
+                DATABASE_NAME, TABLE_NAME, null, firstPtn).build();
+        client.addPartition(addPtn);
+
+        Map<String, String> secondPtn = new HashMap<String, String>();
+        secondPtn.put("ds", "09/03/2013");
+        secondPtn.put("region", "india");
+        HCatAddPartitionDesc addPtn2 = HCatAddPartitionDesc.create(
+                DATABASE_NAME, TABLE_NAME, null, secondPtn).build();
+        client.addPartition(addPtn2);
+
+        Map<String, String> thirdPtn = new HashMap<String, String>();
+        thirdPtn.put("ds", "09/02/2013");
+        thirdPtn.put("region", "india");
+        HCatAddPartitionDesc addPtn3 = HCatAddPartitionDesc.create(
+                DATABASE_NAME, TABLE_NAME, null, thirdPtn).build();
+        client.addPartition(addPtn3);
+    }
+
+    @AfterClass
+    public void tearDown() throws Exception {
+        dropTable();
+        dropDatabase();
+    }
+
+    private void dropTable() throws Exception {
+        client.dropTable(DATABASE_NAME, TABLE_NAME, true);
+    }
+
+    private void dropDatabase() throws Exception {
+        client.dropDatabase(DATABASE_NAME, true, HCatClient.DropDBMode.CASCADE);
+    }
+
+    @Test
+    public void testGet() throws Exception {
+        Assert.assertNotNull(HiveCatalogService.get(METASTORE_URL));
+    }
+
+    @Test
+    public void testIsAlive() throws Exception {
+        Assert.assertTrue(hiveCatalogService.isAlive(METASTORE_URL));
+    }
+
+    @Test (expectedExceptions = FalconException.class)
+    public void testIsAliveNegative() throws Exception {
+        hiveCatalogService.isAlive("thrift://localhost:9999");
+    }
+
+    @Test (expectedExceptions = FalconException.class)
+    public void testTableExistsNegative() throws Exception {
+        hiveCatalogService.tableExists(METASTORE_URL, DATABASE_NAME, "blah");
+    }
+
+    @Test
+    public void testTableExists() throws Exception {
+        Assert.assertTrue(hiveCatalogService.tableExists(METASTORE_URL, DATABASE_NAME, TABLE_NAME));
+    }
+
+    @Test
+    public void testListTableProperties() throws Exception {
+        Map<String, String> tableProperties =
+                hiveCatalogService.listTableProperties(METASTORE_URL, DATABASE_NAME, TABLE_NAME);
+        Assert.assertEquals(tableProperties.get("database"), DATABASE_NAME);
+        Assert.assertEquals(tableProperties.get("tableName"), TABLE_NAME);
+        Assert.assertEquals(tableProperties.get("tabletype"), "MANAGED_TABLE");
+        Assert.assertTrue(tableProperties.containsKey("location"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/f84ed0c4/webapp/src/test/resources/cluster-template.xml
----------------------------------------------------------------------
diff --git a/webapp/src/test/resources/cluster-template.xml b/webapp/src/test/resources/cluster-template.xml
index fbc46c5..32eb643 100644
--- a/webapp/src/test/resources/cluster-template.xml
+++ b/webapp/src/test/resources/cluster-template.xml
@@ -28,7 +28,7 @@
                    version="3.1"/>
         <interface type="messaging" endpoint="tcp://localhost:61616?daemon=true"
                    version="5.1.6"/>
-        <interface type="registry" endpoint="http://localhost:48080/templeton/v1/"
+        <interface type="registry" endpoint="thrift://localhost:49083"
                    version="0.11.0"/>
     </interfaces>
     <locations>


Mime
View raw message