-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor metacat-connector-druid http client to support custom extens…
…ions
- Loading branch information
1 parent
52066ec
commit fb89b1f
Showing
8 changed files
with
123 additions
and
90 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
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
77 changes: 77 additions & 0 deletions
77
.../src/main/java/com/netflix/metacat/connector/druid/configs/BaseDruidHttpClientConfig.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,77 @@ | ||
package com.netflix.metacat.connector.druid.configs; | ||
|
||
import com.netflix.metacat.common.server.connectors.ConnectorContext; | ||
import com.netflix.metacat.common.server.connectors.util.TimeUtil; | ||
import com.netflix.metacat.connector.druid.DruidConfigConstants; | ||
import com.netflix.metacat.connector.druid.MetacatDruidClient; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* DruidHttpClientConfig. | ||
* | ||
* @author zhenl jtuglu | ||
* @since 1.2.0 | ||
*/ | ||
public abstract class BaseDruidHttpClientConfig { | ||
/** | ||
* Druid client instance. | ||
* | ||
* @param connectorContext connector context | ||
* @param restTemplate rest template | ||
* @return MetacatDruidClient | ||
*/ | ||
@Bean | ||
public abstract MetacatDruidClient createMetacatDruidClient( | ||
final ConnectorContext connectorContext, | ||
final RestTemplate restTemplate | ||
); | ||
|
||
/** | ||
* Rest template. | ||
* | ||
* @param connectorContext connector context | ||
* @return RestTemplate | ||
*/ | ||
@Bean | ||
public RestTemplate restTemplate(final ConnectorContext connectorContext) { | ||
return new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient(connectorContext))); | ||
} | ||
|
||
/** | ||
* Http client. | ||
* | ||
* @param connectorContext connector context | ||
* @return HttpClient | ||
*/ | ||
@Bean | ||
public HttpClient httpClient(final ConnectorContext connectorContext) { | ||
final int timeout = (int) TimeUtil.toTime( | ||
connectorContext.getConfiguration().getOrDefault(DruidConfigConstants.HTTP_TIMEOUT, "5s"), | ||
TimeUnit.SECONDS, | ||
TimeUnit.MILLISECONDS | ||
); | ||
final int poolSize = Integer.parseInt(connectorContext.getConfiguration() | ||
.getOrDefault(DruidConfigConstants.POOL_SIZE, "10")); | ||
final RequestConfig config = RequestConfig.custom() | ||
.setConnectTimeout(timeout) | ||
.setConnectionRequestTimeout(timeout) | ||
.setSocketTimeout(timeout) | ||
.setMaxRedirects(3) | ||
.build(); | ||
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); | ||
connectionManager.setMaxTotal(poolSize); | ||
return HttpClientBuilder | ||
.create() | ||
.setDefaultRequestConfig(config) | ||
.setConnectionManager(connectionManager) | ||
.build(); | ||
} | ||
} |
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
10 changes: 5 additions & 5 deletions
10
...ctor/druid/DruidHttpClientUtilSpec.groovy → ...onnector/druid/DruidClientUtilSpec.groovy
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