diff options
Diffstat (limited to 'runtime-controlloop')
5 files changed, 32 insertions, 54 deletions
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 0b7bc9a26..472348ac3 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 @@ -40,6 +40,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider 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.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; @@ -108,23 +109,13 @@ public class CommissioningProvider { synchronized (lockit) { modelsProvider.createServiceTemplate(serviceTemplate); List<Participant> 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); - } + participantProvider.getParticipants(null, null); + if (!participantList.isEmpty()) { + this.supervisionHandler.handleSendCommissionMessage( + getCommonOrInstancePropertiesFromNodeTypes(true, + serviceTemplate.getName(), + serviceTemplate.getVersion())); } - } var response = new CommissioningResponse(); @@ -159,21 +150,9 @@ public class CommissioningProvider { List<Participant> 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); - } + if (!participantList.isEmpty()) { + this.supervisionHandler.handleSendDeCommissionMessage(); } - modelsProvider.deleteServiceTemplate(name, version); } @@ -342,7 +321,7 @@ public class CommissioningProvider { * @return the node types with common or instance properties * @throws PfModelException on errors getting node type properties */ - private Map<String, ToscaNodeType> getCommonOrInstancePropertiesFromNodeTypes(boolean common, String name, + public Map<String, ToscaNodeType> getCommonOrInstancePropertiesFromNodeTypes(boolean common, String name, String version) throws PfModelException { var serviceTemplates = new ToscaServiceTemplates(); serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(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 c4ca568f7..1747bbd3c 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 @@ -52,6 +52,7 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantReg import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -149,8 +150,7 @@ public class SupervisionHandler { participantRegisterAckPublisher.send(participantRegisterMessage.getMessageId(), participantRegisterMessage.getParticipantId(), participantRegisterMessage.getParticipantType()); - participantUpdatePublisher.send(participantRegisterMessage.getParticipantId(), - participantRegisterMessage.getParticipantType(), true); + participantUpdatePublisher.send(null, true); } /** @@ -209,25 +209,19 @@ public class SupervisionHandler { /** * 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); + public void handleSendCommissionMessage(Map<String, ToscaNodeType> commonPropertiesMap) { + LOGGER.debug("Participant update message being sent {}"); + participantUpdatePublisher.send(commonPropertiesMap, 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); + public void handleSendDeCommissionMessage() { + LOGGER.debug("Participant update message being sent"); + participantUpdatePublisher.send(null, false); } /** @@ -429,6 +423,7 @@ public class SupervisionHandler { participant.setName(participantStatusMessage.getParticipantId().getName()); participant.setVersion(participantStatusMessage.getParticipantId().getVersion()); participant.setDefinition(participantStatusMessage.getParticipantId()); + participant.setParticipantType(participantStatusMessage.getParticipantType()); participant.setParticipantState(participantStatusMessage.getState()); participant.setHealthStatus(participantStatusMessage.getHealthStatus()); diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java index d13d66c5d..fde94bc0d 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java @@ -144,7 +144,7 @@ public class SupervisionScanner { if (participantUpdateCounter.count(id)) { LOGGER.debug("retry message ParticipantUpdate"); - participantUpdatePublisher.send(id.getLeft(), id.getRight(), true); + participantUpdatePublisher.send(null, true); } else { LOGGER.debug("report Participant Update fault"); participantUpdateCounter.setFault(id); 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 fe46297f1..0f6cc7cbc 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 @@ -25,6 +25,7 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm; import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.util.Map; import lombok.AllArgsConstructor; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; @@ -34,6 +35,7 @@ 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.ToscaNodeType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,14 +55,9 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par /** * Send ParticipantUpdate to Participant. * - * @param participantId the participant Id - * @param participantType the participant Type */ - public void send(ToscaConceptIdentifier participantId, ToscaConceptIdentifier participantType, - boolean commissionFlag) { + public void send(Map<String, ToscaNodeType> commonPropertiesMap, boolean commissionFlag) { var message = new ParticipantUpdate(); - message.setParticipantId(participantId); - message.setParticipantType(participantType); message.setTimestamp(Instant.now()); ToscaServiceTemplate toscaServiceTemplate = null; @@ -82,7 +79,7 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par var clParticipantType = ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(), - toscaInputEntry.getValue(), participantDefinitionUpdates); + toscaInputEntry.getValue(), participantDefinitionUpdates, commonPropertiesMap); } } } @@ -99,11 +96,17 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par } private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey, - ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) { + ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates, + Map<String, ToscaNodeType> commonPropertiesMap) { var clDefinition = new ControlLoopElementDefinition(); clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion())); clDefinition.setControlLoopElementToscaNodeTemplate(entryValue); + ToscaNodeType nodeType = commonPropertiesMap.get(entryValue.getType()); + if (nodeType != null) { + clDefinition.setCommonPropertiesMap(nodeType.getProperties()); + } + List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>(); if (participantDefinitionUpdates.isEmpty()) { diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java index 2ba321d36..9b64f9076 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java @@ -139,6 +139,7 @@ class SupervisionScannerTest { participant.setHealthStatus(ParticipantHealthStatus.HEALTHY); participant.setParticipantState(ParticipantState.ACTIVE); participant.setDefinition(new ToscaConceptIdentifier("unknown", "0.0.0")); + participant.setParticipantType(new ToscaConceptIdentifier("ParticipantType1", "1.0.0")); var participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider.updateParticipants(List.of(participant)); |