/** * Constructor. * * @param name Name of the webservice */ public TestDruidWebService(String name) { this(new DruidServiceConfig(name, null, null, null)); }
/** * IOC constructor. * * @param config the configuration for this druid service * @param asyncHttpClient the HTTP client * @param mapper A shared jackson object mapper resource * @param headersToAppend Supplier for map of headers for Druid requests * @param jsonNodeBuilderStrategy A function to build JSON nodes from the response */ public AsyncDruidWebServiceImpl( DruidServiceConfig config, AsyncHttpClient asyncHttpClient, ObjectMapper mapper, Supplier<Map<String, String>> headersToAppend, Function<Response, JsonNode> jsonNodeBuilderStrategy ) { this.serviceConfig = config; if (serviceConfig.getUrl() == null) { String msg = DRUID_URL_INVALID.format(config.getNameAndUrl()); LOG.error(msg); throw new IllegalStateException(msg); } LOG.info("Configured with druid server config: {}", config.toString()); this.headersToAppend = headersToAppend; this.webClient = asyncHttpClient; this.writer = mapper.writer(); this.httpErrorMeter = REGISTRY.meter("druid.errors.http"); this.exceptionMeter = REGISTRY.meter("druid.errors.exceptions"); this.jsonNodeBuilderStrategy = jsonNodeBuilderStrategy; }
@Override public Integer getTimeout() { return serviceConfig.getTimeout(); }
@Override public String toString() { return " name: " + serviceConfig.getNameAndUrl() + " hash code: " + hashCode(); }
@Override public Future<Response> getJsonObject( SuccessCallback success, HttpErrorCallback error, FailureCallback failure, String resourcePath ) { String url = String.format("%s%s", serviceConfig.getUrl(), resourcePath); BoundRequestBuilder requestBuilder = webClient.prepareGet(url); headersToAppend.get().forEach(requestBuilder::addHeader); return sendRequest( success, error, failure, requestBuilder, DRUID_SEGMENT_METADATA_TIMER, new AtomicLong(1) ); }
@Override public boolean handleRequest( RequestContext context, DataApiRequest request, DruidAggregationQuery<?> druidQuery, ResponseProcessor response ) { WebServiceHandler handler = handlerSelector.select(druidQuery, request, context); // Add a timeout to the query if the selected webService is configured with one Integer timeout = handler.getWebService().getTimeout(); // Add a priority to the query if there is one configured Integer priority = handler.getWebService().getServiceConfig().getPriority(); QueryContext qc = druidQuery.getContext().withTimeout(timeout).withPriority(priority); if (!qc.isEmpty()) { druidQuery = druidQuery.withContext(qc); } return handler.handleRequest(context, request, druidQuery, response); } }
@Override public String toString() { return " name: " + serviceConfig.getNameAndUrl() + " hash code: " + hashCode(); }
BoundRequestBuilder requestBuilder = webClient.preparePost(serviceConfig.getUrl()) .setBody(entityBody) .addHeader("Content-Type", "application/json; charset=UTF-8");
/** * Constructor. * * @param serviceConfig Config to use when building the test druid web service */ public TestDruidWebService(DruidServiceConfig serviceConfig) { this.serviceConfig = serviceConfig; this.timeout = serviceConfig.getTimeout(); }
@Override public void onThrowable(Throwable t) { RequestLog.restore(logCtx); RequestLog.stopTiming(timerName); if (outstanding.decrementAndGet() == 0) { RequestLog.startTiming(RESPONSE_WORKFLOW_TIMER); } exceptionMeter.mark(); LOG.error("druid {} request failed:", serviceConfig.getNameAndUrl(), t); failure.invoke(t); } });
/** * Constructor. * <p> * Uses the default name. */ public TestDruidWebService() { this(new DruidServiceConfig(DEFAULT_NAME, null, null, null)); }
/** * Constructor. * * @param serviceConfig Config to use when building the test druid web service */ public TestDruidWebService(DruidServiceConfig serviceConfig) { this.serviceConfig = serviceConfig; this.timeout = serviceConfig.getTimeout(); }
/** * Count and log error, then send error response. * * @param status The response status * @param response The druid response * @param druidQueryId The Druid query ID * @param error callback for handling http errors. */ private void markError(Status status, Response response, String druidQueryId, HttpErrorCallback error) { getHttpErrorMeter().mark(); LOG.debug( "druid {} error: {} {} {} and druid query id: {}", getServiceConfig().getNameAndUrl(), status.getStatusCode(), status.getReasonPhrase(), response.getResponseBody(), druidQueryId ); error.invoke( status.getStatusCode(), status.getReasonPhrase(), response.getResponseBody() ); } }
/** * Constructor. * <p> * Uses the default name. */ public TestDruidWebService() { this(new DruidServiceConfig(DEFAULT_NAME, null, null, null)); }
@Override public Integer getTimeout() { return serviceConfig.getTimeout(); }
getServiceConfig().getNameAndUrl(), status.getStatusCode(), status,
/** * Constructor. * * @param name Name of the webservice */ public TestDruidWebService(String name) { this(new DruidServiceConfig(name, null, null, null)); }
@Override public Integer getTimeout() { return serviceConfig.getTimeout(); }
RequestLog.startTiming(RESPONSE_WORKFLOW_TIMER); LOG.error("druid {} http request failed: ", serviceConfig.getNameAndUrl(), t); failure.invoke(t); return CompletedFuture.throwing(t);
/** * Create a druid service configuration object for the metadata service. * * @return a druid service configuration object with all configuration parameters set */ public static DruidServiceConfig getMetadataServiceConfig() { return new DruidServiceConfig( "Coordinator", getDruidCoordUrl(), getDruidTimeout(), getDruidPriority() ); }