summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/main/java/org
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-31 11:25:34 +0100
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-09-01 16:48:18 +0100
commit83b5318e545fbc72e3612c4300c4d738b0b577de (patch)
treec4429d0f64b16f510ca00160cd1eb49d91657b45 /runtime-controlloop/src/main/java/org
parentbd376e1dd5e8ccb1893ef244dcd9e4b1a0686150 (diff)
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 <sirisha.manchikanti@est.tech> Change-Id: I2b98d7dc6946b0c27763f1a150d1bf4adca90a2f
Diffstat (limited to 'runtime-controlloop/src/main/java/org')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java36
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java2
2 files changed, 36 insertions, 2 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 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<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;
/**
* Send ControlLoopUpdate to Participant.
@@ -54,9 +62,37 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con
controlLoopUpdateMsg.setControlLoopId(controlLoop.getKey().asIdentifier());
controlLoopUpdateMsg.setMessageId(UUID.randomUUID());
controlLoopUpdateMsg.setTimestamp(Instant.now());
+ ToscaServiceTemplate toscaServiceTemplate;
+ try {
+ toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
+ } catch (PfModelException pfme) {
+ LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
+ return;
+ }
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);
}
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<Par
if (commissionFlag) {
// Commission the controlloop but sending participantdefinitions to participants
message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- message.setToscaServiceTemplate(toscaServiceTemplate);
} else {
// DeCommission the controlloop but deleting participantdefinitions on participants
message.setParticipantDefinitionUpdates(null);
- message.setToscaServiceTemplate(null);
}
LOGGER.debug("Participant Update sent {}", message);
super.send(message);