aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLathish <lathishbabu.ganesan@est.tech>2022-01-26 17:45:24 +0530
committerLathish <lathishbabu.ganesan@est.tech>2022-01-27 18:37:25 +0530
commit82d8d6b7187c9d8c2bcb40045d0c1a8dd538e024 (patch)
tree0ec0768e6eeb6ad24fce4cafc78d5d36481fa14d
parent68d15b4d0241f03790bb0f5949e1f4abdeada428 (diff)
Fix HTTP Participant Status Change on API Failure
Issue-ID: POLICY-3874 Change-Id: Id5eb4529942e36ead245d28151ffccd4dcb21486 Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java29
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java5
2 files changed, 25 insertions, 9 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
index 86a864efc..69d8c750a 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,12 +23,16 @@ package org.onap.policy.clamp.controlloop.participant.http.main.handler;
import java.io.Closeable;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.stream.Collectors;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidationException;
@@ -50,6 +54,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -128,14 +133,21 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl
.getValidator().validate(configRequest);
if (violations.isEmpty()) {
invokeHttpClient(configRequest);
- intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(),
- ControlLoopOrderedState.PASSIVE, ControlLoopState.PASSIVE,
- ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ List<Pair<Integer, String>> failedResponseStatus = restResponseMap.values().stream()
+ .filter(response -> !HttpStatus.valueOf(response.getKey())
+ .is2xxSuccessful()).collect(Collectors.toList());
+ if (failedResponseStatus.isEmpty()) {
+ intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(),
+ ControlLoopOrderedState.PASSIVE, ControlLoopState.PASSIVE,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ } else {
+ LOGGER.error("Error on Invoking the http request: {}", failedResponseStatus);
+ }
} else {
LOGGER.error("Violations found in the config request parameters: {}", violations);
throw new ValidationException("Constraint violations in the config request");
}
- } catch (CoderException | ValidationException e) {
+ } catch (CoderException | ValidationException | InterruptedException | ExecutionException e) {
LOGGER.error("Error invoking the http request for the config ", e);
}
}
@@ -144,9 +156,12 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl
* Invoke a runnable thread to execute http requests.
* @param configRequest ConfigRequest
*/
- public void invokeHttpClient(ConfigRequest configRequest) {
+ public void invokeHttpClient(ConfigRequest configRequest) throws ExecutionException, InterruptedException {
// Invoke runnable thread to execute https requests of all config entities
- executor.execute(new ClHttpClient(configRequest, restResponseMap));
+ Future<Map> result = executor.submit(new ClHttpClient(configRequest, restResponseMap), restResponseMap);
+ if (!result.get().isEmpty()) {
+ LOGGER.debug("Http Request Completed: {}", result.isDone());
+ }
}
/**
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java
index 28b62c2c5..08f008ef3 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/controlloop/participant/http/handler/ClElementHandlerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.doNothing;
import java.io.IOException;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -93,7 +94,7 @@ class ClElementHandlerTest {
}
@Test
- void test_ControlLoopElementUpdate() {
+ void test_ControlLoopElementUpdate() throws ExecutionException, InterruptedException {
doNothing().when(controlLoopElementHandler).invokeHttpClient(any());
ControlLoopElement element = commonTestData.getControlLoopElement();