Created
December 27, 2017 17:23
-
-
Save GEverding/97a9eaa65417aaa66fe3ff58b6c9cced to your computer and use it in GitHub Desktop.
Atomix Bootstrap Cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.geverding.hermes.cluster.core | |
(:require [mount.core :as mount] | |
[clojure.tools.logging :as log] | |
[com.rave.hermes.config :refer (config)]) | |
(:import io.atomix.core.Atomix | |
io.atomix.cluster.Node | |
io.atomix.cluster.Node$Type | |
io.atomix.messaging.Endpoint | |
)) | |
(defn- node-builder [name host port] | |
(log/infof "Creating Node name=%s host=%s port=%s" name host port) | |
(-> (Node/builder name) | |
(.withType Node$Type/DATA) | |
(.withEndpoint (Endpoint/from host port)) | |
(.build))) | |
(defn start [] | |
(log/info "Starting Cluster") | |
(let [nodes (->> (get-in config [:cluster :bootstrap-nodes]) | |
(map (fn [{:keys [name host port]}] | |
(node-builder name host port))) | |
(into-array Node)) | |
local-node (node-builder (get-in config [:cluster :name]) | |
"localhost" | |
(get-in config [:cluster :port])) | |
_ (log/info local-node) | |
atomix (-> (Atomix/builder) | |
(.withClusterName "test") | |
(.withLocalNode local-node) | |
(.withBootstrapNodes nodes) | |
(.build)) | |
a (.get (.start atomix) 10 java.util.concurrent.TimeUnit/SECONDS)] | |
(log/info "Started Cluster") | |
a)) | |
(defn stop [cluster] | |
(log/info "Stopping Cluster")) | |
(mount/defstate cluster | |
:start (start) | |
:stop (stop cluster)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment