[ 
https://issues.apache.org/jira/browse/STORM-361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14058030#comment-14058030
 ] 

ASF GitHub Bot commented on STORM-361:
--------------------------------------

Github user d2r commented on a diff in the pull request:

    https://github.com/apache/incubator-storm/pull/159#discussion_r14796687
  
    --- Diff: storm-core/src/clj/backtype/storm/ui/core.clj ---
    @@ -815,29 +815,35 @@
       [sys?]
       (if (or (nil? sys?) (= "false" sys?)) false true))
     
    -(defn json-response [data & [status]]
    -  {:status (or status 200)
    -   :headers {"Content-Type" "application/json"}
    -   :body (to-json data)})
    +(defn add-padding-to-json [callback response]
    +  (str callback "(" response ");"))
    +
    +(defn json-response
    +  [data callback & [status]]
    +     {:status (or status 200)
    +      :headers (if (not-nil? callback) {"Content-Type" 
"application/javascript"}
    +                {"Content-Type" "application/json"})
    +      :body (if (not-nil? callback) (add-padding-to-json callback (to-json 
data))
    +                (to-json data))})
    --- End diff --
    
    What if instead of deserializing and re-serializing the cluster conf, we 
rewrite `json-response` as a keyword function:
    
    ```Clojure
    (defnk json-response
      [data callback :serialize-fn to-json :status 200]
      {:status status
       :headers (if (not-nil? callback)
                    {"Content-Type" "application/javascript"}
                    {"Content-Type" "application/json"})
       :body (if (not-nil? callback)
                 (add-padding-to-json callback (serialize-fn data))
                 (serialize-fn data))})
    ```
    
    And then for the route to `/api/v1/cluster/configuration`, we can just call:
    
    ```Clojure
    (GET "/api/v1/cluster/configuration" [& m]
      (json-response (cluster-configuration)
                     (:callback m)
                     :serialize-fn identity))
    ```



> Add JSON-P support to Storm UI API
> ----------------------------------
>
>                 Key: STORM-361
>                 URL: https://issues.apache.org/jira/browse/STORM-361
>             Project: Apache Storm (Incubating)
>          Issue Type: Improvement
>    Affects Versions: 0.9.2-incubating
>            Reporter: Mike Sukmanowsky
>            Assignee: Sriharsha Chintalapani
>            Priority: Minor
>              Labels: api, ui
>
> The recent API that is being released in Storm UI with 0.9.2 is great, but 
> it'd be useful if the API supported an optional {{?callback}} parameter that 
> would provide a wrapped [JSON-P response|http://json-p.org/] for all 
> endpoints.
> *Example:*
> {code}
> GET 
> https://my-storm-head.cogtree.com/api/v1/cluster/summary?callback=myFunction
> myFunction({"stormVersion":"0.9.2-incubating","nimbusUptime":"4m 
> 55s","supervisors":2,"slotsTotal":32,"slotsUsed":0,"slotsFree":32,"executorsTotal":0,"tasksTotal":0});
> {code}
> This would allow users to write clients similar to 
> [elasticsearch-head|https://github.com/mobz/elasticsearch-head] (which I was 
> hoping to build) where they could use a single UI to manage multiple Storm 
> environments.
> Having a JSON-P {{?callback}} param would allow clients to get around 
> browsers enforcing same-origin policies.
> The JSON-P site has examples of valid callback parameters:
> {code}
> functionName({JSON});
> obj.functionName({JSON});
> obj["function-name"]({JSON});
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to