diff options
Diffstat (limited to 'participant/participant-intermediary/src/main/java')
10 files changed, 166 insertions, 250 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java index e46c6db1b..0b9110bd0 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java @@ -20,7 +20,7 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.comm; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange; import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.springframework.stereotype.Component; @@ -28,7 +28,7 @@ import org.springframework.stereotype.Component; * Listener for Participant State Change messages sent by CLAMP. */ @Component -public class ControlLoopStateChangeListener extends ParticipantListener<ParticipantControlLoopStateChange> { +public class ControlLoopStateChangeListener extends ParticipantListener<ControlLoopStateChange> { /** * Constructs the object. @@ -36,7 +36,7 @@ public class ControlLoopStateChangeListener extends ParticipantListener<Particip * @param participantHandler the handler for managing the state of the participant */ public ControlLoopStateChangeListener(final ParticipantHandler participantHandler) { - super(ParticipantControlLoopStateChange.class, participantHandler, + super(ControlLoopStateChange.class, participantHandler, participantHandler::handleControlLoopStateChange); } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java index d15643e0f..56bc1fd9a 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java @@ -20,7 +20,7 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.comm; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate; import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.springframework.stereotype.Component; @@ -28,7 +28,7 @@ import org.springframework.stereotype.Component; * Listener for Control Loop Update messages sent by CLAMP. */ @Component -public class ControlLoopUpdateListener extends ParticipantListener<ParticipantControlLoopUpdate> { +public class ControlLoopUpdateListener extends ParticipantListener<ControlLoopUpdate> { /** * Constructs the object. @@ -36,6 +36,6 @@ public class ControlLoopUpdateListener extends ParticipantListener<ParticipantCo * @param participantHandler the handler for managing the state of the participant */ public ControlLoopUpdateListener(final ParticipantHandler participantHandler) { - super(ParticipantControlLoopUpdate.class, participantHandler, participantHandler::handleControlLoopUpdate); + super(ControlLoopUpdate.class, participantHandler, participantHandler::handleControlLoopUpdate); } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java index 1bfce1374..3ff420ffa 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java @@ -22,7 +22,10 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.comm; import java.io.Closeable; import java.time.Instant; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.TimerTask; +import java.util.UUID; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -30,9 +33,9 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseDetails; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck; @@ -67,18 +70,13 @@ public class MessageSender extends TimerTask implements Closeable { // Kick off the timer timerPool = makeTimerPool(); - timerPool.scheduleAtFixedRate(this, 0, interval, TimeUnit.SECONDS); + timerPool.scheduleAtFixedRate(this, 0, interval, TimeUnit.MILLISECONDS); } @Override public void run() { LOGGER.debug("Sent heartbeat to CLAMP"); - - var response = new ParticipantResponseDetails(); - - response.setResponseTo(null); - response.setResponseStatus(ParticipantResponseStatus.PERIODIC); - response.setResponseMessage("Periodic response from participant"); + this.sendHeartbeat(); } @Override @@ -89,48 +87,23 @@ public class MessageSender extends TimerTask implements Closeable { /** * Send a response message for this participant. * - * @param response the details to include in the response message + * @param ackMessage the details to include in the response message */ - public void sendResponse(ParticipantResponseDetails response) { - sendResponse(null, response); + public void sendAckResponse(ControlLoopAck ackMessage) { + sendAckResponse(null, ackMessage); } /** * Dispatch a response message for this participant. * * @param controlLoopId the control loop to which this message is a response - * @param response the details to include in the response message + * @param ackMessage the details to include in the response message */ - public void sendResponse(ToscaConceptIdentifier controlLoopId, ParticipantResponseDetails response) { - var status = new ParticipantStatus(); - + public void sendAckResponse(ToscaConceptIdentifier controlLoopId, ControlLoopAck ackMessage) { // Participant related fields - status.setParticipantType(participantHandler.getParticipantType()); - status.setParticipantId(participantHandler.getParticipantId()); - status.setState(participantHandler.getState()); - status.setHealthStatus(participantHandler.getHealthStatus()); - - // Control loop related fields - var controlLoops = participantHandler.getControlLoopHandler().getControlLoops(); - status.setControlLoopId(controlLoopId); - status.setControlLoops(controlLoops); - status.setResponse(response); - - var participantStatistics = new ParticipantStatistics(); - participantStatistics.setTimeStamp(Instant.now()); - participantStatistics.setParticipantId(participantHandler.getParticipantId()); - participantStatistics.setHealthStatus(participantHandler.getHealthStatus()); - participantStatistics.setState(participantHandler.getState()); - status.setParticipantStatistics(participantStatistics); - - for (ControlLoopElementListener clElementListener : - participantHandler.getControlLoopHandler().getListeners()) { - updateClElementStatistics(controlLoops, clElementListener); - } - - status.setControlLoops(controlLoops); - - publisher.sendParticipantStatus(status); + ackMessage.setParticipantType(participantHandler.getParticipantType()); + ackMessage.setParticipantId(participantHandler.getParticipantId()); + publisher.sendControlLoopAck(ackMessage); } /** @@ -161,6 +134,28 @@ public class MessageSender extends TimerTask implements Closeable { } /** + * Send a ParticipantStatus message for this participant. + * + * @param participantStatus the ParticipantStatus message + */ + public void sendParticipantStatus(ParticipantStatus participantStatus) { + var controlLoops = participantHandler.getControlLoopHandler().getControlLoops(); + for (ControlLoopElementListener clElementListener : + participantHandler.getControlLoopHandler().getListeners()) { + updateClElementStatistics(controlLoops, clElementListener); + } + + publisher.sendParticipantStatus(participantStatus); + } + + /** + * Dispatch a heartbeat for this participant. + */ + public void sendHeartbeat() { + publisher.sendHeartbeat(participantHandler.makeHeartbeat()); + } + + /** * Update ControlLoopElement statistics. The control loop elements listening will be * notified to retrieve statistics from respective controlloop elements, and controlloopelements * data on the handler will be updated. diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java index 9e1b84620..d8cc9eb6b 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java @@ -21,6 +21,7 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.comm; import java.util.List; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus; @@ -90,4 +91,24 @@ public class ParticipantMessagePublisher { topicSinkClient.send(participantUpdateAck); LOGGER.debug("Sent Participant Update Ack message to CLAMP - {}", participantUpdateAck); } + + /** + * Method to send ControlLoop Update/StateChange Ack message to runtime. + * + * @param controlLoopAck ControlLoop Update/StateChange Ack + */ + public void sendControlLoopAck(final ControlLoopAck controlLoopAck) { + topicSinkClient.send(controlLoopAck); + LOGGER.debug("Sent ControlLoop Update/StateChange Ack to runtime - {}", controlLoopAck); + } + + /** + * Method to send Participant heartbeat to clamp on demand. + * + * @param participantStatus the Participant Status + */ + public void sendHeartbeat(final ParticipantStatus participantStatus) { + topicSinkClient.send(participantStatus); + LOGGER.debug("Sent Participant heartbeat to CLAMP - {}", participantStatus); + } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java deleted file mode 100644 index ec6548a7c..000000000 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.controlloop.participant.intermediary.comm; - -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange; -import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; -import org.springframework.stereotype.Component; - -/** - * Listener for Participant State Change messages sent by CLAMP. - * - */ -@Component -public class ParticipantStateChangeListener extends ParticipantListener<ParticipantStateChange> { - - /** - * Constructs the object. - * - * @param participantHandler the handler for managing the state of the participant - */ - public ParticipantStateChangeListener(final ParticipantHandler participantHandler) { - super(ParticipantStateChange.class, participantHandler, participantHandler::handleParticipantStateChange); - } -} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusReqListener.java index 15f5140eb..0881edb19 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusReqListener.java @@ -20,22 +20,22 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.comm; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatusReq; import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.springframework.stereotype.Component; /** - * Listener for Participant health status messages sent by CLAMP. + * Listener for Participant status request messages sent by runtime to all/one participant. */ @Component -public class ParticipantHealthCheckListener extends ParticipantListener<ParticipantHealthCheck> { +public class ParticipantStatusReqListener extends ParticipantListener<ParticipantStatusReq> { /** * Constructs the object. * * @param participantHandler the handler for managing the state and health of the participant */ - public ParticipantHealthCheckListener(final ParticipantHandler participantHandler) { - super(ParticipantHealthCheck.class, participantHandler, participantHandler::handleParticipantHealthCheck); + public ParticipantStatusReqListener(final ParticipantHandler participantHandler) { + super(ParticipantStatusReq.class, participantHandler, participantHandler::handleParticipantStatusReq); } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java index 50048ffc2..876a4cc52 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java @@ -28,16 +28,18 @@ import java.util.UUID; import lombok.Getter; import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; 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.controlloop.concepts.ControlLoops; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseDetails; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType; import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.MessageSender; import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; @@ -59,6 +61,7 @@ public class ControlLoopHandler { private final Map<ToscaConceptIdentifier, ControlLoop> controlLoopMap = new LinkedHashMap<>(); + @Getter private final Map<UUID, ControlLoopElement> elementsOnThisParticipant = new LinkedHashMap<>(); @Getter @@ -92,21 +95,23 @@ public class ControlLoopHandler { ControlLoopState newState) { if (id == null) { - return null; + LOGGER.warn("Cannot update Control loop element state, id is null"); } + ControlLoopAck controlLoopStateChangeAck = + new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK); ControlLoopElement clElement = elementsOnThisParticipant.get(id); if (clElement != null) { clElement.setOrderedState(orderedState); clElement.setState(newState); + controlLoopStateChangeAck.getControlLoopResultMap().put(clElement.getId(), + Pair.of(true, "Control loop element {} state changed to {}\", id, newState)")); LOGGER.debug("Control loop element {} state changed to {}", id, newState); - var response = new ParticipantResponseDetails(); - response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage("ControlLoopElement state changed to {} " + newState); - messageSender.sendResponse(response); + controlLoopStateChangeAck.setMessage("ControlLoopElement state changed to {} " + newState); + controlLoopStateChangeAck.setResult(true); + messageSender.sendAckResponse(controlLoopStateChangeAck); return clElement; } - return null; } @@ -130,7 +135,7 @@ public class ControlLoopHandler { * * @param stateChangeMsg the state change message */ - public void handleControlLoopStateChange(ParticipantControlLoopStateChange stateChangeMsg) { + public void handleControlLoopStateChange(ControlLoopStateChange stateChangeMsg) { if (stateChangeMsg.getControlLoopId() == null) { return; } @@ -142,9 +147,11 @@ public class ControlLoopHandler { return; } - var response = new ParticipantResponseDetails(stateChangeMsg); - handleState(controlLoop, response, stateChangeMsg.getOrderedState()); - messageSender.sendResponse(response); + var controlLoopStateChangeAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK); + controlLoopStateChangeAck.setResponseTo(stateChangeMsg.getMessageId()); + controlLoopStateChangeAck.setControlLoopId(stateChangeMsg.getControlLoopId()); + handleState(controlLoop, controlLoopStateChangeAck, stateChangeMsg.getOrderedState()); + messageSender.sendAckResponse(controlLoopStateChangeAck); } /** @@ -154,7 +161,7 @@ public class ControlLoopHandler { * @param response participant response * @param orderedState controlloop ordered state */ - private void handleState(final ControlLoop controlLoop, final ParticipantResponseDetails response, + private void handleState(final ControlLoop controlLoop, final ControlLoopAck response, ControlLoopOrderedState orderedState) { switch (orderedState) { case UNINITIALISED: @@ -177,7 +184,8 @@ public class ControlLoopHandler { * * @param updateMsg the update message */ - public void handleControlLoopUpdate(ParticipantControlLoopUpdate updateMsg) { + public void handleControlLoopUpdate(ControlLoopUpdate updateMsg, + Map<UUID, ControlLoopElementDefinition> clElementDefinitions) { if (!updateMsg.appliesTo(participantType, participantId)) { return; @@ -185,16 +193,17 @@ public class ControlLoopHandler { var controlLoop = controlLoopMap.get(updateMsg.getControlLoopId()); - var response = new ParticipantResponseDetails(updateMsg); + var controlLoopUpdateAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_UPDATE_ACK); // TODO: Updates to existing ControlLoops are not supported yet (Addition/Removal of ControlLoop // elements to existing ControlLoop has to be supported). if (controlLoop != null) { - response.setResponseStatus(ParticipantResponseStatus.FAIL); - response.setResponseMessage("Control loop " + updateMsg.getControlLoopId() - + " already defined on participant " + participantId); - - messageSender.sendResponse(response); + controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId()); + controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId()); + controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId() + + " already defined on participant " + participantId); + controlLoopUpdateAck.setResult(false); + messageSender.sendAckResponse(controlLoopUpdateAck); return; } @@ -211,18 +220,20 @@ public class ControlLoopHandler { for (ControlLoopElementListener clElementListener : listeners) { try { for (ControlLoopElement element : updateMsg.getControlLoop().getElements().values()) { - clElementListener.controlLoopElementUpdate(element, updateMsg.getControlLoopDefinition()); + clElementListener.controlLoopElementUpdate(element, + clElementDefinitions.get(element.getId()).getControlLoopElementToscaServiceTemplate()); } } catch (PfModelException e) { LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId()); } } - response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage( - "Control loop " + updateMsg.getControlLoopId() + " defined on participant " + participantId); - - messageSender.sendResponse(response); + controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId()); + controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId()); + controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId() + + " defined on participant " + participantId); + controlLoopUpdateAck.setResult(true); + messageSender.sendAckResponse(controlLoopUpdateAck); } /** @@ -233,7 +244,7 @@ public class ControlLoopHandler { * @param response participant response */ private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - final ParticipantResponseDetails response) { + final ControlLoopAck response) { handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED, response); controlLoopMap.remove(controlLoop.getKey().asIdentifier()); @@ -256,7 +267,7 @@ public class ControlLoopHandler { * @param response participant response */ private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - final ParticipantResponseDetails response) { + final ControlLoopAck response) { handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE, response); } @@ -268,7 +279,7 @@ public class ControlLoopHandler { * @param response participant response */ private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - final ParticipantResponseDetails response) { + final ControlLoopAck response) { handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING, response); } @@ -281,11 +292,11 @@ public class ControlLoopHandler { * @param response the response to the state change request */ private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - ControlLoopState newState, ParticipantResponseDetails response) { + ControlLoopState newState, ControlLoopAck response) { if (orderedState.equals(controlLoop.getOrderedState())) { - response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage("Control loop is already in state " + orderedState); + response.setMessage("Control loop is already in state " + orderedState); + response.setResult(false); return; } @@ -296,9 +307,8 @@ public class ControlLoopHandler { }); } - response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage( - "ControlLoop state changed from " + controlLoop.getOrderedState() + " to " + orderedState); + response.setMessage("ControlLoop state changed from " + controlLoop.getOrderedState() + " to " + orderedState); + response.setResult(true); controlLoop.setOrderedState(orderedState); } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java index 0aa536746..4fc0ae1b1 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java @@ -28,9 +28,8 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.api.Participan import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantDeregisterAckListener; -import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantHealthCheckListener; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantRegisterAckListener; -import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStateChangeListener; +import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStatusReqListener; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantUpdateListener; import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; @@ -120,16 +119,13 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl private void registerMsgDispatcher() { MessageTypeDispatcher msgDispatcher = applicationContext.getBean(MessageTypeDispatcher.class); - msgDispatcher.register(ParticipantMessageType.PARTICIPANT_STATE_CHANGE.name(), - applicationContext.getBean(ParticipantStateChangeListener.class)); + msgDispatcher.register(ParticipantMessageType.PARTICIPANT_STATUS_REQ.name(), + applicationContext.getBean(ParticipantStatusReqListener.class)); - msgDispatcher.register(ParticipantMessageType.PARTICIPANT_HEALTH_CHECK.name(), - applicationContext.getBean(ParticipantHealthCheckListener.class)); - - msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_STATE_CHANGE.name(), + msgDispatcher.register(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE.name(), applicationContext.getBean(ControlLoopStateChangeListener.class)); - msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_UPDATE.name(), + msgDispatcher.register(ParticipantMessageType.CONTROL_LOOP_UPDATE.name(), applicationContext.getBean(ControlLoopUpdateListener.class)); msgDispatcher.register(ParticipantMessageType.PARTICIPANT_REGISTER_ACK.name(), 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 a8913c1f0..6a0e758dd 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 @@ -32,17 +32,18 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseDetails; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatusReq; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.MessageSender; @@ -85,7 +86,8 @@ public class ParticipantHandler implements Closeable { this.participantType = parameters.getIntermediaryParameters().getParticipantType(); this.participantId = parameters.getIntermediaryParameters().getParticipantId(); this.sender = - new MessageSender(this, publisher, parameters.getIntermediaryParameters().getReportingTimeInterval()); + new MessageSender(this, publisher, + parameters.getIntermediaryParameters().getReportingTimeIntervalMs()); this.controlLoopHandler = new ControlLoopHandler(parameters.getIntermediaryParameters(), sender); this.participantStatistics = new ParticipantStatistics(); } @@ -96,56 +98,17 @@ public class ParticipantHandler implements Closeable { } /** - * Method which handles a participant state change event from clamp. - * - * @param stateChangeMsg participant state change message - */ - public void handleParticipantStateChange(final ParticipantStateChange stateChangeMsg) { - - if (!stateChangeMsg.appliesTo(participantType, participantId)) { - return; - } - - var response = new ParticipantResponseDetails(stateChangeMsg); - - switch (stateChangeMsg.getState()) { - case PASSIVE: - handlePassiveState(response); - break; - case ACTIVE: - handleActiveState(response); - break; - case SAFE: - handleSafeState(response); - break; - case TEST: - handleTestState(response); - break; - case TERMINATED: - handleTerminatedState(response); - break; - default: - LOGGER.debug("StateChange message has no state, state is null {}", stateChangeMsg.getParticipantId()); - response.setResponseStatus(ParticipantResponseStatus.FAIL); - response.setResponseMessage( - "StateChange message has invalid state for participantId " + stateChangeMsg.getParticipantId()); - break; - } - - sender.sendResponse(response); - } - - /** * Method which handles a participant health check event from clamp. * - * @param healthCheckMsg participant health check message + * @param participantStatusReqMsg participant participantStatusReq message */ - public void handleParticipantHealthCheck(final ParticipantHealthCheck healthCheckMsg) { - var response = new ParticipantResponseDetails(healthCheckMsg); - response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage(healthStatus.toString()); - - sender.sendResponse(response); + public void handleParticipantStatusReq(final ParticipantStatusReq participantStatusReqMsg) { + ParticipantStatus participantStatus = new ParticipantStatus(); + participantStatus.setParticipantId(participantId); + participantStatus.setParticipantStatistics(participantStatistics); + participantStatus.setParticipantType(participantType); + participantStatus.setHealthStatus(healthStatus); + sender.sendParticipantStatus(participantStatus); } /** @@ -153,8 +116,8 @@ public class ParticipantHandler implements Closeable { * * @param updateMsg the update message */ - public void handleControlLoopUpdate(ParticipantControlLoopUpdate updateMsg) { - controlLoopHandler.handleControlLoopUpdate(updateMsg); + public void handleControlLoopUpdate(ControlLoopUpdate updateMsg) { + controlLoopHandler.handleControlLoopUpdate(updateMsg, clElementDefsOnThisParticipant); } /** @@ -162,62 +125,17 @@ public class ParticipantHandler implements Closeable { * * @param stateChangeMsg the state change message */ - public void handleControlLoopStateChange(ParticipantControlLoopStateChange stateChangeMsg) { + public void handleControlLoopStateChange(ControlLoopStateChange stateChangeMsg) { controlLoopHandler.handleControlLoopStateChange(stateChangeMsg); } - /** - * Method to handle when the new state from participant is active. - * - * @param response participant response - */ - private void handleActiveState(final ParticipantResponseDetails response) { - handleStateChange(ParticipantState.ACTIVE, response); - } - - /** - * Method to handle when the new state from participant is passive. - * - * @param response participant response - */ - private void handlePassiveState(final ParticipantResponseDetails response) { - handleStateChange(ParticipantState.PASSIVE, response); - } - - /** - * Method to handle when the new state from participant is safe. - * - * @param response participant response - */ - private void handleSafeState(final ParticipantResponseDetails response) { - handleStateChange(ParticipantState.SAFE, response); - } - - /** - * Method to handle when the new state from participant is TEST. - * - * @param response participant response - */ - private void handleTestState(final ParticipantResponseDetails response) { - handleStateChange(ParticipantState.TEST, response); - } - - /** - * Method to handle when the new state from participant is Terminated. - * - * @param response participant response - */ - private void handleTerminatedState(final ParticipantResponseDetails response) { - handleStateChange(ParticipantState.TERMINATED, response); - } - - private void handleStateChange(ParticipantState newParticipantState, ParticipantResponseDetails response) { + private void handleStateChange(ParticipantState newParticipantState, ParticipantUpdateAck response) { if (state.equals(newParticipantState)) { - response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage("Participant already in state " + newParticipantState); + response.setResult(false); + response.setMessage("Participant already in state " + newParticipantState); } else { - response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage("Participant state changed from " + state + " to " + newParticipantState); + response.setResult(true); + response.setMessage("Participant state changed from " + state + " to " + newParticipantState); state = newParticipantState; } } @@ -234,9 +152,10 @@ public class ParticipantHandler implements Closeable { LOGGER.debug("No participant with this ID {}", definition.getName()); return null; } - var response = new ParticipantResponseDetails(); - handleStateChange(participantState, response); - sender.sendResponse(response); + + var participantUpdateAck = new ParticipantUpdateAck(); + handleStateChange(participantState, participantUpdateAck); + sender.sendParticipantUpdateAck(participantUpdateAck); return getParticipant(definition.getName(), definition.getVersion()); } @@ -341,7 +260,21 @@ public class ParticipantHandler implements Closeable { participantUpdateAck.setResponseTo(messageId); participantUpdateAck.setMessage("Participant Update Ack message"); participantUpdateAck.setResult(true); + participantUpdateAck.setParticipantId(participantId); + participantUpdateAck.setParticipantType(participantType); sender.sendParticipantUpdateAck(participantUpdateAck); } + + /** + * Method to send heartbeat to controlloop runtime. + */ + public ParticipantStatus makeHeartbeat() { + ParticipantStatus heartbeat = new ParticipantStatus(); + heartbeat.setParticipantId(participantId); + heartbeat.setParticipantStatistics(participantStatistics); + heartbeat.setParticipantType(participantType); + heartbeat.setHealthStatus(healthStatus); + return heartbeat; + } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java index 5627abfe6..fdc451e6b 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java @@ -23,6 +23,7 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.parameters; import javax.validation.Valid; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Positive; import lombok.Getter; import lombok.Setter; import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; @@ -50,7 +51,9 @@ public class ParticipantIntermediaryParameters { private ToscaConceptIdentifier participantType; // The time interval for periodic reporting of status to the CLAMP control loop server - private long reportingTimeInterval; + @Valid + @Positive + private long reportingTimeIntervalMs; @NotNull @ParameterGroupConstraint |