From 83b5318e545fbc72e3612c4300c4d738b0b577de Mon Sep 17 00:00:00 2001 From: Sirisha_Manchikanti Date: Tue, 31 Aug 2021 11:25:34 +0100 Subject: Send ToscaServiceTemplateFragment with policies, policy-types ToscaServiceTemplateFragment contains policies, policy-types and respective datatypes to be sent to Policy participant, and there on to Policy Framework to create new policies or policy-types that doesnot exist in the database. https://wiki.onap.org/display/DW/The+CLAMP+Policy+Framework+Participant Issue-ID: POLICY-3607 Signed-off-by: Sirisha_Manchikanti Change-Id: I2b98d7dc6946b0c27763f1a150d1bf4adca90a2f --- .../main/handler/ControlLoopElementHandler.java | 2 +- .../policy/main/utils/TestListenerUtils.java | 31 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'participant/participant-impl/participant-impl-policy') diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java index b17ae4311..4f8dcf1f9 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java @@ -130,7 +130,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { throws PfModelException { intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(), ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE); - ToscaServiceTemplate controlLoopDefinition = intermediaryApi.getToscaServiceTemplate(); + ToscaServiceTemplate controlLoopDefinition = element.getToscaServiceTemplateFragment(); if (controlLoopDefinition.getToscaTopologyTemplate() != null) { if (controlLoopDefinition.getPolicyTypes() != null) { for (ToscaPolicyType policyType : controlLoopDefinition.getPolicyTypes().values()) { diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java index 4c87e0875..52ec98ea2 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java @@ -50,6 +50,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils; 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.ToscaTopologyTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,6 +61,8 @@ public class TestListenerUtils { static CommonTestData commonTestData = new CommonTestData(); private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class); private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement"; + private static final String POLICY_TYPE_ID = "policy_type_id"; + private static final String POLICY_ID = "policy_id"; private TestListenerUtils() {} @@ -147,6 +150,7 @@ public class TestListenerUtils { Map elements = new LinkedHashMap<>(); ToscaServiceTemplate toscaServiceTemplate = testControlLoopRead(); + TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate); Map nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); for (Map.Entry toscaInputEntry : nodeTemplatesMap.entrySet()) { @@ -176,12 +180,38 @@ public class TestListenerUtils { List participantUpdates = new ArrayList<>(); for (ControlLoopElement element : elements.values()) { + populateToscaNodeTemplateFragment(element, toscaServiceTemplate); prepareParticipantUpdateForControlLoop(element, participantUpdates); } clUpdateMsg.setParticipantUpdatesList(participantUpdates); return clUpdateMsg; } + private static void populateToscaNodeTemplateFragment(ControlLoopElement clElement, + ToscaServiceTemplate toscaServiceTemplate) { + ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate + .getToscaTopologyTemplate().getNodeTemplates().get(clElement.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()); + + clElement.setToscaServiceTemplateFragment(toscaServiceTemplateFragment); + } + } + } + private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement, List participantUpdates) { if (participantUpdates.isEmpty()) { @@ -248,7 +278,6 @@ public class TestListenerUtils { } participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates); - participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate); return participantUpdateMsg; } -- cgit 1.2.3-korg