Skip to content

Commit

Permalink
Remove the last parts of dynamic var-based connection API
Browse files Browse the repository at this point in the history
References #80.
  • Loading branch information
michaelklishin committed Apr 25, 2014
1 parent d5f8da0 commit 1c7ad25
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 75 deletions.
108 changes: 40 additions & 68 deletions src/clojurewerkz/elastisch/native.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,74 +48,6 @@
org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest
org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest))



;;
;; Implementation
;;

(def ^{:dynamic true}
*client*)

;;
;; API
;;

(defn ^Client connect
"Connects to one or more ElasticSearch cluster nodes using
TCP/IP communication transport. Returns the client."
([]
(TransportClient.))
([pairs]
(let [tc (TransportClient.)]
(doseq [[host port] pairs]
(.addTransportAddress tc (cnv/->socket-transport-address host port)))
tc))
([pairs settings]
(let [tc (TransportClient. (cnv/->settings settings))]
(doseq [[host port] pairs]
(.addTransportAddress tc (cnv/->socket-transport-address host port)))
tc)))

(defn ^Client connect!
"Connects to one or more ElasticSearch cluster nodes using
TCP/IP communication transport. Alters the *client* var root."
[& args]
(alter-var-root (var *client*) (constantly (apply connect args))))

(defn ^Node build-local-node
[settings]
(let [is (cnv/->settings settings)
nb (.. NodeBuilder nodeBuilder
(settings is)
(client true))]
(.build ^NodeBuilder nb)))

(defn ^Thread start-local-node
[^Node node]
(.start node)
node)

(defn ^Client connect-to-local-node
"Connects to a local ElasticSearch cluster nodes using
local transport. Returns the client. Supposed to be used for automated testing."
[^Node node]
(.client node))

(defn ^Client connect-to-local-node!
"Connects to one or more local ElasticSearch cluster nodes using
local transport. Returns the client. Alters the *client* var root.
Supposed to be used for automated testing."
[^Node node]
(alter-var-root (var *client*) (constantly (connect-to-local-node node))))

(defn connected?
"Returns true if current client is connected (*client* is bound)"
[]
(bound? (var *client*)))



;;
;; Core
;;
Expand Down Expand Up @@ -284,3 +216,43 @@
"Executes a delete index template request"
[^Client conn ^DeleteIndexTemplateRequest req]
(-> ^Client conn .admin .indices (.deleteTemplate req)))


;;
;; API
;;

(defn ^Client connect
"Connects to one or more ElasticSearch cluster nodes using
TCP/IP communication transport. Returns the client."
([]
(TransportClient.))
([pairs]
(let [tc (TransportClient.)]
(doseq [[host port] pairs]
(.addTransportAddress tc (cnv/->socket-transport-address host port)))
tc))
([pairs settings]
(let [tc (TransportClient. (cnv/->settings settings))]
(doseq [[host port] pairs]
(.addTransportAddress tc (cnv/->socket-transport-address host port)))
tc)))

(defn ^Node build-local-node
[settings]
(let [is (cnv/->settings settings)
nb (.. NodeBuilder nodeBuilder
(settings is)
(client true))]
(.build ^NodeBuilder nb)))

(defn ^Thread start-local-node
[^Node node]
(.start node)
node)

(defn ^Client connect-to-local-node
"Connects to a local ElasticSearch cluster nodes using
local transport. Returns the client. Supposed to be used for automated testing."
[^Node node]
(.client node))
9 changes: 2 additions & 7 deletions test/clojurewerkz/elastisch/test/helpers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,5 @@
([]
(connect-native-client (infer-cluster-name)))
([cluster-name]
(es/connect! [["127.0.0.1" 9300]]
{"cluster.name" cluster-name })))

(defn maybe-connect-native-client
[]
(when (not (es/connected?))
(connect-native-client)))
(es/connect [["127.0.0.1" 9300]]
{"cluster.name" cluster-name})))

0 comments on commit 1c7ad25

Please sign in to comment.