From 17f9123bf5d192412124535965393179ebe14cc8 Mon Sep 17 00:00:00 2001 From: "saul.gill" Date: Tue, 24 Aug 2021 14:38:06 +0100 Subject: Added dmaap messages on commission/decommission Added dmaap message trigger to commissioning endpoint Added dmapp message trigger to decommissioning endpoint Issue-ID: POLICY-3415 Change-Id: I37ab580c9713d1002becd3bc3af674c2ca17b3c9 Signed-off-by: saul.gill --- .../commissioning/CommissioningProvider.java | 49 +++++++++++++++++++++- .../runtime/supervision/SupervisionHandler.java | 28 ++++++++++++- .../comm/ParticipantUpdatePublisher.java | 25 +++++++---- 3 files changed, 90 insertions(+), 12 deletions(-) (limited to 'runtime-controlloop/src/main/java/org') diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java index ba632f9cc..74b5394f4 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java @@ -34,8 +34,12 @@ import javax.ws.rs.core.Response.Status; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.clamp.controlloop.models.messages.rest.commissioning.CommissioningResponse; +import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; @@ -63,6 +67,8 @@ public class CommissioningProvider { private final PolicyModelsProvider modelsProvider; private final ControlLoopProvider clProvider; private final ObjectMapper mapper = new ObjectMapper(); + private final ParticipantProvider participantProvider; + private final SupervisionHandler supervisionHandler; private static final Object lockit = new Object(); @@ -72,9 +78,14 @@ public class CommissioningProvider { * @param modelsProvider the PolicyModelsProvider * @param clProvider the ControlLoopProvider */ - public CommissioningProvider(PolicyModelsProvider modelsProvider, ControlLoopProvider clProvider) { + public CommissioningProvider(PolicyModelsProvider modelsProvider, + ControlLoopProvider clProvider, + SupervisionHandler supervisionHandler, + ParticipantProvider participantProvider) { this.modelsProvider = modelsProvider; this.clProvider = clProvider; + this.supervisionHandler = supervisionHandler; + this.participantProvider = participantProvider; mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); } @@ -95,6 +106,24 @@ public class CommissioningProvider { synchronized (lockit) { modelsProvider.createServiceTemplate(serviceTemplate); + List participantList = + participantProvider.getParticipants(null, + null); + + if (participantList != null) { + for (Participant participant: participantList) { + var participantType = new ToscaConceptIdentifier(); + participantType.setName(participant.getType()); + participantType.setVersion(participant.getTypeVersion()); + + var participantUpdate = new ParticipantUpdate(); + participantUpdate.setParticipantId(participant.getDefinition()); + participantUpdate.setParticipantType(participantType); + + this.supervisionHandler.handleSendCommissionMessage(participantUpdate); + } + } + } var response = new CommissioningResponse(); @@ -126,6 +155,24 @@ public class CommissioningProvider { } synchronized (lockit) { + List participantList = + participantProvider.getParticipants(null, + null); + + if (participantList != null) { + for (Participant participant : participantList) { + var participantType = new ToscaConceptIdentifier(); + participantType.setName(participant.getType()); + participantType.setVersion(participant.getTypeVersion()); + + var participantUpdate = new ParticipantUpdate(); + participantUpdate.setParticipantId(participant.getDefinition()); + participantUpdate.setParticipantType(participantType); + + this.supervisionHandler.handleSendDeCommissionMessage(participantUpdate); + } + } + modelsProvider.deleteServiceTemplate(name, version); } diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java index 0e2ff5ca9..7cc5d7fee 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java @@ -21,7 +21,6 @@ package org.onap.policy.clamp.controlloop.runtime.supervision; import java.util.List; -import java.util.Map; import javax.ws.rs.core.Response; import lombok.AllArgsConstructor; import org.apache.commons.collections4.CollectionUtils; @@ -35,6 +34,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider 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; +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.runtime.monitoring.MonitoringProvider; import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher; @@ -141,7 +141,7 @@ public class SupervisionHandler { participantRegisterAckPublisher.send(participantRegisterMessage.getMessageId()); participantUpdatePublisher.send(participantRegisterMessage.getParticipantId(), - participantRegisterMessage.getParticipantType()); + participantRegisterMessage.getParticipantType(), true); } /** @@ -165,6 +165,30 @@ public class SupervisionHandler { LOGGER.debug("Participant Update Ack received {}", participantUpdateAckMessage); } + /** + * Send commissioning update message to dmaap. + * + * @param participantUpdateMessage the ParticipantUpdate message to send + */ + public void handleSendCommissionMessage(ParticipantUpdate participantUpdateMessage) { + LOGGER.debug("Participant update message being sent {}", participantUpdateMessage); + + participantUpdatePublisher.send(participantUpdateMessage.getParticipantId(), + participantUpdateMessage.getParticipantType(), true); + } + + /** + * Send decommissioning update message to dmaap. + * + * @param participantUpdateMessage the ParticipantUpdate message to send + */ + public void handleSendDeCommissionMessage(ParticipantUpdate participantUpdateMessage) { + LOGGER.debug("Participant update message being sent {}", participantUpdateMessage); + + participantUpdatePublisher.send(participantUpdateMessage.getParticipantId(), + participantUpdateMessage.getParticipantType(), false); + } + /** * Supervise a control loop, performing whatever actions need to be performed on the control loop. * diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java index 5edf528b8..d5dc4a6d0 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java @@ -22,22 +22,21 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm; import java.time.Instant; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import lombok.AllArgsConstructor; -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.ParticipantDefinition; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate; -import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -51,7 +50,7 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher controlLoopElementDefinitionList) { - ParticipantDefinition participantDefinition = new ParticipantDefinition(); + var participantDefinition = new ParticipantDefinition(); participantDefinition.setParticipantId(clParticipantId); controlLoopElementDefinitionList.add(clDefinition); participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList); -- cgit 1.2.3-korg