forked from influxdata/influxdb-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfluxDB.java
438 lines (394 loc) · 13.7 KB
/
InfluxDB.java
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
package org.influxdb;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.Pong;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import java.util.List;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
* Interface with all available methods to access a InfluxDB database.
*
* A full list of currently available interfaces is implemented in:
*
* <a
* href="https://github.com/influxdb/influxdb/blob/master/src/api/http/api.go">https://github.com/
* influxdb/influxdb/blob/master/src/api/http/api.go</a>
*
* @author stefan.majer [at] gmail.com
*
*/
public interface InfluxDB {
/** Controls the level of logging of the REST layer. */
public enum LogLevel {
/** No logging. */
NONE,
/** Log only the request method and URL and the response status code and execution time. */
BASIC,
/** Log the basic information along with request and response headers. */
HEADERS,
/**
* Log the headers, body, and metadata for both requests and responses.
* <p>
* Note: This requires that the entire request and response body be buffered in memory!
*/
FULL;
}
/**
* ConsistencyLevel for write Operations.
*/
public enum ConsistencyLevel {
/** Write succeeds only if write reached all cluster members. */
ALL("all"),
/** Write succeeds if write reached any cluster members. */
ANY("any"),
/** Write succeeds if write reached at least one cluster members. */
ONE("one"),
/** Write succeeds only if write reached a quorum of cluster members. */
QUORUM("quorum");
private final String value;
private ConsistencyLevel(final String value) {
this.value = value;
}
/**
* Get the String value of the ConsistencyLevel.
*
* @return the lowercase String.
*/
public String value() {
return this.value;
}
}
/**
* Set the loglevel which is used for REST related actions.
*
* @param logLevel
* the loglevel to set.
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB setLogLevel(final LogLevel logLevel);
/**
* Enable Gzip compress for http request body.
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB enableGzip();
/**
* Disable Gzip compress for http request body.
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB disableGzip();
/**
* Returns whether Gzip compress for http request body is enabled.
* @return true if gzip is enabled.
*/
public boolean isGzipEnabled();
/**
* Enable batching of single Point writes as {@link #enableBatch(int, int, TimeUnit, ThreadFactory)}}
* using {@linkplain java.util.concurrent.Executors#defaultThreadFactory() default thread factory}.
*
* @param actions
* the number of actions to collect
* @param flushDuration
* the time to wait at most.
* @param flushDurationTimeUnit
* the TimeUnit for the given flushDuration.
*
* @see #enableBatch(int, int, TimeUnit, ThreadFactory)
*
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB enableBatch(final int actions, final int flushDuration, final TimeUnit flushDurationTimeUnit);
/**
* Enable batching of single Point writes as
* {@link #enableBatch(int, int, TimeUnit, ThreadFactory, BiConsumer)}
* using with a exceptionHandler that does nothing.
*
* @param actions
* the number of actions to collect
* @param flushDuration
* the time to wait at most.
* @param flushDurationTimeUnit
* the TimeUnit for the given flushDuration.
* @param threadFactory
* a ThreadFactory instance to be used.
*
* @see #enableBatch(int, int, TimeUnit, ThreadFactory, BiConsumer)
*
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB enableBatch(final int actions, final int flushDuration, final TimeUnit flushDurationTimeUnit,
final ThreadFactory threadFactory);
/**
* Enable batching of single Point writes to speed up writes significant. If either actions or
* flushDurations is reached first, a batch write is issued.
* Note that batch processing needs to be explicitly stopped before the application is shutdown.
* To do so call disableBatch().
*
* @param actions
* the number of actions to collect
* @param flushDuration
* the time to wait at most.
* @param flushDurationTimeUnit
* the TimeUnit for the given flushDuration.
* @param threadFactory
* a ThreadFactory instance to be used.
* @param exceptionHandler
* a consumer function to handle asynchronous errors
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB enableBatch(final int actions, final int flushDuration, final TimeUnit flushDurationTimeUnit,
final ThreadFactory threadFactory,
final BiConsumer<Iterable<Point>, Throwable> exceptionHandler);
/**
* Disable Batching.
*/
public void disableBatch();
/**
* Returns whether Batching is enabled.
* @return true if batch is enabled.
*/
public boolean isBatchEnabled();
/**
* Ping this influxDB.
*
* @return the response of the ping execution.
*/
public Pong ping();
/**
* Return the version of the connected influxDB Server.
*
* @return the version String, otherwise unknown.
*/
public String version();
/**
* Write a single Point to the default database.
*
* @param point
* The point to write
*/
public void write(final Point point);
/**
* Write a set of Points to the default database with the string records.
*
* @param records
* the points in the correct lineprotocol.
*/
public void write(final String records);
/**
* Write a set of Points to the default database with the list of string records.
*
* @param records
* the List of points in the correct lineprotocol.
*/
public void write(final List<String> records);
/**
* Write a single Point to the database.
*
* @param database
* the database to write to.
* @param retentionPolicy
* the retentionPolicy to use.
* @param point
* The point to write
*/
public void write(final String database, final String retentionPolicy, final Point point);
/**
* Write a single Point to the database through UDP.
*
* @param udpPort
* the udpPort to write to.
* @param point
* The point to write.
*/
public void write(final int udpPort, final Point point);
/**
* Write a set of Points to the influxdb database with the new (>= 0.9.0rc32) lineprotocol.
*
* @see <a href="https://github.com/influxdb/influxdb/pull/2696">2696</a>
*
* @param batchPoints
* the points to write in BatchPoints.
*/
public void write(final BatchPoints batchPoints);
/**
* Write a set of Points to the influxdb database with the string records.
*
* @see <a href="https://github.com/influxdb/influxdb/pull/2696">2696</a>
*
* @param database
* the name of the database to write
* @param retentionPolicy
* the retentionPolicy to use
* @param consistency
* the ConsistencyLevel to use
* @param records
* the points in the correct lineprotocol.
*/
public void write(final String database, final String retentionPolicy,
final ConsistencyLevel consistency, final String records);
/**
* Write a set of Points to the influxdb database with the list of string records.
*
* @see <a href="https://github.com/influxdb/influxdb/pull/2696">2696</a>
*
* @param database
* the name of the database to write
* @param retentionPolicy
* the retentionPolicy to use
* @param consistency
* the ConsistencyLevel to use
* @param records
* the List of points in the correct lineprotocol.
*/
public void write(final String database, final String retentionPolicy,
final ConsistencyLevel consistency, final List<String> records);
/**
* Write a set of Points to the influxdb database with the string records through UDP.
*
* @param udpPort
* the udpPort where influxdb is listening
* @param records
* the content will be encoded by UTF-8 before sent.
*/
public void write(final int udpPort, final String records);
/**
* Write a set of Points to the influxdb database with the list of string records through UDP.
*
* @param udpPort
* the udpPort where influxdb is listening
* @param records
* list of record, the content will be encoded by UTF-8 before sent.
*/
public void write(final int udpPort, final List<String> records);
/**
* Execute a query against a database.
*
* @param query
* the query to execute.
* @return a List of Series which matched the query.
*/
public QueryResult query(final Query query);
/**
* Execute a streaming query against a database.
*
* @param query
* the query to execute.
* @param chunkSize
* the number of QueryResults to process in one chunk.
* @param consumer
* the consumer to invoke for each received QueryResult
*/
public void query(Query query, int chunkSize, Consumer<QueryResult> consumer);
/**
* Execute a query against a database.
*
* @param query
* the query to execute.
* @param timeUnit the time unit of the results.
* @return a List of Series which matched the query.
*/
public QueryResult query(final Query query, TimeUnit timeUnit);
/**
* Create a new Database.
*
* @param name
* the name of the new database.
*/
public void createDatabase(final String name);
/**
* Delete a database.
*
* @param name
* the name of the database to delete.
*/
public void deleteDatabase(final String name);
/**
* Describe all available databases.
*
* @return a List of all Database names.
*/
public List<String> describeDatabases();
/**
* Check if a database exists.
*
* @param name
* the name of the database to search.
*
* @return true if the database exists or false if it doesn't exist
*/
public boolean databaseExists(final String name);
/**
* Send any buffered points to InfluxDB. This method is synchronous and will block while all pending points are
* written.
*
* @throws IllegalStateException if batching is not enabled.
*/
public void flush();
/**
* close thread for asynchronous batch write and UDP socket to release resources if need.
*/
public void close();
/**
* Set the consistency level which is used for writing points.
*
* @param consistency
* the consistency level to set.
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB setConsistency(final ConsistencyLevel consistency);
/**
* Set the database which is used for writing points.
*
* @param database
* the database to set.
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB setDatabase(final String database);
/**
* Set the retention policy which is used for writing points.
*
* @param retentionPolicy
* the retention policy to set.
* @return the InfluxDB instance to be able to use it in a fluent manner.
*/
public InfluxDB setRetentionPolicy(final String retentionPolicy);
/**
* Creates a retentionPolicy.
* @param rpName the name of the retentionPolicy(rp)
* @param database the name of the database
* @param duration the duration of the rp
* @param shardDuration the shardDuration
* @param replicationFactor the replicationFactor of the rp
* @param isDefault if the rp is the default rp for the database or not
*/
public void createRetentionPolicy(final String rpName, final String database, final String duration,
final String shardDuration, final int replicationFactor, final boolean isDefault);
/**
* Creates a retentionPolicy. (optional shardDuration)
* @param rpName the name of the retentionPolicy(rp)
* @param database the name of the database
* @param duration the duration of the rp
* @param replicationFactor the replicationFactor of the rp
* @param isDefault if the rp is the default rp for the database or not
*/
public void createRetentionPolicy(final String rpName, final String database, final String duration,
final int replicationFactor, final boolean isDefault);
/**
* Creates a retentionPolicy. (optional shardDuration and isDefault)
* @param rpName the name of the retentionPolicy(rp)
* @param database the name of the database
* @param duration the duration of the rp
* @param replicationFactor the replicationFactor of the rp
*/
public void createRetentionPolicy(final String rpName, final String database, final String duration,
final String shardDuration, final int replicationFactor);
/**
* Drops a retentionPolicy in a database.
* @param rpName the name of the retentionPolicy
* @param database the name of the database
*/
public void dropRetentionPolicy(final String rpName, final String database);
}