import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
// A map indexed by the property name. Each map entry is the serialized value of the property,
// which can be deserialized into an instance of the type of the property.
- private Map<String, String> commonPropertiesMap = new LinkedHashMap<>();
+ private Map<String, ToscaProperty> propertiesMap = new LinkedHashMap<>();
/**
* Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
this.description = otherElement.description;
this.clElementStatistics = otherElement.clElementStatistics;
- this.commonPropertiesMap = PfUtils.mapMap(otherElement.commonPropertiesMap, UnaryOperator.identity());
+ this.propertiesMap = PfUtils.mapMap(otherElement.propertiesMap, UnaryOperator.identity());
}
}
import org.onap.policy.models.base.PfUtils;
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;
/**
* Class to represent a control loop element definition instance.
// A map indexed by the property name. Each map entry is the serialized value of the property,
// which can be deserialized into an instance of the type of the property.
- private Map<String, String> commonPropertiesMap = new LinkedHashMap<>();
+ private Map<String, ToscaProperty> commonPropertiesMap = new LinkedHashMap<>();
/**
* Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
@NonNull
private ParticipantHealthStatus healthStatus = ParticipantHealthStatus.UNKNOWN;
+ @NonNull
+ private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier();
+
@Override
public String getType() {
return definition.getName();
this.definition = new ToscaConceptIdentifier(otherParticipant.definition);
this.participantState = otherParticipant.participantState;
this.healthStatus = otherParticipant.healthStatus;
+ this.participantType = otherParticipant.participantType;
}
}
private PfConceptKey definition;
// @formatter:on
+ @NotNull
+ @AttributeOverride(name = "name", column = @Column(name = "participant_type_name"))
+ @AttributeOverride(name = "version", column = @Column(name = "participant_type_version"))
+ private PfConceptKey participantType;
+
@Column
@NotNull
private ParticipantState participantState;
this.participantState = copyConcept.participantState;
this.healthStatus = copyConcept.healthStatus;
this.description = copyConcept.description;
+ this.participantType = copyConcept.participantType;
}
/**
participant.setParticipantState(participantState);
participant.setHealthStatus(healthStatus);
participant.setDescription(description);
+ participant.setParticipantType(new ToscaConceptIdentifier(participantType));
return participant;
}
this.setParticipantState(participant.getParticipantState());
this.setHealthStatus(participant.getHealthStatus());
this.setDescription(participant.getDescription());
+ this.participantType = participant.getParticipantType().asConceptKey();
}
@Override
List<PfKey> keyList = getKey().getKeys();
keyList.add(definition);
+ keyList.add(participantType);
return keyList;
}
key.clean();
definition.clean();
description = (description == null ? null : description.trim());
+ participantType.clean();
}
@Override
return result;
}
+ result = ObjectUtils.compare(participantType, other.participantType);
+ if (result != 0) {
+ return result;
+ }
+
return ObjectUtils.compare(description, other.description);
}
}
testParticipant.setName("participant");
testParticipant.setVersion("0.0.1");
testParticipant.setDefinition(new ToscaConceptIdentifier("participantDefinitionName", "0.0.1"));
+ testParticipant.setParticipantType(new ToscaConceptIdentifier("participantTypeName", "0.0.1"));
return testParticipant;
}
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
/**
* Test the copy constructor.
clElement.setParticipantId(id);
clElement.setParticipantType(id);
- Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
- clElement.setCommonPropertiesMap(commonPropertiesMap);
+ ToscaProperty property = new ToscaProperty();
+ property.setName("test");
+ property.setType("testType");
+ Map<String, ToscaProperty> propertiesMap = Map.of("Prop1", property);
+ clElement.setPropertiesMap(propertiesMap);
ParticipantUpdates participantUpdates = new ParticipantUpdates();
participantUpdates.setParticipantId(id);
import org.onap.policy.common.utils.coder.CoderException;
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;
class ParticipantStatusTest {
ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
clDefinition.setClElementDefinitionId(id);
clDefinition.setControlLoopElementToscaNodeTemplate(toscaNodeTemplate);
- Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
+
+ ToscaProperty property = new ToscaProperty();
+ property.setName("test");
+ property.setType("testType");
+ Map<String, ToscaProperty> commonPropertiesMap = Map.of("Prop1", property);
clDefinition.setCommonPropertiesMap(commonPropertiesMap);
return clDefinition;
}
import org.onap.policy.common.utils.coder.CoderException;
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.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
clDefinition.setClElementDefinitionId(id);
clDefinition.setControlLoopElementToscaNodeTemplate(toscaNodeTemplate);
- Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
+
+ ToscaProperty property = new ToscaProperty();
+ property.setName("test");
+ property.setType("testType");
+ Map<String, ToscaProperty> commonPropertiesMap = Map.of("Prop1", property);
clDefinition.setCommonPropertiesMap(commonPropertiesMap);
return clDefinition;
}
},
"participantState": "PASSIVE",
"healthStatus": "HEALTHY",
- "description": "A dummy PMSH participant1"
+ "description": "A dummy PMSH participant1",
+ "participantType":{
+ "name": "org.onap.domain.pmsh.PolicyControlLoopDefinition",
+ "version": "1.0.0"
+ }
}
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.
*/
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.
*
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;
/**
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);
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;
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;
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();
}
}
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;
+ }
}
import java.time.Instant;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
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;
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.
*
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;
}
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.models.messages.rest.commissioning.CommissioningResponse;
import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
synchronized (lockit) {
modelsProvider.createServiceTemplate(serviceTemplate);
List<Participant> participantList =
- participantProvider.getParticipants(null,
- null);
-
- if (participantList != null) {
- for (Participant participant: participantList) {
- var participantType = new ToscaConceptIdentifier();
- participantType.setName(participant.getType());
- participantType.setVersion(participant.getTypeVersion());
-
- var participantUpdate = new ParticipantUpdate();
- participantUpdate.setParticipantId(participant.getDefinition());
- participantUpdate.setParticipantType(participantType);
-
- this.supervisionHandler.handleSendCommissionMessage(participantUpdate);
- }
+ participantProvider.getParticipants(null, null);
+ if (!participantList.isEmpty()) {
+ this.supervisionHandler.handleSendCommissionMessage(
+ getCommonOrInstancePropertiesFromNodeTypes(true,
+ serviceTemplate.getName(),
+ serviceTemplate.getVersion()));
}
-
}
var response = new CommissioningResponse();
List<Participant> participantList =
participantProvider.getParticipants(null,
null);
-
- if (participantList != null) {
- for (Participant participant : participantList) {
- var participantType = new ToscaConceptIdentifier();
- participantType.setName(participant.getType());
- participantType.setVersion(participant.getTypeVersion());
-
- var participantUpdate = new ParticipantUpdate();
- participantUpdate.setParticipantId(participant.getDefinition());
- participantUpdate.setParticipantType(participantType);
-
- this.supervisionHandler.handleSendDeCommissionMessage(participantUpdate);
- }
+ if (!participantList.isEmpty()) {
+ this.supervisionHandler.handleSendDeCommissionMessage();
}
-
modelsProvider.deleteServiceTemplate(name, version);
}
* @return the node types with common or instance properties
* @throws PfModelException on errors getting node type properties
*/
- private Map<String, ToscaNodeType> getCommonOrInstancePropertiesFromNodeTypes(boolean common, String name,
+ public Map<String, ToscaNodeType> getCommonOrInstancePropertiesFromNodeTypes(boolean common, String name,
String version) throws PfModelException {
var serviceTemplates = new ToscaServiceTemplates();
serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
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;
participantRegisterAckPublisher.send(participantRegisterMessage.getMessageId(),
participantRegisterMessage.getParticipantId(), participantRegisterMessage.getParticipantType());
- participantUpdatePublisher.send(participantRegisterMessage.getParticipantId(),
- participantRegisterMessage.getParticipantType(), true);
+ participantUpdatePublisher.send(null, true);
}
/**
/**
* Send commissioning update message to dmaap.
*
- * @param participantUpdateMessage the ParticipantUpdate message to send
*/
- public void handleSendCommissionMessage(ParticipantUpdate participantUpdateMessage) {
- LOGGER.debug("Participant update message being sent {}", participantUpdateMessage);
-
- participantUpdatePublisher.send(participantUpdateMessage.getParticipantId(),
- participantUpdateMessage.getParticipantType(), true);
+ public void handleSendCommissionMessage(Map<String, ToscaNodeType> commonPropertiesMap) {
+ LOGGER.debug("Participant update message being sent {}");
+ participantUpdatePublisher.send(commonPropertiesMap, true);
}
/**
* Send decommissioning update message to dmaap.
*
- * @param participantUpdateMessage the ParticipantUpdate message to send
*/
- public void handleSendDeCommissionMessage(ParticipantUpdate participantUpdateMessage) {
- LOGGER.debug("Participant update message being sent {}", participantUpdateMessage);
-
- participantUpdatePublisher.send(participantUpdateMessage.getParticipantId(),
- participantUpdateMessage.getParticipantType(), false);
+ public void handleSendDeCommissionMessage() {
+ LOGGER.debug("Participant update message being sent");
+ participantUpdatePublisher.send(null, false);
}
/**
participant.setName(participantStatusMessage.getParticipantId().getName());
participant.setVersion(participantStatusMessage.getParticipantId().getVersion());
participant.setDefinition(participantStatusMessage.getParticipantId());
+ participant.setParticipantType(participantStatusMessage.getParticipantType());
participant.setParticipantState(participantStatusMessage.getState());
participant.setHealthStatus(participantStatusMessage.getHealthStatus());
if (participantUpdateCounter.count(id)) {
LOGGER.debug("retry message ParticipantUpdate");
- participantUpdatePublisher.send(id.getLeft(), id.getRight(), true);
+ participantUpdatePublisher.send(null, true);
} else {
LOGGER.debug("report Participant Update fault");
participantUpdateCounter.setFault(id);
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
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.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;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Send ParticipantUpdate to Participant.
*
- * @param participantId the participant Id
- * @param participantType the participant Type
*/
- public void send(ToscaConceptIdentifier participantId, ToscaConceptIdentifier participantType,
- boolean commissionFlag) {
+ public void send(Map<String, ToscaNodeType> commonPropertiesMap, boolean commissionFlag) {
var message = new ParticipantUpdate();
- message.setParticipantId(participantId);
- message.setParticipantType(participantType);
message.setTimestamp(Instant.now());
ToscaServiceTemplate toscaServiceTemplate = null;
var clParticipantType =
ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ toscaInputEntry.getValue(), participantDefinitionUpdates, commonPropertiesMap);
}
}
}
}
private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates,
+ Map<String, ToscaNodeType> commonPropertiesMap) {
var clDefinition = new ControlLoopElementDefinition();
clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
+ ToscaNodeType nodeType = commonPropertiesMap.get(entryValue.getType());
+ if (nodeType != null) {
+ clDefinition.setCommonPropertiesMap(nodeType.getProperties());
+ }
+
List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
if (participantDefinitionUpdates.isEmpty()) {
participant.setHealthStatus(ParticipantHealthStatus.HEALTHY);
participant.setParticipantState(ParticipantState.ACTIVE);
participant.setDefinition(new ToscaConceptIdentifier("unknown", "0.0.0"));
+ participant.setParticipantType(new ToscaConceptIdentifier("ParticipantType1", "1.0.0"));
var participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider.updateParticipants(List.of(participant));