@Test public void testWithNoQueryParams() throws IOException { FullHttpRequest request = createQueryRequest(""); ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class); handler.handle(context, request); verify(channel).write(argument.capture()); String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset()); ErrorResponse errorResponse = getErrorResponse(errorResponseBody); assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size()); assertEquals("Invalid error message", "Invalid Query String", errorResponse.getErrors().get(0).getMessage()); assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId()); assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus()); }
@Override public void handle(ChannelHandlerContext ctx, FullHttpRequest request) { Tracker.getInstance().track(request); final String tenantId = request.headers().get("tenantId"); HttpRequestWithDecodedQueryParams requestWithParams = (HttpRequestWithDecodedQueryParams) request; List<String> query = requestWithParams.getQueryParams().get("query"); if (query == null || query.size() != 1) { DefaultHandler.sendErrorResponse(ctx, request, "Invalid Query String", HttpResponseStatus.BAD_REQUEST); return; } discoveryHandle = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); if (discoveryHandle == null) { sendResponse(ctx, request, null, HttpResponseStatus.NOT_FOUND); return; } try { List<SearchResult> searchResults = discoveryHandle.search(tenantId, query.get(0)); sendResponse(ctx, request, getSerializedJSON(searchResults), HttpResponseStatus.OK); } catch (Exception e) { log.error(String.format("Exception occurred while trying to get metrics index for %s", tenantId), e); DefaultHandler.sendErrorResponse(ctx, request, "Error getting metrics index", HttpResponseStatus.INTERNAL_SERVER_ERROR); } }
HttpMetricsIndexHandler implements HttpRequestHandler { @Override public void handle(ChannelHandlerContext ctx, FullHttpRequest request) { Tracker.getInstance().track(request); final String tenantId = request.headers().get("tenantId"); HttpRequestWithDecodedQueryParams requestWithParams = (HttpRequestWithDecodedQueryParams) request; List<String> query = requestWithParams.getQueryParams().get("query"); if (query == null || query.size() != 1) { DefaultHandler.sendErrorResponse(ctx, request, "Invalid Query String", HttpResponseStatus.BAD_REQUEST); return; } discoveryHandle = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); if (discoveryHandle == null) { sendResponse(ctx, request, null, HttpResponseStatus.NOT_FOUND); return; } try { List<SearchResult> searchResults = discoveryHandle.search(tenantId, query.get(0)); sendResponse(ctx, request, getSerializedJSON(searchResults), HttpResponseStatus.OK); } catch (Exception e) { log.error(String.format("Exception occurred while trying to get metrics index for %s", tenantId), e); DefaultHandler.sendErrorResponse(ctx, request, "Error getting metrics index", HttpResponseStatus.INTERNAL_SERVER_ERROR); } } }
HttpMetricsIndexHandler implements HttpRequestHandler { @Override public void handle(ChannelHandlerContext ctx, FullHttpRequest request) { Tracker.getInstance().track(request); final String tenantId = request.headers().get("tenantId"); HttpRequestWithDecodedQueryParams requestWithParams = (HttpRequestWithDecodedQueryParams) request; List<String> query = requestWithParams.getQueryParams().get("query"); if (query == null || query.size() != 1) { DefaultHandler.sendErrorResponse(ctx, request, "Invalid Query String", HttpResponseStatus.BAD_REQUEST); return; } discoveryHandle = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); if (discoveryHandle == null) { sendResponse(ctx, request, null, HttpResponseStatus.NOT_FOUND); return; } try { List<SearchResult> searchResults = discoveryHandle.search(tenantId, query.get(0)); sendResponse(ctx, request, getSerializedJSON(searchResults), HttpResponseStatus.OK); } catch (Exception e) { log.error(String.format("Exception occurred while trying to get metrics index for %s", tenantId), e); DefaultHandler.sendErrorResponse(ctx, request, "Error getting metrics index", HttpResponseStatus.INTERNAL_SERVER_ERROR); } }  }
HttpMetricsIndexHandler implements HttpRequestHandler { @Override public void handle(ChannelHandlerContext ctx, FullHttpRequest request) { Tracker.getInstance().track(request); final String tenantId = request.headers().get("tenantId"); HttpRequestWithDecodedQueryParams requestWithParams = (HttpRequestWithDecodedQueryParams) request; List<String> query = requestWithParams.getQueryParams().get("query"); if (query == null || query.size() != 1) { DefaultHandler.sendErrorResponse(ctx, request, "Invalid Query String", HttpResponseStatus.BAD_REQUEST); return; } discoveryHandle = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); if (discoveryHandle == null) { sendResponse(ctx, request, null, HttpResponseStatus.NOT_FOUND); return; } try { List<SearchResult> searchResults = discoveryHandle.search(tenantId, query.get(0)); sendResponse(ctx, request, getSerializedJSON(searchResults), HttpResponseStatus.OK); } catch (Exception e) { log.error(String.format("Exception occurred while trying to get metrics index for %s", tenantId), e); DefaultHandler.sendErrorResponse(ctx, request, "Error getting metrics index", HttpResponseStatus.INTERNAL_SERVER_ERROR); } }  @Override void handle(ChannelHandlerContext ctx, FullHttpRequest request); static String getSerializedJSON(List<SearchResult> searchResults); }
HttpMetricsIndexHandler implements HttpRequestHandler { @Override public void handle(ChannelHandlerContext ctx, FullHttpRequest request) { Tracker.getInstance().track(request); final String tenantId = request.headers().get("tenantId"); HttpRequestWithDecodedQueryParams requestWithParams = (HttpRequestWithDecodedQueryParams) request; List<String> query = requestWithParams.getQueryParams().get("query"); if (query == null || query.size() != 1) { DefaultHandler.sendErrorResponse(ctx, request, "Invalid Query String", HttpResponseStatus.BAD_REQUEST); return; } discoveryHandle = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); if (discoveryHandle == null) { sendResponse(ctx, request, null, HttpResponseStatus.NOT_FOUND); return; } try { List<SearchResult> searchResults = discoveryHandle.search(tenantId, query.get(0)); sendResponse(ctx, request, getSerializedJSON(searchResults), HttpResponseStatus.OK); } catch (Exception e) { log.error(String.format("Exception occurred while trying to get metrics index for %s", tenantId), e); DefaultHandler.sendErrorResponse(ctx, request, "Error getting metrics index", HttpResponseStatus.INTERNAL_SERVER_ERROR); } }  @Override void handle(ChannelHandlerContext ctx, FullHttpRequest request); static String getSerializedJSON(List<SearchResult> searchResults);  }