diff options
Diffstat (limited to 'participant/participant-impl/participant-impl-policy/src')
2 files changed, 31 insertions, 2 deletions
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<UUID, ControlLoopElement> elements = new LinkedHashMap<>(); ToscaServiceTemplate toscaServiceTemplate = testControlLoopRead(); + TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate); Map<String, ToscaNodeTemplate> nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) { @@ -176,12 +180,38 @@ public class TestListenerUtils { List<ParticipantUpdates> 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> participantUpdates) { if (participantUpdates.isEmpty()) { @@ -248,7 +278,6 @@ public class TestListenerUtils { } participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates); - participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate); return participantUpdateMsg; } |