diff options
author | Liam Fallon <liam.fallon@est.tech> | 2021-10-29 08:55:32 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-10-29 08:55:32 +0000 |
commit | 0086ef431dfea90dc0a4143ba8121bac14c8ee3f (patch) | |
tree | 227eb8a55fde32554e68c7849d5d23c15a353db1 /runtime-controlloop | |
parent | 5b1714f58b0e9543a2dda894b5daa0148d28d741 (diff) | |
parent | e90fadeec27e0249bb64da08d817fa1c475630fa (diff) |
Merge "Move code to common, avoid duplication"
Diffstat (limited to 'runtime-controlloop')
2 files changed, 8 insertions, 101 deletions
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java index 74d987240..06fbcd649 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java @@ -27,15 +27,14 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; import lombok.AllArgsConstructor; +import org.onap.policy.clamp.controlloop.common.utils.CommonUtils; 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.ParticipantUpdates; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.provider.PolicyModelsProvider; -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.ToscaTopologyTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -48,8 +47,6 @@ import org.springframework.stereotype.Component; public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<ControlLoopUpdate> { private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopUpdatePublisher.class); - private static final String POLICY_TYPE_ID = "policy_type_id"; - private static final String POLICY_ID = "policy_id"; private final PolicyModelsProvider modelsProvider; /** @@ -83,59 +80,12 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con List<ParticipantUpdates> participantUpdates = new ArrayList<>(); for (ControlLoopElement element : controlLoop.getElements().values()) { - ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate - .getToscaTopologyTemplate().getNodeTemplates().get(element.getDefinition().getName()); - // If the ControlLoopElement has policy_type_id or policy_id, identify it as a PolicyControlLoopElement - // and pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment - if ((toscaNodeTemplate.getProperties().get(POLICY_TYPE_ID) != null) - || (toscaNodeTemplate.getProperties().get(POLICY_ID) != null)) { - // ControlLoopElement for policy framework, send policies and policyTypes to participants - if ((toscaServiceTemplate.getPolicyTypes() != null) - || (toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() != null)) { - ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate(); - toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes()); - - ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate(); - toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies()); - toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate); - - toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes()); - - element.setToscaServiceTemplateFragment(toscaServiceTemplateFragment); - } - } - prepareParticipantUpdate(element, participantUpdates); + CommonUtils.setServiceTemplatePolicyInfo(element, toscaServiceTemplate); + CommonUtils.prepareParticipantUpdate(element, participantUpdates); } controlLoopUpdateMsg.setParticipantUpdatesList(participantUpdates); LOGGER.debug("ControlLoopUpdate message sent {}", controlLoopUpdateMsg); super.send(controlLoopUpdateMsg); } - - private void prepareParticipantUpdate(ControlLoopElement clElement, - List<ParticipantUpdates> participantUpdates) { - if (participantUpdates.isEmpty()) { - participantUpdates.add(getControlLoopElementList(clElement)); - } else { - var participantExists = false; - for (ParticipantUpdates participantUpdate : participantUpdates) { - if (participantUpdate.getParticipantId().equals(clElement.getParticipantId())) { - participantUpdate.getControlLoopElementList().add(clElement); - participantExists = true; - } - } - if (!participantExists) { - participantUpdates.add(getControlLoopElementList(clElement)); - } - } - } - - private ParticipantUpdates getControlLoopElementList(ControlLoopElement clElement) { - var participantUpdate = new ParticipantUpdates(); - List<ControlLoopElement> controlLoopElementList = new ArrayList<>(); - participantUpdate.setParticipantId(clElement.getParticipantId()); - controlLoopElementList.add(clElement); - participantUpdate.setControlLoopElementList(controlLoopElementList); - return participantUpdate; - } } 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 5d879dc56..c6788f12c 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 @@ -27,14 +27,13 @@ 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.common.utils.CommonUtils; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ServiceTemplateProvider; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.models.base.PfModelException; 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; @@ -99,10 +98,10 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par for (var toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) { if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) { - var clParticipantType = - ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); - prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(), - toscaInputEntry.getValue(), participantDefinitionUpdates, commonPropertiesMap); + CommonUtils.prepareParticipantDefinitionUpdate( + ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()), + toscaInputEntry.getKey(), toscaInputEntry.getValue(), + participantDefinitionUpdates, commonPropertiesMap); } } @@ -113,48 +112,6 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par return true; } - private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey, - 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()) { - participantDefinitionUpdates - .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); - } else { - var participantExists = false; - for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) { - if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) { - participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition); - participantExists = true; - } - } - if (!participantExists) { - participantDefinitionUpdates.add( - getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); - } - } - } - - private ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition, - ToscaConceptIdentifier clParticipantType, - List<ControlLoopElementDefinition> controlLoopElementDefinitionList) { - var participantDefinition = new ParticipantDefinition(); - participantDefinition.setParticipantType(clParticipantType); - controlLoopElementDefinitionList.add(clDefinition); - participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList); - return participantDefinition; - } - /** * Send ParticipantUpdate to Participant after that commissioning has been removed. */ |