forked from incjung/cl-maprcli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapr-api.lisp
234 lines (223 loc) · 8.46 KB
/
mapr-api.lisp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
;;;; -*- Mode: LISP; Base: 10; Syntax: ANSI-Common-lisp; Package: CL-MAPRCLI -*-
(in-package :cl-maprcli)
;;; MapR CLI basic context
(defparameter *context* '((:host . "http://localhost:8443/rest")
(:basic-authorization . ("mapr" "mapr"))
(:output . :pretty)))
;;; setter/getter context info
(defun set-host (host)
"Setter for host name. ex: (set-host \"https://192.168.2.51:8443/rest\")"
(let ((ctx (assoc :host *context*)))
(when ctx
(rplacd ctx host))))
(defun set-output-option (option)
"Set default output format"
(let ((ctx (assoc :output *context*)))
(when ctx
(rplacd ctx option))))
(defun set-authentication (auth)
"Set cluster authentication credentials. ex: (set-authentication (list \"mapr\" \"mapr\"))"
(let ((ctx (assoc :basic-authorization *context*)))
(when ctx
(rplacd ctx auth))))
(defun list-to-alist (olist)
"Convert list to alist"
(when (and olist (evenp (length olist)))
(cons (cons (car olist) (cadr olist)) (list-to-alist (cddr olist)))))
(defun get-val (item alist)
"Getter for alist"
(cdr (assoc item alist)))
(defun make-inputformat-from-user (rest)
"Convert user input list into parameter type.
ex: (make-inputformat-from-user '(:a 1 :b 2 :host \"abc\" :basic-authorization '(\"m\" \"m\")))"
(let* ((alist (list-to-alist rest))
(output (let ((tmp (get-val :output alist)))
(if tmp (progn
(setf alist (remove-assoc :output alist))
tmp)
(get-val :output *context*))))
(host (let ((tmp (get-val :host alist)))
(if tmp (progn
(setf alist (remove-assoc :host alist))
tmp)
(get-val :host *context*))))
(basic-authorization (let ((tmp (get-val :basic-authorization alist)))
(if tmp (progn
(setf alist (remove-assoc :basic-authorization alist))
tmp)
(get-val :basic-authorization *context*)))))
(values host basic-authorization alist output)))
(defmacro maprcli (cmd-path &rest rest)
"Run maprcli command. ex: (maprcli \"/VOLUME/INFO\" :path \"/\")"
`(multiple-value-bind (host basic-authorization alist output)
(make-inputformat-from-user ',rest)
(rest-call host ,cmd-path basic-authorization alist output)))
(defmacro maprcli-defs (cmd-path)
"Macro for creating maprcli request functions"
(let ((function-name (intern (string-upcase (subseq (substitute #\- #\/ cmd-path) 1)))))
`(defun ,function-name (&rest rest)
(multiple-value-bind (host basic-authorization alist output)
(make-inputformat-from-user rest)
(rest-call host ,cmd-path basic-authorization alist output)))))
;;; Create the MapR API
(maprcli-defs "/ACL/EDIT")
(maprcli-defs "/ACL/SET")
(maprcli-defs "/ACL/SHOW")
(maprcli-defs "/ALARM/CLEAR")
(maprcli-defs "/ALARM/CLEARALL")
(maprcli-defs "/ALARM/CONFIG/LOAD")
(maprcli-defs "/ALARM/CONFIG/SAVE")
(maprcli-defs "/ALARM/LIST")
(maprcli-defs "/ALARM/NAMES")
(maprcli-defs "/ALARM/RAISE")
(maprcli-defs "/AUDIT/CLUSTER")
(maprcli-defs "/AUDIT/DATA")
(maprcli-defs "/AUDIT/INFO")
(maprcli-defs "/CLUSTER/GATEWAY/DELETE")
(maprcli-defs "/CLUSTER/GATEWAY/GET")
(maprcli-defs "/CLUSTER/GATEWAY/LIST")
(maprcli-defs "/CLUSTER/GATEWAY/LOCAL")
(maprcli-defs "/CLUSTER/GATEWAY/RESOLVE")
(maprcli-defs "/CLUSTER/GATEWAY/SET")
(maprcli-defs "/CLUSTER/MAPREDUCE/GET")
(maprcli-defs "/CLUSTER/MAPREDUCE/SET")
(maprcli-defs "/CONFIG/LOAD")
(maprcli-defs "/CONFIG/SAVE")
(maprcli-defs "/DASHBOARD/INFO")
(maprcli-defs "/DIALHOME/ACKDIAL")
(maprcli-defs "/DIALHOME/ENABLE")
(maprcli-defs "/DIALHOME/LASTDIALED")
(maprcli-defs "/DIALHOME/METRICS")
(maprcli-defs "/DIALHOME/STATUS")
(maprcli-defs "/DISK/ADD")
(maprcli-defs "/DISK/LIST")
(maprcli-defs "/DISK/LISTALL")
(maprcli-defs "/DISK/REMOVE")
(maprcli-defs "/ENTITY/INFO")
(maprcli-defs "/ENTITY/LIST")
(maprcli-defs "/ENTITY/MODIFY")
(maprcli-defs "/ENTITY/REMOVE")
(maprcli-defs "/JOB/CHANGEPRIORITY")
(maprcli-defs "/JOB/KILL")
(maprcli-defs "/JOB/LINKLOGS")
(maprcli-defs "/JOB/TABLE")
(maprcli-defs "/LICENSE/ADD")
(maprcli-defs "/LICENSE/ADDCRL")
(maprcli-defs "/LICENSE/APPS")
(maprcli-defs "/LICENSE/LIST")
(maprcli-defs "/LICENSE/LISTCRL")
(maprcli-defs "/LICENSE/REMOVE")
(maprcli-defs "/LICENSE/SHOWID")
(maprcli-defs "/NAGIOS/GENERATE")
(maprcli-defs "/NODE/ALLOW-INTO-CLUSTER")
(maprcli-defs "/NODE/CLDBMASTER")
(maprcli-defs "/NODE/FAILOVER")
(maprcli-defs "/NODE/HEATMAP")
(maprcli-defs "/NODE/LIST")
(maprcli-defs "/NODE/LISTCLDBS")
(maprcli-defs "/NODE/LISTCLDBZKS")
(maprcli-defs "/NODE/LISTZOOKEEPERS")
(maprcli-defs "/NODE/MAINTENANCE")
(maprcli-defs "/NODE/MOVE")
(maprcli-defs "/NODE/REMOVE")
(maprcli-defs "/NODE/SERVICES")
(maprcli-defs "/NODE/TOPO")
(maprcli-defs "/RLIMIT/GET")
(maprcli-defs "/RLIMIT/SET")
(maprcli-defs "/SCHEDULE/CREATE")
(maprcli-defs "/SCHEDULE/LIST")
(maprcli-defs "/SCHEDULE/MODIFY")
(maprcli-defs "/SCHEDULE/REMOVE")
(maprcli-defs "/SERVICE/LIST")
(maprcli-defs "/SETLOGLEVEL/CLDB")
(maprcli-defs "/SETLOGLEVEL/FILESERVER")
(maprcli-defs "/SETLOGLEVEL/HBMASTER")
(maprcli-defs "/SETLOGLEVEL/HBREGIONSERVER")
(maprcli-defs "/SETLOGLEVEL/JOBTRACKER")
(maprcli-defs "/SETLOGLEVEL/NFS")
(maprcli-defs "/SETLOGLEVEL/TASKTRACKER")
(maprcli-defs "/STREAM/ASSIGN/LIST")
(maprcli-defs "/STREAM/CREATE")
(maprcli-defs "/STREAM/CURSOR/DELETE")
(maprcli-defs "/STREAM/CURSOR/LIST")
(maprcli-defs "/STREAM/DELETE")
(maprcli-defs "/STREAM/EDIT")
(maprcli-defs "/STREAM/INFO")
(maprcli-defs "/STREAM/PURGE")
(maprcli-defs "/STREAM/REPLICA/ADD")
(maprcli-defs "/STREAM/REPLICA/AUTOSETUP")
(maprcli-defs "/STREAM/REPLICA/EDIT")
(maprcli-defs "/STREAM/REPLICA/LIST")
(maprcli-defs "/STREAM/REPLICA/PAUSE")
(maprcli-defs "/STREAM/REPLICA/REMOVE")
(maprcli-defs "/STREAM/REPLICA/RESUME")
(maprcli-defs "/STREAM/UPSTREAM/ADD")
(maprcli-defs "/STREAM/UPSTREAM/LIST")
(maprcli-defs "/STREAM/UPSTREAM/REMOVE")
(maprcli-defs "/STREAM/TOPIC/CREATE")
(maprcli-defs "/STREAM/TOPIC/DELETE")
(maprcli-defs "/STREAM/TOPIC/EDIT")
(maprcli-defs "/STREAM/TOPIC/INFO")
(maprcli-defs "/STREAM/TOPIC/LIST")
(maprcli-defs "/TABLE/CREATE")
(maprcli-defs "/TABLE/CF/COLPERM/GET")
(maprcli-defs "/TABLE/CF/COLPERM/SET")
(maprcli-defs "/TABLE/CF/COLPERM/DELETE")
(maprcli-defs "/TABLE/CF/CREATE")
(maprcli-defs "/TABLE/CF/DELETE")
(maprcli-defs "/TABLE/CF/EDIT")
(maprcli-defs "/TABLE/CF/LIST")
(maprcli-defs "/TABLE/DELETE")
(maprcli-defs "/TABLE/EDIT")
(maprcli-defs "/TABLE/INFO")
(maprcli-defs "/TABLE/REGION/LIST")
(maprcli-defs "/TABLE/REGION/MERGE")
(maprcli-defs "/TABLE/REGION/PACK")
(maprcli-defs "/TABLE/REGION/SPLIT")
(maprcli-defs "/TABLE/REPLICA/ADD")
(maprcli-defs "/TABLE/REPLICA/AUTOSETUP")
(maprcli-defs "/TABLE/REPLICA/EDIT")
(maprcli-defs "/TABLE/REPLICA/LIST")
(maprcli-defs "/TABLE/REPLICA/PAUSE")
(maprcli-defs "/TABLE/REPLICA/REMOVE")
(maprcli-defs "/TABLE/REPLICA/RESUME")
(maprcli-defs "/TABLE/REPLICA/ELASTICSEARCH/AUTOSETUP")
(maprcli-defs "/TABLE/REPLICA/ELASTICSEARCH/EDIT")
(maprcli-defs "/TABLE/REPLICA/ELASTICSEARCH/LIST")
(maprcli-defs "/TABLE/REPLICA/ELASTICSEARCH/PAUSE")
(maprcli-defs "/TABLE/REPLICA/ELASTICSEARCH/RESUME")
(maprcli-defs "/TABLE/REPLICA/ELASTICSEARCH/REMOVE")
(maprcli-defs "/TABLE/UPSTREAM/ADD")
(maprcli-defs "/TABLE/UPSTREAM/LIST")
(maprcli-defs "/TABLE/UPSTREAM/REMOVE")
(maprcli-defs "/TASK/FAILATTEMPT")
(maprcli-defs "/TASK/KILLATTEMPT")
(maprcli-defs "/TASK/TABLE")
(maprcli-defs "/VIRTUALIP/ADD")
(maprcli-defs "/VIRTUALIP/EDIT")
(maprcli-defs "/VIRTUALIP/LIST")
(maprcli-defs "/VIRTUALIP/MOVE")
(maprcli-defs "/VIRTUALIP/REMOVE")
(maprcli-defs "/VOLUME/AUDIT")
(maprcli-defs "/VOLUME/CONTAINER/MOVE")
(maprcli-defs "/VOLUME/CONTAINER/SWITCHMASTER")
(maprcli-defs "/VOLUME/CREATE")
(maprcli-defs "/VOLUME/FIXMOUNTPATH")
(maprcli-defs "/VOLUME/INFO")
(maprcli-defs "/VOLUME/LINK/CREATE")
(maprcli-defs "/VOLUME/LINK/REMOVE")
(maprcli-defs "/VOLUME/LIST")
(maprcli-defs "/VOLUME/MIRROR/START")
(maprcli-defs "/VOLUME/MIRROR/STOP")
(maprcli-defs "/VOLUME/MODIFY")
(maprcli-defs "/VOLUME/MOUNT")
(maprcli-defs "/VOLUME/MOVE")
(maprcli-defs "/VOLUME/REMOVE")
(maprcli-defs "/VOLUME/RENAME")
(maprcli-defs "/VOLUME/SHOWMOUNTS")
(maprcli-defs "/VOLUME/SNAPSHOT/CREATE")
(maprcli-defs "/VOLUME/SNAPSHOT/LIST")
(maprcli-defs "/VOLUME/SNAPSHOT/PRESERVE")
(maprcli-defs "/VOLUME/SNAPSHOT/REMOVE")
(maprcli-defs "/VOLUME/UNMOUNT")
(maprcli-defs "/VOLUME/UPGRADEFORMAT")