Java Code Examples for com.linecorp.armeria.common.AggregatedHttpResponse#of()
The following examples show how to use
com.linecorp.armeria.common.AggregatedHttpResponse#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/traces/:trace_id") public AggregatedHttpResponse getTrace(@Param("trace_id") String traceId) { try { if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); ReadOnlyKeyValueStore<String, List<Span>> store = storage.getTraceStorageStream() .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore()); List<Span> spans = store.get(traceId); return AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON, SpanBytesEncoder.JSON_V2.encodeList(spans)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example 2
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/traceMany") public AggregatedHttpResponse getTraces(@Param("traceIds") String traceIds) { try { if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); ReadOnlyKeyValueStore<String, List<Span>> store = storage.getTraceStorageStream() .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore()); List<List<Span>> result = new ArrayList<>(); for (String traceId : traceIds.split(",", 1000)) { result.add(store.get(traceId)); } return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.JSON, writeTraces(result)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example 3
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 5 votes |
@Get("/dependencies") public AggregatedHttpResponse getDependencies( @Param("endTs") long endTs, @Param("lookback") long lookback ) { try { if (!storage.dependencyQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); ReadOnlyWindowStore<Long, DependencyLink> store = storage.getDependencyStorageStream() .store(DEPENDENCIES_STORE_NAME, QueryableStoreTypes.windowStore()); List<DependencyLink> links = new ArrayList<>(); Instant from = Instant.ofEpochMilli(endTs - lookback); Instant to = Instant.ofEpochMilli(endTs); try (KeyValueIterator<Windowed<Long>, DependencyLink> iterator = store.fetchAll(from, to)) { iterator.forEachRemaining(keyValue -> links.add(keyValue.value)); } List<DependencyLink> mergedLinks = DependencyLinker.merge(links); LOG.debug("Dependencies found from={}-to={}: {}", from, to, mergedLinks.size()); return AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON, DependencyLinkBytesEncoder.JSON_V1.encodeList(mergedLinks)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example 4
Source File: HealthCheckServiceBuilder.java From armeria with Apache License 2.0 | 5 votes |
/** * Make a copy just in case the content is modified by the caller or is backed by ByteBuf. */ private static AggregatedHttpResponse copyResponse(AggregatedHttpResponse res) { return AggregatedHttpResponse.of(res.informationals(), res.headers(), HttpData.copyOf(res.content().array()), res.trailers()); }
Example 5
Source File: HealthCheckService.java From armeria with Apache License 2.0 | 5 votes |
private AggregatedHttpResponse setCommonHeaders(AggregatedHttpResponse res) { return AggregatedHttpResponse.of(res.informationals(), setCommonHeaders(res.headers()), res.content(), res.trailers().toBuilder() .removeAndThen(ARMERIA_LPHC) .build()); }
Example 6
Source File: HealthCheckService.java From armeria with Apache License 2.0 | 5 votes |
private static AggregatedHttpResponse clearCommonHeaders(AggregatedHttpResponse res) { return AggregatedHttpResponse.of(res.informationals(), res.headers().toBuilder() .removeAndThen(ARMERIA_LPHC) .build(), res.content(), res.trailers().toBuilder() .removeAndThen(ARMERIA_LPHC) .build()); }
Example 7
Source File: AnnotatedServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Post @Path("/a/string-aggregate-response1") public AggregatedHttpResponse postStringAggregateResponse1(AggregatedHttpRequest request, RequestContext ctx) { validateContext(ctx); return AggregatedHttpResponse.of(ResponseHeaders.of(HttpStatus.OK), request.content()); }
Example 8
Source File: AnnotatedServiceHandlersOrderTest.java From armeria with Apache License 2.0 | 5 votes |
@Post("/exceptionHandlerOrder") @ExceptionHandler(MethodLevelExceptionHandler.class) public HttpResponse exceptionHandlerOrder(@RequestObject String name) { assertThat(name).isEqualTo("foo"); final AggregatedHttpResponse response = AggregatedHttpResponse.of( HttpStatus.NOT_IMPLEMENTED, MediaType.PLAIN_TEXT_UTF_8, "hello " + name); throw HttpResponseException.of(response); }
Example 9
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 4 votes |
@Get("/traces") public AggregatedHttpResponse getTraces( @Param("serviceName") Optional<String> serviceName, @Param("remoteServiceName") Optional<String> remoteServiceName, @Param("spanName") Optional<String> spanName, @Param("annotationQuery") Optional<String> annotationQuery, @Param("minDuration") Optional<Long> minDuration, @Param("maxDuration") Optional<Long> maxDuration, @Param("endTs") Optional<Long> endTs, @Default("86400000") @Param("lookback") Long lookback, @Default("10") @Param("limit") int limit ) { try { if (!storage.traceSearchEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); QueryRequest request = QueryRequest.newBuilder() .serviceName(serviceName.orElse(null)) .remoteServiceName(remoteServiceName.orElse(null)) .spanName(spanName.orElse(null)) .parseAnnotationQuery(annotationQuery.orElse(null)) .minDuration(minDuration.orElse(null)) .maxDuration(maxDuration.orElse(null)) .endTs(endTs.orElse(System.currentTimeMillis())) .lookback(lookback) .limit(limit) .build(); ReadOnlyKeyValueStore<String, List<Span>> tracesStore = storage.getTraceStorageStream() .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore()); ReadOnlyKeyValueStore<Long, Set<String>> traceIdsByTsStore = storage.getTraceStorageStream() .store(SPAN_IDS_BY_TS_STORE_NAME, QueryableStoreTypes.keyValueStore()); List<List<Span>> traces = new ArrayList<>(); List<String> traceIds = new ArrayList<>(); long from = MILLISECONDS.toMicros(request.endTs() - request.lookback()); long to = MILLISECONDS.toMicros(request.endTs()); long bucket = SECONDS.toMicros(30); long checkpoint = to - bucket; // 30 sec before upper bound if (checkpoint <= from || tracesStore.approximateNumEntries() <= minTracesStored) { // do one run try (KeyValueIterator<Long, Set<String>> spanIds = traceIdsByTsStore.range(from, to)) { addResults(request, tracesStore, traces, traceIds, spanIds); } } else { while (checkpoint > from && traces.size() < request.limit()) { try (KeyValueIterator<Long, Set<String>> spanIds = traceIdsByTsStore.range(checkpoint, to)) { addResults(request, tracesStore, traces, traceIds, spanIds); } to = checkpoint; checkpoint = checkpoint - bucket; // 1 min before more } } traces.sort(Comparator.<List<Span>>comparingLong(o -> o.get(0).timestampAsLong()).reversed()); LOG.debug("Traces found from query {}: {}", request, traces.size()); List<List<Span>> result = traces.stream().limit(request.limit()).collect(Collectors.toList()); return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.JSON, writeTraces(result)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example 10
Source File: ArmeriaAutoConfigurationTest.java From armeria with Apache License 2.0 | 4 votes |
@Get("/get") public AggregatedHttpResponse get() { return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "annotated"); }
Example 11
Source File: HttpResponseAggregator.java From armeria with Apache License 2.0 | 4 votes |
@Override protected AggregatedHttpResponse onSuccess(HttpData content) { checkState(headers != null, "An aggregated message does not have headers."); return AggregatedHttpResponse.of(firstNonNull(informationals, Collections.emptyList()), headers, content, trailers); }
Example 12
Source File: AnnotatedServiceBlockingTest.java From armeria with Apache License 2.0 | 4 votes |
@Get("/aggregatedHttpResponse") public AggregatedHttpResponse aggregatedHttpResponse(RequestContext ctx) { return AggregatedHttpResponse.of(HttpStatus.OK); }
Example 13
Source File: AnnotatedServiceBlockingTest.java From armeria with Apache License 2.0 | 4 votes |
@Get("/aggregatedHttpResponse") @Blocking public AggregatedHttpResponse aggregatedHttpResponse(RequestContext ctx) { return AggregatedHttpResponse.of(HttpStatus.OK); }