hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiv...@apache.org
Subject incubator-hawq git commit: HAWQ-191. Handle retired pxf apis
Date Mon, 14 Dec 2015 17:57:02 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-191 b126f9923 -> ee21bc3c4


HAWQ-191. Handle retired pxf apis


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

Branch: refs/heads/HAWQ-191
Commit: ee21bc3c4bc8ca5f125827e850a0dea23dcd817e
Parents: b126f99
Author: Shivram Mani <shivram.mani@gmail.com>
Authored: Mon Dec 14 09:56:54 2015 -0800
Committer: Shivram Mani <shivram.mani@gmail.com>
Committed: Mon Dec 14 09:56:54 2015 -0800

----------------------------------------------------------------------
 .../pxf/service/rest/InvalidPathResource.java   | 50 ++++++++++++++++++--
 1 file changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ee21bc3c/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java
b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java
index bf45381..1dee254 100644
--- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java
+++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java
@@ -24,12 +24,17 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hawq.pxf.service.utilities.Utilities;
 
+import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.List;
+
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriInfo;
@@ -52,6 +57,9 @@ public class InvalidPathResource {
     UriInfo rootUri;
 
     private static final Log Log = LogFactory.getLog(InvalidPathResource.class);
+    // Set of retired endpoints
+    private final ImmutableSet<String> retiredEndPoints = ImmutableSet.of(
+            "Analyzer");
 
     public InvalidPathResource() {
     }
@@ -114,10 +122,16 @@ public class InvalidPathResource {
         Log.debug("REST request: " + rootUri.getAbsolutePath() + ". " +
                 "Version " + version + ", supported version is " + Version.PXF_PROTOCOL_VERSION);
 
-        // if version is not of the format "v<number>" then it's not a version but
a wrong path
-        if (version.equals(Version.PXF_PROTOCOL_VERSION)  || !(version.matches("v[0-9]+")))
{
+        if(version.equals(Version.PXF_PROTOCOL_VERSION)) { // api with incorrect path
+            String endPoint = parseEndpoint(path);
+            if (retiredEndPoints.contains(endPoint)) {
+                errmsg = getRetiredPathMsg(endPoint);
+            } else {
+                errmsg = getUnknownPathMsg();
+            }
+        } else if(!(version.matches("v[0-9]+"))) { // api with version not of the format
"v<number>"
             errmsg = getUnknownPathMsg();
-        } else {
+        } else { // api with wrong version number
             errmsg = "Wrong version " + version + ", supported version is " + Version.PXF_PROTOCOL_VERSION;
         }
 
@@ -153,9 +167,39 @@ public class InvalidPathResource {
     }
 
     /**
+     * Parses the version part from the path.
+     * The the absolute path is
+     * http://<host>:<port>/pxf/<version>/<rest of path>
+     *
+     * path - the endpoint part after /pxf/
+     * returns the first element after /pxf/
+     */
+    private String parseEndpoint(String path) {
+        List<PathSegment> pathSegments = rootUri.getPathSegments();
+        if(pathSegments.size() < 2) {
+            return null;
+        }
+        return pathSegments.get(1).getPath();
+    }
+
+    /**
      * Returns unknown path message, with the path's special characters masked.
      */
     private String getUnknownPathMsg() {
         return "Unknown path \"" + Utilities.maskNonPrintables(rootUri.getAbsolutePath().toString())
+ "\"";
     }
+
+    /**
+     * Warn on recently retired paths
+     * eg: http://<host>:<port>/pxf/<version>/Analyzer/<rest of path>
+     *
+     * Returns message about path not being supported
+     */
+    private String getRetiredPathMsg(String endpoint) {
+        if("Analyzer".equals(endpoint)) {
+            return endpoint + " API is retired. Please use /Fragmenter/getFragmentsStats
instead";
+        } else {
+            return endpoint + " API is retired";
+        }
+    }
 }


Mime
View raw message