Skip to content

Commit 5f77f00

Browse files
committed
refactoring
1 parent a9a8171 commit 5f77f00

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

.github/workflows/cluster-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
- name: Setup Java
9595
uses: actions/setup-java@v5
9696
with:
97-
java-version: '11'
97+
java-version: '21'
9898
distribution: 'temurin'
9999

100100
- name: Install leiningen

scalardb/src/scalardb/db/cluster.clj

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353

5454
:imagePullSecrets [{:name "scalardb-ghcr-secret"}]}})
5555

56+
(defn- throw-unsupported-db-error
57+
[db-type]
58+
(throw (ex-info "Unsupported DB for ScalarDB Cluster test" {:db db-type})))
59+
5660
(defn- update-cluster-values
5761
[test values]
5862
(let [path [:scalardbCluster :scalardbClusterNodeProperties]
@@ -91,7 +95,7 @@
9195
(case db-type
9296
:postgres (c/exec :helm :repo :add
9397
"bitnami" "https://charts.bitnami.com/bitnami")
94-
(throw (ex-info "Unsupported DB for ScalarDB Cluster" {:db db-type})))
98+
(throw-unsupported-db-error db-type))
9599
;; ScalarDB cluster
96100
(c/exec :helm :repo :add
97101
"scalar-labs" "https://scalar-labs.github.io/helm-charts")
@@ -102,15 +106,16 @@
102106

103107
(defn- configure!
104108
[]
105-
(binding [c/*dir* (System/getProperty "user.dir")]
106-
(try
107-
(c/exec :kubectl :delete :secret "scalardb-ghcr-secret")
109+
(when (and (seq (env :docker-username)) (seq (env :docker-access-token)))
110+
(binding [c/*dir* (System/getProperty "user.dir")]
111+
(try
112+
(c/exec :kubectl :delete :secret "scalardb-ghcr-secret")
108113
;; ignore the failure when the secret doesn't exist
109-
(catch Exception _))
110-
(c/exec :kubectl :create :secret :docker-registry "scalardb-ghcr-secret"
111-
"--docker-server=ghcr.io"
112-
(str "--docker-username=" (env :docker-username))
113-
(str "--docker-password=" (env :docker-access-token))))
114+
(catch Exception _))
115+
(c/exec :kubectl :create :secret :docker-registry "scalardb-ghcr-secret"
116+
"--docker-server=ghcr.io"
117+
(str "--docker-username=" (env :docker-username))
118+
(str "--docker-password=" (env :docker-access-token)))))
114119

115120
;; Chaos Mesh
116121
(try
@@ -134,7 +139,7 @@
134139
:--set "metrics.image.repository=bitnamilegacy/postgres-exporter"
135140
:--set "global.security.allowInsecureImages=true"
136141
:--version "16.7.0")
137-
(throw (ex-info "Unsupported DB for ScalarDB Cluster" {:db db-type})))
142+
(throw-unsupported-db-error db-type))
138143

139144
;; ScalarDB Cluster
140145
(let [chart-version (or (some-> (env :helm-chart-version) not-empty)
@@ -170,14 +175,13 @@
170175
(apply c/exec :rm :-f))
171176
(catch Exception _ nil)))
172177
(info "wiping the pods...")
173-
(try (c/exec :helm :uninstall POSTGRESQL_NAME) (catch Exception _ nil))
174-
(try (c/exec :kubectl :delete
175-
:pvc :-l "app.kubernetes.io/instance=postgresql-scalardb-cluster")
176-
(catch Exception _ nil))
177-
(try (c/exec :helm :uninstall CLUSTER_NAME) (catch Exception _ nil))
178-
(try (c/exec :helm :uninstall CLUSTER2_NAME) (catch Exception _ nil))
179-
(try (c/exec :helm :uninstall "chaos-mesh" :-n "chaos-mesh")
180-
(catch Exception _ nil)))
178+
(doseq [cmd [[:helm :uninstall POSTGRESQL_NAME]
179+
[:kubectl :delete
180+
:pvc :-l "app.kubernetes.io/instance=postgresql-scalardb-cluster"]
181+
[:helm :uninstall CLUSTER_NAME]
182+
[:helm :uninstall CLUSTER2_NAME]
183+
[:helm :uninstall "chaos-mesh" :-n "chaos-mesh"]]]
184+
(try (apply c/exec cmd) (catch Exception _ nil))))
181185

182186
(defn- get-pod-list
183187
[name]
@@ -313,8 +317,7 @@
313317
(str "jdbc:postgresql://" ip ":5432/postgres"))
314318
(.setProperty "scalar.db.username" "postgres")
315319
(.setProperty "scalar.db.password" "postgres")))
316-
(throw (ex-info "Unsupported DB for ScalarDB Cluster"
317-
{:db db-type}))))))
320+
(throw-unsupported-db-error db-type)))))
318321

319322
(defn gen-db
320323
[faults admin db-type]

scalardb/src/scalardb/runner.clj

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,17 @@
9292
(into (map name admin))
9393
(->> (remove nil?) (string/join "-"))))
9494

95-
(defn- load-module
96-
[db-type]
97-
(if (= (env :cluster?) "true")
98-
(require 'scalardb.db.cluster)
99-
(case db-type
100-
:cassandra (require 'scalardb.db.cassandra)
101-
:postgres (require 'scalardb.db.postgres)
102-
(throw (ex-info "Unsupported DB" {:db db-type})))))
103-
10495
(defn- gen-db
10596
"Returns [extended-db constructed-nemesis num-max-nodes]."
10697
[db-type faults admin]
107-
(load-module db-type)
10898
(let [gen-db-sym (if (= (env :cluster?) "true")
109-
'scalardb.db.cluster/gen-db
99+
(do (require 'scalardb.db.cluster)
100+
'scalardb.db.cluster/gen-db)
110101
(case db-type
111-
:cassandra 'scalardb.db.cassandra/gen-db
112-
:postgres 'scalardb.db.postgres/gen-db
102+
:cassandra (do (require 'scalardb.db.cassandra)
103+
'scalardb.db.cassandra/gen-db)
104+
:postgres (do (require 'scalardb.db.postgres)
105+
'scalardb.db.postgres/gen-db)
113106
(throw (ex-info "Unsupported DB" {:db db-type}))))
114107
gen-db-fn (resolve gen-db-sym)]
115108
(gen-db-fn faults admin db-type)))

0 commit comments

Comments
 (0)