Skip to content

Commit

Permalink
tested module :cargo-qdrant
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Mar 22, 2024
1 parent 9e55f74 commit bdf1f4c
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 31 deletions.
66 changes: 56 additions & 10 deletions src/main/resources/com/github/jlangch/venice/cargo-arangodb.venice
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@

(defn
^{ :arglists '(
"(cargo-arangodb/start cname version mapped-port root-passwd memory cores log)")
"(cargo-arangodb/start cname version mapped-port root-passwd memory cores log)"
"(cargo-arangodb/start cname version volumes mapped-port root-passwd memory cores log)")
:doc """
Starts an ArangoDB container.

Expand Down Expand Up @@ -81,6 +82,7 @@
(ca/start "db-test" "3.11.4" 8500 "test" "8GB" 1 nil))
""")
:see-also '(
"cargo-arangodb/logs"
"cargo-arangodb/stop"
"cargo-arangodb/running?") }

Expand Down Expand Up @@ -128,7 +130,9 @@


(defn
^{ :arglists '("(cargo-arangodb/stop cname log)")
^{ :arglists '(
"(cargo-arangodb/stop cname)"
"(cargo-arangodb/stop cname log)")
:doc """
Stops an ArangoDB container

Expand All @@ -150,12 +154,15 @@
"cargo-arangodb/start"
"cargo-arangodb/running?") }

stop [cname log]

{ :pre [(string? cname)] }
stop

(let [log (or log default-log)]
(cargo/stop cname log)))
([cname]
(stop cname nil))

([cname log]
{ :pre [(string? cname)] }
(let [log (or log default-log)]
(cargo/stop cname log))))


(defn
Expand All @@ -171,11 +178,13 @@
"""
;; Test if ArangoDB container is running
(do
(load-module :cargo-arangodb)
(cargo-arangodb/running? "db-test"))
(load-module :cargo-arangodb ['cargo-arangodb :as 'ca])
(ca/running? "db-test"))
""")
:see-also '(
"cargo-arangodb/start", "cargo-arangodb/stop") }
"cargo-arangodb/logs"
"cargo-arangodb/start",
"cargo-arangodb/stop") }

running? [cname]

Expand All @@ -184,6 +193,43 @@
(docker/container-running-with-name? cname))


(defn
^{ :arglists '(
"(cargo-arangodb/logs cname)"
"(cargo-arangodb/logs cname lines)")
:doc """
Prints the ArangoDB docker container logs

Args:

| cname | A unique container name |
| lines | The number of tail lines. Defaults to 100 |
"""
:examples '(
"""
(do
(load-module :cargo-arangodb ['cargo-arangodb :as 'ca])
(ca/logs "db-test"))
""",
"""
(do
(load-module :cargo-arangodb ['cargo-arangodb :as 'ca])
(ca/logs "db-test" 100))
""")
:see-also '(
"cargo-arangodb/start"
"cargo-arangodb/running?") }

logs

([cname]
(logs cname 100))

([cname lines]
(->> (docker/container-logs cname :tail lines)
(println))))



;; ---------------------------------------------------------------------------
;; ArangoDB dump & restore databases
Expand Down
98 changes: 77 additions & 21 deletions src/main/resources/com/github/jlangch/venice/cargo-qdrant.venice
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
;;;; This is just a configuration wrapper on top of the :cargo module to
;;;; simplify using Qdrant testcontainers

;;;; docker run -p 6333:6333 -p 6334:6334 \
;;;; -v /data/qdrant-storage:/qdrant/storage:z \
;;;; qdrant/qdrant

(ns cargo-qdrant)

(load-module :docker)
Expand All @@ -45,7 +49,9 @@

(defn
^{ :arglists '(
"(cargo-qdrant/start cname version storage-dir)")
"(cargo-qdrant/start cname version storage-dir)"
"(cargo-qdrant/start cname version storage-dir config-file log)"
"(cargo-qdrant/start cname version mapped-rest-port mapped-grpc-port storage-dir config-file log)")
:doc """
Starts a Qdrant container.

Expand Down Expand Up @@ -87,10 +93,14 @@
""")
:see-also '(
"cargo-qdrant/stop"
"cargo-qdrant/running?") }
"cargo-qdrant/running?"
"cargo-qdrant/logs") }

start


([cname version storage-dir]
(start cname version storage-dir nil nil))

([cname version storage-dir config-file log]
(start cname
version
Expand All @@ -113,17 +123,17 @@
(string? config-file)
(io/file? config-file))] }
(when-not (io/exists-dir? storage-dir)
(throw :VncException
"The Qdrant storage directory \"~{storage-dir}\" does not exist!"))
(when-not (and (some? config-file) (io/exists-file? config-file))
(throw :VncException
"The Qdrant config file \"~{config-file}\" does not exist!"))
(throw (ex :VncException
"The Qdrant storage directory \"~(io/file-canonical storage-dir)\" does not exist!")))
(when (and (some? config-file) (not (io/exists-file? config-file)))
(throw (ex :VncException
"The Qdrant config file \"~(io/file-canonical config-file)\" does not exist!")))
(let [publish ["~{mapped-rest-port}:~{internal-rest-port}"
"~{mapped-grpc-port}:~{internal-grpc-port}"]
envs []
volumes (if (nil? config-file)
["~{storage-dir}:/qdrant/storage"]
["~{storage-dir}:/qdrant/storage"
["~{storage-dir}:/qdrant/storage:z"]
["~{storage-dir}:/qdrant/storage:z"
"~{config-file}:/qdrant/config/production.yaml"])
args []
log (or log default-log)
Expand All @@ -142,9 +152,11 @@


(defn
^{ :arglists '("(cargo-qdrant/stop cname log)")
^{ :arglists '(
"(cargo-qdrant/stop cname)"
"(cargo-qdrant/stop cname log)")
:doc """
Stops an Qdrant container
Stops a Qdrant container

Args:

Expand All @@ -162,12 +174,15 @@
"cargo-qdrant/start"
"cargo-qdrant/running?") }

