-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a factory for building
ResponseProcessor
. (#663)
-- We would like to do a little bit of Druid error analysis to extract some more illuminating error codes out of some of Druid's 500's. The error callback is controlled by the `ResponseProcessor`. -- Unfortunately, the `ResponseProcessor` can't be injected directly because it depends on the `DataApiRequest`, which is built directly in each request. So instead we wrap the creation of `ResponseProcessor` in a factory that can be injected.
- Loading branch information
Showing
5 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../main/java/com/yahoo/bard/webservice/web/responseprocessors/ResponseProcessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2018 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.web.responseprocessors; | ||
|
||
import com.yahoo.bard.webservice.application.ObjectMappersSuite; | ||
import com.yahoo.bard.webservice.data.DruidResponseParser; | ||
import com.yahoo.bard.webservice.data.HttpResponseMaker; | ||
import com.yahoo.bard.webservice.web.DataApiRequest; | ||
import com.yahoo.bard.webservice.web.PreResponse; | ||
|
||
import rx.subjects.Subject; | ||
|
||
/** | ||
* A {@link ResponseProcessor} relies on things that are directly constructed at request time (i.e. the | ||
* {@link DataApiRequest}). Therefore, we can't inject a `ResponseProcessor` directly. We can however inject a factory. | ||
*/ | ||
public interface ResponseProcessorFactory { | ||
|
||
/** | ||
* Constructs a custom ResponseProcessor. | ||
* | ||
* @param apiRequest The current request | ||
* @param responseEmitter Generates the response to be processed | ||
* @param druidResponseParser Transforms a druid response into a {@link ResultSet} | ||
* @param objectMappers Dictates how to format | ||
* @param httpResponseMaker Crafts an HTTP response to be sent back to the user from a ResultSet or error message | ||
* | ||
* @return An object that handles parsing and post-processing of Druid requests | ||
*/ | ||
ResponseProcessor build( | ||
DataApiRequest apiRequest, | ||
Subject<PreResponse, PreResponse> responseEmitter, | ||
DruidResponseParser druidResponseParser, | ||
ObjectMappersSuite objectMappers, | ||
HttpResponseMaker httpResponseMaker | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
...a/com/yahoo/bard/webservice/web/responseprocessors/ResultSetResponseProcessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.web.responseprocessors; | ||
|
||
import com.yahoo.bard.webservice.application.ObjectMappersSuite; | ||
import com.yahoo.bard.webservice.data.DruidResponseParser; | ||
import com.yahoo.bard.webservice.data.HttpResponseMaker; | ||
import com.yahoo.bard.webservice.web.DataApiRequest; | ||
import com.yahoo.bard.webservice.web.PreResponse; | ||
|
||
import rx.subjects.Subject; | ||
|
||
/** | ||
* Builds the default Druid response processor: {@link ResultSetResponseProcessor}. | ||
*/ | ||
public class ResultSetResponseProcessorFactory implements ResponseProcessorFactory { | ||
|
||
@Override | ||
public ResponseProcessor build( | ||
DataApiRequest apiRequest, | ||
Subject<PreResponse, PreResponse> responseEmitter, | ||
DruidResponseParser druidResponseParser, | ||
ObjectMappersSuite objectMappers, | ||
HttpResponseMaker httpResponseMaker | ||
) { | ||
return new ResultSetResponseProcessor( | ||
apiRequest, | ||
responseEmitter, | ||
druidResponseParser, | ||
objectMappers, | ||
httpResponseMaker | ||
); | ||
} | ||
} |