summaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2021-08-26 08:21:49 +0000
committerGerrit Code Review <gerrit@onap.org>2021-08-26 08:21:49 +0000
commit281a36c50d68f29e0e47dfec10ee8be38f5e5761 (patch)
tree1ad3f98fd4c9a74b601577e463210e73eaa4f4f2 /participant/participant-intermediary
parentdb82b84e140e78e5f4145ed6d73fe089134dd173 (diff)
parent3971c419e094cb149c3e01781343d6265af64db6 (diff)
Merge "Updated handling of ack messages"
Diffstat (limited to 'participant/participant-intermediary')
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java3
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java6
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java2
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java67
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java51
5 files changed, 81 insertions, 48 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
index aa2027ab8..ed0aea4b3 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -31,6 +31,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
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.ParticipantMessageType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -123,7 +124,7 @@ public interface ParticipantIntermediaryApi {
* @return ControlLoopElement updated control loop element
*/
ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState,
- ControlLoopState newState);
+ ControlLoopState newState, ParticipantMessageType messageType);
/**
* Update the control loop element statistics.
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index a2a4c3436..ded102f5a 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -33,6 +33,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
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.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
@@ -127,8 +128,9 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState,
- ControlLoopState newState) {
- return participantHandler.getControlLoopHandler().updateControlLoopElementState(id, currentState, newState);
+ ControlLoopState newState, ParticipantMessageType messageType) {
+ return participantHandler.getControlLoopHandler().updateControlLoopElementState(id, currentState, newState,
+ messageType);
}
@Override
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 990c3df7d..680acd276 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
@@ -146,7 +146,7 @@ public class MessageSender extends TimerTask implements Closeable {
* Dispatch a heartbeat for this participant.
*/
public void sendHeartbeat() {
- publisher.sendHeartbeat(participantHandler.makeHeartbeat());
+ publisher.sendHeartbeat(participantHandler.makeHeartbeat(false));
}
/**
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 2bc21f713..0e276f390 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
@@ -64,6 +64,7 @@ public class ControlLoopHandler {
private ToscaConceptIdentifier participantId = null;
private MessageSender messageSender = null;
+ @Getter
private final Map<ToscaConceptIdentifier, ControlLoop> controlLoopMap = new LinkedHashMap<>();
@Getter
@@ -97,7 +98,7 @@ public class ControlLoopHandler {
* @return controlLoopElement the updated controlloop element
*/
public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState orderedState,
- ControlLoopState newState) {
+ ControlLoopState newState, ParticipantMessageType messageType) {
if (id == null) {
LOGGER.warn("Cannot update Control loop element state, id is null");
@@ -146,37 +147,38 @@ public class ControlLoopHandler {
}
var controlLoop = controlLoopMap.get(stateChangeMsg.getControlLoopId());
+ var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
if (controlLoop == null) {
+ controlLoopAck.setMessage("Control loop " + stateChangeMsg.getControlLoopId()
+ + " does not use this participant " + participantId);
+ controlLoopAck.setResult(false);
+ controlLoopAck.setResponseTo(stateChangeMsg.getMessageId());
+ controlLoopAck.setControlLoopId(stateChangeMsg.getControlLoopId());
+ messageSender.sendAckResponse(controlLoopAck);
LOGGER.debug("Control loop {} does not use this participant", stateChangeMsg.getControlLoopId());
return;
}
- var controlLoopStateChangeAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
- controlLoopStateChangeAck.setResponseTo(stateChangeMsg.getMessageId());
- controlLoopStateChangeAck.setControlLoopId(stateChangeMsg.getControlLoopId());
- handleState(controlLoop, controlLoopStateChangeAck, stateChangeMsg.getOrderedState());
- messageSender.sendAckResponse(controlLoopStateChangeAck);
+ handleState(controlLoop, stateChangeMsg.getOrderedState());
}
/**
* Method to handle state changes.
*
* @param controlLoop participant response
- * @param response participant response
* @param orderedState controlloop ordered state
*/
- private void handleState(final ControlLoop controlLoop, final ControlLoopAck response,
- ControlLoopOrderedState orderedState) {
+ private void handleState(final ControlLoop controlLoop, ControlLoopOrderedState orderedState) {
switch (orderedState) {
case UNINITIALISED:
- handleUninitialisedState(controlLoop, orderedState, response);
+ handleUninitialisedState(controlLoop, orderedState);
break;
case PASSIVE:
- handlePassiveState(controlLoop, orderedState, response);
+ handlePassiveState(controlLoop, orderedState);
break;
case RUNNING:
- handleRunningState(controlLoop, orderedState, response);
+ handleRunningState(controlLoop, orderedState);
break;
default:
LOGGER.debug("StateChange message has no state, state is null {}", controlLoop.getDefinition());
@@ -203,11 +205,11 @@ public class ControlLoopHandler {
// TODO: Updates to existing ControlLoops are not supported yet (Addition/Removal of ControlLoop
// elements to existing ControlLoop has to be supported).
if (controlLoop != null) {
- controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId());
- controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId());
controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId()
+ " already defined on participant " + participantId);
controlLoopUpdateAck.setResult(false);
+ controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId());
+ controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId());
messageSender.sendAckResponse(controlLoopUpdateAck);
return;
}
@@ -231,13 +233,6 @@ public class ControlLoopHandler {
controlLoop.setDefinition(updateMsg.getControlLoopId());
controlLoop.setElements(clElementMap);
controlLoopMap.put(updateMsg.getControlLoopId(), controlLoop);
-
- controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId());
- controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId());
- controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId()
- + " defined on participant " + participantId);
- controlLoopUpdateAck.setResult(true);
- messageSender.sendAckResponse(controlLoopUpdateAck);
}
private ToscaNodeTemplate getClElementNodeTemplate(List<ControlLoopElementDefinition> clElementDefinitions,
@@ -276,11 +271,9 @@ public class ControlLoopHandler {
*
* @param controlLoop participant response
* @param orderedState orderedState
- * @param response participant response
*/
- private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- final ControlLoopAck response) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED, response);
+ private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
+ handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED);
controlLoopMap.remove(controlLoop.getKey().asIdentifier());
for (ControlLoopElementListener clElementListener : listeners) {
@@ -299,11 +292,9 @@ public class ControlLoopHandler {
*
* @param controlLoop participant response
* @param orderedState orderedState
- * @param response participant response
*/
- private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- final ControlLoopAck response) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE, response);
+ private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
+ handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE);
}
/**
@@ -311,11 +302,9 @@ public class ControlLoopHandler {
*
* @param controlLoop participant response
* @param orderedState orderedState
- * @param response participant response
*/
- private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- final ControlLoopAck response) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING, response);
+ private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
+ handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING);
}
/**
@@ -324,14 +313,16 @@ public class ControlLoopHandler {
* @param controlLoop participant status in memory
* @param orderedState orderedState the new ordered state the participant should have
* @param newState new state of the control loop elements
- * @param response the response to the state change request
*/
private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- ControlLoopState newState, ControlLoopAck response) {
+ ControlLoopState newState) {
if (orderedState.equals(controlLoop.getOrderedState())) {
- response.setMessage("Control loop is already in state " + orderedState);
- response.setResult(false);
+ var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ controlLoopAck.setMessage("Control loop is already in state" + orderedState);
+ controlLoopAck.setResult(false);
+ controlLoopAck.setControlLoopId(controlLoop.getDefinition());
+ messageSender.sendAckResponse(controlLoopAck);
return;
}
@@ -342,8 +333,6 @@ public class ControlLoopHandler {
});
}
- 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/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
index f887f6578..1947fda1a 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
@@ -26,11 +26,16 @@ import java.io.Closeable;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
@@ -112,7 +117,7 @@ public class ParticipantHandler implements Closeable {
* @param participantStatusReqMsg participant participantStatusReq message
*/
public void handleParticipantStatusReq(final ParticipantStatusReq participantStatusReqMsg) {
- sender.sendParticipantStatus(makeHeartbeat());
+ sender.sendParticipantStatus(makeHeartbeat(true));
}
/**
@@ -247,10 +252,17 @@ public class ParticipantHandler implements Closeable {
}
toscaServiceTemplate = participantUpdateMsg.getToscaServiceTemplate();
- for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) {
- if (participantDefinition.getParticipantId().equals(participantType)) {
- clElementDefsOnThisParticipant = participantDefinition.getControlLoopElementDefinitionList();
+ if (toscaServiceTemplate != null) {
+ // This message is to commission the controlloop
+ for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) {
+ if (participantDefinition.getParticipantId().equals(participantType)) {
+ clElementDefsOnThisParticipant = participantDefinition.getControlLoopElementDefinitionList();
+ break;
+ }
}
+ } else {
+ // This message is to decommision the controlloop
+ clElementDefsOnThisParticipant.clear();
}
sendParticipantUpdateAck(participantUpdateMsg.getMessageId());
}
@@ -272,7 +284,7 @@ public class ParticipantHandler implements Closeable {
/**
* Method to send heartbeat to controlloop runtime.
*/
- public ParticipantStatus makeHeartbeat() {
+ public ParticipantStatus makeHeartbeat(boolean responseToParticipantStatusReq) {
this.participantStatistics.setState(state);
this.participantStatistics.setHealthStatus(healthStatus);
this.participantStatistics.setTimeStamp(Instant.now());
@@ -283,6 +295,35 @@ public class ParticipantHandler implements Closeable {
heartbeat.setParticipantType(participantType);
heartbeat.setHealthStatus(healthStatus);
heartbeat.setState(state);
+ heartbeat.setControlLoopInfoList(getControlLoopInfoList());
+
+ if (responseToParticipantStatusReq) {
+ List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
+ ParticipantDefinition participantDefinition = new ParticipantDefinition();
+ participantDefinition.setParticipantId(participantId);
+ participantDefinition.setControlLoopElementDefinitionList(clElementDefsOnThisParticipant);
+ participantDefinitionUpdates.add(participantDefinition);
+ heartbeat.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ }
+
return heartbeat;
}
+
+ private List<ControlLoopInfo> getControlLoopInfoList() {
+ List<ControlLoopInfo> controlLoopInfoList = new ArrayList<>();
+ for (Map.Entry<ToscaConceptIdentifier, ControlLoop> entry :
+ controlLoopHandler.getControlLoopMap().entrySet()) {
+ ControlLoopInfo clInfo = new ControlLoopInfo();
+ clInfo.setControlLoopId(entry.getKey());
+ ControlLoopStatistics clStatitistics = new ControlLoopStatistics();
+ clStatitistics.setControlLoopId(entry.getKey());
+ ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList();
+ clElementStatisticsList.setClElementStatistics(
+ entry.getValue().getControlLoopElementStatisticsList(entry.getValue()));
+ clStatitistics.setClElementStatisticsList(clElementStatisticsList);
+ clInfo.setControlLoopStatistics(clStatitistics);
+ clInfo.setState(entry.getValue().getState());
+ }
+ return controlLoopInfoList;
+ }
}