diff --git hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java index 11d44fe..6e75909 100644 --- hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/Server.java @@ -154,6 +154,39 @@ } /** + * 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. */ diff --git hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java new file mode 100644 index 0000000..53f3df3 --- /dev/null +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/VersionDelegator.java @@ -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"); + } +} diff --git hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java index 2f085ef..bf05ba9 100644 --- hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java +++ hcatalog/webhcat/svr/src/test/java/org/apache/hive/hcatalog/templeton/TestWebHCatE2e.java @@ -197,6 +197,39 @@ public void describeNoSuchTable() throws IOException { 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 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 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 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