stop [cname log]

{ :pre [(string? cname)] }
stop

([cname]
(stop cname nil))

(let [log (or log default-log)]
(cargo/stop cname log)))
([cname log]
{ :pre [(string? cname)] }
(let [log (or log default-log)]
(cargo/stop cname log))))


(defn
Expand All @@ -186,7 +201,8 @@
(load-module :cargo-qdrant ['cargo-qdrant :as 'cq])
(cq/running? "qdrant"))
""")
:see-also '(
:see-also '(
"cargo-qdrant/logs"
"cargo-qdrant/start",
"cargo-qdrant/stop") }

Expand All @@ -197,6 +213,43 @@
(docker/container-running-with-name? cname))


(defn
^{ :arglists '(
"(cargo-qdrant/logs cname)"
"(cargo-qdrant/logs cname lines)")
:doc """
Prints the Qdrant docker container logs

Args:

| cname | A unique container name |
| lines | The number of tail lines. Defaults to 100 |
"""
:examples '(
"""
(do
(load-module :cargo-qdrant ['cargo-qdrant :as 'cq])
(cq/logs "qdrant"))
""",
"""
(do
(load-module :cargo-qdrant ['cargo-qdrant :as 'cq])
(cq/logs "qdrant" 100))
""")
:see-also '(
"cargo-qdrant/start"
"cargo-qdrant/running?") }

logs

([cname]
(logs cname 100))

([cname lines]
(->> (docker/container-logs cname :tail lines)
(println))))



;; ---------------------------------------------------------------------------
;; utils
Expand All @@ -206,9 +259,12 @@
(println "Qdrant:" s))

(defn qdrant-ready? [cname]
(-> (docker/container-logs cname :tail 1)
(str/trim)
(match? #".*is ready for business. Have fun.*")))
(->> (docker/container-logs cname :tail 100)
(str/split-lines)
(map str/trim)
(filter #(match? % #".*Qdrant HTTP listening on [0-9]{4}.*"))
(count)
(pos?)))

(defn dir-empty? [dir]
(zero? (count (io/list-files dir))))
Expand Down

0 comments on commit bdf1f4c

Please sign in to comment.