From 9b982666d6ddb6c964a1e539fea97231b5053f5b Mon Sep 17 00:00:00 2001
From: Sirisha_Manchikanti <sirisha.manchikanti@est.tech>
Date: Mon, 20 Sep 2021 16:08:25 +0100
Subject: Add participantType to participant class

Add participantType to participant class, cascade common and
instance properties from runtime to participants

Issue-ID: POLICY-3576
Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech>
Change-Id: Ic9205aafe269ccc6dae0b3463fc6df5c47129e5d
---
 .../api/ParticipantIntermediaryApi.java            |  9 +++++++++
 .../api/impl/ParticipantIntermediaryApiImpl.java   |  6 ++++++
 .../intermediary/handler/ControlLoopHandler.java   | 22 ++++++++++++++++++++-
 .../intermediary/handler/ParticipantHandler.java   | 23 +++++++++++++++++-----
 4 files changed, 54 insertions(+), 6 deletions(-)

(limited to 'participant/participant-intermediary/src/main/java/org')

diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
index 891d67e2d..0cb4963ec 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -34,6 +34,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
 
 /**
  * This interface is used by participant implementations to use the participant intermediary.
@@ -56,6 +57,14 @@ public interface ParticipantIntermediaryApi {
      */
     List<Participant> getParticipants(String name, String version);
 
+    /**
+     * Get common properties of a controlloopelement.
+     *
+     * @param clElementDef the control loop element definition
+     * @return the common properties
+     */
+    Map<String, ToscaProperty> getClElementDefinitionCommonProperties(ToscaConceptIdentifier clElementDef);
+
     /**
      * Update the state of a participant.
      *
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index aa1febadd..43ac3464c 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -40,6 +40,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.api.Participan
 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ControlLoopHandler;
 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
 import org.springframework.stereotype.Component;
 
 /**
@@ -76,6 +77,11 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
         return List.of(participantHandler.getParticipant(name, version));
     }
 
+    @Override
+    public Map<String, ToscaProperty> getClElementDefinitionCommonProperties(ToscaConceptIdentifier clElementDef) {
+        return participantHandler.getClElementDefinitionCommonProperties(clElementDef);
+    }
+
     @Override
     public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
         return participantHandler.updateParticipantState(definition, state);
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
index 30a06ba22..5cb79a37f 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
@@ -22,6 +22,7 @@
 package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -47,6 +48,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.Par
 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.ToscaProperty;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -265,7 +267,8 @@ public class ControlLoopHandler {
     private ToscaNodeTemplate getClElementNodeTemplate(List<ControlLoopElementDefinition> clElementDefinitions,
             ToscaConceptIdentifier clElementDefId) {
         for (var clElementDefinition : clElementDefinitions) {
-            if (clElementDefinition.getClElementDefinitionId().equals(clElementDefId)) {
+            if (clElementDefId.getName().contains(
+                clElementDefinition.getClElementDefinitionId().getName())) {
                 return clElementDefinition.getControlLoopElementToscaNodeTemplate();
             }
         }
@@ -364,4 +367,21 @@ public class ControlLoopHandler {
         controlLoops.setControlLoopList(new ArrayList<>(controlLoopMap.values()));
         return controlLoops;
     }
+
+    /**
+     * Get properties of a controlloopelement.
+     *
+     * @param id the control loop element id
+     * @return the instance properties
+     */
+    public Map<String, ToscaProperty> getClElementInstanceProperties(UUID id) {
+        Map<String, ToscaProperty> propertiesMap = new HashMap<>();
+        for (var controlLoop : controlLoopMap.values()) {
+            var element = controlLoop.getElements().get(id);
+            if (element != null) {
+                propertiesMap.putAll(element.getPropertiesMap());
+            }
+        }
+        return propertiesMap;
+    }
 }
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
index 69f8febb8..ea7d84501 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
@@ -24,6 +24,7 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
 
 import java.time.Instant;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -60,6 +61,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.comm.Participa
 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -205,6 +207,22 @@ public class ParticipantHandler {
         return null;
     }
 
+    /**
+     * Get common properties of a controlloopelement.
+     *
+     * @param clElementDef the control loop element definition
+     * @return the common properties
+     */
+    public Map<String, ToscaProperty> getClElementDefinitionCommonProperties(ToscaConceptIdentifier clElementDef) {
+        Map<String, ToscaProperty> commonPropertiesMap = new HashMap<>();
+        clElementDefsOnThisParticipant.stream().forEach(definition -> {
+            if (definition.getClElementDefinitionId().equals(clElementDef)) {
+                commonPropertiesMap.putAll(definition.getCommonPropertiesMap());
+            }
+        });
+        return commonPropertiesMap;
+    }
+
     /**
      * Check if a participant message applies to this participant handler.
      *
@@ -284,15 +302,10 @@ public class ParticipantHandler {
         LOGGER.debug("ParticipantUpdate message received for participantId {}",
                 participantUpdateMsg.getParticipantId());
 
-        if (!participantUpdateMsg.appliesTo(participantType, participantId)) {
-            return;
-        }
-
         if (!participantUpdateMsg.getParticipantDefinitionUpdates().isEmpty()) {
             // This message is to commission the controlloop
             for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) {
                 if (participantDefinition.getParticipantType().equals(participantType)) {
-                    clElementDefsOnThisParticipant.clear();
                     clElementDefsOnThisParticipant.addAll(participantDefinition.getControlLoopElementDefinitionList());
                     break;
                 }
-- 
cgit 1.2.3-korg