Fix CL state change failures on participants 52/124552/1
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>
Wed, 29 Sep 2021 09:46:54 +0000 (10:46 +0100)
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>
Wed, 29 Sep 2021 09:46:54 +0000 (10:46 +0100)
Issue-ID: POLICY-3685
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: Ibec537d1ab55fd921481294fc3e193d7f1dc7912

participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java
participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java

index cfe7868..86a864e 100644 (file)
@@ -37,6 +37,7 @@ import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
 import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigRequest;
 import org.onap.policy.clamp.controlloop.participant.http.main.webclient.ClHttpClient;
 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
@@ -90,7 +91,26 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl
     @Override
     public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, UUID controlLoopElementId,
             ControlLoopState currentState, ControlLoopOrderedState newState) throws PfModelException {
-        // Implementation not needed for http participant
+        switch (newState) {
+            case UNINITIALISED:
+                intermediaryApi.updateControlLoopElementState(controlLoopId,
+                        controlLoopElementId, newState, ControlLoopState.UNINITIALISED,
+                        ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+                break;
+            case PASSIVE:
+                intermediaryApi.updateControlLoopElementState(controlLoopId,
+                        controlLoopElementId, newState, ControlLoopState.PASSIVE,
+                        ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+                break;
+            case RUNNING:
+                intermediaryApi.updateControlLoopElementState(controlLoopId,
+                        controlLoopElementId, newState, ControlLoopState.RUNNING,
+                        ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+                break;
+            default:
+                LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState);
+                break;
+        }
     }
 
     /**
@@ -108,6 +128,9 @@ 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);
             } else {
                 LOGGER.error("Violations found in the config request parameters: {}", violations);
                 throw new ValidationException("Constraint violations in the config request");
index 0de2507..d1556ea 100644 (file)
@@ -29,9 +29,11 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
+import org.mockito.Mock;
 import org.mockito.Spy;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
 import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -46,6 +48,9 @@ class ClElementHandlerTest {
     @Spy
     private ControlLoopElementHandler controlLoopElementHandler = new ControlLoopElementHandler();
 
+    @Mock
+    private ParticipantIntermediaryApi participantIntermediaryApi;
+
     private CommonTestData commonTestData = new CommonTestData();
 
     private static ToscaServiceTemplate serviceTemplate;
index a5d1f88..e1e9195 100644 (file)
@@ -103,7 +103,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
                         chartMap.remove(controlLoopElementId);
                         podStatusMap.remove(chart.getReleaseName());
                     } catch (ServiceException se) {
-                        LOGGER.warn("deletion of Helm deployment failed", se);
+                        LOGGER.warn("Deletion of Helm deployment failed", se);
                     }
                 }
                 break;
@@ -118,7 +118,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
                     ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
                 break;
             default:
-                LOGGER.warn("cannot transition from state {} to state {}", currentState, newState);
+                LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState);
                 break;
         }
     }
@@ -148,7 +148,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
             checkPodStatus(chartInfo, config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
 
             intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(),
-                    ControlLoopOrderedState.PASSIVE, ControlLoopState.UNINITIALISED,
+                    ControlLoopOrderedState.PASSIVE, ControlLoopState.PASSIVE,
                     ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
 
         } catch (ServiceException | CoderException | IOException e) {