This is an automated email from the ASF dual-hosted git repository.

billyliu pushed a commit to branch 2.3.x
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit f989aa57c0aa21ec7a0705a007b0bf652e0b31e1
Author: Jiatao Tao <245915...@qq.com>
AuthorDate: Sun Feb 4 21:08:25 2018 +0800

    KYLIN-3233, fix CacheController if cacheKey has "/".
---
 .../apache/kylin/common/restclient/RestClient.java  | 13 +++++++++++--
 .../rest/broadcaster/BroadcasterReceiveServlet.java | 21 ++++++++++++++++++---
 .../kylin/rest/controller/CacheController.java      | 10 ++++++++++
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git 
a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java 
b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java
index e1cc13c..93f5e19 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java
@@ -38,6 +38,7 @@ import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.DefaultHttpClient;
@@ -149,8 +150,16 @@ public class RestClient {
     }
 
     public void wipeCache(String entity, String event, String cacheKey) throws 
IOException {
-        String url = baseUrl + "/cache/" + entity + "/" + cacheKey + "/" + 
event;
-        HttpPut request = new HttpPut(url);
+        HttpPut request;
+        String url;
+        if (cacheKey.contains("/")) {
+            url = baseUrl + "/cache/" + entity + "/" + event;
+            request = new HttpPut(url);
+            request.setEntity(new StringEntity(cacheKey, 
ContentType.create("application/json", "UTF-8")));
+        } else {
+            url = baseUrl + "/cache/" + entity + "/" + cacheKey + "/" + event;
+            request = new HttpPut(url);
+        }
 
         HttpResponse response = null;
         try {
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/broadcaster/BroadcasterReceiveServlet.java
 
b/server-base/src/main/java/org/apache/kylin/rest/broadcaster/BroadcasterReceiveServlet.java
index 0a9c0bf..c6247f0 100644
--- 
a/server-base/src/main/java/org/apache/kylin/rest/broadcaster/BroadcasterReceiveServlet.java
+++ 
b/server-base/src/main/java/org/apache/kylin/rest/broadcaster/BroadcasterReceiveServlet.java
@@ -18,7 +18,9 @@
 
 package org.apache.kylin.rest.broadcaster;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -45,6 +47,7 @@ public class BroadcasterReceiveServlet extends HttpServlet {
     }
 
     private static final Pattern PATTERN = Pattern.compile("/(.+)/(.+)/(.+)");
+    private static final Pattern PATTERN2 = Pattern.compile("/(.+)/(.+)");
 
     @Override
     protected void doPut(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
@@ -61,14 +64,26 @@ public class BroadcasterReceiveServlet extends HttpServlet {
         final String requestURI = req.getRequestURI();
         final String substring = 
requestURI.substring(requestURI.indexOf(startString) + startString.length());
         final Matcher matcher = PATTERN.matcher(substring);
+        final Matcher matcher2 = PATTERN2.matcher(substring);
+
         if (matcher.matches()) {
             String type = matcher.group(1);
-            String name = matcher.group(2);
+            String cacheKey = matcher.group(2);
             String event = matcher.group(3);
             if (handler != null) {
-                handler.handle(type, name, event);
+                handler.handle(type, cacheKey, event);
+            }
+            resp.getWriter().write("type:" + type + " name:" + cacheKey + " 
event:" + event);
+        } else if (matcher2.matches()) {
+            String type = matcher2.group(1);
+            String event = matcher2.group(2);
+            BufferedReader br = new BufferedReader(new 
InputStreamReader(req.getInputStream(), "utf-8"));
+            String cacheKey = br.readLine();
+            br.close();
+            if (handler != null) {
+                handler.handle(type, cacheKey, event);
             }
-            resp.getWriter().write("type:" + type + " name:" + name + " 
event:" + event);
+            resp.getWriter().write("type:" + type + " name:" + cacheKey + " 
event:" + event);
         } else {
             resp.getWriter().write("not valid uri");
         }
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/controller/CacheController.java
 
b/server-base/src/main/java/org/apache/kylin/rest/controller/CacheController.java
index 08b7cc4..ad6e71f 100644
--- 
a/server-base/src/main/java/org/apache/kylin/rest/controller/CacheController.java
+++ 
b/server-base/src/main/java/org/apache/kylin/rest/controller/CacheController.java
@@ -69,6 +69,16 @@ public class CacheController extends BasicController {
         cacheService.notifyMetadataChange(entity, 
Broadcaster.Event.getEvent(event), cacheKey);
     }
 
+    /**
+     * If cacheKey has "/", will lead to this method.
+     */
+    @RequestMapping(value = "/{entity}/{event}", method = { RequestMethod.PUT 
}, produces = { "application/json" })
+    @ResponseBody
+    public void wipeCacheWithRequestBody(@PathVariable String entity, 
@PathVariable String event,
+            @RequestBody String cacheKey) throws IOException {
+        cacheService.notifyMetadataChange(entity, 
Broadcaster.Event.getEvent(event), cacheKey);
+    }
+
     @RequestMapping(value = "/announce/config", method = { RequestMethod.POST 
}, produces = { "application/json" })
     public void hotLoadKylinConfig() throws IOException {
         KylinConfig.getInstanceFromEnv().reloadFromSiteProperties();

-- 
To stop receiving notification emails like this one, please contact
billy...@apache.org.

Reply via email to