forked from hawkular/hawkular-metrics
/
diff.txt
1846 lines (1846 loc) · 85.3 KB
/
diff.txt
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
Only in api/metrics-api-jaxrs: README.adoc
Only in api/metrics-api-jaxrs-1.1: hawkular-metrics-api-jaxrs-1.1.iml
Only in api/metrics-api-jaxrs: hawkular-metrics-api-jaxrs.iml
diff -r '--exclude=target' api/metrics-api-jaxrs/pom.xml api/metrics-api-jaxrs-1.1/pom.xml
21c21
< xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
---
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
31c31
< <artifactId>hawkular-metrics-api-jaxrs</artifactId>
---
> <artifactId>hawkular-metrics-api-jaxrs-1.1</artifactId>
34,35c34,47
< <name>Hawkular Metrics JAX-RS 2.0 API</name>
< <description>JAX-RS 2.0 REST API Implementation</description>
---
> <name>Hawkular Metrics JAX-RS 1.1 API</name>
> <description>JAX-RS 1.1 REST API Implementation</description>
>
> <properties>
> <enforcer.skip>true</enforcer.skip>
> <container.bom.version>6.4.0.Beta1</container.bom.version>
> </properties>
>
> <repositories>
> <repository>
> <id>eap_6_early_access</id>
> <url>https://maven.repository.redhat.com/earlyaccess/all/</url>
> </repository>
> </repositories>
40,42c52,54
< <groupId>org.wildfly.bom</groupId>
< <artifactId>jboss-javaee-7.0-wildfly</artifactId>
< <version>${version.org.wildfly}</version>
---
> <groupId>org.jboss.bom.eap</groupId>
> <artifactId>jboss-javaee-6.0-with-resteasy</artifactId>
> <version>${container.bom.version}</version>
51,54d62
< <groupId>org.antlr</groupId>
< <artifactId>antlr4-runtime</artifactId>
< </dependency>
< <dependency>
60,61c68,78
< <!-- Wildfly provided -->
< <!-- No need to set the jboss-logging scope here since Wildfly BOM includes jboss-logging -->
---
> <!-- AS7 provided -->
> <!-- Set the jboss-logging scope here since EAP6.4 BOM does not include jboss-logging -->
> <dependency>
> <groupId>org.jboss.logging</groupId>
> <artifactId>jboss-logging</artifactId>
> <!--
> This version is "almost" compatible with the version included in EAP6.4:
> we can't use logger methods with primitive arguments
> -->
> <scope>provided</scope>
> </dependency>
69c86
< <artifactId>resteasy-jackson2-provider</artifactId>
---
> <artifactId>resteasy-jackson-provider</artifactId>
74c91
< <artifactId>jboss-servlet-api_3.1_spec</artifactId>
---
> <artifactId>jboss-servlet-api_3.0_spec</artifactId>
82,100d98
<
< <!-- documentation -->
< <dependency>
< <groupId>io.swagger</groupId>
< <artifactId>swagger-annotations</artifactId>
< <scope>provided</scope>
< </dependency>
<
< <!-- test -->
< <dependency>
< <groupId>junit</groupId>
< <artifactId>junit</artifactId>
< <scope>test</scope>
< </dependency>
< <dependency>
< <groupId>org.mockito</groupId>
< <artifactId>mockito-core</artifactId>
< <scope>test</scope>
< </dependency>
104c102
< <finalName>hawkular-metric-rest</finalName>
---
> <finalName>hawkular-metrics-api-rest-1.1</finalName>
106d103
<
108,122c105,111
< <groupId>org.antlr</groupId>
< <artifactId>antlr4-maven-plugin</artifactId>
< <executions>
< <execution>
< <id>antlr4</id>
< <goals>
< <goal>antlr4</goal>
< </goals>
< <phase>generate-sources</phase>
< <configuration>
< <listener>true</listener>
< <visitor>true</visitor>
< </configuration>
< </execution>
< </executions>
---
> <groupId>org.jboss.as.plugins</groupId>
> <artifactId>jboss-as-maven-plugin</artifactId>
> <version>7.7.Final</version>
> <configuration>
> <version>7.5.0.Final-redhat-15</version>
> <port>${jboss-as.management.port}</port>
> </configuration>
140c129
< <exclude>static/index.html</exclude>
---
> <exclude>index.html</exclude>
148c137
< <include>static/index.html</include>
---
> <include>index.html</include>
157,226d145
<
< <profiles>
< <profile>
< <id>docgen</id>
< <properties>
< <swaggerDirectory>${project.build.directory}/generated/swagger-ui</swaggerDirectory>
< </properties>
< <build>
< <!-- Document generation from the Swagger annotations on the REST-API. -->
< <plugins>
< <plugin>
< <groupId>com.github.kongchen</groupId>
< <artifactId>swagger-maven-plugin</artifactId>
< <version>3.1.0</version>
< <configuration>
< <apiSources>
< <apiSource>
< <springmvc>false</springmvc>
< <locations>org.hawkular.metrics.api.jaxrs</locations>
< <basePath>/hawkular/metrics/</basePath>
< <info>
< <title>Hawkular Metrics REST API</title>
< <version>1.0</version>
< </info>
< <swaggerDirectory>${swaggerDirectory}</swaggerDirectory>
< </apiSource>
< </apiSources>
< </configuration>
< <executions>
< <execution>
< <phase>compile</phase>
< <goals>
< <goal>generate</goal>
< </goals>
< </execution>
< </executions>
< </plugin>
< <plugin>
< <groupId>org.codehaus.gmavenplus</groupId>
< <artifactId>gmavenplus-plugin</artifactId>
< <dependencies>
< <dependency>
< <groupId>org.codehaus.groovy</groupId>
< <artifactId>groovy-all</artifactId>
< <version>${version.org.codehaus.groovy}</version>
< </dependency>
< </dependencies>
< <configuration>
< <properties>
< <swaggerFile>${swaggerDirectory}/swagger.json</swaggerFile>
< <outputFile>${project.build.directory}/generated/rest-metrics.adoc</outputFile>
< </properties>
< <scripts>
< <script>file:///${project.basedir}/src/main/script/apidoc.groovy</script>
< </scripts>
< </configuration>
< <executions>
< <execution>
< <id>generate-api-doc</id>
< <phase>compile</phase>
< <goals>
< <goal>execute</goal>
< </goals>
< </execution>
< </executions>
< </plugin>
< </plugins>
< </build>
< </profile>
< </profiles>
Only in api/metrics-api-jaxrs/src/main: antlr4
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/HawkularMetricsRestApp.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/HawkularMetricsRestApp.java
32,33d31
< import org.hawkular.metrics.api.jaxrs.filter.CorsRequestFilter;
< import org.hawkular.metrics.api.jaxrs.filter.CorsResponseFilter;
46d43
< import org.hawkular.metrics.api.jaxrs.influx.InfluxSeriesHandler;
50,51c47,49
< import org.hawkular.metrics.api.jaxrs.param.ConvertersProvider;
< import org.hawkular.metrics.api.jaxrs.util.JacksonConfig;
---
> import org.hawkular.metrics.api.jaxrs.param.DurationConverter;
> import org.hawkular.metrics.api.jaxrs.param.MetricTypeConverter;
> import org.hawkular.metrics.api.jaxrs.param.TagsConverter;
80d77
< classes.add(InfluxSeriesHandler.class);
116,117d112
< classes.add(CorsResponseFilter.class);
< classes.add(CorsRequestFilter.class);
121,122c116,118
< classes.add(ConvertersProvider.class);
< classes.add(JacksonConfig.class);
---
> classes.add(DurationConverter.class);
> classes.add(MetricTypeConverter.class);
> classes.add(TagsConverter.class);
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/ApplicationExceptionMapper.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/ApplicationExceptionMapper.java
21d20
< import javax.ws.rs.core.Response.Status;
37c36
< return ExceptionMapperUtils.buildResponse(exception, Status.INTERNAL_SERVER_ERROR);
---
> return ExceptionMapperUtils.buildResponse(exception, 500);
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/ExceptionMapperUtils.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/ExceptionMapperUtils.java
20a21
> import javax.ws.rs.core.Response.ResponseBuilder;
33a35,39
> public static Response buildResponse(Throwable exception, int statusCode) {
> ResponseBuilder responseBuilder = Response.status(statusCode);
> return buildErrorResponse(exception, responseBuilder);
> }
>
35c41,46
< Response response = Response.status(status)
---
> ResponseBuilder responseBuilder = Response.status(status);
> return buildErrorResponse(exception, responseBuilder);
> }
>
> private static Response buildErrorResponse(Throwable exception, ResponseBuilder responseBuilder) {
> Response response = responseBuilder
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotAcceptableExceptionMapper.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotAcceptableExceptionMapper.java
19d18
< import javax.ws.rs.NotAcceptableException;
22a22,23
>
> import org.jboss.resteasy.spi.NotAcceptableException;
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotAllowedExceptionMapper.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotAllowedExceptionMapper.java
19d18
< import javax.ws.rs.NotAllowedException;
23a23,24
> import org.jboss.resteasy.spi.MethodNotAllowedException;
>
33c34
< public class NotAllowedExceptionMapper implements ExceptionMapper<NotAllowedException> {
---
> public class NotAllowedExceptionMapper implements ExceptionMapper<MethodNotAllowedException> {
36,37c37,38
< public Response toResponse(NotAllowedException exception) {
< return ExceptionMapperUtils.buildResponse(exception, Response.Status.METHOD_NOT_ALLOWED);
---
> public Response toResponse(MethodNotAllowedException exception) {
> return ExceptionMapperUtils.buildResponse(exception, 405);
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotFoundExceptionMapper.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotFoundExceptionMapper.java
19d18
< import javax.ws.rs.NotFoundException;
22a22,23
>
> import org.jboss.resteasy.spi.NotFoundException;
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotSupportedExceptionMapper.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/exception/mappers/NotSupportedExceptionMapper.java
16a17
>
19d19
< import javax.ws.rs.NotSupportedException;
23a24,25
> import org.jboss.resteasy.spi.UnsupportedMediaTypeException;
>
33c35
< public class NotSupportedExceptionMapper implements ExceptionMapper<NotSupportedException> {
---
> public class NotSupportedExceptionMapper implements ExceptionMapper<UnsupportedMediaTypeException> {
36c38
< public Response toResponse(NotSupportedException exception) {
---
> public Response toResponse(UnsupportedMediaTypeException exception) {
Only in api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/filter: CorsFilter.java
Only in api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/filter: CorsRequestFilter.java
Only in api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/filter: CorsResponseFilter.java
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/filter/EmptyPayloadFilter.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/filter/EmptyPayloadFilter.java
20,21c20
< import java.io.IOException;
<
---
> import javax.servlet.http.HttpServletRequest;
23,25c22,23
< import javax.ws.rs.container.ContainerRequestContext;
< import javax.ws.rs.container.ContainerRequestFilter;
< import javax.ws.rs.core.UriInfo;
---
> import javax.ws.rs.WebApplicationException;
> import javax.ws.rs.core.Context;
27a26,32
> import org.jboss.resteasy.annotations.interception.ServerInterceptor;
> import org.jboss.resteasy.core.ResourceMethod;
> import org.jboss.resteasy.core.ServerResponse;
> import org.jboss.resteasy.spi.Failure;
> import org.jboss.resteasy.spi.HttpRequest;
> import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
>
32a38
> * @author Stefan Negrea
35c41,42
< public class EmptyPayloadFilter implements ContainerRequestFilter {
---
> @ServerInterceptor
> public class EmptyPayloadFilter implements PreProcessInterceptor {
37a45,47
> @Context
> HttpServletRequest servletRequest;
>
39,48c49,54
< public void filter(ContainerRequestContext requestContext) throws IOException {
< if (!HttpMethod.POST.equals(requestContext.getMethod())) {
< return;
< }
< UriInfo uriInfo = requestContext.getUriInfo();
< String path = uriInfo.getPath();
< if (path.startsWith("/db")) {
< // Skip some endpoints:
< // - Influx
< return;
---
> public ServerResponse preProcess(HttpRequest request,
> ResourceMethod resourceMethod) throws Failure,
> WebApplicationException {
>
> if (!HttpMethod.POST.equals(request.getHttpMethod())) {
> return null;
50c56,58
< requestContext.setProperty(EMPTY_PAYLOAD, Boolean.TRUE);
---
>
> servletRequest.setAttribute(EMPTY_PAYLOAD, Boolean.TRUE);
> return null;
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/filter/MetricsServiceStateFilter.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/filter/MetricsServiceStateFilter.java
21,22d20
< import java.io.IOException;
<
24,25c22
< import javax.ws.rs.container.ContainerRequestContext;
< import javax.ws.rs.container.ContainerRequestFilter;
---
> import javax.ws.rs.WebApplicationException;
28d24
< import javax.ws.rs.core.UriInfo;
34a31,36
> import org.jboss.resteasy.annotations.interception.ServerInterceptor;
> import org.jboss.resteasy.core.ResourceMethod;
> import org.jboss.resteasy.core.ServerResponse;
> import org.jboss.resteasy.spi.Failure;
> import org.jboss.resteasy.spi.HttpRequest;
> import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
40c42,43
< public class MetricsServiceStateFilter implements ContainerRequestFilter {
---
> @ServerInterceptor
> public class MetricsServiceStateFilter implements PreProcessInterceptor {
50,52c53,55
< public void filter(ContainerRequestContext containerRequestContext) throws IOException {
< UriInfo uriInfo = containerRequestContext.getUriInfo();
< String path = uriInfo.getPath();
---
> public ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure,
> WebApplicationException {
> String path = request.getUri().getPath();
56c59
< return;
---
> return null;
65c68
< containerRequestContext.abortWith(response);
---
> return ServerResponse.copyIfNotServerResponse(response);
72c75
< containerRequestContext.abortWith(response);
---
> return ServerResponse.copyIfNotServerResponse(response);
74c77
< metricsServiceLifecycle.getState() == State.STOPPING) {
---
> metricsServiceLifecycle.getState() == State.STOPPING) {
79c82
< containerRequestContext.abortWith(response);
---
> return ServerResponse.copyIfNotServerResponse(response);
80a84,85
>
> return null;
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/filter/TenantFilter.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/filter/TenantFilter.java
21c21
< import java.io.IOException;
---
> import java.util.List;
23,24c23
< import javax.ws.rs.container.ContainerRequestContext;
< import javax.ws.rs.container.ContainerRequestFilter;
---
> import javax.ws.rs.WebApplicationException;
27d25
< import javax.ws.rs.core.UriInfo;
33a32,37
> import org.jboss.resteasy.annotations.interception.ServerInterceptor;
> import org.jboss.resteasy.core.ResourceMethod;
> import org.jboss.resteasy.core.ServerResponse;
> import org.jboss.resteasy.spi.Failure;
> import org.jboss.resteasy.spi.HttpRequest;
> import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
39c43,44
< public class TenantFilter implements ContainerRequestFilter {
---
> @ServerInterceptor
> public class TenantFilter implements PreProcessInterceptor {
51,53c56,58
< public void filter(ContainerRequestContext requestContext) throws IOException {
< UriInfo uriInfo = requestContext.getUriInfo();
< String path = uriInfo.getPath();
---
> public ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure,
> WebApplicationException {
> String path = request.getUri().getPath();
56c61,63
< || path.equals(BaseHandler.PATH) || path.startsWith(VirtualClockHandler.PATH)) {
---
> //On older version, the path value from localhost:8080/hawkular/metrics is an empty String instead of /
> || path.equals(BaseHandler.PATH) || path.equals("")
> || path.startsWith(VirtualClockHandler.PATH)) {
58c65
< return;
---
> return null;
61c68,69
< String tenant = requestContext.getHeaders().getFirst(TENANT_HEADER_NAME);
---
> List<String> requestHeader = request.getHttpHeaders().getRequestHeader(TENANT_HEADER_NAME);
> String tenant = requestHeader != null && !requestHeader.isEmpty() ? requestHeader.get(0) : null;
64c72
< return;
---
> return null;
69,72c77,80
< .type(APPLICATION_JSON_TYPE)
< .entity(new ApiError(MISSING_TENANT_MSG))
< .build();
< requestContext.abortWith(response);
---
> .type(APPLICATION_JSON_TYPE)
> .entity(new ApiError(MISSING_TENANT_MSG))
> .build();
> return ServerResponse.copyIfNotServerResponse(response);
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/handler/AvailabilityHandler.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/handler/AvailabilityHandler.java
28d27
< import static org.hawkular.metrics.api.jaxrs.util.ApiUtils.valueToResponse;
33a33
> import java.util.Optional;
47,48d46
< import javax.ws.rs.container.AsyncResponse;
< import javax.ws.rs.container.Suspended;
53,54d50
< import org.hawkular.metrics.api.jaxrs.handler.observer.MetricCreatedObserver;
< import org.hawkular.metrics.api.jaxrs.handler.observer.ResultSetObserver;
65a62
> import org.hawkular.metrics.core.api.MetricAlreadyExistsException;
70,74d66
< import io.swagger.annotations.Api;
< import io.swagger.annotations.ApiOperation;
< import io.swagger.annotations.ApiParam;
< import io.swagger.annotations.ApiResponse;
< import io.swagger.annotations.ApiResponses;
84d75
< @Api(tags = "Availability")
96,107c87,88
< @ApiOperation(value = "Create availability metric. Same notes as creating gauge metric apply.")
< @ApiResponses(value = {
< @ApiResponse(code = 201, message = "Metric created successfully"),
< @ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
< @ApiResponse(code = 409, message = "Availability metric with given id already exists",
< response = ApiError.class),
< @ApiResponse(code = 500, message = "Metric creation failed due to an unexpected error",
< response = ApiError.class)
< })
< public void createAvailabilityMetric(
< @Suspended final AsyncResponse asyncResponse,
< @ApiParam(required = true) MetricDefinition metricDefinition,
---
> public Response createAvailabilityMetric(
> MetricDefinition metricDefinition,
111,112c92,93
< asyncResponse.resume(badRequest(new ApiError("MetricDefinition type does not match " + MetricType
< .AVAILABILITY.getText())));
---
> return ApiUtils.badRequest(new ApiError("MetricDefinition type does not match " + MetricType
> .AVAILABILITY.getText()));
117c98,107
< metricsService.createMetric(metric).subscribe(new MetricCreatedObserver(asyncResponse, location));
---
> try {
> Observable<Void> observable = metricsService.createMetric(metric);
> observable.toBlocking().lastOrDefault(null);
> return Response.created(location).build();
> } catch (MetricAlreadyExistsException e) {
> String message = "A metric with name [" + e.getMetric().getId().getName() + "] already exists";
> return Response.status(Response.Status.CONFLICT).entity(new ApiError(message)).build();
> } catch (Exception e) {
> return serverError(e);
> }
122,130c112,114
< @ApiOperation(value = "Retrieve single metric definition.", response = MetricDefinition.class)
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Metric's definition was successfully retrieved."),
< @ApiResponse(code = 204, message = "Query was successful, but no metrics definition is set."),
< @ApiResponse(code = 500, message = "Unexpected error occurred while fetching metric's definition.",
< response = ApiError.class) })
< public void getAvailabilityMetric(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id) {
<
< metricsService.findMetric(new MetricId<>(tenantId, AVAILABILITY, id))
---
> public Response getAvailabilityMetric(@PathParam("id") String id) {
> try {
> return metricsService.findMetric(new MetricId<>(tenantId, AVAILABILITY, id))
134c118,122
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
---
> .toBlocking()
> .firstOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
> }
139,147c127
< @ApiOperation(value = "Retrieve tags associated with the metric definition.", response = String.class,
< responseContainer = "Map")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Metric's tags were successfully retrieved."),
< @ApiResponse(code = 204, message = "Query was successful, but no metrics were found."),
< @ApiResponse(code = 500, message = "Unexpected error occurred while fetching metric's tags.",
< response = ApiError.class) })
< public void getAvailabilityMetricTags(
< @Suspended final AsyncResponse asyncResponse,
---
> public Response getAvailabilityMetricTags(
150,152c130,139
< metricsService.getMetricTags(new MetricId<>(tenantId, AVAILABILITY, id)).subscribe(
< optional -> asyncResponse.resume(valueToResponse(optional)),
< t -> asyncResponse.resume(serverError(t)));
---
> Observable<Optional<Map<String, String>>> something = metricsService
> .getMetricTags(new MetricId<>(tenantId, AVAILABILITY, id));
> try {
> return something
> .map(ApiUtils::valueToResponse)
> .toBlocking()
> .lastOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
> }
154a142
>
157,163c145
< @ApiOperation(value = "Update tags associated with the metric definition.")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Metric's tags were successfully updated."),
< @ApiResponse(code = 500, message = "Unexpected error occurred while updating metric's tags.",
< response = ApiError.class) })
< public void updateAvailabilityMetricTags(
< @Suspended final AsyncResponse asyncResponse,
---
> public Response updateAvailabilityMetricTags(
165c147
< @ApiParam(required = true) Map<String, String> tags
---
> Map<String, String> tags
168c150,155
< metricsService.addTags(metric, tags).subscribe(new ResultSetObserver(asyncResponse));
---
> try {
> metricsService.addTags(metric, tags).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
> return serverError(e);
> }
173,180c160
< @ApiOperation(value = "Delete tags associated with the metric definition.")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Metric's tags were successfully deleted."),
< @ApiResponse(code = 400, message = "Invalid tags", response = ApiError.class),
< @ApiResponse(code = 500, message = "Unexpected error occurred while trying to delete metric's tags.",
< response = ApiError.class) })
< public void deleteAvailabilityMetricTags(
< @Suspended final AsyncResponse asyncResponse,
---
> public Response deleteAvailabilityMetricTags(
182c162
< @ApiParam("Tag list") @PathParam("tags") Tags tags
---
> @PathParam("tags") Tags tags
185c165,171
< metricsService.deleteTags(metric, tags.getTags()).subscribe(new ResultSetObserver(asyncResponse));
---
>
> try {
> metricsService.deleteTags(metric, tags.getTags()).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
> return serverError(e);
> }
190,199c176,178
< @ApiOperation(value = "Add data for a single availability metric.")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Adding data succeeded."),
< @ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
< @ApiResponse(code = 500, message = "Unexpected error happened while storing the data",
< response = ApiError.class)
< })
< public void addAvailabilityForMetric(
< @Suspended final AsyncResponse asyncResponse, @PathParam("id") String id,
< @ApiParam(value = "List of availability datapoints", required = true) List<AvailabilityDataPoint> data
---
> public Response addAvailabilityForMetric(
> @PathParam("id") String id,
> List<AvailabilityDataPoint> data
202,203c181,186
< Observable<Void> observable = metricsService.addDataPoints(AVAILABILITY, metrics);
< observable.subscribe(new ResultSetObserver(asyncResponse));
---
> try {
> metricsService.addDataPoints(AVAILABILITY, metrics).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
> return serverError(e);
> }
208,217c191
< @ApiOperation(value = "Add metric data for multiple availability metrics in a single call.")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Adding data succeeded."),
< @ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
< @ApiResponse(code = 500, message = "Unexpected error happened while storing the data",
< response = ApiError.class)
< })
< public void addAvailabilityData(
< @Suspended final AsyncResponse asyncResponse,
< @ApiParam(value = "List of availability metrics", required = true)
---
> public Response addAvailabilityData(
221,222c195,200
< Observable<Void> observable = metricsService.addDataPoints(AVAILABILITY, metrics);
< observable.subscribe(new ResultSetObserver(asyncResponse));
---
> try {
> metricsService.addDataPoints(AVAILABILITY, metrics).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
> return serverError(e);
> }
227,234c205,206
< @ApiOperation(value = "Find availabilities metrics data by their tags.", response = Map.class)
< @ApiResponses(value = { @ApiResponse(code = 200, message = "Successfully fetched data."),
< @ApiResponse(code = 204, message = "No matching data found."),
< @ApiResponse(code = 400, message = "Missing or invalid tags query", response = ApiError.class),
< @ApiResponse(code = 500, message = "Any error in the query.", response = ApiError.class), })
< public void findAvailabilityDataByTags(
< @Suspended final AsyncResponse asyncResponse,
< @ApiParam(value = "Tag list", required = true) @QueryParam("tags") Tags tags
---
> public Response findAvailabilityDataByTags(
> @QueryParam("tags") Tags tags
237c209
< asyncResponse.resume(badRequest(new ApiError("Missing tags query")));
---
> return badRequest(new ApiError("Missing tags query"));
239,247c211,221
< // @TODO Repeated code, refactor (in GaugeHandler also)
< metricsService.findAvailabilityByTags(tenantId, tags.getTags()).subscribe(m -> {
< if (m.isEmpty()) {
< asyncResponse.resume(noContent());
< } else {
< asyncResponse.resume(Response.ok(m).build());
< }
< }, t -> asyncResponse.resume(serverError(t)));
<
---
> try {
> return metricsService.findAvailabilityByTags(tenantId, tags.getTags()).map(m -> {
> if (m.isEmpty()) {
> return ApiUtils.noContent();
> } else {
> return Response.ok(m).build();
> }
> }).toBlocking().lastOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
> }
253,265c227
< @ApiOperation(value = "Retrieve availability data.", notes = "When buckets or bucketDuration query parameter is " +
< "used, the time range between start and end will be divided in buckets of equal duration, and " +
< "availability statistics will be computed for each bucket.", response = AvailabilityDataPoint.class,
< responseContainer = "List")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Successfully fetched availability data."),
< @ApiResponse(code = 204, message = "No availability data was found."),
< @ApiResponse(code = 400, message = "buckets or bucketDuration parameter is invalid, or both are used.",
< response = ApiError.class),
< @ApiResponse(code = 500, message = "Unexpected error occurred while fetching availability data.",
< response = ApiError.class), })
< public void findAvailabilityData(
< @Suspended AsyncResponse asyncResponse,
---
> public Response findAvailabilityData(
267,271c229,232
< @ApiParam(value = "Defaults to now - 8 hours") @QueryParam("start") final Long start,
< @ApiParam(value = "Defaults to now") @QueryParam("end") final Long end,
< @ApiParam(value = "Total number of buckets") @QueryParam("buckets") Integer bucketsCount,
< @ApiParam(value = "Bucket duration") @QueryParam("bucketDuration") Duration bucketDuration,
< @ApiParam(value = "Set to true to return only distinct, contiguous values")
---
> @QueryParam("start") final Long start,
> @QueryParam("end") final Long end,
> @QueryParam("buckets") Integer bucketsCount,
> @QueryParam("bucketDuration") Duration bucketDuration,
279d239
<
281c241,242
< metricsService.findAvailabilityData(metricId, startTime, endTime, distinct)
---
> try {
> return metricsService.findAvailabilityData(metricId, startTime, endTime, distinct)
285c246,250
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
---
> .toBlocking()
> .lastOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
> }
287c252
< asyncResponse.resume(badRequest(new ApiError("Both buckets and bucketDuration parameters are used")));
---
> return badRequest(new ApiError("Both buckets and bucketDuration parameters are used"));
297,298c262,269
< asyncResponse.resume(badRequest(new ApiError("Bucket: " + e.getMessage())));
< return;
---
> return badRequest(new ApiError("Bucket: " + e.getMessage()));
> }
> try {
> return metricsService.findAvailabilityStats(metricId, startTime, endTime, buckets)
> .map(ApiUtils::collectionToResponse).toBlocking()
> .lastOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
300,303d270
<
< metricsService.findAvailabilityStats(metricId, startTime, endTime, buckets)
< .map(ApiUtils::collectionToResponse)
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
309,315c276
< @ApiOperation(value = "Add or update availability metric's tags.")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Tags were modified successfully."),
< @ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
< })
< public void tagAvailabilityData(
< @Suspended final AsyncResponse asyncResponse,
---
> public Response tagAvailabilityData(
317c278
< @ApiParam(required = true) TagRequest params
---
> TagRequest params
327c288,294
< resultSetObservable.subscribe(new ResultSetObserver(asyncResponse));
---
>
> try {
> resultSetObservable.toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
> return serverError(e);
> }
332,339c299,300
< @ApiOperation(value = "Find availability metric data with given tags.", response = Map.class)
< @ApiResponses(value = { @ApiResponse(code = 200, message = "Availability values fetched successfully"),
< @ApiResponse(code = 204, message = "No matching data found."),
< @ApiResponse(code = 400, message = "Invalid tags", response = ApiError.class),
< @ApiResponse(code = 500, message = "Any error while fetching data.", response = ApiError.class), })
< public void findTaggedAvailabilityData(
< @Suspended final AsyncResponse asyncResponse,
< @ApiParam("Tag list") @PathParam("tags") Tags tags
---
> public Response findTaggedAvailabilityData(
> @PathParam("tags") Tags tags
341,342c302,303
< metricsService.findAvailabilityByTags(tenantId, tags.getTags())
< .subscribe(m -> { // @TODO Repeated code, refactor and use Optional?
---
> try {
> return metricsService.findAvailabilityByTags(tenantId, tags.getTags()).map(m -> {
344c305
< asyncResponse.resume(noContent());
---
> return ApiUtils.noContent();
346c307
< asyncResponse.resume(Response.ok(m).build());
---
> return Response.ok(m).build();
348c309,312
< }, t -> asyncResponse.resume(serverError(t)));
---
> }).toBlocking().lastOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
> }
349a314
>
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/handler/BaseHandler.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/handler/BaseHandler.java
39,40d38
< import io.swagger.annotations.ApiOperation;
<
53,54d50
< @ApiOperation(value = "Returns some basic information about the Hawkular Metrics service.",
< response = String.class, responseContainer = "Map")
diff -r '--exclude=target' api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/handler/CounterHandler.java api/metrics-api-jaxrs-1.1/src/main/java/org/hawkular/metrics/api/jaxrs/handler/CounterHandler.java
42,43d41
< import javax.ws.rs.container.AsyncResponse;
< import javax.ws.rs.container.Suspended;
48,49d45
< import org.hawkular.metrics.api.jaxrs.handler.observer.MetricCreatedObserver;
< import org.hawkular.metrics.api.jaxrs.handler.observer.ResultSetObserver;
56a53
> import org.hawkular.metrics.core.api.MetricAlreadyExistsException;
61,65d57
< import io.swagger.annotations.Api;
< import io.swagger.annotations.ApiOperation;
< import io.swagger.annotations.ApiParam;
< import io.swagger.annotations.ApiResponse;
< import io.swagger.annotations.ApiResponses;
75d66
< @Api(tags = "Counter")
87,102c78,79
< @ApiOperation(
< value = "Create counter metric. This operation also causes the rate to be calculated and " +
< "persisted periodically after raw count data is persisted.",
< notes = "Clients are not required to explicitly create a metric before storing data. Doing so however " +
< "allows clients to prevent naming collisions and to specify tags and data retention.")
< @ApiResponses(value = {
< @ApiResponse(code = 201, message = "Metric created successfully"),
< @ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
< @ApiResponse(code = 409, message = "Counter metric with given id already exists", response = ApiError
< .class),
< @ApiResponse(code = 500, message = "Metric creation failed due to an unexpected error",
< response = ApiError.class)
< })
< public void createCounter(
< @Suspended final AsyncResponse asyncResponse,
< @ApiParam(required = true) MetricDefinition metricDefinition,
---
> public Response createCounter(
> MetricDefinition metricDefinition,
106,107c83,84
< asyncResponse.resume(badRequest(new ApiError("MetricDefinition type does not match " + MetricType
< .COUNTER.getText())));
---
> return badRequest(new ApiError("MetricDefinition type does not match " + MetricType
> .COUNTER.getText()));
112c89,98
< metricsService.createMetric(metric).subscribe(new MetricCreatedObserver(asyncResponse, location));
---
> try {
> Observable<Void> observable = metricsService.createMetric(metric);
> observable.toBlocking().lastOrDefault(null);
> return Response.created(location).build();
> } catch (MetricAlreadyExistsException e) {
> String message = "A metric with name [" + e.getMetric().getId().getName() + "] already exists";
> return Response.status(Response.Status.CONFLICT).entity(new ApiError(message)).build();
> } catch (Exception e) {
> return serverError(e);
> }
117,125c103,105
< @ApiOperation(value = "Retrieve a counter definition", response = MetricDefinition.class)
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Metric's definition was successfully retrieved."),
< @ApiResponse(code = 204, message = "Query was successful, but no metrics definition is set."),
< @ApiResponse(code = 500, message = "Unexpected error occurred while fetching metric's definition.",
< response = ApiError.class) })
< public void getCounter(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id) {
<
< metricsService.findMetric(new MetricId<>(tenantId, COUNTER, id))
---
> public Response getCounter(@PathParam("id") String id) {
> try {
> return metricsService.findMetric(new MetricId<>(tenantId, COUNTER, id))
128,129c108,112
< .switchIfEmpty(Observable.just(noContent()))
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
---
> .switchIfEmpty(Observable.just(noContent()))
> .toBlocking().lastOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
> }
134,143c117
< @ApiOperation(value = "Add data points for multiple counters")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Adding data points succeeded."),
< @ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
< @ApiResponse(code = 500, message = "Unexpected error happened while storing the data points",
< response = ApiError.class)
< })
< public void addData(@Suspended final AsyncResponse asyncResponse,
< @ApiParam(value = "List of metrics", required = true) List<Counter> counters
< ) {
---
> public Response addData(List<Counter> counters) {
145,146c119,124
< Observable<Void> observable = metricsService.addDataPoints(COUNTER, metrics);
< observable.subscribe(new ResultSetObserver(asyncResponse));
---
> try {
> metricsService.addDataPoints(COUNTER, metrics).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
> return serverError(e);
> }
151,159c129
< @ApiOperation(value = "Add data for a single counter")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Adding data succeeded."),
< @ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
< @ApiResponse(code = 500, message = "Unexpected error happened while storing the data",
< response = ApiError.class),
< })
< public void addData(
< @Suspended final AsyncResponse asyncResponse,
---
> public Response addData(
161d130
< @ApiParam(value = "List of data points containing timestamp and value", required = true)
165,166c134,139
< Observable<Void> observable = metricsService.addDataPoints(COUNTER, metrics);
< observable.subscribe(new ResultSetObserver(asyncResponse));
---
> try {
> metricsService.addDataPoints(COUNTER, metrics).toBlocking().lastOrDefault(null);
> return Response.ok().build();
> } catch (Exception e) {
> return serverError(e);
> }
171,181c144
< @ApiOperation(value = "Retrieve counter data points.", response = CounterDataPoint.class,
< responseContainer = "List")
< @ApiResponses(value = {
< @ApiResponse(code = 200, message = "Successfully fetched metric data."),
< @ApiResponse(code = 204, message = "No metric data was found."),
< @ApiResponse(code = 400, message = "start or end parameter is invalid.",
< response = ApiError.class),
< @ApiResponse(code = 500, message = "Unexpected error occurred while fetching metric data.",
< response = ApiError.class) })
< public void findCounterData(
< @Suspended AsyncResponse asyncResponse,
---
> public Response findCounterData(
183,185c146,148
< @ApiParam(value = "Defaults to now - 8 hours") @QueryParam("start") final Long start,
< @ApiParam(value = "Defaults to now") @QueryParam("end") final Long end) {
<
---
> @QueryParam("start") final Long start,
> @QueryParam("end") final Long end
> ) {
190c153,154
< metricsService.findDataPoints(new MetricId<>(tenantId, COUNTER, id), startTime, endTime)
---
> try {
> return metricsService.findDataPoints(new MetricId<>(tenantId, COUNTER, id), startTime, endTime)
194c158,162
< .subscribe(asyncResponse::resume, t -> asyncResponse.resume(serverError(t)));
---
> .toBlocking()
> .lastOrDefault(null);
> } catch (Exception e) {
> return serverError(e);
> }
199,211c167
< @ApiOperation(
< value = "Retrieve counter rate data points which are automatically generated on the server side.",
< notes = "Rate data points are only generated for counters that are explicitly created.",
< response = GaugeDataPoint.class, responseContainer = "List")