diff options
author | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-10-27 08:24:48 +0100 |
---|---|---|
committer | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-10-27 12:48:30 +0100 |
commit | e90fadeec27e0249bb64da08d817fa1c475630fa (patch) | |
tree | d636190965cc80eda07b1d5d98a1ccb6eb273ba5 /runtime-controlloop/src/main | |
parent | d33f694fc4e595054fb11812b2f8010cf94b637f (diff) |
Move code to common, avoid duplication
This commit moves duplicate code from runtime and participant
to common
Issue-ID: POLICY-3542
Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech>
Change-Id: Ia7cea1d2c88031c72af77338e242f8981e536c21
Diffstat (limited to 'runtime-controlloop/src/main')
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. */ |