You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2016/02/25 23:00:11 UTC
[3/5] storm git commit: address review comments
address review comments
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/5c81f0c7
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/5c81f0c7
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/5c81f0c7
Branch: refs/heads/master
Commit: 5c81f0c7ff1e344d9996912dd20038fde32dc505
Parents: 480256e
Author: Jark Wu <im...@gmail.com>
Authored: Wed Feb 24 18:01:08 2016 +0800
Committer: Jark Wu <im...@gmail.com>
Committed: Wed Feb 24 18:09:01 2016 +0800
----------------------------------------------------------------------
.../src/clj/org/apache/storm/daemon/drpc.clj | 5 +-
.../clj/org/apache/storm/daemon/logviewer.clj | 67 ++++++-----
storm-core/src/clj/org/apache/storm/ui/core.clj | 86 +++++++-------
.../src/clj/org/apache/storm/ui/helpers.clj | 11 +-
.../apache/storm/ui/FilterConfiguration.java | 63 ++++++++++
.../src/jvm/org/apache/storm/ui/UIHelpers.java | 114 +++++--------------
.../clj/org/apache/storm/logviewer_test.clj | 21 ++--
7 files changed, 194 insertions(+), 173 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/5c81f0c7/storm-core/src/clj/org/apache/storm/daemon/drpc.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/org/apache/storm/daemon/drpc.clj b/storm-core/src/clj/org/apache/storm/daemon/drpc.clj
index 96e7cb1..001e810 100644
--- a/storm-core/src/clj/org/apache/storm/daemon/drpc.clj
+++ b/storm-core/src/clj/org/apache/storm/daemon/drpc.clj
@@ -16,7 +16,7 @@
(ns org.apache.storm.daemon.drpc
(:import [org.apache.storm.security.auth AuthUtils ThriftServer ThriftConnectionType ReqContext]
- [org.apache.storm.ui UIHelpers IConfigurator])
+ [org.apache.storm.ui UIHelpers IConfigurator FilterConfiguration])
(:import [org.apache.storm.security.auth.authorizer DRPCAuthorizerBase])
(:import [org.apache.storm.utils Utils])
(:import [org.apache.storm.generated DistributedRPC DistributedRPC$Iface DistributedRPC$Processor
@@ -241,8 +241,7 @@
requests-middleware)
filter-class (conf DRPC-HTTP-FILTER)
filter-params (conf DRPC-HTTP-FILTER-PARAMS)
- filters-confs [{:filter-class filter-class
- :filter-params filter-params}]
+ filters-confs [(FilterConfiguration. filter-class filter-params)]
https-port (int (or (conf DRPC-HTTPS-PORT) 0))
https-ks-path (conf DRPC-HTTPS-KEYSTORE-PATH)
https-ks-password (conf DRPC-HTTPS-KEYSTORE-PASSWORD)
http://git-wip-us.apache.org/repos/asf/storm/blob/5c81f0c7/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj b/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
index f296ec2..221dad7 100644
--- a/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
+++ b/storm-core/src/clj/org/apache/storm/daemon/logviewer.clj
@@ -36,7 +36,7 @@
(:import [org.apache.storm.daemon DirectoryCleaner])
(:import [org.yaml.snakeyaml Yaml]
[org.yaml.snakeyaml.constructor SafeConstructor])
- (:import [org.apache.storm.ui InvalidRequestException UIHelpers IConfigurator]
+ (:import [org.apache.storm.ui InvalidRequestException UIHelpers IConfigurator FilterConfiguration]
[org.apache.storm.security.auth AuthUtils])
(:require [org.apache.storm.daemon common [supervisor :as supervisor]])
(:require [compojure.route :as route]
@@ -407,6 +407,14 @@
(defn- is-txt-file [fname]
(re-find #"\.(log.*|txt|yaml|pid)$" fname))
+(defn unauthorized-user-html [user]
+ [[:h2 "User '" (escape-html user) "' is not authorized."]])
+
+(defn ring-response-from-exception [ex]
+ {:headers {}
+ :status 400
+ :body (.getMessage ex)})
+
(def default-bytes-per-page 51200)
(defn log-page [fname start length grep user root-dir]
@@ -456,7 +464,7 @@
(if (nil? (get-log-user-group-whitelist fname))
(-> (resp/response "Page not found")
(resp/status 404))
- [(clojurify-structure (UIHelpers/unauthorizedUserHtml user))])))
+ (unauthorized-user-html user))))
(defn daemonlog-page [fname start length grep user root-dir]
(let [file (.getCanonicalFile (File. root-dir fname))
@@ -505,7 +513,7 @@
(authorized-log-user? user fname *STORM-CONF*))
(-> (resp/response file)
(resp/content-type "application/octet-stream"))
- [(clojurify-structure (UIHelpers/unauthorizedUserHtml user))])
+ (unauthorized-user-html user))
(-> (resp/response "Page not found")
(resp/status 404)))))
@@ -810,25 +818,25 @@
(try
(if (and (not (empty? search))
<= (count (.getBytes search "UTF-8")) grep-max-search-size)
- (clojurify-structure (UIHelpers/jsonResponse
+ (json-response
(substring-search file
search
:num-matches num-matches-int
:start-byte-offset offset-int)
callback
- {"Access-Control-Allow-Origin" origin
- "Access-Control-Allow-Credentials" "true"}))
+ :headers {"Access-Control-Allow-Origin" origin
+ "Access-Control-Allow-Credentials" "true"})
(throw
(InvalidRequestException.
(str "Search substring must be between 1 and 1024 UTF-8 "
"bytes in size (inclusive)"))))
(catch Exception ex
- (clojurify-structure (UIHelpers/jsonResponse (UIHelpers/exceptionToJson ex) callback 500)))))
- (clojurify-structure (UIHelpers/jsonResponse (UIHelpers/unauthorizedUserJson user) callback 401)))
- (clojurify-structure (UIHelpers/jsonResponse {"error" "Not Found"
+ (json-response (UIHelpers/exceptionToJson ex) callback :status 500))))
+ (json-response (UIHelpers/unauthorizedUserJson user) callback :status 401))
+ (json-response {"error" "Not Found"
"errorMessage" "The file was not found on this node."}
callback
- 404)))))
+ :status 404))))
(defn find-n-matches [logs n file-offset offset search]
(let [logs (drop file-offset logs)
@@ -878,7 +886,7 @@
(defn deep-search-logs-for-topology
[topology-id user ^String root-dir search num-matches port file-offset offset search-archived? callback origin]
- (clojurify-structure (UIHelpers/jsonResponse
+ (json-response
(if (or (not search) (not (.exists (File. (str root-dir Utils/FILE_PATH_SEPARATOR topology-id)))))
[]
(let [file-offset (if file-offset (Integer/parseInt file-offset) 0)
@@ -905,8 +913,8 @@
(find-n-matches filtered-logs num-matches file-offset offset search)
(find-n-matches [(first filtered-logs)] num-matches 0 offset search)))))))))
callback
- {"Access-Control-Allow-Origin" origin
- "Access-Control-Allow-Credentials" "true"})))
+ :headers {"Access-Control-Allow-Origin" origin
+ "Access-Control-Allow-Credentials" "true"}))
(defn log-template
([body] (log-template body nil nil))
@@ -962,10 +970,10 @@
[]))))
file-strs (sort (for [file file-results]
(get-topo-port-workerlog file)))]
- (clojurify-structure (UIHelpers/jsonResponse file-strs
+ (json-response file-strs
callback
- {"Access-Control-Allow-Origin" origin
- "Access-Control-Allow-Credentials" "true"}))))
+ :headers {"Access-Control-Allow-Origin" origin
+ "Access-Control-Allow-Credentials" "true"})))
(defn get-profiler-dump-files
[dir]
@@ -992,7 +1000,7 @@
file user))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/ringResponseFromException ex)))))
+ (ring-response-from-exception ex))))
(GET "/dumps/:topo-id/:host-port/:filename"
[:as {:keys [servlet-request servlet-response log-root]} topo-id host-port filename &m]
(let [user (.getUserName http-creds-handler servlet-request)
@@ -1016,7 +1024,7 @@
*STORM-CONF*))
(-> (resp/response file)
(resp/content-type "application/octet-stream"))
- [(clojurify-structure (UIHelpers/unauthorizedUserHtml user))])
+ (unauthorized-user-html user))
(-> (resp/response "Page not found")
(resp/status 404)))))
(GET "/dumps/:topo-id/:host-port"
@@ -1044,7 +1052,7 @@
(for [file (get-profiler-dump-files dir)]
[:li
[:a {:href (str "/dumps/" topo-id "/" host-port "/" file)} file ]])]])
- [(clojurify-structure (UIHelpers/unauthorizedUserHtml user))])
+ (unauthorized-user-html user))
(-> (resp/response "Page not found")
(resp/status 404)))))
(GET "/daemonlog" [:as req & m]
@@ -1060,7 +1068,7 @@
file user))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/ringResponseFromException ex)))))
+ (ring-response-from-exception ex))))
(GET "/download/:file" [:as {:keys [servlet-request servlet-response log-root]} file & m]
(try
(mark! logviewer:num-download-log-file-http-requests)
@@ -1068,7 +1076,7 @@
(download-log-file file servlet-request servlet-response user log-root))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/ringResponseFromException ex)))))
+ (ring-response-from-exception ex))))
(GET "/daemondownload/:file" [:as {:keys [servlet-request servlet-response daemonlog-root]} file & m]
(try
(mark! logviewer:num-download-log-daemon-file-http-requests)
@@ -1076,7 +1084,7 @@
(download-log-file file servlet-request servlet-response user daemonlog-root))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/ringResponseFromException ex)))))
+ (ring-response-from-exception ex))))
(GET "/search/:file" [:as {:keys [servlet-request servlet-response log-root daemonlog-root]} file & m]
;; We do not use servlet-response here, but do not remove it from the
;; :keys list, or this rule could stop working when an authentication
@@ -1093,7 +1101,7 @@
(.getHeader servlet-request "Origin")))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/jsonResponse (UIHelpers/exceptionToJson ex) (:callback m) 400)))))
+ (json-response (UIHelpers/exceptionToJson ex) (:callback m) :status 400))))
(GET "/deepSearch/:topo-id" [:as {:keys [servlet-request servlet-response log-root]} topo-id & m]
;; We do not use servlet-response here, but do not remove it from the
;; :keys list, or this rule could stop working when an authentication
@@ -1113,7 +1121,7 @@
(.getHeader servlet-request "Origin")))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/jsonResponse (UIHelpers/exceptionToJson ex) (:callback m) 400)))))
+ (json-response (UIHelpers/exceptionToJson ex) (:callback m) :status 400))))
(GET "/searchLogs" [:as req & m]
(try
(let [servlet-request (:servlet-request req)
@@ -1126,7 +1134,7 @@
(.getHeader servlet-request "Origin")))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/jsonResponse (UIHelpers/exceptionToJson ex) (:callback m) 400)))))
+ (json-response (UIHelpers/exceptionToJson ex) (:callback m) :status 400))))
(GET "/listLogs" [:as req & m]
(try
(mark! logviewer:num-list-logs-http-requests)
@@ -1140,7 +1148,7 @@
(.getHeader servlet-request "Origin")))
(catch InvalidRequestException ex
(log-error ex)
- (clojurify-structure (UIHelpers/jsonResponse (UIHelpers/exceptionToJson ex) (:callback m) 400)))))
+ (json-response (UIHelpers/exceptionToJson ex) (:callback m) :status 400))))
(route/resources "/")
(route/not-found "Page not found"))
@@ -1159,13 +1167,10 @@
requests-middleware)) ;; query params as map
middle (conf-middleware logapp log-root-dir daemonlog-root-dir)
filters-confs (if (conf UI-FILTER)
- [{:filter-class filter-class
- :filter-params (or (conf UI-FILTER-PARAMS) {})}]
+ [(FilterConfiguration. filter-class (or (conf UI-FILTER-PARAMS) {}))]
[])
filters-confs (concat filters-confs
- [{:filter-class "org.eclipse.jetty.servlets.GzipFilter"
- :filter-name "Gzipper"
- :filter-params {}}])
+ [(FilterConfiguration. "org.eclipse.jetty.servlets.GzipFilter" "Gzipper" {})])
https-port (int (or (conf LOGVIEWER-HTTPS-PORT) 0))
keystore-path (conf LOGVIEWER-HTTPS-KEYSTORE-PATH)
keystore-pass (conf LOGVIEWER-HTTPS-KEYSTORE-PASSWORD)
http://git-wip-us.apache.org/repos/asf/storm/blob/5c81f0c7/storm-core/src/clj/org/apache/storm/ui/core.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/org/apache/storm/ui/core.clj b/storm-core/src/clj/org/apache/storm/ui/core.clj
index a70ae2c..1a016bb 100644
--- a/storm-core/src/clj/org/apache/storm/ui/core.clj
+++ b/storm-core/src/clj/org/apache/storm/ui/core.clj
@@ -28,7 +28,7 @@
start-metrics-reporters]]])
(:import [org.apache.storm.utils Time]
[org.apache.storm.generated NimbusSummary]
- [org.apache.storm.ui UIHelpers IConfigurator])
+ [org.apache.storm.ui UIHelpers IConfigurator FilterConfiguration])
(:use [clojure.string :only [blank? lower-case trim split]])
(:import [org.apache.storm.generated ExecutorSpecificStats
ExecutorStats ExecutorSummary ExecutorInfo TopologyInfo SpoutStats BoltStats
@@ -939,76 +939,76 @@
"Return a JSON response communicating that profiling is disabled and
therefore unavailable."
[callback]
- (clojurify-structure (UIHelpers/jsonResponse {"status" "disabled",
+ (json-response {"status" "disabled",
"message" "Profiling is not enabled on this server"}
callback
- 501)))
+ :status 501))
(defroutes main-routes
(GET "/api/v1/cluster/configuration" [& m]
(mark! ui:num-cluster-configuration-http-requests)
- (clojurify-structure (UIHelpers/jsonResponse (cluster-configuration)
- (:callback m) false nil nil)))
+ (json-response (cluster-configuration)
+ (:callback m) :need-serialize false))
(GET "/api/v1/cluster/summary" [:as {:keys [cookies servlet-request]} & m]
(mark! ui:num-cluster-summary-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getClusterInfo")
(let [user (get-user-name servlet-request)]
- (clojurify-structure (UIHelpers/jsonResponse (assoc (cluster-summary user)
+ (json-response (assoc (cluster-summary user)
"bugtracker-url" (*STORM-CONF* UI-PROJECT-BUGTRACKER-URL)
- "central-log-url" (*STORM-CONF* UI-CENTRAL-LOGGING-URL)) (:callback m)))))
+ "central-log-url" (*STORM-CONF* UI-CENTRAL-LOGGING-URL)) (:callback m))))
(GET "/api/v1/nimbus/summary" [:as {:keys [cookies servlet-request]} & m]
(mark! ui:num-nimbus-summary-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getClusterInfo")
- (clojurify-structure (UIHelpers/jsonResponse (nimbus-summary) (:callback m))))
+ (json-response (nimbus-summary) (:callback m)))
(GET "/api/v1/history/summary" [:as {:keys [cookies servlet-request]} & m]
(let [user (.getUserName http-creds-handler servlet-request)]
- (clojurify-structure (UIHelpers/jsonResponse (topology-history-info user) (:callback m)))))
+ (json-response (topology-history-info user) (:callback m))))
(GET "/api/v1/supervisor/summary" [:as {:keys [cookies servlet-request]} & m]
(mark! ui:num-supervisor-summary-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getClusterInfo")
- (clojurify-structure (UIHelpers/jsonResponse (assoc (supervisor-summary)
- "logviewerPort" (*STORM-CONF* LOGVIEWER-PORT)) (:callback m))))
+ (json-response (assoc (supervisor-summary)
+ "logviewerPort" (*STORM-CONF* LOGVIEWER-PORT)) (:callback m)))
(GET "/api/v1/topology/summary" [:as {:keys [cookies servlet-request]} & m]
(mark! ui:num-all-topologies-summary-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getClusterInfo")
- (clojurify-structure (UIHelpers/jsonResponse (all-topologies-summary) (:callback m))))
+ (json-response (all-topologies-summary) (:callback m)))
(GET "/api/v1/topology-workers/:id" [:as {:keys [cookies servlet-request]} id & m]
(let [id (URLDecoder/decode id)]
- (clojurify-structure (UIHelpers/jsonResponse {"hostPortList" (worker-host-port id)
- "logviewerPort" (*STORM-CONF* LOGVIEWER-PORT)} (:callback m)))))
+ (json-response {"hostPortList" (worker-host-port id)
+ "logviewerPort" (*STORM-CONF* LOGVIEWER-PORT)} (:callback m))))
(GET "/api/v1/topology/:id" [:as {:keys [cookies servlet-request scheme]} id & m]
(mark! ui:num-topology-page-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getTopology" (topology-config id))
(let [user (get-user-name servlet-request)]
- (clojurify-structure (UIHelpers/jsonResponse (topology-page id (:window m) (check-include-sys? (:sys m)) user (= scheme :https)) (:callback m)))))
+ (json-response (topology-page id (:window m) (check-include-sys? (:sys m)) user (= scheme :https)) (:callback m))))
(GET "/api/v1/topology/:id/visualization-init" [:as {:keys [cookies servlet-request]} id & m]
(mark! ui:num-build-visualization-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getTopology" (topology-config id))
- (clojurify-structure (UIHelpers/jsonResponse (build-visualization id (:window m) (check-include-sys? (:sys m))) (:callback m))))
+ (json-response (build-visualization id (:window m) (check-include-sys? (:sys m))) (:callback m)))
(GET "/api/v1/topology/:id/visualization" [:as {:keys [cookies servlet-request]} id & m]
(mark! ui:num-mk-visualization-data-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getTopology" (topology-config id))
- (clojurify-structure (UIHelpers/jsonResponse (mk-visualization-data id (:window m) (check-include-sys? (:sys m))) (:callback m))))
+ (json-response (mk-visualization-data id (:window m) (check-include-sys? (:sys m))) (:callback m)))
(GET "/api/v1/topology/:id/component/:component" [:as {:keys [cookies servlet-request scheme]} id component & m]
(mark! ui:num-component-page-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getTopology" (topology-config id))
(let [user (get-user-name servlet-request)]
- (clojurify-structure (UIHelpers/jsonResponse
+ (json-response
(component-page id component (:window m) (check-include-sys? (:sys m)) user (= scheme :https))
- (:callback m)))))
+ (:callback m))))
(GET "/api/v1/topology/:id/logconfig" [:as {:keys [cookies servlet-request]} id & m]
(mark! ui:num-log-config-http-requests)
(populate-context! servlet-request)
(assert-authorized-user "getTopology" (topology-config id))
- (clojurify-structure (UIHelpers/jsonResponse (log-config id) (:callback m))))
+ (json-response (log-config id) (:callback m)))
(POST "/api/v1/topology/:id/activate" [:as {:keys [cookies servlet-request]} id & m]
(mark! ui:num-activate-topology-http-requests)
(populate-context! servlet-request)
@@ -1021,7 +1021,7 @@
name (.get_name tplg)]
(.activate nimbus name)
(log-message "Activating topology '" name "'")))
- (clojurify-structure (UIHelpers/jsonResponse (topology-op-response id "activate") (m "callback"))))
+ (json-response (topology-op-response id "activate") (m "callback")))
(POST "/api/v1/topology/:id/deactivate" [:as {:keys [cookies servlet-request]} id & m]
(mark! ui:num-deactivate-topology-http-requests)
(populate-context! servlet-request)
@@ -1034,7 +1034,7 @@
name (.get_name tplg)]
(.deactivate nimbus name)
(log-message "Deactivating topology '" name "'")))
- (clojurify-structure (UIHelpers/jsonResponse (topology-op-response id "deactivate") (m "callback"))))
+ (json-response (topology-op-response id "deactivate") (m "callback")))
(POST "/api/v1/topology/:id/debug/:action/:spct" [:as {:keys [cookies servlet-request]} id action spct & m]
(mark! ui:num-debug-topology-http-requests)
(populate-context! servlet-request)
@@ -1048,7 +1048,7 @@
enable? (= "enable" action)]
(.debug nimbus name "" enable? (Integer/parseInt spct))
(log-message "Debug topology [" name "] action [" action "] sampling pct [" spct "]")))
- (clojurify-structure (UIHelpers/jsonResponse (topology-op-response id (str "debug/" action)) (m "callback"))))
+ (json-response (topology-op-response id (str "debug/" action)) (m "callback")))
(POST "/api/v1/topology/:id/component/:component/debug/:action/:spct" [:as {:keys [cookies servlet-request]} id component action spct & m]
(mark! ui:num-component-op-response-http-requests)
(populate-context! servlet-request)
@@ -1062,7 +1062,7 @@
enable? (= "enable" action)]
(.debug nimbus name component enable? (Integer/parseInt spct))
(log-message "Debug topology [" name "] component [" component "] action [" action "] sampling pct [" spct "]")))
- (clojurify-structure (UIHelpers/jsonResponse (component-op-response id component (str "/debug/" action)) (m "callback"))))
+ (json-response (component-op-response id component (str "/debug/" action)) (m "callback")))
(POST "/api/v1/topology/:id/rebalance/:wait-time" [:as {:keys [cookies servlet-request]} id wait-time & m]
(mark! ui:num-topology-op-response-http-requests)
(populate-context! servlet-request)
@@ -1083,7 +1083,7 @@
(.put_to_num_executors options (key keyval) (Integer/parseInt (.toString (val keyval))))))
(.rebalance nimbus name options)
(log-message "Rebalancing topology '" name "' with wait time: " wait-time " secs")))
- (clojurify-structure (UIHelpers/jsonResponse (topology-op-response id "rebalance") (m "callback"))))
+ (json-response (topology-op-response id "rebalance") (m "callback")))
(POST "/api/v1/topology/:id/kill/:wait-time" [:as {:keys [cookies servlet-request]} id wait-time & m]
(mark! ui:num-topology-op-response-http-requests)
(populate-context! servlet-request)
@@ -1098,7 +1098,7 @@
(.set_wait_secs options (Integer/parseInt wait-time))
(.killTopologyWithOpts nimbus name options)
(log-message "Killing topology '" name "' with wait time: " wait-time " secs")))
- (clojurify-structure (UIHelpers/jsonResponse (topology-op-response id "kill") (m "callback"))))
+ (json-response (topology-op-response id "kill") (m "callback")))
(POST "/api/v1/topology/:id/logconfig" [:as {:keys [cookies servlet-request]} id namedLoggerLevels & m]
(mark! ui:num-topology-op-response-http-requests)
(populate-context! servlet-request)
@@ -1126,7 +1126,7 @@
(.put_to_named_logger_level new-log-config logger-name named-logger-level)))
(log-message "Setting topology " id " log config " new-log-config)
(.setLogConfig nimbus id new-log-config)
- (clojurify-structure (UIHelpers/jsonResponse (log-config id) (m "callback"))))))
+ (json-response (log-config id) (m "callback")))))
(GET "/api/v1/topology/:id/profiling/start/:host-port/:timeout"
[:as {:keys [servlet-request]} id host-port timeout & m]
@@ -1142,14 +1142,14 @@
ProfileAction/JPROFILE_STOP)]
(.set_time_stamp request timestamp)
(.setWorkerProfiler nimbus id request)
- (clojurify-structure (UIHelpers/jsonResponse {"status" "ok"
+ (json-response {"status" "ok"
"id" host-port
"timeout" timeout
"dumplink" (worker-dump-link
host
port
id)}
- (m "callback"))))))
+ (m "callback")))))
(json-profiling-disabled (m "callback"))))
(GET "/api/v1/topology/:id/profiling/stop/:host-port"
@@ -1166,9 +1166,9 @@
ProfileAction/JPROFILE_STOP)]
(.set_time_stamp request timestamp)
(.setWorkerProfiler nimbus id request)
- (clojurify-structure (UIHelpers/jsonResponse {"status" "ok"
+ (json-response {"status" "ok"
"id" host-port}
- (m "callback"))))))
+ (m "callback")))))
(json-profiling-disabled (m "callback"))))
(GET "/api/v1/topology/:id/profiling/dumpprofile/:host-port"
@@ -1185,9 +1185,9 @@
ProfileAction/JPROFILE_DUMP)]
(.set_time_stamp request timestamp)
(.setWorkerProfiler nimbus id request)
- (clojurify-structure (UIHelpers/jsonResponse {"status" "ok"
+ (json-response {"status" "ok"
"id" host-port}
- (m "callback"))))))
+ (m "callback")))))
(json-profiling-disabled (m "callback"))))
(GET "/api/v1/topology/:id/profiling/dumpjstack/:host-port"
@@ -1202,9 +1202,9 @@
ProfileAction/JSTACK_DUMP)]
(.set_time_stamp request timestamp)
(.setWorkerProfiler nimbus id request)
- (clojurify-structure (UIHelpers/jsonResponse {"status" "ok"
+ (json-response {"status" "ok"
"id" host-port}
- (m "callback"))))))
+ (m "callback")))))
(GET "/api/v1/topology/:id/profiling/restartworker/:host-port"
[:as {:keys [servlet-request]} id host-port & m]
@@ -1218,9 +1218,9 @@
ProfileAction/JVM_RESTART)]
(.set_time_stamp request timestamp)
(.setWorkerProfiler nimbus id request)
- (clojurify-structure (UIHelpers/jsonResponse {"status" "ok"
+ (json-response {"status" "ok"
"id" host-port}
- (m "callback"))))))
+ (m "callback")))))
(GET "/api/v1/topology/:id/profiling/dumpheap/:host-port"
[:as {:keys [servlet-request]} id host-port & m]
@@ -1234,9 +1234,9 @@
ProfileAction/JMAP_DUMP)]
(.set_time_stamp request timestamp)
(.setWorkerProfiler nimbus id request)
- (clojurify-structure (UIHelpers/jsonResponse {"status" "ok"
+ (json-response {"status" "ok"
"id" host-port}
- (m "callback"))))))
+ (m "callback")))))
(GET "/" [:as {cookies :cookies}]
(mark! ui:num-main-page-http-requests)
@@ -1250,7 +1250,7 @@
(try
(handler request)
(catch Exception ex
- (clojurify-structure (UIHelpers/jsonResponse (UIHelpers/exceptionToJson ex) ((:query-params request) "callback") 500))))))
+ (json-response (UIHelpers/exceptionToJson ex) ((:query-params request) "callback") :status 500)))))
(def app
(handler/site (-> main-routes
@@ -1265,8 +1265,7 @@
(try
(let [conf *STORM-CONF*
header-buffer-size (int (.get conf UI-HEADER-BUFFER-BYTES))
- filters-confs [{:filter-class (conf UI-FILTER)
- :filter-params (conf UI-FILTER-PARAMS)}]
+ filters-confs [(FilterConfiguration. (conf UI-FILTER) (conf UI-FILTER-PARAMS))]
https-port (int (or (conf UI-HTTPS-PORT) 0))
https-ks-path (conf UI-HTTPS-KEYSTORE-PATH)
https-ks-password (conf UI-HTTPS-KEYSTORE-PASSWORD)
@@ -1296,8 +1295,7 @@
https-want-client-auth)
(doseq [connector (.getConnectors server)]
(.setRequestHeaderSize connector header-buffer-size))
- (UIHelpers/configFilter server (ring.util.servlet/servlet app) filters-confs)
- ))))
+ (UIHelpers/configFilter server (ring.util.servlet/servlet app) filters-confs)))))
(catch Exception ex
(log-error ex))))
http://git-wip-us.apache.org/repos/asf/storm/blob/5c81f0c7/storm-core/src/clj/org/apache/storm/ui/helpers.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/org/apache/storm/ui/helpers.clj b/storm-core/src/clj/org/apache/storm/ui/helpers.clj
index c444b11..0ad5e3f 100644
--- a/storm-core/src/clj/org/apache/storm/ui/helpers.clj
+++ b/storm-core/src/clj/org/apache/storm/ui/helpers.clj
@@ -22,7 +22,8 @@
(:use [org.apache.storm config log])
(:use [org.apache.storm.util :only [clojurify-structure defnk not-nil?]])
(:use [clj-time coerce format])
- (:import [org.apache.storm.generated ExecutorInfo ExecutorSummary])
+ (:import [org.apache.storm.generated ExecutorInfo ExecutorSummary]
+ [org.apache.storm.ui UIHelpers])
(:import [org.apache.storm.logging.filters AccessLoggingFilter])
(:import [java.util EnumSet]
[java.net URLEncoder])
@@ -39,6 +40,7 @@
[compojure.handler :as handler])
(:require [metrics.meters :refer [defmeter mark!]]))
+;; TODO this function and its callings will be replace when ui.core and logviewer and drpc move to Java
(defmeter num-web-requests)
(defn requests-middleware
"Coda Hale metric for counting the number of web requests."
@@ -46,3 +48,10 @@
(fn [req]
(mark! num-web-requests)
(handler req)))
+
+;; TODO this function and its callings will be replace when ui.core and logviewer move to Java
+(defnk json-response
+ [data callback :need-serialize true :status 200 :headers {}]
+ {:status status
+ :headers (UIHelpers/getJsonResponseHeaders callback headers)
+ :body (UIHelpers/getJsonResponseBody data callback need-serialize)})
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/storm/blob/5c81f0c7/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java b/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java
new file mode 100644
index 0000000..e852497
--- /dev/null
+++ b/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java
@@ -0,0 +1,63 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.storm.ui;
+
+import java.util.Map;
+
+public class FilterConfiguration {
+ private String filterClass;
+ private String filterName;
+ private Map filterParams;
+
+
+ public FilterConfiguration(Map filterParams, String filterClass) {
+ this.filterParams = filterParams;
+ this.filterClass = filterClass;
+ this.filterName = null;
+ }
+
+ public FilterConfiguration(String filterClass, String filterName, Map filterParams) {
+ this.filterClass = filterClass;
+ this.filterName = filterName;
+ this.filterParams = filterParams;
+ }
+
+ public String getFilterName() {
+ return filterName;
+ }
+
+ public void setFilterName(String filterName) {
+ this.filterName = filterName;
+ }
+
+ public String getFilterClass() {
+ return filterClass;
+ }
+
+ public void setFilterClass(String filterClass) {
+ this.filterClass = filterClass;
+ }
+
+ public Map getFilterParams() {
+ return filterParams;
+ }
+
+ public void setFilterParams(Map filterParams) {
+ this.filterParams = filterParams;
+ }
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/5c81f0c7/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java b/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java
index 26f060d..e046061 100644
--- a/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java
+++ b/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java
@@ -17,12 +17,8 @@
*/
package org.apache.storm.ui;
-import clojure.lang.Keyword;
-import clojure.lang.RT;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringEscapeUtils;
import org.apache.storm.generated.ExecutorInfo;
import org.apache.storm.logging.filters.AccessLoggingFilter;
import org.apache.storm.utils.Utils;
@@ -47,30 +43,31 @@ import java.util.*;
public class UIHelpers {
- private static final String[][] PRETTY_SEC_DIVIDERS = {
- new String[]{"s", "60"},
- new String[]{"m", "60"},
- new String[]{"h", "24"},
- new String[]{"d", null}};
+ private static final Object[][] PRETTY_SEC_DIVIDERS = {
+ new Object[]{"s", 60},
+ new Object[]{"m", 60},
+ new Object[]{"h", 24},
+ new Object[]{"d", null}};
- private static final String[][] PRETTY_MS_DIVIDERS = {
- new String[]{"ms", "1000"},
- new String[]{"s", "60"},
- new String[]{"m", "60"},
- new String[]{"h", "24"},
- new String[]{"d", null}};
+ private static final Object[][] PRETTY_MS_DIVIDERS = {
+ new Object[]{"ms", 1000},
+ new Object[]{"s", 60},
+ new Object[]{"m", 60},
+ new Object[]{"h", 24},
+ new Object[]{"d", null}};
- public static String prettyUptimeStr(String val, String[][] dividers) {
+ public static String prettyUptimeStr(String val, Object[][] dividers) {
int uptime = Integer.parseInt(val);
LinkedList<String> tmp = new LinkedList<>();
- for (String[] divider : dividers) {
+ for (Object[] divider : dividers) {
if (uptime > 0) {
- if (divider[1] != null) {
- int div = Integer.parseInt(divider[1]);
- tmp.addFirst(uptime % div + divider[0]);
+ String state = (String) divider[0];
+ Integer div = (Integer) divider[1];
+ if (div != null) {
+ tmp.addFirst(uptime % div + state);
uptime = uptime / div;
} else {
- tmp.addFirst(uptime + divider[0]);
+ tmp.addFirst(uptime + state);
}
}
}
@@ -109,16 +106,7 @@ public class UIHelpers {
public static Map unauthorizedUserJson(String user) {
return ImmutableMap.of(
"error", "No Authorization",
- "errorMessage", String.format("User %s is not authorized.", user)
- );
- }
-
- public static List unauthorizedUserHtml(String user) {
- return Lists.newArrayList(
- keyword("h1"),
- "User '",
- StringEscapeUtils.escapeHtml(user),
- "' is not authorized.");
+ "errorMessage", String.format("User %s is not authorized.", user));
}
private static SslSocketConnector mkSslConnector(Integer port, String ksPath, String ksPassword, String ksType,
@@ -141,8 +129,7 @@ public class UIHelpers {
if (needClientAuth != null && needClientAuth) {
factory.setNeedClientAuth(true);
- }
- if (wantClientAuth != null && wantClientAuth) {
+ } else if (wantClientAuth != null && wantClientAuth) {
factory.setWantClientAuth(true);
}
@@ -172,17 +159,16 @@ public class UIHelpers {
return new FilterHolder(new AccessLoggingFilter());
}
- public static void configFilter(Server server, Servlet servlet, List filtersConfs) {
+ public static void configFilter(Server server, Servlet servlet, List<FilterConfiguration> filtersConfs) {
if (filtersConfs != null) {
ServletHolder servletHolder = new ServletHolder(servlet);
ServletContextHandler context = new ServletContextHandler(server, "/");
context.addServlet(servletHolder, "/");
context.addFilter(corsFilterHandle(), "/*", EnumSet.allOf(DispatcherType.class));
- for (Object obj : filtersConfs) {
- Map filterConf = (Map) obj;
- String filterName = (String) filterConf.get(keyword("filter-name"));
- String filterClass = (String) filterConf.get(keyword("filter-class"));
- Map filterParams = (Map) filterConf.get(keyword("filter-params"));
+ for (FilterConfiguration filterConf : filtersConfs) {
+ String filterName = filterConf.getFilterName();
+ String filterClass = filterConf.getFilterClass();
+ Map filterParams = filterConf.getFilterParams();
if (filterClass != null) {
FilterHolder filterHolder = new FilterHolder();
filterHolder.setClassName(filterClass);
@@ -204,14 +190,6 @@ public class UIHelpers {
}
}
- public static Map ringResponseFromException(Exception ex) {
- return ImmutableMap.of(
- keyword("headers"), new HashMap<>(),
- keyword("status"), 400,
- keyword("body"), ex.getMessage()
- );
- }
-
private static Server removeNonSslConnector(Server server) {
for (Connector c : server.getConnectors()) {
if (c != null && !(c instanceof SslSocketConnector)) {
@@ -260,19 +238,7 @@ public class UIHelpers {
return callback + "(" + response + ");";
}
- public static Map jsonResponse(Object data, String callback) {
- return jsonResponse(data, callback, true, null, null);
- }
-
- public static Map jsonResponse(Object data, String callback, Long status) {
- return jsonResponse(data, callback, true, status, null);
- }
-
- public static Map jsonResponse(Object data, String callback, Map headers) {
- return jsonResponse(data, callback, true, null, headers);
- }
-
- public static Map jsonResponse(Object data, String callback, boolean needSerialize, Long status, Map headers) {
+ public static Map getJsonResponseHeaders(String callback, Map headers) {
Map<String, String> headersResult = new HashMap<>();
headersResult.put("Cache-Control", "no-cache, no-store");
headersResult.put("Access-Control-Allow-Origin", "*");
@@ -285,26 +251,12 @@ public class UIHelpers {
if (headers != null) {
headersResult.putAll(headers);
}
+ return headersResult;
+ }
- String serializedData;
- if (needSerialize) {
- serializedData = JSONValue.toJSONString(data);
- } else {
- serializedData = (String) data;
- }
-
- String body;
- if (callback != null) {
- body = wrapJsonInCallback(callback, serializedData);
- } else {
- body = serializedData;
- }
-
- return ImmutableMap.of(
- keyword("status"), Utils.getInt(status, 200),
- keyword("headers"), headersResult,
- keyword("body"), body
- );
+ public static String getJsonResponseBody(Object data, String callback, boolean needSerialize) {
+ String serializedData = needSerialize ? JSONValue.toJSONString(data) : (String) data;
+ return callback != null ? wrapJsonInCallback(callback, serializedData) : serializedData;
}
public static Map exceptionToJson(Exception ex) {
@@ -312,8 +264,4 @@ public class UIHelpers {
ex.printStackTrace(new PrintWriter(sw));
return ImmutableMap.of("error", "Internal Server Error", "errorMessage", sw.toString());
}
-
- private static Keyword keyword(String key) {
- return RT.keyword(null, key);
- }
}
http://git-wip-us.apache.org/repos/asf/storm/blob/5c81f0c7/storm-core/test/clj/org/apache/storm/logviewer_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/org/apache/storm/logviewer_test.clj b/storm-core/test/clj/org/apache/storm/logviewer_test.clj
index 1aeac32..4889c8e 100644
--- a/storm-core/test/clj/org/apache/storm/logviewer_test.clj
+++ b/storm-core/test/clj/org/apache/storm/logviewer_test.clj
@@ -24,8 +24,7 @@
[org.apache.storm.ui helpers])
(:import [org.apache.storm.daemon DirectoryCleaner]
[org.apache.storm.utils Utils Time]
- [org.apache.storm.utils.staticmocking UtilsInstaller]
- [org.apache.storm.ui UIHelpers])
+ [org.apache.storm.utils.staticmocking UtilsInstaller])
(:import [java.nio.file Files Path DirectoryStream])
(:import [java.nio.file Files])
(:import [java.nio.file.attribute FileAttribute])
@@ -335,19 +334,19 @@
_ (.createNewFile file2)
_ (.createNewFile file3)
origin "www.origin.server.net"
- expected-all (clojurify-structure (UIHelpers/jsonResponse '("topoA/port1/worker.log" "topoA/port2/worker.log"
+ expected-all (json-response '("topoA/port1/worker.log" "topoA/port2/worker.log"
"topoB/port1/worker.log")
nil
- {"Access-Control-Allow-Origin" origin
- "Access-Control-Allow-Credentials" "true"}))
- expected-filter-port (clojurify-structure (UIHelpers/jsonResponse '("topoA/port1/worker.log" "topoB/port1/worker.log")
+ :headers {"Access-Control-Allow-Origin" origin
+ "Access-Control-Allow-Credentials" "true"})
+ expected-filter-port (json-response '("topoA/port1/worker.log" "topoB/port1/worker.log")
nil
- {"Access-Control-Allow-Origin" origin
- "Access-Control-Allow-Credentials" "true"}))
- expected-filter-topoId (clojurify-structure (UIHelpers/jsonResponse '("topoB/port1/worker.log")
+ :headers {"Access-Control-Allow-Origin" origin
+ "Access-Control-Allow-Credentials" "true"})
+ expected-filter-topoId (json-response '("topoB/port1/worker.log")
nil
- {"Access-Control-Allow-Origin" origin
- "Access-Control-Allow-Credentials" "true"}))
+ :headers {"Access-Control-Allow-Origin" origin
+ "Access-Control-Allow-Credentials" "true"})
returned-all (logviewer/list-log-files "user" nil nil root-path nil origin)
returned-filter-port (logviewer/list-log-files "user" nil "port1" root-path nil origin)
returned-filter-topoId (logviewer/list-log-files "user" "topoB" nil root-path nil origin)]