aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java7
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/AaiClientPropertiesImpl.java7
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/AAIPropertiesImpl.java10
-rw-r--r--common/src/main/java/org/onap/so/client/RestClient.java8
-rw-r--r--common/src/main/java/org/onap/so/client/RestClientSSL.java4
-rw-r--r--common/src/main/java/org/onap/so/client/RestProperties.java9
-rw-r--r--common/src/test/java/org/onap/so/client/RestClientTest.java61
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java7
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiPropertiesImpl.java8
9 files changed, 113 insertions, 8 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java
index 12e416f43c..b7e214f9fc 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java
@@ -32,6 +32,7 @@ public class AaiClientPropertiesImpl implements AAIProperties {
private String aaiEndpoint;
private String auth;
private String key;
+ private Long readTimeout;
private static final String SYSTEM_NAME = "MSO";
public AaiClientPropertiesImpl() {
@@ -39,6 +40,7 @@ public class AaiClientPropertiesImpl implements AAIProperties {
aaiEndpoint = context.getEnvironment().getProperty("aai.endpoint");
this.auth = context.getEnvironment().getProperty("aai.auth");
this.key = context.getEnvironment().getProperty("mso.msoKey");
+ this.readTimeout = context.getEnvironment().getProperty("aai.readTimeout", Long.class, new Long(60000));
}
@Override
@@ -65,4 +67,9 @@ public class AaiClientPropertiesImpl implements AAIProperties {
public String getKey() {
return this.key;
}
+
+ @Override
+ public Long getReadTimeout() {
+ return this.readTimeout;
+ }
}
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/AaiClientPropertiesImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/AaiClientPropertiesImpl.java
index 3ae815dd71..7b89af0910 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/AaiClientPropertiesImpl.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/AaiClientPropertiesImpl.java
@@ -32,6 +32,7 @@ public class AaiClientPropertiesImpl implements AAIProperties {
private String aaiEndpoint;
private String auth;
private String key;
+ private Long readTimeout;
private static final String SYSTEM_NAME = "MSO";
public AaiClientPropertiesImpl() {
@@ -39,6 +40,7 @@ public class AaiClientPropertiesImpl implements AAIProperties {
aaiEndpoint = context.getEnvironment().getProperty("mso.aai.endpoint");
this.auth = context.getEnvironment().getProperty("aai.auth");
this.key = context.getEnvironment().getProperty("mso.msoKey");
+ this.readTimeout = context.getEnvironment().getProperty("aai.readTimeout", Long.class, new Long(60000));
}
@Override
@@ -67,4 +69,9 @@ public class AaiClientPropertiesImpl implements AAIProperties {
public String getKey() {
return this.key;
}
+
+ @Override
+ public Long getReadTimeout() {
+ return this.readTimeout;
+ }
}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/AAIPropertiesImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/AAIPropertiesImpl.java
index 692d581b0d..f67af20ef1 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/AAIPropertiesImpl.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/AAIPropertiesImpl.java
@@ -22,9 +22,9 @@ package org.onap.so.client.restproperties;
import java.net.MalformedURLException;
import java.net.URL;
-import org.onap.so.bpmn.core.UrnPropertiesReader;
import org.onap.aaiclient.client.aai.AAIProperties;
import org.onap.aaiclient.client.aai.AAIVersion;
+import org.onap.so.bpmn.core.UrnPropertiesReader;
import org.springframework.stereotype.Component;
@Component
@@ -33,6 +33,8 @@ public class AAIPropertiesImpl implements AAIProperties {
public static final String MSO_MSO_KEY = "mso.msoKey";
public static final String AAI_AUTH = "aai.auth";
public static final String AAI_ENDPOINT = "aai.endpoint";
+ public static final String AAI_READ_TIMEOUT = "aai.readTimeout";
+ private UrnPropertiesReader reader;
@Override
public URL getEndpoint() throws MalformedURLException {
@@ -58,4 +60,10 @@ public class AAIPropertiesImpl implements AAIProperties {
public String getKey() {
return UrnPropertiesReader.getVariable(MSO_MSO_KEY);
}
+
+ @Override
+ public Long getReadTimeout() {
+ return Long.valueOf(reader.getVariable(AAI_READ_TIMEOUT, "60000"));
+ }
+
}
diff --git a/common/src/main/java/org/onap/so/client/RestClient.java b/common/src/main/java/org/onap/so/client/RestClient.java
index ece1333f83..9fce328b1d 100644
--- a/common/src/main/java/org/onap/so/client/RestClient.java
+++ b/common/src/main/java/org/onap/so/client/RestClient.java
@@ -34,10 +34,12 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.ResponseProcessingException;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
@@ -187,7 +189,7 @@ public abstract class RestClient {
}
protected Client getClient() {
- return ClientBuilder.newBuilder().build();
+ return ClientBuilder.newBuilder().readTimeout(props.getReadTimeout(), TimeUnit.MILLISECONDS).build();
}
protected abstract ONAPComponentsList getTargetEntity();
@@ -201,7 +203,6 @@ public abstract class RestClient {
metricLogClientFilter = new SOMetricLogClientFilter();
mdcSetup.setTargetEntity(getTargetEntity());
client.register(metricLogClientFilter);
-
if (!path.isPresent()) {
webTarget = client.target(host.toString());
} else {
@@ -225,6 +226,9 @@ public abstract class RestClient {
result.add(e -> {
return e.getCause() instanceof ConnectException;
});
+ result.add(e -> {
+ return e.getCause() instanceof ResponseProcessingException;
+ });
return result;
}
diff --git a/common/src/main/java/org/onap/so/client/RestClientSSL.java b/common/src/main/java/org/onap/so/client/RestClientSSL.java
index 1e8953892e..8956e20a5a 100644
--- a/common/src/main/java/org/onap/so/client/RestClientSSL.java
+++ b/common/src/main/java/org/onap/so/client/RestClientSSL.java
@@ -24,6 +24,7 @@ import java.net.URI;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@@ -56,7 +57,8 @@ public abstract class RestClientSSL extends RestClient {
}
}
// Use default SSL context
- client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()).build();
+ client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault())
+ .readTimeout(props.getReadTimeout(), TimeUnit.MILLISECONDS).build();
logger.info("RestClientSSL using default SSL context!");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
diff --git a/common/src/main/java/org/onap/so/client/RestProperties.java b/common/src/main/java/org/onap/so/client/RestProperties.java
index 9e4e99cb4e..36da424f93 100644
--- a/common/src/main/java/org/onap/so/client/RestProperties.java
+++ b/common/src/main/java/org/onap/so/client/RestProperties.java
@@ -40,4 +40,13 @@ public interface RestProperties {
public default boolean mapNotFoundToEmpty() {
return false;
}
+
+ /**
+ * Time in milliseconds
+ *
+ * @return
+ */
+ public default Long getReadTimeout() {
+ return Long.valueOf(60000);
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java
index cd00a9e4de..c6e282c14a 100644
--- a/common/src/test/java/org/onap/so/client/RestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/RestClientTest.java
@@ -21,6 +21,8 @@
package org.onap.so.client;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
@@ -28,7 +30,13 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Optional;
import javax.ws.rs.NotFoundException;
+import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriBuilderException;
@@ -37,21 +45,24 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
-import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.logging.filter.base.ONAPComponents;
+import org.onap.logging.filter.base.ONAPComponentsList;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
@RunWith(MockitoJUnitRunner.class)
public class RestClientTest {
private final HttpClientFactory httpClientFactory = new HttpClientFactory();
- @Mock
- private RestProperties props;
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.options().dynamicPort());
+
@Test
public void retries() throws Exception {
RestClient spy = buildSpy();
@@ -80,6 +91,50 @@ public class RestClientTest {
}
+ @Test
+ public void timeoutTest() throws URISyntaxException {
+ wireMockRule.stubFor(get("/chunked/delayed")
+ .willReturn(aResponse().withStatus(200).withBody("Hello world!").withChunkedDribbleDelay(2, 300)));
+
+
+ RestProperties props = new RestProperties() {
+
+ @Override
+ public URL getEndpoint() throws MalformedURLException {
+ return new URL(String.format("http://localhost:%s", wireMockRule.port()));
+ }
+
+ @Override
+ public String getSystemName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Long getReadTimeout() {
+ return Long.valueOf(100);
+ }
+ };
+ RestClient client = new RestClient(props, Optional.of(new URI("/chunked/delayed"))) {
+
+ @Override
+ protected void initializeHeaderMap(Map<String, String> headerMap) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected ONAPComponentsList getTargetEntity() {
+ return ONAPComponents.EXTERNAL;
+ }
+
+ };
+
+ thrown.expect(ProcessingException.class);
+ client.get();
+
+ }
+
private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException {
RestClient client = httpClientFactory.newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(),
ONAPComponents.BPMN);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java
index 822627863a..6e6a9d2b07 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java
@@ -32,6 +32,7 @@ public class AaiClientPropertiesImpl implements AAIProperties {
private String aaiEndpoint;
private String auth;
private String key;
+ private Long readTimeout;
public AaiClientPropertiesImpl() {
@@ -39,6 +40,7 @@ public class AaiClientPropertiesImpl implements AAIProperties {
aaiEndpoint = context.getEnvironment().getProperty("mso.aai.endpoint");
this.auth = context.getEnvironment().getProperty("aai.auth");
this.key = context.getEnvironment().getProperty("mso.msoKey");
+ this.readTimeout = context.getEnvironment().getProperty("aai.readTimeout", Long.class, new Long(60000));
}
@Override
@@ -65,4 +67,9 @@ public class AaiClientPropertiesImpl implements AAIProperties {
public String getKey() {
return this.key;
}
+
+ @Override
+ public Long getReadTimeout() {
+ return this.readTimeout;
+ }
}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiPropertiesImpl.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiPropertiesImpl.java
index 3df3580907..910d5fa75c 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiPropertiesImpl.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiPropertiesImpl.java
@@ -33,14 +33,15 @@ public class AaiPropertiesImpl implements AAIProperties {
private final String encryptedBasicAuth;
private final String encryptionKey;
private final String aaiVersion;
+ private final Long readTimeout;
public AaiPropertiesImpl() {
-
final ApplicationContext context = SpringContextHelper.getAppContext();
this.endpoint = context.getEnvironment().getProperty("aai.endpoint");
this.encryptedBasicAuth = context.getEnvironment().getProperty("aai.auth");
this.encryptionKey = context.getEnvironment().getProperty("mso.key");
this.aaiVersion = context.getEnvironment().getProperty("aai.version");
+ this.readTimeout = context.getEnvironment().getProperty("aai.readTimeout", Long.class, new Long(60000));
}
@Override
@@ -73,4 +74,9 @@ public class AaiPropertiesImpl implements AAIProperties {
public String getKey() {
return encryptionKey;
}
+
+ @Override
+ public Long getReadTimeout() {
+ return this.readTimeout;
+ }
}