From ec8d5b0ddd63810a5ad9d5529c75aaf73b9194ff Mon Sep 17 00:00:00 2001 From: Antonio Andelic Date: Mon, 24 Oct 2022 08:12:24 +0000 Subject: [PATCH] Add support for testing different products --- tests/jepsen.clickhouse-keeper/project.clj | 6 +- .../resources/keeper_config.xml | 2 +- .../keeper}/bench.clj | 2 +- .../keeper}/constants.clj | 2 +- .../keeper}/counter.clj | 4 +- .../keeper}/db.clj | 8 +- .../keeper}/main.clj | 121 ++---------------- .../keeper}/nemesis.clj | 6 +- .../keeper}/queue.clj | 4 +- .../keeper}/register.clj | 4 +- .../keeper}/set.clj | 4 +- .../keeper}/unique.clj | 4 +- .../keeper}/utils.clj | 4 +- .../keeper}/zookeeperdb.clj | 4 +- .../src/jepsen/clickhouse/main.clj | 105 +++++++++++++++ .../src/jepsen/clickhouse/server/main.clj | 7 + 16 files changed, 152 insertions(+), 135 deletions(-) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/bench.clj (96%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/constants.clj (94%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/counter.clj (95%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/db.clj (97%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/main.clj (63%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/nemesis.clj (97%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/queue.clj (97%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/register.clj (96%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/set.clj (95%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/unique.clj (93%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/utils.clj (98%) rename tests/jepsen.clickhouse-keeper/src/jepsen/{clickhouse_keeper => clickhouse/keeper}/zookeeperdb.clj (95%) create mode 100644 tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/main.clj create mode 100644 tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/server/main.clj diff --git a/tests/jepsen.clickhouse-keeper/project.clj b/tests/jepsen.clickhouse-keeper/project.clj index 98049835cb1..1f4a762753b 100644 --- a/tests/jepsen.clickhouse-keeper/project.clj +++ b/tests/jepsen.clickhouse-keeper/project.clj @@ -1,10 +1,10 @@ -(defproject jepsen.keeper "0.1.0-SNAPSHOT" +(defproject jepsen.clickhouse "0.1.0-SNAPSHOT" :injections [(.. System (setProperty "zookeeper.request.timeout" "10000"))] - :description "A jepsen tests for ClickHouse Keeper" + :description "A jepsen tests for ClickHouse" :url "https://clickhouse.com/" :license {:name "EPL-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} - :main jepsen.clickhouse-keeper.main + :main jepsen.clickhouse.main :plugins [[lein-cljfmt "0.7.0"]] :dependencies [[org.clojure/clojure "1.10.1"] [jepsen "0.2.7"] diff --git a/tests/jepsen.clickhouse-keeper/resources/keeper_config.xml b/tests/jepsen.clickhouse-keeper/resources/keeper_config.xml index 2ab747fbd71..20ca74c1cf5 100644 --- a/tests/jepsen.clickhouse-keeper/resources/keeper_config.xml +++ b/tests/jepsen.clickhouse-keeper/resources/keeper_config.xml @@ -1,5 +1,5 @@ - :: + 0.0.0.0 trace diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/bench.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/bench.clj similarity index 96% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/bench.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/bench.clj index 040d2eaa77b..d0d30e05650 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/bench.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/bench.clj @@ -1,4 +1,4 @@ -(ns jepsen.clickhouse-keeper.bench +(ns jepsen.clickhouse.keeper.bench (:require [clojure.tools.logging :refer :all] [jepsen [client :as client]]) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/constants.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/constants.clj similarity index 94% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/constants.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/constants.clj index cd62d66e652..0c0116deef3 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/constants.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/constants.clj @@ -1,4 +1,4 @@ -(ns jepsen.clickhouse-keeper.constants) +(ns jepsen.clickhouse.keeper.constants) (def common-prefix "/home/robot-clickhouse") diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/counter.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/counter.clj similarity index 95% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/counter.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/counter.clj index 60b29bd799a..3abb4843287 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/counter.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/counter.clj @@ -1,11 +1,11 @@ -(ns jepsen.clickhouse-keeper.counter +(ns jepsen.clickhouse.keeper.counter (:require [clojure.tools.logging :refer :all] [jepsen [checker :as checker] [client :as client] [generator :as gen]] - [jepsen.clickhouse-keeper.utils :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] [zookeeper :as zk]) (:import (org.apache.zookeeper ZooKeeper KeeperException KeeperException$BadVersionException))) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/db.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/db.clj similarity index 97% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/db.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/db.clj index c354e36e430..861bb434957 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/db.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/db.clj @@ -1,11 +1,11 @@ -(ns jepsen.clickhouse-keeper.db +(ns jepsen.clickhouse.keeper.db (:require [clojure.tools.logging :refer :all] [jepsen [control :as c] [db :as db] [util :as util :refer [meh]]] - [jepsen.clickhouse-keeper.constants :refer :all] - [jepsen.clickhouse-keeper.utils :refer :all] + [jepsen.clickhouse.keeper.constants :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] [clojure.java.io :as io] [jepsen.control.util :as cu] [jepsen.os.ubuntu :as ubuntu])) @@ -30,7 +30,7 @@ [dest])) nil) -(ns jepsen.clickhouse-keeper.db) +(ns jepsen.clickhouse.keeper.db) (defn get-clickhouse-url [url] diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/main.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/main.clj similarity index 63% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/main.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/main.clj index 46fc8651bfe..efbceb314d7 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/main.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/main.clj @@ -1,112 +1,17 @@ -(ns jepsen.control.sshj - (:require [jepsen.control [core :as core] - [sshj :as sshj]] - [slingshot.slingshot :refer [try+ throw+]]) - (:import (net.schmizz.sshj SSHClient - DefaultConfig) - (net.schmizz.sshj.transport.verification PromiscuousVerifier) - (java.util.concurrent Semaphore))) - -(defrecord SSHJRemote [concurrency-limit - conn-spec - ^SSHClient client - ^Semaphore semaphore] - core/Remote - (connect [this conn-spec] - (if (:dummy conn-spec) - (assoc this :conn-spec conn-spec) - (try+ (let [c (as-> (SSHClient.) client - (do - (if (:strict-host-key-checking conn-spec) - (.loadKnownHosts client) - (.addHostKeyVerifier client (PromiscuousVerifier.))) - (.connect client (:host conn-spec) (:port conn-spec)) - (auth! client conn-spec) - client))] - (assoc this - :conn-spec conn-spec - :client c - :semaphore (Semaphore. concurrency-limit true))) - (catch Exception e - ; SSHJ wraps InterruptedException in its own exceptions, so we - ; have to see through that and rethrow properly. - (let [cause (util/ex-root-cause e)] - (when (instance? InterruptedException cause) - (throw cause))) - (throw+ (assoc conn-spec - :type :jepsen.control/session-error - :message "Error opening SSH session. Verify username, password, and node hostnames are correct.")))))) - - (disconnect! [this] - (when-let [c client] - (.close c))) - - (execute! [this ctx action] - ; (info :permits (.availablePermits semaphore)) - (when (:dummy conn-spec) - (throw+ {:type :jepsen.control/dummy})) - (.acquire semaphore) - (sshj/with-errors conn-spec ctx - (try - (with-open [session (.startSession client)] - (let [cmd (.exec session (:cmd action)) - ; Feed it input - _ (when-let [input (:in action)] - (let [stream (.getOutputStream cmd)] - (bs/transfer input stream) - (send-eof! client session) - (.close stream))) - ; Read output - out (.toString (IOUtils/readFully (.getInputStream cmd))) - err (.toString (IOUtils/readFully (.getErrorStream cmd))) - ; Wait on command - _ (.join cmd)] - ; Return completion - (assoc action - :out out - :err err - ; There's also a .getExitErrorMessage that might be - ; interesting here? - :exit (.getExitStatus cmd)))) - (finally - (.release semaphore))))) - - (upload! [this ctx local-paths remote-path _opts] - (when (:dummy conn-spec) - (throw+ {:type :jepsen.control/dummy})) - (with-errors conn-spec ctx - (with-open [sftp (.newSFTPClient client)] - (.put sftp (FileSystemFile. local-paths) remote-path)))) - - (download! [this ctx remote-paths local-path _opts] - (when (:dummy conn-spec) - (throw+ {:type :jepsen.control/dummy})) - (with-errors conn-spec ctx - (with-open [sftp (.newSFTPClient client)] - (.get sftp remote-paths (FileSystemFile. local-path)))))) - -(defn remote - "Constructs an SSHJ remote." - [] - (-> (SSHJRemote. concurrency-limit nil nil nil) - ; We *can* use our own SCP, but shelling out is faster. - scp/remote - retry/remote)) - -(ns jepsen.clickhouse-keeper.main +(ns jepsen.clickhouse.keeper.main (:require [clojure.tools.logging :refer :all] - [jepsen.clickhouse-keeper.utils :refer :all] [clojure.pprint :refer [pprint]] - [jepsen.clickhouse-keeper.set :as set] - [jepsen.clickhouse-keeper.db :refer :all] - [jepsen.clickhouse-keeper.zookeeperdb :refer :all] - [jepsen.clickhouse-keeper.nemesis :as custom-nemesis] - [jepsen.clickhouse-keeper.register :as register] - [jepsen.clickhouse-keeper.unique :as unique] - [jepsen.clickhouse-keeper.queue :as queue] - [jepsen.clickhouse-keeper.counter :as counter] - [jepsen.clickhouse-keeper.bench :as bench] - [jepsen.clickhouse-keeper.constants :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] + [jepsen.clickhouse.keeper.set :as set] + [jepsen.clickhouse.keeper.db :refer :all] + [jepsen.clickhouse.keeper.zookeeperdb :refer :all] + [jepsen.clickhouse.keeper.nemesis :as custom-nemesis] + [jepsen.clickhouse.keeper.register :as register] + [jepsen.clickhouse.keeper.unique :as unique] + [jepsen.clickhouse.keeper.queue :as queue] + [jepsen.clickhouse.keeper.counter :as counter] + [jepsen.clickhouse.keeper.bench :as bench] + [jepsen.clickhouse.keeper.constants :refer :all] [clojure.string :as str] [jepsen [checker :as checker] @@ -281,7 +186,7 @@ (map test-fn (all-test-options cli (cart [lightweight-workloads useful-nemesises]))) (map test-fn (all-test-options cli (cart [all-workloads all-nemesises]))))) -(defn -main +(defn main "Handles command line arguments. Can either run a test, or a web server for browsing results." [& args] diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/nemesis.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/nemesis.clj similarity index 97% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/nemesis.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/nemesis.clj index caf59d3a25f..1048d19e28f 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/nemesis.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/nemesis.clj @@ -1,12 +1,12 @@ -(ns jepsen.clickhouse-keeper.nemesis +(ns jepsen.clickhouse.keeper.nemesis (:require [clojure.tools.logging :refer :all] [jepsen [nemesis :as nemesis] [control :as c] [generator :as gen]] - [jepsen.clickhouse-keeper.constants :refer :all] - [jepsen.clickhouse-keeper.utils :refer :all])) + [jepsen.clickhouse.keeper.constants :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all])) (defn random-node-killer-nemesis [] diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/queue.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/queue.clj similarity index 97% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/queue.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/queue.clj index 1c306a0ff04..3c7c16de90e 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/queue.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/queue.clj @@ -1,4 +1,4 @@ -(ns jepsen.clickhouse-keeper.queue +(ns jepsen.clickhouse.keeper.queue (:require [clojure.tools.logging :refer :all] [jepsen @@ -7,7 +7,7 @@ [generator :as gen]] [knossos.model :as model] [jepsen.checker.timeline :as timeline] - [jepsen.clickhouse-keeper.utils :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] [zookeeper :as zk]) (:import (org.apache.zookeeper ZooKeeper KeeperException KeeperException$BadVersionException))) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/register.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/register.clj similarity index 96% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/register.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/register.clj index a1605192b51..ab3c39be945 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/register.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/register.clj @@ -1,4 +1,4 @@ -(ns jepsen.clickhouse-keeper.register +(ns jepsen.clickhouse.keeper.register (:require [jepsen [checker :as checker] [client :as client] @@ -6,7 +6,7 @@ [generator :as gen]] [jepsen.checker.timeline :as timeline] [knossos.model :as model] - [jepsen.clickhouse-keeper.utils :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] [zookeeper :as zk]) (:import (org.apache.zookeeper ZooKeeper KeeperException KeeperException$BadVersionException))) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/set.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/set.clj similarity index 95% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/set.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/set.clj index b992a6abcbb..12450ab5ff6 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/set.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/set.clj @@ -1,11 +1,11 @@ -(ns jepsen.clickhouse-keeper.set +(ns jepsen.clickhouse.keeper.set (:require [clojure.tools.logging :refer :all] [jepsen [checker :as checker] [client :as client] [generator :as gen]] - [jepsen.clickhouse-keeper.utils :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] [zookeeper :as zk]) (:import (org.apache.zookeeper ZooKeeper KeeperException KeeperException$BadVersionException))) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/unique.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/unique.clj similarity index 93% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/unique.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/unique.clj index 752240722d8..89c5f9ccb3a 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/unique.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/unique.clj @@ -1,11 +1,11 @@ -(ns jepsen.clickhouse-keeper.unique +(ns jepsen.clickhouse.keeper.unique (:require [clojure.tools.logging :refer :all] [jepsen [checker :as checker] [client :as client] [generator :as gen]] - [jepsen.clickhouse-keeper.utils :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] [zookeeper :as zk]) (:import (org.apache.zookeeper ZooKeeper KeeperException KeeperException$BadVersionException))) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/utils.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/utils.clj similarity index 98% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/utils.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/utils.clj index 3625b24b4f9..bf1a82faf21 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/utils.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/utils.clj @@ -1,10 +1,10 @@ -(ns jepsen.clickhouse-keeper.utils +(ns jepsen.clickhouse.keeper.utils (:require [clojure.string :as str] [zookeeper.data :as data] [zookeeper :as zk] [zookeeper.internal :as zi] [jepsen.control.util :as cu] - [jepsen.clickhouse-keeper.constants :refer :all] + [jepsen.clickhouse.keeper.constants :refer :all] [jepsen.control :as c] [clojure.tools.logging :refer :all] [clojure.java.io :as io]) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/zookeeperdb.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/zookeeperdb.clj similarity index 95% rename from tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/zookeeperdb.clj rename to tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/zookeeperdb.clj index 7cb88cd1fd9..6712b35fb24 100644 --- a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse_keeper/zookeeperdb.clj +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/keeper/zookeeperdb.clj @@ -1,6 +1,6 @@ -(ns jepsen.clickhouse-keeper.zookeeperdb +(ns jepsen.clickhouse.keeper.zookeeperdb (:require [clojure.tools.logging :refer :all] - [jepsen.clickhouse-keeper.utils :refer :all] + [jepsen.clickhouse.keeper.utils :refer :all] [clojure.java.io :as io] [jepsen [control :as c] diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/main.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/main.clj new file mode 100644 index 00000000000..74e47115b48 --- /dev/null +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/main.clj @@ -0,0 +1,105 @@ +(ns jepsen.control.sshj + (:require [jepsen.control [core :as core] + [sshj :as sshj]] + [slingshot.slingshot :refer [try+ throw+]]) + (:import (net.schmizz.sshj SSHClient + DefaultConfig) + (net.schmizz.sshj.transport.verification PromiscuousVerifier) + (java.util.concurrent Semaphore))) + +(defrecord SSHJRemote [concurrency-limit + conn-spec + ^SSHClient client + ^Semaphore semaphore] + core/Remote + (connect [this conn-spec] + (if (:dummy conn-spec) + (assoc this :conn-spec conn-spec) + (try+ (let [c (as-> (SSHClient.) client + (do + (if (:strict-host-key-checking conn-spec) + (.loadKnownHosts client) + (.addHostKeyVerifier client (PromiscuousVerifier.))) + (.connect client (:host conn-spec) (:port conn-spec)) + (auth! client conn-spec) + client))] + (assoc this + :conn-spec conn-spec + :client c + :semaphore (Semaphore. concurrency-limit true))) + (catch Exception e + ; SSHJ wraps InterruptedException in its own exceptions, so we + ; have to see through that and rethrow properly. + (let [cause (util/ex-root-cause e)] + (when (instance? InterruptedException cause) + (throw cause))) + (throw+ (assoc conn-spec + :type :jepsen.control/session-error + :message "Error opening SSH session. Verify username, password, and node hostnames are correct.")))))) + + (disconnect! [this] + (when-let [c client] + (.close c))) + + (execute! [this ctx action] + ; (info :permits (.availablePermits semaphore)) + (when (:dummy conn-spec) + (throw+ {:type :jepsen.control/dummy})) + (.acquire semaphore) + (sshj/with-errors conn-spec ctx + (try + (with-open [session (.startSession client)] + (let [cmd (.exec session (:cmd action)) + ; Feed it input + _ (when-let [input (:in action)] + (let [stream (.getOutputStream cmd)] + (bs/transfer input stream) + (send-eof! client session) + (.close stream))) + ; Read output + out (.toString (IOUtils/readFully (.getInputStream cmd))) + err (.toString (IOUtils/readFully (.getErrorStream cmd))) + ; Wait on command + _ (.join cmd)] + ; Return completion + (assoc action + :out out + :err err + ; There's also a .getExitErrorMessage that might be + ; interesting here? + :exit (.getExitStatus cmd)))) + (finally + (.release semaphore))))) + + (upload! [this ctx local-paths remote-path _opts] + (when (:dummy conn-spec) + (throw+ {:type :jepsen.control/dummy})) + (with-errors conn-spec ctx + (with-open [sftp (.newSFTPClient client)] + (.put sftp (FileSystemFile. local-paths) remote-path)))) + + (download! [this ctx remote-paths local-path _opts] + (when (:dummy conn-spec) + (throw+ {:type :jepsen.control/dummy})) + (with-errors conn-spec ctx + (with-open [sftp (.newSFTPClient client)] + (.get sftp remote-paths (FileSystemFile. local-path)))))) + +(defn remote + "Constructs an SSHJ remote." + [] + (-> (SSHJRemote. concurrency-limit nil nil nil) + ; We *can* use our own SCP, but shelling out is faster. + scp/remote + retry/remote)) + +(ns jepsen.clickhouse.main + (:require [jepsen.clickhouse.keeper.main] + [jepsen.clickhouse.server.main])) + +(defn -main + [product & args] + (case product + "keeper" (apply jepsen.clickhouse.keeper.main/main args) + "server" (apply jepsen.clickhouse.server.main/main args) + (throw (Exception. (str "Unknown option specified: " product))))) diff --git a/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/server/main.clj b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/server/main.clj new file mode 100644 index 00000000000..1b7ba0190d0 --- /dev/null +++ b/tests/jepsen.clickhouse-keeper/src/jepsen/clickhouse/server/main.clj @@ -0,0 +1,7 @@ +(ns jepsen.clickhouse.server.main) + +(defn main + "Handles command line arguments. Can either run a test, or a web server for + browsing results." + [& args] + (print "Not yet implemented" args))