Add woody with deadlines (#35)

This commit is contained in:
Pavel Popov 2018-09-20 13:32:48 +03:00 committed by GitHub
parent f4d18b0369
commit fe9b71f013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 32 deletions

View File

@ -12,7 +12,7 @@
</parent>
<artifactId>proxy-mocketbank</artifactId>
<version>1.0.5-SNAPSHOT</version>
<version>1.0.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>proxy-mocketbank</name>
@ -61,7 +61,7 @@
<dependency>
<groupId>com.rbkmoney.woody</groupId>
<artifactId>woody-thrift</artifactId>
<version>1.1.13</version>
<version>1.1.15</version>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>

View File

@ -1,32 +1,39 @@
package com.rbkmoney.proxy.mocketbank.configuration;
import com.rbkmoney.woody.api.trace.ContextUtils;
import com.rbkmoney.woody.api.trace.context.TraceContext;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.annotation.RequestScope;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
@Configuration
public class RestTemplateConfiguration {
@Value("${restTemplate.networkTimeout}")
private int networkTimeout;
@Bean
SSLContext sslContext() throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException {
public SSLContext sslContext() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
return new SSLContextBuilder()
.loadTrustMaterial((x509Certificates, s) -> true)
.build();
}
@Bean
CloseableHttpClient httpClient(SSLContext sslContext) {
public CloseableHttpClient httpClient(SSLContext sslContext) {
return HttpClients.custom()
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSSLContext(sslContext)
@ -34,15 +41,21 @@ public class RestTemplateConfiguration {
}
@Bean
HttpComponentsClientHttpRequestFactory requestFactory(CloseableHttpClient httpClient) {
public HttpComponentsClientHttpRequestFactory requestFactory(CloseableHttpClient httpClient) {
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
return requestFactory;
}
@Bean
RestTemplate restTemplate(HttpComponentsClientHttpRequestFactory requestFactory) {
return new RestTemplate(requestFactory);
@RequestScope
public RestTemplate restTemplate(HttpComponentsClientHttpRequestFactory requestFactory) {
int executionTimeout = ContextUtils.getExecutionTimeout(TraceContext.getCurrentTraceData().getServiceSpan(), networkTimeout);
return new RestTemplateBuilder()
.requestFactory(requestFactory)
.setConnectTimeout(executionTimeout)
.setReadTimeout(executionTimeout)
.build();
}
}

View File

@ -22,19 +22,7 @@ public class CdsStorageApi {
private static final Logger LOGGER = LoggerFactory.getLogger(CdsStorageApi.class);
private StorageSrv.Iface storageSrv;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
* Constructs a new {@link CdsStorageApi CdsApi} instance.
*/
public CdsStorageApi() {
// Constructs default a new {@link CdsApi CdsApi} instance.
}
private final StorageSrv.Iface storageSrv;
/**
* Constructs a new {@link CdsStorageApi CdsApi} instance with the given
@ -63,7 +51,7 @@ public class CdsStorageApi {
LOGGER.info("getCardData: token: {}", token);
try {
CardData cardData = storageSrv.getCardData(token);
LOGGER.info("getCardData: response, token: {}");
LOGGER.info("getCardData: response, token: {}", token);
return cardData;
} catch (Exception ex) {
throw new CdsException(String.format("Exception in getCardData with token: %s", token), ex);

View File

@ -40,6 +40,9 @@ timer:
fixture:
cards: classpath:fixture/cards.csv
---
restTemplate:
networkTimeout: 5000
---
error-mapping:
file: classpath:fixture/errors.json
patternReason: "'%s' - '%s'" # 'code' - 'description'

View File

@ -6,6 +6,8 @@ import com.palantir.docker.compose.execution.DockerComposeExecArgument;
import com.palantir.docker.compose.execution.DockerComposeExecOption;
import org.junit.rules.ExternalResource;
import java.io.IOException;
public class IntegrationBaseRule extends ExternalResource {
private static final String CDS = "cds";
@ -19,25 +21,23 @@ public class IntegrationBaseRule extends ExternalResource {
.waitingForService(PROXY_MOCKETBANK_MPI, HealthChecks.toHaveAllPortsOpen())
.build();
@Override
protected void before() throws Throwable {
docker.before();
executeHolmesScripts();
}
@Override
protected void after() {
docker.after();
}
private void executeHolmesScripts() {
try {
docker.dockerCompose().exec(
DockerComposeExecOption.noOptions(),
HOLMES,
DockerComposeExecArgument.arguments("/opt/holmes/scripts/cds/init-keyring.sh")
);
} catch (Exception e) {
e.printStackTrace();
}
private void executeHolmesScripts() throws IOException, InterruptedException {
docker.dockerCompose().exec(
DockerComposeExecOption.options("-T"),
HOLMES,
DockerComposeExecArgument.arguments("/opt/holmes/scripts/cds/init-keyring.sh")
);
}
}