diff options
Diffstat (limited to 'participant')
4 files changed, 45 insertions, 11 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 cfe786865..86a864efc 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 @@ -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"); diff --git a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java index 0de25072d..d1556ea08 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java @@ -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; diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java index a5d1f8841..e1e9195eb 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java @@ -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) { diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java index ea7d84501..0734cb9c7 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java @@ -262,14 +262,19 @@ public class ParticipantHandler { public void handleParticipantRegisterAck(ParticipantRegisterAck participantRegisterAckMsg) { LOGGER.debug("ParticipantRegisterAck message received as responseTo {}", participantRegisterAckMsg.getResponseTo()); + statusToPassive(); + publisher.sendParticipantStatus(makeHeartbeat(false)); + } + + private void statusToPassive() { if (ParticipantHealthStatus.UNKNOWN.equals(this.healthStatus)) { this.healthStatus = ParticipantHealthStatus.HEALTHY; } - if (ParticipantState.UNKNOWN.equals(this.state)) { + if (ParticipantState.UNKNOWN.equals(this.state) || ParticipantState.TERMINATED.equals(this.state)) { this.state = ParticipantState.PASSIVE; } - publisher.sendParticipantStatus(makeHeartbeat(false)); + } /** @@ -303,6 +308,7 @@ public class ParticipantHandler { participantUpdateMsg.getParticipantId()); if (!participantUpdateMsg.getParticipantDefinitionUpdates().isEmpty()) { + statusToPassive(); // This message is to commission the controlloop for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) { if (participantDefinition.getParticipantType().equals(participantType)) { @@ -311,7 +317,7 @@ public class ParticipantHandler { } } } else { - // This message is to decommision the controlloop + // This message is to decommission the controlloop clElementDefsOnThisParticipant.clear(); this.state = ParticipantState.TERMINATED; } @@ -374,12 +380,12 @@ public class ParticipantHandler { private List<ControlLoopInfo> getControlLoopInfoList() { List<ControlLoopInfo> controlLoopInfoList = new ArrayList<>(); - for (Map.Entry<ToscaConceptIdentifier, ControlLoop> entry : controlLoopHandler.getControlLoopMap().entrySet()) { - ControlLoopInfo clInfo = new ControlLoopInfo(); + for (var entry : controlLoopHandler.getControlLoopMap().entrySet()) { + var clInfo = new ControlLoopInfo(); clInfo.setControlLoopId(entry.getKey()); - ControlLoopStatistics clStatitistics = new ControlLoopStatistics(); + var clStatitistics = new ControlLoopStatistics(); clStatitistics.setControlLoopId(entry.getKey()); - ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList(); + var clElementStatisticsList = new ClElementStatisticsList(); clElementStatisticsList .setClElementStatistics(entry.getValue().getElements().values() .stream() |