You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ga...@apache.org on 2014/02/05 19:28:13 UTC

svn commit: r1564867 - in /hive/trunk/hcatalog/webhcat/svr/src: main/java/org/apache/hive/hcatalog/templeton/Server.java main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java

Author: gates
Date: Wed Feb  5 18:28:13 2014
New Revision: 1564867

URL: http://svn.apache.org/r1564867
Log:
HIVE-6226 It should be possible to get hadoop, hive, and pig version being used by WebHCat (gates, reviewed by Thejas Nair)

Added:
    hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java
Modified:
    hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java
    hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java

Modified: hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java
URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java?rev=1564867&r1=1564866&r2=1564867&view=diff
==============================================================================
--- hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java (original)
+++ hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java Wed Feb  5 18:28:13 2014
@@ -154,6 +154,39 @@ public class Server {
   }
 
   /**
+   * Get version of hadoop software being run by this WebHCat server
+   */
+  @GET
+  @Path("version/hadoop")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response hadoopVersion()  throws IOException {
+    VersionDelegator d = new VersionDelegator(appConf);
+    return d.getVersion("hadoop");
+  }
+
+  /**
+   * Get version of hive software being run by this WebHCat server
+   */
+  @GET
+  @Path("version/hive")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response hiveVersion()  throws IOException {
+    VersionDelegator d = new VersionDelegator(appConf);
+    return d.getVersion("hive");
+  }
+
+  /**
+   * Get version of hive software being run by this WebHCat server
+   */
+  @GET
+  @Path("version/pig")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response pigVersion()  throws IOException {
+    VersionDelegator d = new VersionDelegator(appConf);
+    return d.getVersion("pig");
+  }
+
+  /**
    * Execute an hcat ddl expression on the local box.  It is run
    * as the authenticated user and rate limited.
    */

Added: hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java
URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java?rev=1564867&view=auto
==============================================================================
--- hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java (added)
+++ hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java Wed Feb  5 18:28:13 2014
@@ -0,0 +1,72 @@
+/**
+ * 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.hive.hcatalog.templeton;
+
+import org.apache.hadoop.util.VersionInfo;
+import org.apache.hive.common.util.HiveVersionInfo;
+import org.eclipse.jetty.http.HttpStatus;
+
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+/**
+ * Find the version of Hive, Hadoop, or Pig that is being used in this
+ * interface.
+ */
+public class VersionDelegator extends TempletonDelegator {
+
+  public VersionDelegator(AppConfig appConf) {
+    super(appConf);
+
+  }
+
+  public Response getVersion(String module) throws IOException {
+    if (module.toLowerCase().equals("hadoop")) {
+      return getHadoopVersion();
+    } else if (module.toLowerCase().equals("hive")) {
+      return getHiveVersion();
+    } else if (module.toLowerCase().equals("pig")) {
+      return getPigVersion();
+    } else {
+      return SimpleWebException.buildMessage(HttpStatus.NOT_FOUND_404, null,
+          "Unknown module " + module);
+    }
+  }
+
+  private Response getHadoopVersion() throws IOException {
+    String version = VersionInfo.getVersion();
+    return JsonBuilder.create()
+        .put("module", "hadoop")
+        .put("version", version)
+        .build();
+  }
+
+  private Response getHiveVersion() throws IOException {
+    String version = HiveVersionInfo.getVersion();
+    return JsonBuilder.create()
+        .put("module", "hive")
+        .put("version", version)
+        .build();
+  }
+
+  private Response getPigVersion() {
+    return SimpleWebException.buildMessage(HttpStatus.NOT_IMPLEMENTED_501,
+        null, "Pig version request not yet implemented");
+  }
+}

Modified: hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java
URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java?rev=1564867&r1=1564866&r2=1564867&view=diff
==============================================================================
--- hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java (original)
+++ hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java Wed Feb  5 18:28:13 2014
@@ -197,6 +197,39 @@ public class TestWebHCatE2e {
       ErrorMsg.INVALID_TABLE.getErrorCode(),
       getErrorCode(p.responseBody));
   }
+
+  @Test
+  public void getHadoopVersion() throws Exception {
+    MethodCallRetVal p = doHttpCall(templetonBaseUrl + "/version/hadoop",
+        HTTP_METHOD_TYPE.GET);
+    Assert.assertEquals(HttpStatus.OK_200, p.httpStatusCode);
+    Map<String, Object> props = JsonBuilder.jsonToMap(p.responseBody);
+    Assert.assertEquals("hadoop", props.get("module"));
+    Assert.assertTrue(p.getAssertMsg(),
+        ((String)props.get("version")).matches("[1-2].[0-9]+.[0-9]+.*"));
+  }
+
+  @Test
+  public void getHiveVersion() throws Exception {
+    MethodCallRetVal p = doHttpCall(templetonBaseUrl + "/version/hive",
+        HTTP_METHOD_TYPE.GET);
+    Assert.assertEquals(HttpStatus.OK_200, p.httpStatusCode);
+    Map<String, Object> props = JsonBuilder.jsonToMap(p.responseBody);
+    Assert.assertEquals("hive", props.get("module"));
+    Assert.assertTrue(p.getAssertMsg(),
+        ((String) props.get("version")).matches("0.[0-9]+.[0-9]+.*"));
+  }
+
+  @Test
+  public void getPigVersion() throws Exception {
+    MethodCallRetVal p = doHttpCall(templetonBaseUrl + "/version/pig",
+        HTTP_METHOD_TYPE.GET);
+    Assert.assertEquals(HttpStatus.NOT_IMPLEMENTED_501, p.httpStatusCode);
+    Map<String, Object> props = JsonBuilder.jsonToMap(p.responseBody);
+    Assert.assertEquals(p.getAssertMsg(), "Pig version request not yet " +
+        "implemented", (String)props.get("error"));
+  }
+
   /**
    * It's expected that Templeton returns a properly formatted JSON object when it
    * encounters an error.  It should have {@code ERROR_CODE} element in it which