diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2023-12-19 15:24:28 +0000 |
---|---|---|
committer | Waqas Ikram <waqas.ikram@est.tech> | 2023-12-20 09:49:58 +0000 |
commit | 177d66d0048466cba23eb3a1cc4fe56bf1dce58e (patch) | |
tree | 2434b8acb250a78eefd7ce5d42a0f5d5ad84c4df | |
parent | 89945a1bde22e0ab0a9fb35d26d8084fadf909ee (diff) |
Updating config variable names for HttpClient
for DMI
Issue-ID: CPS-2016
Change-Id: Ief5428e6e4afc8309ceed2a8221365e2fab31686
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
4 files changed, 18 insertions, 13 deletions
diff --git a/cps-application/src/main/resources/application.yml b/cps-application/src/main/resources/application.yml index 8dafdec11a..f973b6fa9c 100644 --- a/cps-application/src/main/resources/application.yml +++ b/cps-application/src/main/resources/application.yml @@ -166,6 +166,11 @@ logging: cps: INFO ncmp: dmi: + httpclient: + connectionTimeoutInSeconds: 180 + maximumConnectionsPerRoute: 50 + maximumConnectionsTotal: 100 + idleConnectionEvictionThresholdInSeconds: 5 auth: username: ${DMI_USERNAME} password: ${DMI_PASSWORD} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java index aaa4f1e5bb..729930e65e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java @@ -29,7 +29,7 @@ import org.springframework.boot.convert.DurationUnit; @Getter @Setter -@ConfigurationProperties(prefix = "httpclient5", ignoreUnknownFields = true) +@ConfigurationProperties(prefix = "ncmp.dmi.httpclient", ignoreUnknownFields = true) public class HttpClientConfiguration { /** diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java index 4460094f54..c6ff116a7f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java @@ -72,33 +72,33 @@ public class NcmpConfiguration { */ @Bean @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) - public static RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder, + public static RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder, final HttpClientConfiguration httpClientConfiguration) { - + final ConnectionConfig connectionConfig = ConnectionConfig.copy(ConnectionConfig.DEFAULT) .setConnectTimeout(Timeout.of(httpClientConfiguration.getConnectionTimeoutInSeconds())) .build(); - + final PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create() .setDefaultConnectionConfig(connectionConfig) .setMaxConnTotal(httpClientConfiguration.getMaximumConnectionsTotal()) .setMaxConnPerRoute(httpClientConfiguration.getMaximumConnectionsPerRoute()) .build(); - + final CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connectionManager) .evictExpiredConnections() .evictIdleConnections( TimeValue.of(httpClientConfiguration.getIdleConnectionEvictionThresholdInSeconds())) .build(); - + final ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); - + final RestTemplate restTemplate = restTemplateBuilder .requestFactory(() -> requestFactory) .setConnectTimeout(httpClientConfiguration.getConnectionTimeoutInSeconds()) .build(); - + setRestTemplateMessageConverters(restTemplate); return restTemplate; } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy index 941c8b8a70..2c76b5bb44 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy @@ -31,7 +31,7 @@ import spock.lang.Specification @SpringBootTest @ContextConfiguration(classes = [HttpClientConfiguration]) @EnableConfigurationProperties(HttpClientConfiguration.class) -@TestPropertySource(properties = ["httpclient5.connectionTimeoutInSeconds=1", "httpclient5.maximumConnectionsTotal=200"]) +@TestPropertySource(properties = ["ncmp.dmi.httpclient.connectionTimeoutInSeconds=1", "ncmp.dmi.httpclient.maximumConnectionsTotal=200"]) class HttpClientConfigurationSpec extends Specification { @Autowired @@ -39,10 +39,10 @@ class HttpClientConfigurationSpec extends Specification { def 'Test HttpClientConfiguration properties with custom and default values'() { expect: 'custom property values' - httpClientConfiguration.getConnectionTimeoutInSeconds() == Duration.ofSeconds(1) - httpClientConfiguration.getMaximumConnectionsTotal() == 200 + assert httpClientConfiguration.getConnectionTimeoutInSeconds() == Duration.ofSeconds(1) + assert httpClientConfiguration.getMaximumConnectionsTotal() == 200 and: 'default property values' - httpClientConfiguration.getMaximumConnectionsPerRoute() == 50 - httpClientConfiguration.getIdleConnectionEvictionThresholdInSeconds() == Duration.ofSeconds(5) + assert httpClientConfiguration.getMaximumConnectionsPerRoute() == 50 + assert httpClientConfiguration.getIdleConnectionEvictionThresholdInSeconds() == Duration.ofSeconds(5) } } |