summaryrefslogtreecommitdiffstats
path: root/rest-services
diff options
context:
space:
mode:
authorPawel <pawel.kasperkiewicz@nokia.com>2021-06-07 10:46:00 +0200
committerPawel <pawel.kasperkiewicz@nokia.com>2021-06-07 10:46:00 +0200
commitc42b1c55eedbac2663ada8cf5b2a9a67560300e9 (patch)
treed3cf6cfbc1be17d12e5ebd52c78bbd807a668293 /rest-services
parent837f51c82b40d9c251a082768af7a196ff7c901c (diff)
Handle 429 error Too Many Requests
Issue-ID: DCAEGEN2-2827 Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com> Change-Id: Iedfb6572f008876b52a102948aeb640d27e51314
Diffstat (limited to 'rest-services')
-rw-r--r--rest-services/cbs-client/pom.xml2
-rw-r--r--rest-services/dmaap-client/pom.xml2
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/error/ClientErrorReasons.java9
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/impl/MessageRouterPublisherImpl.java2
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java3
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java58
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherTest.java5
-rw-r--r--rest-services/http-client/pom.xml2
-rw-r--r--rest-services/model/pom.xml2
-rw-r--r--rest-services/pom.xml2
10 files changed, 77 insertions, 10 deletions
diff --git a/rest-services/cbs-client/pom.xml b/rest-services/cbs-client/pom.xml
index 071763c5..717e3a4f 100644
--- a/rest-services/cbs-client/pom.xml
+++ b/rest-services/cbs-client/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.5-SNAPSHOT</version>
+ <version>1.8.6-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/dmaap-client/pom.xml b/rest-services/dmaap-client/pom.xml
index f3a612a6..2462a440 100644
--- a/rest-services/dmaap-client/pom.xml
+++ b/rest-services/dmaap-client/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.5-SNAPSHOT</version>
+ <version>1.8.6-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/error/ClientErrorReasons.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/error/ClientErrorReasons.java
index 431843ae..f6e5c2bb 100644
--- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/error/ClientErrorReasons.java
+++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/error/ClientErrorReasons.java
@@ -30,7 +30,8 @@ public class ClientErrorReasons {
.header("408 Request Timeout")
.text("Client timeout exception occurred, Error code is %1")
.messageId("SVC0001")
- .variables(Collections.singletonList("408")).build();
+ .variables(Collections.singletonList("408"))
+ .build();
public static final ClientErrorReason SERVICE_UNAVAILABLE = ImmutableClientErrorReason.builder()
.header("503 Service unavailable")
@@ -38,4 +39,10 @@ public class ClientErrorReasons {
.messageId("SVC2001")
.build();
+ public static final ClientErrorReason CONNECTION_POLL_LIMIT = ImmutableClientErrorReason.builder()
+ .header("429 Too Many Requests")
+ .text("Pending acquire queue has reached its maximum size")
+ .messageId("SVC2000")
+ .variables(Collections.singletonList("429"))
+ .build();
}
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/impl/MessageRouterPublisherImpl.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/impl/MessageRouterPublisherImpl.java
index 6e4679c3..534fca6b 100644
--- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/impl/MessageRouterPublisherImpl.java
+++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/impl/MessageRouterPublisherImpl.java
@@ -50,6 +50,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
+import reactor.netty.internal.shaded.reactor.pool.PoolAcquirePendingLimitException;
import java.net.ConnectException;
import java.time.Duration;
@@ -95,6 +96,7 @@ public class MessageRouterPublisherImpl implements MessageRouterPublisher {
e -> LOGGER.error("Timeout exception occurred when sending items to DMaaP MR", e))
.onErrorResume(ReadTimeoutException.class, e -> buildErrorResponse(ClientErrorReasons.TIMEOUT))
.doOnError(ConnectException.class, e -> LOGGER.error("DMaaP MR is unavailable, {}", e.getMessage()))
+ .onErrorResume(PoolAcquirePendingLimitException.class, e -> buildErrorResponse(ClientErrorReasons.CONNECTION_POLL_LIMIT))
.onErrorResume(ConnectException.class, e -> buildErrorResponse(ClientErrorReasons.SERVICE_UNAVAILABLE))
.onErrorResume(RetryableException.class, e -> Mono.just(buildResponse(e.getResponse(), batch)));
}
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java
index 38166e4e..4a4add0e 100644
--- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java
+++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/model/config/DmaapConnectionPoolConfig.java
@@ -20,13 +20,14 @@
package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config;
import org.immutables.value.Value;
+import reactor.netty.resources.ConnectionProvider;
@Value.Immutable
public interface DmaapConnectionPoolConfig {
@Value.Default
default int connectionPool(){
- return 16;
+ return ConnectionProvider.DEFAULT_POOL_MAX_CONNECTIONS;
}
@Value.Default
default int maxLifeTime(){
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java
index 70adf59d..a1ad951f 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherIT.java
@@ -95,6 +95,18 @@ class MessageRouterPublisherIT {
+ "}"
+ "}"
+ "}";
+ private static final String CONNECTION_POLL_LIMIT_MESSAGE = "429 Too Many Requests\n"
+ + "{"
+ + "\"requestError\":"
+ + "{"
+ + "\"serviceException\":"
+ + "{"
+ + "\"messageId\":\"SVC2000\","
+ + "\"text\":\"Pending acquire queue has reached its maximum size\","
+ + "\"variables\":[\"429\"]"
+ + "}"
+ + "}"
+ + "}";
private final MessageRouterPublisher publisher = DmaapClientFactory
.createMessageRouterPublisher(MessageRouterPublisherConfig.createDefault());
@@ -570,6 +582,48 @@ class MessageRouterPublisherIT {
.withHeader("Authorization" ,"Basic dXNlcm5hbWU6cGFzc3dvcmQ="), VerificationTimes.exactly(1));
}
+ @Test
+ void publisher_shouldHandleError429WhenConnectionPollLimitsHasBeenReached() {
+ //given
+ final String topic = "TOPIC17";
+ final String topicUrl = String.format("%s/%s", PROXY_MOCK_EVENTS_PATH, topic);
+
+ final List<String> twoJsonMessages = List.of("{\"message\":\"message1\"}",
+ "{\"differentMessage\":\"message2\"}");
+ final Flux<JsonElement> plainBatch = plainBatch(twoJsonMessages);
+
+ final MessageRouterPublishRequest publishRequest = createPublishRequest(topicUrl, Duration.ofSeconds(1));
+
+ final MessageRouterPublishResponse expectedResponse = errorPublishResponse(
+ CONNECTION_POLL_LIMIT_MESSAGE);
+
+ final String path = String.format("/events/%s", topic);
+
+ //maxConnectionPoll + pendingAcquireMaxCount(default 2*maxConnectionPoll)
+ final int maxNumberOfConcurrentRequest = 3;
+ MOCK_SERVER_CLIENT
+ .when(request().withPath(path), Times.exactly(maxNumberOfConcurrentRequest))
+ .respond(response().withStatusCode(429).withDelay(TimeUnit.SECONDS,1));
+
+ MOCK_SERVER_CLIENT
+ .when(request().withPath(path), Times.once())
+ .respond(response().withStatusCode(200));
+
+ final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher(connectionPoolConfiguration());
+
+ //when
+ final Flux<MessageRouterPublishResponse> result = publisher.put(publishRequest, plainBatch);
+
+ for(int i = 0; i < maxNumberOfConcurrentRequest; i++) {
+ publisher.put(publishRequest, plainBatch).subscribe();
+ }
+
+ //then
+ StepVerifier.create(result)
+ .expectNext(expectedResponse)
+ .expectComplete()
+ .verify();
+ }
private MessageRouterPublisherConfig retryConfig(int retryInterval, int retryCount) {
return ImmutableMessageRouterPublisherConfig.builder()
@@ -582,7 +636,7 @@ class MessageRouterPublisherIT {
private MessageRouterPublisherConfig connectionPoolConfiguration() {
return ImmutableMessageRouterPublisherConfig.builder()
.connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
- .connectionPool(10)
+ .connectionPool(1)
.maxIdleTime(10)
.maxLifeTime(20)
.build())
@@ -592,7 +646,7 @@ class MessageRouterPublisherIT {
private MessageRouterPublisherConfig connectionPoolAndRetryConfiguration() {
return ImmutableMessageRouterPublisherConfig.builder()
.connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
- .connectionPool(10)
+ .connectionPool(1)
.maxIdleTime(10)
.maxLifeTime(20)
.build())
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherTest.java
index 82a2b008..97fd26f5 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/api/MessageRouterPublisherTest.java
@@ -64,6 +64,7 @@ class MessageRouterPublisherTest {
private static final String FAILING_WITH_403_RESP_PATH = "/events/TOPIC403";
private static final String FAILING_WITH_404_RESP_PATH = "/events/TOPIC404";
private static final String FAILING_WITH_500_RESP_PATH = "/events/TOPIC500";
+ private static final String FAILING_WITH_429_RESP_PATH = "/events/TOPIC429";
private static final Duration TIMEOUT = Duration.ofSeconds(10);
private static final Flux<JsonPrimitive> messageBatch = Flux.just("ala", "ma", "kota")
.map(JsonPrimitive::new);
@@ -82,6 +83,7 @@ class MessageRouterPublisherTest {
.post(FAILING_WITH_403_RESP_PATH, (req, resp) -> sendError(resp, 403, ERROR_MESSAGE))
.post(FAILING_WITH_404_RESP_PATH, (req, resp) -> sendError(resp, 404, ERROR_MESSAGE))
.post(FAILING_WITH_500_RESP_PATH, (req, resp) -> sendError(resp, 500, ERROR_MESSAGE))
+ .post(FAILING_WITH_429_RESP_PATH, (req, resp) -> sendError(resp, 429, ERROR_MESSAGE))
);
}
@@ -107,7 +109,8 @@ class MessageRouterPublisherTest {
FAILING_WITH_401_RESP_PATH + "," + "401 Unauthorized",
FAILING_WITH_403_RESP_PATH + "," + "403 Forbidden",
FAILING_WITH_404_RESP_PATH + "," + "404 Not Found",
- FAILING_WITH_500_RESP_PATH + "," + "500 Internal Server Error"
+ FAILING_WITH_500_RESP_PATH + "," + "500 Internal Server Error",
+ FAILING_WITH_429_RESP_PATH + "," + "429 Too Many Requests"
})
void publisher_shouldHandleError(String failingPath, String failReason) {
//given
diff --git a/rest-services/http-client/pom.xml b/rest-services/http-client/pom.xml
index 3669aabe..15338406 100644
--- a/rest-services/http-client/pom.xml
+++ b/rest-services/http-client/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.5-SNAPSHOT</version>
+ <version>1.8.6-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/model/pom.xml b/rest-services/model/pom.xml
index ea018c1f..431039eb 100644
--- a/rest-services/model/pom.xml
+++ b/rest-services/model/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>
<artifactId>dcaegen2-services-sdk-rest-services</artifactId>
- <version>1.8.5-SNAPSHOT</version>
+ <version>1.8.6-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
diff --git a/rest-services/pom.xml b/rest-services/pom.xml
index e4190868..0f777a27 100644
--- a/rest-services/pom.xml
+++ b/rest-services/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>org.onap.dcaegen2.services</groupId>
<artifactId>sdk</artifactId>
- <version>1.8.5-SNAPSHOT</version>
+ <version>1.8.6-SNAPSHOT</version>
</parent>
<groupId>org.onap.dcaegen2.services.sdk</groupId>