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 --- .../comm/ControlLoopUpdatePublisher.java | 36 ++++++++++++++++++++++ .../comm/ParticipantUpdatePublisher.java | 2 -- .../supervision/comm/SupervisionMessagesTest.java | 1 - .../servicetemplates/pmsh_multiple_cl_tosca.yaml | 6 ++++ 4 files changed, 42 insertions(+), 3 deletions(-) (limited to 'runtime-controlloop/src') 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 6df030d32..d68a643d2 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 @@ -31,6 +31,11 @@ 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; @@ -43,6 +48,9 @@ import org.springframework.stereotype.Component; public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher { 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; /** * Send ControlLoopUpdate to Participant. @@ -54,9 +62,37 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher 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); } controlLoopUpdateMsg.setParticipantUpdatesList(participantUpdates); 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 efd262560..113823648 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 @@ -95,11 +95,9 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher