Saturday, September 06, 2014

Clojure and Storm

$ lein repl
(require '[clj-http.client :as client])
(client/get "http://asterdc:8080/api/v1/getfile?name=stream.10.log")
(def stream (client/get "http://node1:8080/api/v1/getfile?name=stream.10.log"))
(require '[clojure.data.json :as json])


user=> (type stream)
clojure.lang.PersistentArrayMap
user=> (keys stream)
(:orig-content-encoding :trace-redirects :request-time :status :headers :body)
user=> (count (:body stream)) ;; count characters in body
20279
user=> (get (.split (:body stream) "\n") 0) ;; get first body from array
"{\"id\":\"tag:search.twitter.com,2005:178204609083473921\",\"body\":\"RT @mikeanikevans: I am such a queer\",\"verb\":\"share\",\"link\":\"http://twitter.com/gthang42069/statuses/178204609083473921\",\"generator\":...{\"klout_score\":27}}\r"
user=> (get (json/read-str (get (.split (:body stream) "\n") 9)) "body")
"@MEMOZ809 No se :("
user=> (keys (json/read-str (get (.split (:body stream) "\n") 9)))
("inReplyTo" "body" "postedTime" "twitter_entities" "gnip" "provider" "generator" "actor" "objectType" "link" "id" "verb" "object")

# run topology from command line (no Storm runtime)
$ lein run -m fiat.topology/run!


lein clear
lein compile
lein jar

To run on a local cluster:

```bash
lein run -m fiat.topology/run!
# OR
lein run -m fiat.topology/run! debug false workers 10
```

To run on a distributed cluster:

```bash
lein uberjar
# copy jar to nimbus, and then on nimbus:
bin/storm jar path/to/uberjar.jar fiat.TopologySubmitter workers 30 debug false
```

Install local Storm jars on master node
```
/usr/lib/maven/bin/mvn deploy:deploy-file  -Dfile=/usr/lib/storm/lib/storm-core-0.9.1.2.1.2.0-402.jar -DartifactId=storm -DgroupId=local -Dversion=0.9.1.2.1.2.0-402 -Dpackaging=jar -Durl=file:repo
```


lein clean; lein deps; lein compile; lein uberjar

No comments: