-
Notifications
You must be signed in to change notification settings - Fork 93
/
InfluxDBClient.cs
1002 lines (875 loc) · 37 KB
/
InfluxDBClient.cs
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Diagnostics;
using System.Reactive;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
using InfluxDB.Client.Api.Client;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Api.Service;
using InfluxDB.Client.Core;
using InfluxDB.Client.Core.Exceptions;
using InfluxDB.Client.Core.Internal;
using InfluxDB.Client.Internal;
namespace InfluxDB.Client
{
public interface IInfluxDBClient : IDisposable
{
/// <summary>
/// Get the Query client.
/// </summary>
/// <param name="mapper">the mapper used for mapping FluxResults to POCO</param>
/// <returns>the new client instance for the Query API</returns>
IQueryApi GetQueryApi(IDomainObjectMapper mapper = null);
/// <summary>
/// Get the synchronous version of Query client.
/// </summary>
/// <param name="mapper">the mapper used for mapping FluxResults to POCO</param>
/// <returns>the new synchronous client instance for the Query API</returns>
IQueryApiSync GetQueryApiSync(IDomainObjectMapper mapper = null);
/// <summary>
/// Get the Write client.
/// </summary>
/// <param name="mapper">the mapper used for mapping to PointData</param>
/// <returns>the new client instance for the Write API</returns>
IWriteApi GetWriteApi(IDomainObjectMapper mapper = null);
/// <summary>
/// Get the Write client.
/// </summary>
/// <param name="writeOptions">the configuration for a write client</param>
/// <param name="mapper">the converter used for mapping to PointData</param>
/// <returns>the new client instance for the Write API</returns>
IWriteApi GetWriteApi(WriteOptions writeOptions, IDomainObjectMapper mapper = null);
/// <summary>
/// Get the Write async client.
/// </summary>
/// <param name="mapper">the converter used for mapping to PointData</param>
/// <returns>the new client instance for the Write API Async without batching</returns>
IWriteApiAsync GetWriteApiAsync(IDomainObjectMapper mapper = null);
/// <summary>
/// Get the <see cref="Organization" /> client.
/// </summary>
/// <returns>the new client instance for Organization API</returns>
IOrganizationsApi GetOrganizationsApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.User" /> client.
/// </summary>
/// <returns>the new client instance for User API</returns>
IUsersApi GetUsersApi();
/// <summary>
/// Get the <see cref="Bucket" /> client.
/// </summary>
/// <returns>the new client instance for Bucket API</returns>
IBucketsApi GetBucketsApi();
/// <summary>
/// Get the <see cref="Source" /> client.
/// </summary>
/// <returns>the new client instance for Source API</returns>
ISourcesApi GetSourcesApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Authorization" /> client.
/// </summary>
/// <returns>the new client instance for Authorization API</returns>
IAuthorizationsApi GetAuthorizationsApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.TaskType" /> client.
/// </summary>
/// <returns>the new client instance for Task API</returns>
ITasksApi GetTasksApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.ScraperTargetResponse" /> client.
/// </summary>
/// <returns>the new client instance for Scraper API</returns>
IScraperTargetsApi GetScraperTargetsApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Telegraf" /> client.
/// </summary>
/// <returns>the new client instance for Telegrafs API</returns>
ITelegrafsApi GetTelegrafsApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Label" /> client.
/// </summary>
/// <returns>the new client instance for Label API</returns>
ILabelsApi GetLabelsApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.NotificationEndpoint" /> client.
/// </summary>
/// <returns>the new client instance for NotificationEndpoint API</returns>
INotificationEndpointsApi GetNotificationEndpointsApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.NotificationRules" /> client.
/// </summary>
/// <returns>the new client instance for NotificationRules API</returns>
INotificationRulesApi GetNotificationRulesApi();
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Check" /> client.
/// </summary>
/// <returns>the new client instance for Checks API</returns>
IChecksApi GetChecksApi();
/// <summary>
/// Get the Delete client.
/// </summary>
/// <returns>the new client instance for Delete API</returns>
IDeleteApi GetDeleteApi();
/// <summary>
/// Create an InvokableScripts API instance.
/// </summary>
/// <param name="mapper">the mapper used for mapping invocation results to POCO</param>
/// <returns>New instance of InvokableScriptsApi.</returns>
IInvokableScriptsApi GetInvokableScriptsApi(IDomainObjectMapper mapper = null);
/// <summary>
/// Create a service for specified type.
/// </summary>
/// <param name="serviceType">type of service</param>
/// <typeparam name="TS">type of service</typeparam>
/// <returns>new instance of service</returns>
TS CreateService<TS>(Type serviceType) where TS : IApiAccessor;
/// <summary>
/// Set the log level for the request and response information.
/// </summary>
/// <param name="logLevel">the log level to set</param>
void SetLogLevel(LogLevel logLevel);
/// <summary>
/// Set the <see cref="LogLevel" /> that is used for logging requests and responses.
/// </summary>
/// <returns>Log Level</returns>
LogLevel GetLogLevel();
/// <summary>
/// Enable Gzip compress for http requests.
///
/// <para>Currently only the "Write" and "Query" endpoints supports the Gzip compression.</para>
/// </summary>
/// <returns></returns>
IInfluxDBClient EnableGzip();
/// <summary>
/// Disable Gzip compress for http request body.
/// </summary>
/// <returns>this</returns>
IInfluxDBClient DisableGzip();
/// <summary>
/// Returns whether Gzip compress for http request body is enabled.
/// </summary>
/// <returns>true if gzip is enabled.</returns>
bool IsGzipEnabled();
/// <summary>
/// Get the health of an instance.
/// </summary>
/// <returns>health of an instance</returns>
[Obsolete("This method is obsolete. Call 'PingAsync()' instead.", false)]
Task<HealthCheck> HealthAsync();
/// <summary>
/// Check the status of InfluxDB Server.
/// </summary>
/// <returns>true if server is healthy otherwise return false</returns>
Task<bool> PingAsync();
/// <summary>
/// Return the version of the connected InfluxDB Server.
/// </summary>
/// <returns>the version String, otherwise unknown</returns>
/// <exception cref="InfluxException">throws when request did not succesfully ends</exception>
Task<string> VersionAsync();
/// <summary>
/// Check the readiness of InfluxDB Server at startup. It is not supported by InfluxDB Cloud.
/// </summary>
/// <returns>return null if the InfluxDB is not ready</returns>
Task<Ready> ReadyAsync();
/// <summary>
/// Post onboarding request, to setup initial user, org and bucket.
/// </summary>
/// <param name="onboarding">to setup defaults</param>
/// <exception cref="HttpException">With status code 422 when an onboarding has already been completed</exception>
/// <returns>defaults for first run</returns>
Task<OnboardingResponse> OnboardingAsync(OnboardingRequest onboarding);
/// <summary>
/// Check if database has default user, org, bucket created, returns true if not.
/// </summary>
/// <returns>True if onboarding has already been completed otherwise false</returns>
Task<bool> IsOnboardingAllowedAsync();
}
public class InfluxDBClient : AbstractRestClient, IInfluxDBClient
{
private readonly ApiClient _apiClient;
private readonly ExceptionFactory _exceptionFactory;
private readonly HealthService _healthService;
private readonly LoggingHandler _loggingHandler;
private readonly GzipHandler _gzipHandler;
private readonly ReadyService _readyService;
private readonly PingService _pingService;
private readonly SetupService _setupService;
private readonly InfluxDBClientOptions _options;
private readonly Subject<Unit> _disposeNotification = new Subject<Unit>();
/// <summary>
/// Create a instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
/// <para>
/// e.g.: "http://localhost:8086?timeout=5000&logLevel=BASIC
/// The following options are supported:
/// <list type="bullet">
/// <item>org - default destination organization for writes and queries</item>
/// <item>bucket - default destination bucket for writes</item>
/// <item>token - the token to use for the authorization</item>
/// <item>logLevel (default - NONE) - rest client verbosity level</item>
/// <item>timeout (default - 10000) - The timespan to wait before the HTTP request times out in milliseconds</item>
/// <item>allowHttpRedirects (default - false) - Configure automatically following HTTP 3xx redirects</item>
/// <item>verifySsl (default - true) - Ignore Certificate Validation Errors when false</item>
/// </list>
/// Options for logLevel:
/// <list type="bullet">
/// <item>Basic - Logs request and response lines.</item>
/// <item>Body - Logs request and response lines including headers and body (if present). Note that applying the `Body` LogLevel will disable chunking while streaming and will load the whole response into memory.</item>
/// <item>Headers - Logs request and response lines including headers.</item>
/// <item>None - Disable logging.</item>
/// </list>
/// </para>
/// </summary>
/// <param name="url">connection string with various configurations</param>
public InfluxDBClient(string url) :
this(new InfluxDBClientOptions(url))
{
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB 2.x</param>
/// <param name="username">the username to use in the basic auth</param>
/// <param name="password">the password to use in the basic auth</param>
public InfluxDBClient(string url, string username, string password) :
this(new InfluxDBClientOptions(url)
{
Username = username,
Password = password
})
{
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB 2.x</param>
/// <param name="token">the token to use for the authorization</param>
public InfluxDBClient(string url, string token) :
this(new InfluxDBClientOptions(url)
{
Token = token
})
{
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client to connect into InfluxDB 1.8.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB 1.8</param>
/// <param name="username">authorization username</param>
/// <param name="password">authorization password</param>
/// <param name="database">database name</param>
/// <param name="retentionPolicy">retention policy</param>
public InfluxDBClient(string url, string username, string password, string database, string retentionPolicy) :
this(new InfluxDBClientOptions(url)
{
Org = "-",
Token = $"{username}:{password}",
Bucket = $"{database}/{retentionPolicy}"
})
{
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client.
/// </summary>
/// <param name="options">the connection configuration</param>
public InfluxDBClient(InfluxDBClientOptions options)
{
Arguments.CheckNotNull(options, nameof(options));
_options = options;
_loggingHandler = new LoggingHandler(options.LogLevel);
_gzipHandler = new GzipHandler();
_apiClient = new ApiClient(options, _loggingHandler, _gzipHandler);
_exceptionFactory = (methodName, response) =>
!response.IsSuccessful ? HttpException.Create(response, response.Content) : null;
_setupService = new SetupService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
_healthService = new HealthService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
_readyService = new ReadyService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
_pingService = new PingService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
}
public void Dispose()
{
//
// Dispose child APIs
//
_disposeNotification.OnNext(Unit.Default);
//
// signout
//
try
{
_apiClient.Signout();
}
catch (Exception e)
{
Trace.WriteLine("The signout exception", InfluxDBTraceFilter.CategoryInfluxError);
Trace.WriteLine(e, InfluxDBTraceFilter.CategoryInfluxError);
}
//
// Dispose HttpClient
//
_apiClient.RestClient.Dispose();
}
/// <summary>
/// Get the Query client.
/// </summary>
/// <param name="mapper">the mapper used for mapping FluxResults to POCO</param>
/// <returns>the new client instance for the Query API</returns>
IQueryApi IInfluxDBClient.GetQueryApi(IDomainObjectMapper mapper)
{
return GetQueryApi(mapper);
}
/// <summary>
/// Get the Query client.
/// </summary>
/// <param name="mapper">the mapper used for mapping FluxResults to POCO</param>
/// <returns>the new client instance for the Query API</returns>
public QueryApi GetQueryApi(IDomainObjectMapper mapper = null)
{
var service = new QueryService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new QueryApi(_options, service, mapper ?? new DefaultDomainObjectMapper());
}
/// <summary>
/// Get the synchronous version of Query client.
/// </summary>
/// <param name="mapper">the mapper used for mapping FluxResults to POCO</param>
/// <returns>the new synchronous client instance for the Query API</returns>
IQueryApiSync IInfluxDBClient.GetQueryApiSync(IDomainObjectMapper mapper)
{
return GetQueryApiSync(mapper);
}
/// <summary>
/// Get the synchronous version of Query client.
/// </summary>
/// <param name="mapper">the mapper used for mapping FluxResults to POCO</param>
/// <returns>the new synchronous client instance for the Query API</returns>
public QueryApiSync GetQueryApiSync(IDomainObjectMapper mapper = null)
{
var service = new QueryService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new QueryApiSync(_options, service, mapper ?? new DefaultDomainObjectMapper());
}
/// <summary>
/// Get the Write client.
/// </summary>
/// <param name="mapper">the mapper used for mapping to PointData</param>
/// <returns>the new client instance for the Write API</returns>
IWriteApi IInfluxDBClient.GetWriteApi(IDomainObjectMapper mapper)
{
return GetWriteApi(mapper);
}
/// <summary>
/// Get the Write client.
/// </summary>
/// <param name="mapper">the mapper used for mapping to PointData</param>
/// <returns>the new client instance for the Write API</returns>
public WriteApi GetWriteApi(IDomainObjectMapper mapper = null)
{
return GetWriteApi(new WriteOptions(), mapper);
}
/// <summary>
/// Get the Write async client.
/// </summary>
/// <param name="mapper">the converter used for mapping to PointData</param>
/// <returns>the new client instance for the Write API Async without batching</returns>
IWriteApiAsync IInfluxDBClient.GetWriteApiAsync(IDomainObjectMapper mapper)
{
return GetWriteApiAsync(mapper);
}
/// <summary>
/// Get the Write async client.
/// </summary>
/// <param name="mapper">the converter used for mapping to PointData</param>
/// <returns>the new client instance for the Write API Async without batching</returns>
public WriteApiAsync GetWriteApiAsync(IDomainObjectMapper mapper = null)
{
var service = new WriteService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new WriteApiAsync(_options, service, mapper ?? new DefaultDomainObjectMapper(), this);
}
/// <summary>
/// Get the Write client.
/// </summary>
/// <param name="writeOptions">the configuration for a write client</param>
/// <param name="mapper">the converter used for mapping to PointData</param>
/// <returns>the new client instance for the Write API</returns>
IWriteApi IInfluxDBClient.GetWriteApi(WriteOptions writeOptions, IDomainObjectMapper mapper)
{
return GetWriteApi(writeOptions, mapper);
}
/// <summary>
/// Get the Write client.
/// </summary>
/// <param name="writeOptions">the configuration for a write client</param>
/// <param name="mapper">the converter used for mapping to PointData</param>
/// <returns>the new client instance for the Write API</returns>
public WriteApi GetWriteApi(WriteOptions writeOptions, IDomainObjectMapper mapper = null)
{
var service = new WriteService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
var writeApi = new WriteApi(_options, service, writeOptions, mapper ?? new DefaultDomainObjectMapper(),
this, _disposeNotification);
return writeApi;
}
/// <summary>
/// Get the <see cref="Organization" /> client.
/// </summary>
/// <returns>the new client instance for Organization API</returns>
IOrganizationsApi IInfluxDBClient.GetOrganizationsApi()
{
return GetOrganizationsApi();
}
/// <summary>
/// Get the <see cref="Organization" /> client.
/// </summary>
/// <returns>the new client instance for Organization API</returns>
public OrganizationsApi GetOrganizationsApi()
{
var service = new OrganizationsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
var secretService = new SecretsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new OrganizationsApi(service, secretService);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.User" /> client.
/// </summary>
/// <returns>the new client instance for User API</returns>
IUsersApi IInfluxDBClient.GetUsersApi()
{
return GetUsersApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.User" /> client.
/// </summary>
/// <returns>the new client instance for User API</returns>
public UsersApi GetUsersApi()
{
var service = new UsersService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new UsersApi(service);
}
/// <summary>
/// Get the <see cref="Bucket" /> client.
/// </summary>
/// <returns>the new client instance for Bucket API</returns>
IBucketsApi IInfluxDBClient.GetBucketsApi()
{
return GetBucketsApi();
}
/// <summary>
/// Get the <see cref="Bucket" /> client.
/// </summary>
/// <returns>the new client instance for Bucket API</returns>
public BucketsApi GetBucketsApi()
{
var service = new BucketsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new BucketsApi(service);
}
/// <summary>
/// Get the <see cref="Source" /> client.
/// </summary>
/// <returns>the new client instance for Source API</returns>
ISourcesApi IInfluxDBClient.GetSourcesApi()
{
return GetSourcesApi();
}
/// <summary>
/// Get the <see cref="Source" /> client.
/// </summary>
/// <returns>the new client instance for Source API</returns>
public SourcesApi GetSourcesApi()
{
var service = new SourcesService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new SourcesApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Authorization" /> client.
/// </summary>
/// <returns>the new client instance for Authorization API</returns>
IAuthorizationsApi IInfluxDBClient.GetAuthorizationsApi()
{
return GetAuthorizationsApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Authorization" /> client.
/// </summary>
/// <returns>the new client instance for Authorization API</returns>
public AuthorizationsApi GetAuthorizationsApi()
{
var service = new AuthorizationsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new AuthorizationsApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.TaskType" /> client.
/// </summary>
/// <returns>the new client instance for Task API</returns>
ITasksApi IInfluxDBClient.GetTasksApi()
{
return GetTasksApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.TaskType" /> client.
/// </summary>
/// <returns>the new client instance for Task API</returns>
public TasksApi GetTasksApi()
{
var service = new TasksService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new TasksApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.ScraperTargetResponse" /> client.
/// </summary>
/// <returns>the new client instance for Scraper API</returns>
IScraperTargetsApi IInfluxDBClient.GetScraperTargetsApi()
{
return GetScraperTargetsApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.ScraperTargetResponse" /> client.
/// </summary>
/// <returns>the new client instance for Scraper API</returns>
public ScraperTargetsApi GetScraperTargetsApi()
{
var service = new ScraperTargetsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new ScraperTargetsApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Telegraf" /> client.
/// </summary>
/// <returns>the new client instance for Telegrafs API</returns>
ITelegrafsApi IInfluxDBClient.GetTelegrafsApi()
{
return GetTelegrafsApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Telegraf" /> client.
/// </summary>
/// <returns>the new client instance for Telegrafs API</returns>
public TelegrafsApi GetTelegrafsApi()
{
var service = new TelegrafsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new TelegrafsApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Label" /> client.
/// </summary>
/// <returns>the new client instance for Label API</returns>
ILabelsApi IInfluxDBClient.GetLabelsApi()
{
return GetLabelsApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Label" /> client.
/// </summary>
/// <returns>the new client instance for Label API</returns>
public LabelsApi GetLabelsApi()
{
var service = new LabelsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new LabelsApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.NotificationEndpoint" /> client.
/// </summary>
/// <returns>the new client instance for NotificationEndpoint API</returns>
INotificationEndpointsApi IInfluxDBClient.GetNotificationEndpointsApi()
{
return GetNotificationEndpointsApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.NotificationEndpoint" /> client.
/// </summary>
/// <returns>the new client instance for NotificationEndpoint API</returns>
public NotificationEndpointsApi GetNotificationEndpointsApi()
{
var service = new NotificationEndpointsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new NotificationEndpointsApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.NotificationRules" /> client.
/// </summary>
/// <returns>the new client instance for NotificationRules API</returns>
INotificationRulesApi IInfluxDBClient.GetNotificationRulesApi()
{
return GetNotificationRulesApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.NotificationRules" /> client.
/// </summary>
/// <returns>the new client instance for NotificationRules API</returns>
public NotificationRulesApi GetNotificationRulesApi()
{
var service = new NotificationRulesService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new NotificationRulesApi(service);
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Check" /> client.
/// </summary>
/// <returns>the new client instance for Checks API</returns>
IChecksApi IInfluxDBClient.GetChecksApi()
{
return GetChecksApi();
}
/// <summary>
/// Get the <see cref="InfluxDB.Client.Api.Domain.Check" /> client.
/// </summary>
/// <returns>the new client instance for Checks API</returns>
public ChecksApi GetChecksApi()
{
var service = new ChecksService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new ChecksApi(service);
}
/// <summary>
/// Get the Delete client.
/// </summary>
/// <returns>the new client instance for Delete API</returns>
IDeleteApi IInfluxDBClient.GetDeleteApi()
{
return GetDeleteApi();
}
/// <summary>
/// Get the Delete client.
/// </summary>
/// <returns>the new client instance for Delete API</returns>
public DeleteApi GetDeleteApi()
{
var service = new DeleteService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new DeleteApi(service);
}
/// <summary>
/// Create an InvokableScripts API instance.
/// </summary>
/// <param name="mapper">the mapper used for mapping invocation results to POCO</param>
/// <returns>New instance of InvokableScriptsApi.</returns>
IInvokableScriptsApi IInfluxDBClient.GetInvokableScriptsApi(IDomainObjectMapper mapper)
{
return GetInvokableScriptsApi(mapper);
}
/// <summary>
/// Create an InvokableScripts API instance.
/// </summary>
/// <param name="mapper">the mapper used for mapping invocation results to POCO</param>
/// <returns>New instance of InvokableScriptsApi.</returns>
public InvokableScriptsApi GetInvokableScriptsApi(IDomainObjectMapper mapper = null)
{
var service = new InvokableScriptsService((Configuration)_apiClient.Configuration)
{
ExceptionFactory = _exceptionFactory
};
return new InvokableScriptsApi(service, mapper ?? new DefaultDomainObjectMapper());
}
/// <summary>
/// Create a service for specified type.
/// </summary>
/// <param name="serviceType">type of service</param>
/// <typeparam name="TS">type of service</typeparam>
/// <returns>new instance of service</returns>
public TS CreateService<TS>(Type serviceType) where TS : IApiAccessor
{
var instance = (TS)Activator.CreateInstance(serviceType, (Configuration)_apiClient.Configuration);
instance.ExceptionFactory = _exceptionFactory;
return instance;
}
/// <summary>
/// Set the log level for the request and response information.
/// </summary>
/// <param name="logLevel">the log level to set</param>
public void SetLogLevel(LogLevel logLevel)
{
Arguments.CheckNotNull(logLevel, nameof(logLevel));
_loggingHandler.Level = logLevel;
}
/// <summary>
/// Set the <see cref="LogLevel" /> that is used for logging requests and responses.
/// </summary>
/// <returns>Log Level</returns>
public LogLevel GetLogLevel()
{
return _loggingHandler.Level;
}
/// <summary>
/// Enable Gzip compress for http requests.
///
/// <para>Currently only the "Write" and "Query" endpoints supports the Gzip compression.</para>
/// </summary>
/// <returns></returns>
IInfluxDBClient IInfluxDBClient.EnableGzip()
{
return EnableGzip();
}
/// <summary>
/// Enable Gzip compress for http requests.
///
/// <para>Currently only the "Write" and "Query" endpoints supports the Gzip compression.</para>
/// </summary>
/// <returns></returns>
public InfluxDBClient EnableGzip()
{
_gzipHandler.EnableGzip();
return this;
}
/// <summary>
/// Disable Gzip compress for http request body.
/// </summary>
/// <returns>this</returns>
IInfluxDBClient IInfluxDBClient.DisableGzip()
{
return DisableGzip();
}
/// <summary>
/// Disable Gzip compress for http request body.
/// </summary>
/// <returns>this</returns>
public InfluxDBClient DisableGzip()
{
_gzipHandler.DisableGzip();
return this;
}
/// <summary>
/// Returns whether Gzip compress for http request body is enabled.
/// </summary>
/// <returns>true if gzip is enabled.</returns>
public bool IsGzipEnabled()
{
return _gzipHandler.IsEnabledGzip();
}
/// <summary>
/// Get the health of an instance.
/// </summary>
/// <returns>health of an instance</returns>
[Obsolete("This method is obsolete. Call 'PingAsync()' instead.", false)]
public Task<HealthCheck> HealthAsync()
{
return GetHealthAsync(_healthService.GetHealthAsync());
}
/// <summary>
/// Check the status of InfluxDB Server.
/// </summary>
/// <returns>true if server is healthy otherwise return false</returns>
public async Task<bool> PingAsync()
{
return await PingAsync(_pingService.GetPingAsyncWithIRestResponse());
}
/// <summary>
/// Return the version of the connected InfluxDB Server.
/// </summary>
/// <returns>the version String, otherwise unknown</returns>
/// <exception cref="InfluxException">throws when request did not succesfully ends</exception>
public async Task<string> VersionAsync()
{
return await VersionAsync(_pingService.GetPingAsyncWithIRestResponse());
}
/// <summary>
/// Check the readiness of InfluxDB Server at startup. It is not supported by InfluxDB Cloud.
/// </summary>
/// <returns>return null if the InfluxDB is not ready</returns>
public async Task<Ready> ReadyAsync()
{
try
{
return await _readyService.GetReadyAsync().ConfigureAwait(false);
}
catch (Exception e)
{
Trace.TraceError($"The exception: '{e.Message}' occurs during check instance readiness.");
return null;
}
}
/// <summary>
/// Post onboarding request, to setup initial user, org and bucket.
/// </summary>
/// <param name="onboarding">to setup defaults</param>
/// <exception cref="HttpException">With status code 422 when an onboarding has already been completed</exception>
/// <returns>defaults for first run</returns>
public Task<OnboardingResponse> OnboardingAsync(OnboardingRequest onboarding)
{
Arguments.CheckNotNull(onboarding, nameof(onboarding));
return _setupService.PostSetupAsync(onboarding);
}
/// <summary>
/// Check if database has default user, org, bucket created, returns true if not.
/// </summary>
/// <returns>True if onboarding has already been completed otherwise false</returns>
public async Task<bool> IsOnboardingAllowedAsync()
{
var isOnboarding = await _setupService.GetSetupAsync().ConfigureAwait(false);
return isOnboarding.Allowed == true;
}
internal static string AuthorizationHeader(string username, string password)
{
return "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + password));
}
internal static async Task<HealthCheck> GetHealthAsync(Task<HealthCheck> task)
{
Arguments.CheckNotNull(task, nameof(task));
try
{
return await task.ConfigureAwait(false);
}
catch (Exception e)
{
return new HealthCheck("influxdb", e.Message, default, HealthCheck.StatusEnum.Fail);
}
}