/
admin.clj
76 lines (63 loc) · 1.86 KB
/
admin.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(in-ns 'jackdaw.data)
(import '[org.apache.kafka.clients.admin
Config ConfigEntry DescribeClusterResult NewTopic
TopicDescription])
;;; ConfigEntry
(defn ->ConfigEntry
"value can be a string else is a map where value is the :value key"
^ConfigEntry [^String k v]
(if (string? v)
(ConfigEntry. k v)
(ConfigEntry. k (:value v))))
(defn->data ConfigEntry->data
""
[^ConfigEntry e]
{:name (.name e)
:value (.value e)
:default? (.isDefault e)
:read-only? (.isReadOnly e)
:sensitive? (.isSensitive e)})
;;; Config
(defn map->Config
""
^Config [m]
(Config.
(map (partial apply ->ConfigEntry) m)))
(defn->data Config->data
""
[^Config c]
(into {}
(comp (map ConfigEntry->data)
(map (fn [{:keys [name] :as e}]
[name e])))
(.entries c)))
;;; TopicDescription
(defn->data TopicDescription->data
""
[^TopicDescription td]
{:is-internal? (.isInternal td)
:partition-info (map datafy (.partitions td))})
;;; NewTopic
(defn map->NewTopic
""
[{:keys [:topic-name
:partition-count
:replication-factor
:topic-config]
:as m}]
(try
(cond-> (NewTopic. ^String topic-name (int partition-count) (short replication-factor))
topic-config (.configs (into {} (map (fn [[k v]]
(assert (string? k))
(assert (string? v))
[k v]))
topic-config)))
(catch Exception e
(throw (ex-info "While making NewTopic descriptor for topic" m e)))))
;;;; Result types
(defn->data DescribeClusterResult->data
""
[^DescribeClusterResult dcr]
{:cluster-id (-> dcr .clusterId .get)
:controller (-> dcr .controller .get datafy)
:nodes (->> dcr .nodes .get (mapv datafy))})