blob: 72744ea99cae7ab8e2c76e3033d0492a05ed29c1 [file] [log] [blame]
Max-Gerd Retzlaff04057ac2022-08-23 17:38:34 +02001(in-package :cl-user)
2
3#+(or ccl sbcl) /development/source/library/
4(load "build-init.lisp")
5
6;;; ! first, select the api version in the cassandra system definition
7;;; as only one should be loaded at a time.
8(asdf:load-system :de.setf.cassandra)
9
10(in-package :de.setf.cassandra)
11
12(defparameter *c-location*
13 ;; remote
14 ;; #u"thrift://ec2-174-129-66-148.compute-1.amazonaws.com:9160"
15 ;; local
16 #u"thrift://127.0.0.1:9160"
17 "A cassandra service location - either the local one or a remote service
18 - always a 'thrift' uri.")
19
20(defparameter *c* (thrift:client *c-location*))
21
22
23(cassandra:describe-keyspaces *c*)
24;; => ("Keyspace1" "system")
25
26(cassandra:describe-cluster-name *c*)
27;; =>"Test Cluster"
28
29(cassandra:describe-version *c*)
30;; => "2.1.0"
31
32(loop for space in (cassandra:describe-keyspaces *c*)
33 collect (loop for key being each hash-key of (cassandra:describe-keyspace *c* space)
34 using (hash-value value)
35 collect (cons key
36 (loop for key being each hash-key of value
37 using (hash-value value)
38 collect (cons key value)))))
39
40
41(close *c*)
42
43(defun describe-cassandra (location &optional (stream *standard-output*))
44 "Print the first-order store metadata for a cassandra LOCATION."
45
46 (thrift:with-client (cassandra location)
47 (let* ((keyspace-names (cassandra:describe-keyspaces cassandra))
48 (cluster (cassandra:describe-cluster-name cassandra))
49 (version (cassandra:describe-version cassandra))
50 (keyspace-descriptions (loop for space in keyspace-names
51 collect (cons space
52 (loop for key being each hash-key
53 of (cassandra:describe-keyspace cassandra space)
54 using (hash-value value)
55 collect (cons key
56 (loop for key being each hash-key of value
57 using (hash-value value)
58 collect (cons key value))))))))
59 (format stream "~&connection to : ~a" cassandra)
60 (format stream "~&version : ~a" version)
61 (format stream "~&cluster : ~a" cluster)
62 (format stream "~&keyspaces~{~{~%~%space: ~a~@{~% ~{~a :~@{~20t~:w~^~%~}~}~}~}~}" keyspace-descriptions))))
63
64;;; (describe-cassandra *c-location*)