Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping all curator exceptions in RuntimeExceptions. #671

Merged
merged 3 commits into from
Sep 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions storm-core/src/clj/backtype/storm/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
(:use [backtype.storm log])
)

(defn wrap-in-runtime
"Wraps an exception in a RuntimeException if needed"
[^Exception e]
(if (instance? RuntimeException e)
e
(RuntimeException. e)))

(defmacro defalias
"Defines an alias for a var: a new var with the same root binding (if
any) and similar metadata. The metadata of the alias is its initial
Expand Down
31 changes: 20 additions & 11 deletions storm-core/src/clj/backtype/storm/zookeeper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,25 @@

(defn create-node
([^CuratorFramework zk ^String path ^bytes data mode]
(.. zk (create) (withMode (zk-create-modes mode)) (withACL ZooDefs$Ids/OPEN_ACL_UNSAFE) (forPath (normalize-path path) data)))
(try
(.. zk (create) (withMode (zk-create-modes mode)) (withACL ZooDefs$Ids/OPEN_ACL_UNSAFE) (forPath (normalize-path path) data))
(catch Exception e (throw (wrap-in-runtime e)))))
([^CuratorFramework zk ^String path ^bytes data]
(create-node zk path data :persistent)))

(defn exists-node? [^CuratorFramework zk ^String path watch?]
((complement nil?)
(if watch?
(.. zk (checkExists) (watched) (forPath (normalize-path path)))
(.. zk (checkExists) (forPath (normalize-path path))))))
(try
(if watch?
(.. zk (checkExists) (watched) (forPath (normalize-path path)))
(.. zk (checkExists) (forPath (normalize-path path))))
(catch Exception e (throw (wrap-in-runtime e))))))

(defnk delete-node [^CuratorFramework zk ^String path :force false]
(try-cause (.. zk (delete) (forPath (normalize-path path)))
(catch KeeperException$NoNodeException e
(when-not force (throw e))
)))
(when-not force (throw e)))
(catch Exception e (throw (wrap-in-runtime e)))))

(defn mkdirs [^CuratorFramework zk ^String path]
(let [path (normalize-path path)]
Expand All @@ -103,15 +107,20 @@
(.. zk (getData) (forPath path))))
(catch KeeperException$NoNodeException e
;; this is fine b/c we still have a watch from the successful exists call
nil ))))
nil )
(catch Exception e (throw (wrap-in-runtime e))))))

(defn get-children [^CuratorFramework zk ^String path watch?]
(if watch?
(.. zk (getChildren) (watched) (forPath (normalize-path path)))
(.. zk (getChildren) (forPath (normalize-path path)))))
(try
(if watch?
(.. zk (getChildren) (watched) (forPath (normalize-path path)))
(.. zk (getChildren) (forPath (normalize-path path))))
(catch Exception e (throw (wrap-in-runtime e)))))

(defn set-data [^CuratorFramework zk ^String path ^bytes data]
(.. zk (setData) (forPath (normalize-path path) data)))
(try
(.. zk (setData) (forPath (normalize-path path) data))
(catch Exception e (throw (wrap-in-runtime e)))))

(defn exists [^CuratorFramework zk ^String path watch?]
(exists-node? zk path watch?))
Expand Down