You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2018/03/03 04:53:50 UTC
[kylin] 02/11: KYLIN-3233, fix CacheController if cacheKey has "/".
This is an automated email from the ASF dual-hosted git repository.
liyang pushed a commit to branch sync
in repository https://gitbox.apache.org/repos/asf/kylin.git
commit d63160d2df0ea7db7f919d10a5f94c3f05bb6653
Author: Jiatao Tao <24...@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
liyang@apache.org.