aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2021-09-29 12:16:06 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2021-10-05 15:03:31 +0100
commitf84a61a944d6561550d96880a54c410ca03deabe (patch)
tree70ddc9091d5b3c86ba2225324b5a32b51c3914f5 /runtime-controlloop/src
parent680b87d278673b1768be1c13fca90d6f7dfef3af (diff)
Handle ParticipantRegister
Send ParticipantUpdate to participant after registration if commissioning has already been created Issue-ID: POLICY-3689 Change-Id: Iccc4fc1c0b95e1f270b6810c5b5f130726f24650 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-controlloop/src')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java210
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java20
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java21
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java2
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java75
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java29
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java4
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java8
8 files changed, 135 insertions, 234 deletions
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
index d2d57ed83..72c153b6d 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
@@ -37,17 +37,16 @@ import org.apache.commons.collections4.MapUtils;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.controlloop.models.messages.rest.commissioning.CommissioningResponse;
import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
@@ -64,7 +63,7 @@ public class CommissioningProvider {
public static final String CONTROL_LOOP_NODE_TYPE = "org.onap.policy.clamp.controlloop.ControlLoop";
private static final String INSTANCE_TEXT = "_Instance";
- private final PolicyModelsProvider modelsProvider;
+ private final ServiceTemplateProvider serviceTemplateProvider;
private final ControlLoopProvider clProvider;
private final ObjectMapper mapper = new ObjectMapper();
private final ParticipantProvider participantProvider;
@@ -75,14 +74,14 @@ public class CommissioningProvider {
/**
* Create a commissioning provider.
*
- * @param modelsProvider the PolicyModelsProvider
- * @param clProvider the ControlLoopProvider
+ * @param serviceTemplateProvider the ServiceTemplate Provider
+ * @param clProvider the ControlLoop Provider
+ * @param supervisionHandler the Supervision Handler
+ * @param participantProvider the Participant Provider
*/
- public CommissioningProvider(PolicyModelsProvider modelsProvider,
- ControlLoopProvider clProvider,
- SupervisionHandler supervisionHandler,
- ParticipantProvider participantProvider) {
- this.modelsProvider = modelsProvider;
+ public CommissioningProvider(ServiceTemplateProvider serviceTemplateProvider, ControlLoopProvider clProvider,
+ SupervisionHandler supervisionHandler, ParticipantProvider participantProvider) {
+ this.serviceTemplateProvider = serviceTemplateProvider;
this.clProvider = clProvider;
this.supervisionHandler = supervisionHandler;
this.participantProvider = participantProvider;
@@ -97,22 +96,17 @@ public class CommissioningProvider {
* @throws PfModelException on creation errors
*/
public CommissioningResponse createControlLoopDefinitions(ToscaServiceTemplate serviceTemplate)
- throws PfModelException {
+ throws PfModelException {
if (verifyIfInstancePropertiesExists()) {
- throw new PfModelException(Status.BAD_REQUEST,
- "Delete instances, to commission control loop definitions");
+ throw new PfModelException(Status.BAD_REQUEST, "Delete instances, to commission control loop definitions");
}
synchronized (lockit) {
- modelsProvider.createServiceTemplate(serviceTemplate);
- List<Participant> participantList =
- participantProvider.getParticipants(null, null);
+ serviceTemplateProvider.createServiceTemplate(serviceTemplate);
+ List<Participant> participantList = participantProvider.getParticipants(null, null);
if (!participantList.isEmpty()) {
- this.supervisionHandler.handleSendCommissionMessage(
- getCommonOrInstancePropertiesFromNodeTypes(true,
- serviceTemplate.getName(),
- serviceTemplate.getVersion()));
+ supervisionHandler.handleSendCommissionMessage(serviceTemplate.getName(), serviceTemplate.getVersion());
}
}
@@ -136,22 +130,18 @@ public class CommissioningProvider {
* @return the result of the deletion
* @throws PfModelException on deletion errors
*/
- public CommissioningResponse deleteControlLoopDefinition(String name, String version)
- throws PfModelException {
+ public CommissioningResponse deleteControlLoopDefinition(String name, String version) throws PfModelException {
if (verifyIfInstancePropertiesExists()) {
- throw new PfModelException(Status.BAD_REQUEST,
- "Delete instances, to commission control loop definitions");
+ throw new PfModelException(Status.BAD_REQUEST, "Delete instances, to commission control loop definitions");
}
synchronized (lockit) {
- List<Participant> participantList =
- participantProvider.getParticipants(null,
- null);
+ List<Participant> participantList = participantProvider.getParticipants(null, null);
if (!participantList.isEmpty()) {
- this.supervisionHandler.handleSendDeCommissionMessage();
+ supervisionHandler.handleSendDeCommissionMessage();
}
- modelsProvider.deleteServiceTemplate(name, version);
+ serviceTemplateProvider.deleteServiceTemplate(name, version);
}
var response = new CommissioningResponse();
@@ -224,143 +214,6 @@ public class CommissioningProvider {
}
/**
- * Get the initial node types with common or instance properties.
- *
- * @param fullNodeTypes map of all the node types in the specified template
- * @param common boolean to indicate whether common or instance properties are required
- * @return node types map that only has common properties
- * @throws PfModelException on errors getting node type with common properties
- */
- private Map<String, ToscaNodeType> getInitialNodeTypesMap(Map<String, ToscaNodeType> fullNodeTypes,
- boolean common) {
-
- var tempNodeTypesMap = new HashMap<String, ToscaNodeType>();
-
- fullNodeTypes.forEach((key, nodeType) -> {
- var tempToscaNodeType = new ToscaNodeType();
- tempToscaNodeType.setName(key);
-
- var resultantPropertyMap = findCommonOrInstancePropsInNodeTypes(nodeType, common);
-
- if (!resultantPropertyMap.isEmpty()) {
- tempToscaNodeType.setProperties(resultantPropertyMap);
- tempNodeTypesMap.put(key, tempToscaNodeType);
- }
- });
- return tempNodeTypesMap;
- }
-
- private Map<String, ToscaProperty> findCommonOrInstancePropsInNodeTypes(ToscaNodeType nodeType, boolean common) {
-
- var tempCommonPropertyMap = new HashMap<String, ToscaProperty>();
- var tempInstancePropertyMap = new HashMap<String, ToscaProperty>();
-
- nodeType.getProperties().forEach((propKey, prop) -> {
-
- if (prop.getMetadata() != null) {
- prop.getMetadata().forEach((k, v) -> {
- if (k.equals("common") && v.equals("true") && common) {
- tempCommonPropertyMap.put(propKey, prop);
- } else if (k.equals("common") && v.equals("false") && !common) {
- tempInstancePropertyMap.put(propKey, prop);
- }
-
- });
- } else {
- tempInstancePropertyMap.put(propKey, prop);
- }
- });
-
- if (tempCommonPropertyMap.isEmpty() && !common) {
- return tempInstancePropertyMap;
- } else {
- return tempCommonPropertyMap;
- }
- }
-
- /**
- * Get the node types derived from those that have common properties.
- *
- * @param initialNodeTypes map of all the node types in the specified template
- * @param filteredNodeTypes map of all the node types that have common or instance properties
- * @return all node types that have common properties including their children
- * @throws PfModelException on errors getting node type with common properties
- */
- private Map<String, ToscaNodeType> getFinalNodeTypesMap(Map<String, ToscaNodeType> initialNodeTypes,
- Map<String, ToscaNodeType> filteredNodeTypes) {
- for (var i = 0; i < initialNodeTypes.size(); i++) {
- initialNodeTypes.forEach((key, nodeType) -> {
- var tempToscaNodeType = new ToscaNodeType();
- tempToscaNodeType.setName(key);
-
- if (filteredNodeTypes.get(nodeType.getDerivedFrom()) != null) {
- tempToscaNodeType.setName(key);
-
- var finalProps = new HashMap<String, ToscaProperty>(
- filteredNodeTypes.get(nodeType.getDerivedFrom()).getProperties());
-
- tempToscaNodeType.setProperties(finalProps);
- } else {
- return;
- }
- filteredNodeTypes.putIfAbsent(key, tempToscaNodeType);
-
- });
- }
- return filteredNodeTypes;
- }
-
- /**
- * Get the requested node types with common or instance properties.
- *
- * @param common boolean indicating common or instance properties
- * @param name the name of the definition to get, null for all definitions
- * @param version the version of the definition to get, null for all definitions
- * @return the node types with common or instance properties
- * @throws PfModelException on errors getting node type properties
- */
- public Map<String, ToscaNodeType> getCommonOrInstancePropertiesFromNodeTypes(boolean common, String name,
- String version) throws PfModelException {
- var serviceTemplates = new ToscaServiceTemplates();
- serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
- var tempNodeTypesMap =
- this.getInitialNodeTypesMap(serviceTemplates.getServiceTemplates().get(0).getNodeTypes(), common);
-
- return this.getFinalNodeTypesMap(serviceTemplates.getServiceTemplates().get(0).getNodeTypes(),
- tempNodeTypesMap);
-
- }
-
- /**
- * Get node templates with appropriate common or instance properties added.
- *
- * @param initialNodeTemplates map of all the node templates in the specified template
- * @param nodeTypeProps map of all the node types that have common or instance properties including children
- * @return all node templates with appropriate common or instance properties added
- * @throws PfModelException on errors getting map of node templates with common or instance properties added
- */
- private Map<String, ToscaNodeTemplate> getDerivedCommonOrInstanceNodeTemplates(
- Map<String, ToscaNodeTemplate> initialNodeTemplates, Map<String, ToscaNodeType> nodeTypeProps) {
-
- var finalNodeTemplatesMap = new HashMap<String, ToscaNodeTemplate>();
-
- initialNodeTemplates.forEach((templateKey, template) -> {
- if (nodeTypeProps.containsKey(template.getType())) {
- var finalMergedProps = new HashMap<String, Object>();
-
- nodeTypeProps.get(template.getType()).getProperties().forEach(finalMergedProps::putIfAbsent);
-
- template.setProperties(finalMergedProps);
-
- finalNodeTemplatesMap.put(templateKey, template);
- } else {
- return;
- }
- });
- return finalNodeTemplatesMap;
- }
-
- /**
* Get node templates with common properties added.
*
* @param common boolean indicating common or instance properties to be used
@@ -374,17 +227,17 @@ public class CommissioningProvider {
if (common && verifyIfInstancePropertiesExists()) {
throw new PfModelException(Status.BAD_REQUEST,
- "Cannot create or edit common properties, delete all the instantiations first");
+ "Cannot create or edit common properties, delete all the instantiations first");
}
+ var serviceTemplateList = serviceTemplateProvider.getServiceTemplateList(name, version);
var commonOrInstanceNodeTypeProps =
- this.getCommonOrInstancePropertiesFromNodeTypes(common, name, version);
+ serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(common, serviceTemplateList.get(0));
var serviceTemplates = new ToscaServiceTemplates();
- serviceTemplates.setServiceTemplates(filterToscaNodeTemplateInstance(
- modelsProvider.getServiceTemplateList(name, version)));
+ serviceTemplates.setServiceTemplates(filterToscaNodeTemplateInstance(serviceTemplateList));
- return this.getDerivedCommonOrInstanceNodeTemplates(
+ return serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates(
serviceTemplates.getServiceTemplates().get(0).getToscaTopologyTemplate().getNodeTemplates(),
commonOrInstanceNodeTypeProps);
}
@@ -398,9 +251,7 @@ public class CommissioningProvider {
* @throws PfModelException on errors getting control loop definitions
*/
public ToscaServiceTemplate getToscaServiceTemplate(String name, String version) throws PfModelException {
- var serviceTemplates = new ToscaServiceTemplates();
- serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
- return serviceTemplates.getServiceTemplates().get(0);
+ return serviceTemplateProvider.getToscaServiceTemplate(name, version);
}
/**
@@ -411,14 +262,11 @@ public class CommissioningProvider {
* @return the tosca service template
* @throws PfModelException on errors getting tosca service template
*/
- public String getToscaServiceTemplateReduced(String name, String version)
- throws PfModelException {
+ public String getToscaServiceTemplateReduced(String name, String version) throws PfModelException {
- var serviceTemplates = new ToscaServiceTemplates();
- serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
+ var serviceTemplateList = serviceTemplateProvider.getServiceTemplateList(name, version);
- ToscaServiceTemplate fullTemplate = filterToscaNodeTemplateInstance(
- serviceTemplates.getServiceTemplates()).get(0);
+ ToscaServiceTemplate fullTemplate = filterToscaNodeTemplateInstance(serviceTemplateList).get(0);
var template = new HashMap<String, Object>();
template.put("tosca_definitions_version", fullTemplate.getToscaDefinitionsVersion());
@@ -511,7 +359,7 @@ public class CommissioningProvider {
*/
private boolean verifyIfInstancePropertiesExists() {
return clProvider.getNodeTemplates(null, null).stream()
- .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains(INSTANCE_TEXT));
+ .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains(INSTANCE_TEXT));
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java
index fbb2742a7..d975ec6bc 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
@@ -74,10 +75,21 @@ public class SupervisionAspect implements Closeable {
executor.execute(() -> supervisionScanner.handleParticipantStatus(participantStatusMessage.getParticipantId()));
}
- @Before("@annotation(MessageIntercept) && args(participantRegisterMessage,..)")
- public void handleParticipantRegister(ParticipantRegister participantRegisterMessage) {
- executor.execute(() -> supervisionScanner.handleParticipantRegister(new ImmutablePair<>(
- participantRegisterMessage.getParticipantId(), participantRegisterMessage.getParticipantType())));
+ /**
+ * Intercepts participant Register Message
+ * if there is a Commissioning starts an execution of handleParticipantRegister.
+ *
+ * @param participantRegisterMessage the ParticipantRegister message
+ * @param isCommissioning is Commissioning
+ */
+ @AfterReturning(
+ value = "@annotation(MessageIntercept) && args(participantRegisterMessage,..)",
+ returning = "isCommissioning")
+ public void handleParticipantRegister(ParticipantRegister participantRegisterMessage, boolean isCommissioning) {
+ if (isCommissioning) {
+ executor.execute(() -> supervisionScanner.handleParticipantRegister(new ImmutablePair<>(
+ participantRegisterMessage.getParticipantId(), participantRegisterMessage.getParticipantType())));
+ }
}
@Before("@annotation(MessageIntercept) && args(participantUpdateAckMessage,..)")
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
index a031cfaf6..960cb4304 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
@@ -21,7 +21,6 @@
package org.onap.policy.clamp.controlloop.runtime.supervision;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -53,7 +52,6 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantReg
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -144,15 +142,21 @@ public class SupervisionHandler {
*
* @param participantRegisterMessage the ParticipantRegister message received from a participant
*/
- public void handleParticipantMessage(ParticipantRegister participantRegisterMessage) {
+ @MessageIntercept
+ public boolean handleParticipantMessage(ParticipantRegister participantRegisterMessage) {
LOGGER.debug("Participant Register received {}", participantRegisterMessage);
try {
checkParticipant(participantRegisterMessage, ParticipantState.UNKNOWN, ParticipantHealthStatus.UNKNOWN);
} catch (PfModelException | ControlLoopException svExc) {
LOGGER.warn("error saving participant {}", participantRegisterMessage.getParticipantId(), svExc);
}
+
+ var isCommissioning = participantUpdatePublisher.sendCommissioning(null, null,
+ participantRegisterMessage.getParticipantId(), participantRegisterMessage.getParticipantType());
+
participantRegisterAckPublisher.send(participantRegisterMessage.getMessageId(),
participantRegisterMessage.getParticipantId(), participantRegisterMessage.getParticipantType());
+ return isCommissioning;
}
/**
@@ -213,10 +217,13 @@ public class SupervisionHandler {
/**
* Send commissioning update message to dmaap.
*
+ * @param name the ToscaServiceTemplate name
+ * @param version the ToscaServiceTemplate version
*/
- public void handleSendCommissionMessage(Map<String, ToscaNodeType> commonPropertiesMap) {
- LOGGER.debug("Participant update message being sent {}");
- participantUpdatePublisher.send(commonPropertiesMap, true);
+ public void handleSendCommissionMessage(String name, String version) {
+ LOGGER.debug("Participant update message with serviveTemplate {} {} being sent to all participants", name,
+ version);
+ participantUpdatePublisher.sendComissioningBroadcast(name, version);
}
/**
@@ -225,7 +232,7 @@ public class SupervisionHandler {
*/
public void handleSendDeCommissionMessage() {
LOGGER.debug("Participant update message being sent");
- participantUpdatePublisher.send(Collections.emptyMap(), false);
+ participantUpdatePublisher.sendDecomisioning();
}
/**
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
index df7efbe9c..5147aa241 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
@@ -160,7 +160,7 @@ public class SupervisionScanner {
if (participantUpdateCounter.count(id)) {
LOGGER.debug("retry message ParticipantUpdate");
- participantUpdatePublisher.send(null, true);
+ participantUpdatePublisher.sendCommissioning(null, null, id.getLeft(), id.getRight());
} else {
LOGGER.debug("report Participant Update fault");
participantUpdateCounter.setFault(id);
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 0f6cc7cbc..5d879dc56 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
@@ -30,9 +30,9 @@ import lombok.AllArgsConstructor;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.provider.PolicyModelsProvider;
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.ToscaNodeType;
@@ -50,49 +50,67 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
- private final PolicyModelsProvider modelsProvider;
+ private final ServiceTemplateProvider serviceTemplateProvider;
/**
- * Send ParticipantUpdate to Participant.
+ * Send ParticipantUpdate to all Participants.
*
+ * @param name the ToscaServiceTemplate name
+ * @param version the ToscaServiceTemplate version
*/
- public void send(Map<String, ToscaNodeType> commonPropertiesMap, boolean commissionFlag) {
+ public void sendComissioningBroadcast(String name, String version) {
+ sendCommissioning(name, version, null, null);
+ }
+
+ /**
+ * Send ParticipantUpdate to Participant
+ * if participantType and participantId are null then message is broadcast.
+ *
+ * @param name the ToscaServiceTemplate name
+ * @param version the ToscaServiceTemplate version
+ * @param participantType the ParticipantType
+ * @param participantId the ParticipantId
+ */
+ public boolean sendCommissioning(String name, String version, ToscaConceptIdentifier participantType,
+ ToscaConceptIdentifier participantId) {
var message = new ParticipantUpdate();
+ message.setParticipantType(participantType);
+ message.setParticipantId(participantId);
message.setTimestamp(Instant.now());
ToscaServiceTemplate toscaServiceTemplate = null;
+ Map<String, ToscaNodeType> commonPropertiesMap = null;
try {
- var list = modelsProvider.getServiceTemplateList(null, null);
+ var list = serviceTemplateProvider.getServiceTemplateList(name, version);
if (!list.isEmpty()) {
toscaServiceTemplate = list.get(0);
+ commonPropertiesMap =
+ serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, toscaServiceTemplate);
+ } else {
+ LOGGER.warn("No tosca service template found, cannot send participantupdate {} {}", name, version);
+ return false;
}
} catch (PfModelException pfme) {
LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
- return;
+ return false;
}
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- if (toscaServiceTemplate != null) {
- for (var toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
- toscaServiceTemplate)) {
- var clParticipantType =
- ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
- prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates, commonPropertiesMap);
- }
+ for (var toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
+ prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
+ toscaInputEntry.getValue(), participantDefinitionUpdates, commonPropertiesMap);
}
}
- if (commissionFlag) {
- // Commission the controlloop but sending participantdefinitions to participants
- message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- } else {
- // DeCommission the controlloop but deleting participantdefinitions on participants
- message.setParticipantDefinitionUpdates(null);
- }
+ // Commission the controlloop but sending participantdefinitions to participants
+ message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
LOGGER.debug("Participant Update sent {}", message);
super.send(message);
+ return true;
}
private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
@@ -136,4 +154,17 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
return participantDefinition;
}
+
+ /**
+ * Send ParticipantUpdate to Participant after that commissioning has been removed.
+ */
+ public void sendDecomisioning() {
+ var message = new ParticipantUpdate();
+ message.setTimestamp(Instant.now());
+ // DeCommission the controlloop but deleting participantdefinitions on participants
+ message.setParticipantDefinitionUpdates(null);
+
+ LOGGER.debug("Participant Update sent {}", message);
+ super.send(message);
+ }
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
index b0ea00913..3fd74f22e 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
@@ -90,8 +91,8 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider =
- new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
+ clProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
@@ -128,8 +129,8 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider =
- new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
+ clProvider, null, participantProvider);
// Test Service template is null
assertThatThrownBy(() -> provider.createControlLoopDefinitions(null)).hasMessageMatching(TEMPLATE_IS_NULL);
List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
@@ -158,8 +159,8 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider =
- new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
+ clProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate =
InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML);
@@ -187,8 +188,8 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider =
- new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
+ clProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate =
InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML);
@@ -216,8 +217,8 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider =
- new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
+ clProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate =
InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML);
@@ -262,8 +263,8 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider =
- new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
+ clProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
@@ -291,8 +292,8 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider =
- new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
+ clProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
provider.getControlLoopDefinitions(null, null);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
index abf0cfc3e..82f7e66d5 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
@@ -40,6 +40,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantStatisticsProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
@@ -122,7 +123,8 @@ class ControlLoopInstantiationProviderTest {
new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
var clElementStatisticsProvider =
new ClElementStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
- commissioningProvider = new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ commissioningProvider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider), clProvider, null,
+ participantProvider);
var monitoringProvider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
index 25ce61122..0ad8aad43 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
@@ -23,7 +23,6 @@ package org.onap.policy.clamp.controlloop.runtime.supervision;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
-import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -230,9 +229,10 @@ class SupervisionHandlerTest {
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
participantUpdatePublisher);
- handler.handleSendCommissionMessage(Map.of());
+ handler.handleSendCommissionMessage(participantId.getName(), participantId.getVersion());
- verify(participantUpdatePublisher).send(anyMap(), eq(true));
+ verify(participantUpdatePublisher).sendComissioningBroadcast(eq(participantId.getName()),
+ eq(participantId.getVersion()));
}
@Test
@@ -244,7 +244,7 @@ class SupervisionHandlerTest {
participantUpdatePublisher);
handler.handleSendDeCommissionMessage();
- verify(participantUpdatePublisher).send(anyMap(), eq(false));
+ verify(participantUpdatePublisher).sendDecomisioning();
}
private SupervisionHandler createSupervisionHandler(ControlLoopProvider controlLoopProvider,