hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odiache...@apache.org
Subject incubator-hawq git commit: HAWQ-340. Make getVersion API return JSON format. [Forced Update!]
Date Tue, 26 Jan 2016 02:15:49 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-340 1141c9d1a -> 6815499ca (forced update)


HAWQ-340. Make getVersion API return JSON format.


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

Branch: refs/heads/HAWQ-340
Commit: 6815499caf958c93ed7cef754e4b728226f39e4d
Parents: bee0137
Author: Oleksandr Diachenko <odiachenko@pivotal.io>
Authored: Fri Jan 22 15:58:06 2016 -0800
Committer: Oleksandr Diachenko <odiachenko@pivotal.io>
Committed: Mon Jan 25 18:15:38 2016 -0800

----------------------------------------------------------------------
 pxf/build.gradle                                | 44 +++++++++++++++++++-
 pxf/gradle.properties                           |  1 +
 .../hawq/pxf/service/rest/VersionResource.java  | 26 ++++++++++--
 .../pxf/service/rest/VersionResourceTest.java   |  7 +++-
 4 files changed, 73 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/6815499c/pxf/build.gradle
----------------------------------------------------------------------
diff --git a/pxf/build.gradle b/pxf/build.gradle
index 0d260d4..2eb333a 100644
--- a/pxf/build.gradle
+++ b/pxf/build.gradle
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+import org.apache.tools.ant.filters.ReplaceTokens
+
 buildscript {
     repositories {
         // mavenCentral without https:
@@ -122,6 +124,47 @@ subprojects { subProject ->
 }
 
 project('pxf-service') {
+
+// Copy existing sources and replace any occurrences of @tokenName@ with desired values
+    task generateSources {
+        doFirst {
+            copy {
+                from('src/main/java') {
+                    include '**/*.java'
+                    filter(ReplaceTokens,
+                        tokens:['pxfProtocolVersion': project.pxfProtocolVersion ])}
+                into "tmp/generatedSources"
+            }
+        }
+    }
+
+// Call cleanup taskAfter Java code compilation
+    compileJava.doLast {
+        tasks.cleanGeneratedSources.execute()
+    }
+
+// Delete "tmp" directory under current project directory
+// rm -r pxf-service/tmp
+    task cleanGeneratedSources() {
+        doFirst {
+            delete "tmp"
+        }
+    }
+
+// Call generateSources task before Java compilation
+    gradle.projectsEvaluated {
+        compileJava.dependsOn(generateSources)
+    }
+
+// Use custom sources directory with generated sources
+    sourceSets {
+        main {
+            java {
+                srcDirs = ["tmp/generatedSources"]
+            }
+        }
+    }
+
     apply plugin: 'war'
     tasks.war {
         archiveName = 'pxf.war'
@@ -137,7 +180,6 @@ project('pxf-service') {
             }
         }
     }
-
     dependencies {
         compile(project(':pxf-api'))
         compile 'com.sun.jersey:jersey-core:1.9'

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/6815499c/pxf/gradle.properties
----------------------------------------------------------------------
diff --git a/pxf/gradle.properties b/pxf/gradle.properties
index 6a7b2d6..6827b89 100644
--- a/pxf/gradle.properties
+++ b/pxf/gradle.properties
@@ -23,3 +23,4 @@ hiveVersion=1.2.1
 hbaseVersionJar=1.1.2
 hbaseVersionRPM=1.1.2
 tomcatVersion=7.0.62
+pxfProtocolVersion=v14
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/6815499c/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java
b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java
index 6f326d6..753f016 100644
--- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java
+++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java
@@ -21,6 +21,7 @@ package org.apache.hawq.pxf.service.rest;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
@@ -33,7 +34,25 @@ import org.apache.commons.logging.LogFactory;
  * version e.g. {@code ...pxf/v14/Bridge}
  */
 class Version {
-    final static String PXF_PROTOCOL_VERSION = "v14";
+	/**
+	 * Constant which holds current protocol version.
+	 * Getting replaced with actual value on build stage, using pxfProtocolVersion parameter
from
+	 * gradle.properties
+	 */
+	final static String PXF_PROTOCOL_VERSION = "@pxfProtocolVersion@";
+
+	public Version() {
+	}
+
+	public String version;
+
+	public String getVersion() {
+		return version;
+	}
+
+	public void setVersion(String version) {
+		this.version = version;
+	}
 }
 
 /**
@@ -58,11 +77,12 @@ public class VersionResource {
      * @return response with the PXF protocol version
      */
     @GET
+    @Produces("application/json")
     public Response getProtocolVersion() {
 
         ResponseBuilder b = Response.ok();
-        b.entity("PXF protocol version " + Version.PXF_PROTOCOL_VERSION);
-        b.type(MediaType.TEXT_PLAIN_TYPE);
+        b.entity("{ \"version\": \"" + Version.PXF_PROTOCOL_VERSION + "\"}");
+        b.type(MediaType.APPLICATION_JSON_TYPE);
         return b.build();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/6815499c/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/VersionResourceTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/VersionResourceTest.java
b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/VersionResourceTest.java
index 58ca4e3..d9f8f36 100644
--- a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/VersionResourceTest.java
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/VersionResourceTest.java
@@ -22,6 +22,8 @@ package org.apache.hawq.pxf.service.rest;
 
 import static org.junit.Assert.assertEquals;
 
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.junit.Test;
@@ -36,7 +38,10 @@ public class VersionResourceTest {
 
         assertEquals(Response.Status.OK,
                 Response.Status.fromStatusCode(result.getStatus()));
-        assertEquals("PXF protocol version " + Version.PXF_PROTOCOL_VERSION,
+        assertEquals(
+                "{ \"version\": \"" + Version.PXF_PROTOCOL_VERSION + "\"}",
                 result.getEntity().toString());
+        assertEquals(result.getMetadata().get(HttpHeaders.CONTENT_TYPE).get(0),
+                MediaType.APPLICATION_JSON_TYPE);
     }
 }


Mime
View raw message