Skip to content

Commit 52f051d

Browse files
committed
Issue #2: If default Zookeeper port is not available when running Local Mode, then use an arbitrary available port instead.
1 parent 5b9820a commit 52f051d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/clj/backtype/storm/testing.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
;; can customize the supervisors (except for ports) by passing in map for :supervisors parameter
8989
;; if need to customize amt of ports more, can use add-supervisor calls afterwards
9090
(defnk mk-local-storm-cluster [:supervisors 2 :ports-per-supervisor 3 :daemon-conf {}]
91-
(let [zk-port 2181
91+
(let [zk-port (available-port 2181)
9292
daemon-conf (merge (read-storm-config)
9393
{TOPOLOGY-SKIP-MISSING-SERIALIZATIONS true
9494
ZMQ-LINGER-MILLIS 0

src/clj/backtype/storm/util.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
(defn local-hostname []
2323
(.getCanonicalHostName (InetAddress/getLocalHost)))
2424

25+
(letfn [(try-port [port]
26+
(with-open [socket (java.net.ServerSocket. port)]
27+
(.getLocalPort socket)))]
28+
(defn available-port
29+
([] (try-port 0))
30+
([preferred]
31+
(try
32+
(try-port preferred)
33+
(catch java.io.IOException e
34+
(available-port))))))
35+
2536
(defn uuid []
2637
(str (UUID/randomUUID)))
2738

0 commit comments

Comments
 (0)