summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-controlloop/src/main/java')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java49
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java253
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java13
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java4
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java7
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java75
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java35
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java51
8 files changed, 376 insertions, 111 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 fbfc1de69..0b7bc9a26 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
@@ -34,7 +34,6 @@ import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
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;
@@ -64,6 +63,7 @@ import org.springframework.stereotype.Component;
@Component
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 ControlLoopProvider clProvider;
@@ -98,10 +98,10 @@ public class CommissioningProvider {
* @throws PfModelException on creation errors
*/
public CommissioningResponse createControlLoopDefinitions(ToscaServiceTemplate serviceTemplate)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
if (verifyIfInstancePropertiesExists()) {
- throw new ControlLoopException(Status.BAD_REQUEST,
+ throw new PfModelException(Status.BAD_REQUEST,
"Delete instances, to commission control loop definitions");
}
@@ -148,10 +148,10 @@ public class CommissioningProvider {
* @throws PfModelException on deletion errors
*/
public CommissioningResponse deleteControlLoopDefinition(String name, String version)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
if (verifyIfInstancePropertiesExists()) {
- throw new ControlLoopException(Status.BAD_REQUEST,
+ throw new PfModelException(Status.BAD_REQUEST,
"Delete instances, to commission control loop definitions");
}
@@ -395,10 +395,17 @@ public class CommissioningProvider {
public Map<String, ToscaNodeTemplate> getNodeTemplatesWithCommonOrInstanceProperties(boolean common, String name,
String version) throws PfModelException {
- var commonOrInstanceNodeTypeProps = this.getCommonOrInstancePropertiesFromNodeTypes(common, name, version);
+ if (common && verifyIfInstancePropertiesExists()) {
+ throw new PfModelException(Status.BAD_REQUEST,
+ "Cannot create or edit common properties, delete all the instantiations first");
+ }
+
+ var commonOrInstanceNodeTypeProps =
+ this.getCommonOrInstancePropertiesFromNodeTypes(common, name, version);
var serviceTemplates = new ToscaServiceTemplates();
- serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
+ serviceTemplates.setServiceTemplates(filterToscaNodeTemplateInstance(
+ modelsProvider.getServiceTemplateList(name, version)));
return this.getDerivedCommonOrInstanceNodeTemplates(
serviceTemplates.getServiceTemplates().get(0).getToscaTopologyTemplate().getNodeTemplates(),
@@ -433,7 +440,8 @@ public class CommissioningProvider {
var serviceTemplates = new ToscaServiceTemplates();
serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
- ToscaServiceTemplate fullTemplate = serviceTemplates.getServiceTemplates().get(0);
+ ToscaServiceTemplate fullTemplate = filterToscaNodeTemplateInstance(
+ serviceTemplates.getServiceTemplates()).get(0);
var template = new HashMap<String, Object>();
template.put("tosca_definitions_version", fullTemplate.getToscaDefinitionsVersion());
@@ -496,6 +504,29 @@ public class CommissioningProvider {
}
}
+ private List<ToscaServiceTemplate> filterToscaNodeTemplateInstance(List<ToscaServiceTemplate> serviceTemplates) {
+
+ List<ToscaServiceTemplate> toscaServiceTemplates = new ArrayList<>();
+
+ serviceTemplates.stream().forEach(serviceTemplate -> {
+
+ Map<String, ToscaNodeTemplate> toscaNodeTemplates = new HashMap<>();
+
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, nodeTemplate) -> {
+ if (!nodeTemplate.getName().contains(INSTANCE_TEXT)) {
+ toscaNodeTemplates.put(key, nodeTemplate);
+ }
+ });
+
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().clear();
+ serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(toscaNodeTemplates);
+
+ toscaServiceTemplates.add(serviceTemplate);
+ });
+
+ return toscaServiceTemplates;
+ }
+
/**
* Validates to see if there is any instance properties saved.
*
@@ -503,7 +534,7 @@ public class CommissioningProvider {
*/
private boolean verifyIfInstancePropertiesExists() {
return clProvider.getNodeTemplates(null, null).stream()
- .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains("_Instance"));
+ .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains(INSTANCE_TEXT));
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
index a71772624..dc40cc274 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
@@ -21,18 +21,27 @@
package org.onap.policy.clamp.controlloop.runtime.instantiation;
+import com.google.gson.Gson;
+import com.google.gson.internal.LinkedTreeMap;
+import com.google.gson.reflect.TypeToken;
+import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
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.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
@@ -49,6 +58,7 @@ import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNameVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.stereotype.Component;
@@ -59,48 +69,102 @@ import org.springframework.stereotype.Component;
@Component
@AllArgsConstructor
public class ControlLoopInstantiationProvider {
+ private static final String CONTROL_LOOP_NODE_TYPE = "org.onap.policy.clamp.controlloop.ControlLoop";
+ private static final String CONTROL_LOOP_NODE_ELEMENT_TYPE = "ControlLoopElement";
+ private static final String PARTICIPANT_ID_PROPERTY_KEY = "participant_id";
+ private static final String CL_ELEMENT_NAME = "name";
+ private static final String CL_ELEMENT_VERSION = "version";
private static final String INSTANCE_TEXT = "_Instance";
+ private static final Gson GSON = new Gson();
+
private final ControlLoopProvider controlLoopProvider;
private final CommissioningProvider commissioningProvider;
private final SupervisionHandler supervisionHandler;
private static final Object lockit = new Object();
- private static final String CL_ELEMENT_NAME = "name";
-
/**
- * Create Instance Properties.
+ * Creates Instance Properties and Control Loop.
*
* @param serviceTemplate the service template
* @return the result of the instantiation operation
* @throws PfModelException on creation errors
*/
- public InstancePropertiesResponse saveInstanceProperties(ToscaServiceTemplate serviceTemplate) {
+ public InstancePropertiesResponse createInstanceProperties(ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
String instanceName = generateSequentialInstanceName();
+ ControlLoop controlLoop = new ControlLoop();
+ Map<UUID, ControlLoopElement> controlLoopElements = new HashMap<>();
+
+ ToscaServiceTemplate toscaServiceTemplate = commissioningProvider
+ .getToscaServiceTemplate(null, null);
- Map<String, ToscaNodeTemplate> nodeTemplates = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ Map<String, ToscaNodeTemplate> persistedNodeTemplateMap = toscaServiceTemplate
+ .getToscaTopologyTemplate().getNodeTemplates();
+
+ Map<String, ToscaNodeTemplate> nodeTemplates =
+ deepCloneNodeTemplate(serviceTemplate);
nodeTemplates.forEach((key, template) -> {
+ ToscaNodeTemplate newNodeTemplate = new ToscaNodeTemplate();
String name = key + instanceName;
+ String version = template.getVersion();
String description = template.getDescription() + instanceName;
- template.setName(name);
- template.setDescription(description);
+ newNodeTemplate.setName(name);
+ newNodeTemplate.setVersion(version);
+ newNodeTemplate.setDescription(description);
+ newNodeTemplate.setProperties(new HashMap<>(template.getProperties()));
+ newNodeTemplate.setType(template.getType());
+ newNodeTemplate.setTypeVersion(template.getTypeVersion());
+ newNodeTemplate.setMetadata(template.getMetadata());
- changeInstanceElementsName(template, instanceName);
+ crateNewControlLoopInstance(instanceName, controlLoop, controlLoopElements, template, newNodeTemplate);
+ persistedNodeTemplateMap.put(name, newNodeTemplate);
});
- Map<String, ToscaNodeTemplate> toscaSavedNodeTemplate = controlLoopProvider
- .saveInstanceProperties(serviceTemplate);
+ ControlLoops controlLoops = new ControlLoops();
- var response = new InstancePropertiesResponse();
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(persistedNodeTemplateMap);
+
+ controlLoop.setElements(controlLoopElements);
+ controlLoops.getControlLoopList().add(controlLoop);
+
+ return saveInstancePropertiesAndControlLoop(serviceTemplate, controlLoops);
+ }
+
+ /**
+ * Deletes Instance Properties.
+ *
+ * @param name the name of the control loop to delete
+ * @param version the version of the control loop to delete
+ * @return the result of the deletion
+ * @throws PfModelException on deletion errors
+ */
+ public InstantiationResponse deleteInstanceProperties(String name, String version) throws PfModelException {
+
+ String instanceName = getInstancePropertyName(name, version);
+
+ Map<String, ToscaNodeTemplate> filteredToscaNodeTemplateMap = new HashMap<>();
- // @formatter:off
- response.setAffectedInstanceProperties(toscaSavedNodeTemplate.values().stream().map(template ->
- template.getKey().asIdentifier()).collect(Collectors.toList()));
- // @formatter:on
+ ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(name, version);
+
+ toscaServiceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates().forEach((key, nodeTemplate) -> {
+ if (!nodeTemplate.getName().contains(instanceName)) {
+ filteredToscaNodeTemplateMap.put(key, nodeTemplate);
+ }
+ });
+
+ List<ToscaNodeTemplate> filteredToscaNodeTemplateList =
+ toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().values().stream()
+ .filter(nodeTemplate -> nodeTemplate.getName().contains(instanceName)).collect(Collectors.toList());
+
+ InstantiationResponse response = this.deleteControlLoop(name, version);
+
+ controlLoopProvider.deleteInstanceProperties(filteredToscaNodeTemplateMap, filteredToscaNodeTemplateList);
return response;
}
@@ -116,7 +180,8 @@ public class ControlLoopInstantiationProvider {
synchronized (lockit) {
for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
- var checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier());
+ var checkControlLoop = controlLoopProvider
+ .getControlLoop(controlLoop.getKey().asIdentifier());
if (checkControlLoop != null) {
throw new PfModelException(Response.Status.BAD_REQUEST,
controlLoop.getKey().asIdentifier() + " already defined");
@@ -323,27 +388,102 @@ public class ControlLoopInstantiationProvider {
}
/**
- * Creates instance element name.
+ * Saves Instance Properties and Control Loop.
*
- * @param serviceTemplate the service serviceTemplate
- * @param instanceName to amend to the element name
+ * @param serviceTemplate the service template
+ * @param controlLoops a list of control loops
+ * @return the result of the instance properties and instantiation operation
+ * @throws PfModelException on creation errors
*/
- private void changeInstanceElementsName(ToscaNodeTemplate serviceTemplate, String instanceName) {
+ private InstancePropertiesResponse saveInstancePropertiesAndControlLoop(
+ ToscaServiceTemplate serviceTemplate, ControlLoops controlLoops) throws PfModelException {
- @SuppressWarnings("unchecked")
- List<Map<String, String>> controlLoopElements = (List<Map<String, String>>) serviceTemplate.getProperties()
- .get("elements");
+ var response = new InstancePropertiesResponse();
- if (controlLoopElements != null) {
- controlLoopElements.forEach(clElement -> {
- String name = clElement.get(CL_ELEMENT_NAME) + instanceName;
- clElement.replace(CL_ELEMENT_NAME, name);
- });
+ Map<String, ToscaNodeTemplate> toscaSavedNodeTemplate;
+
+ synchronized (lockit) {
+ for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
+ var checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier());
+ if (checkControlLoop != null) {
+ throw new PfModelException(Response.Status.BAD_REQUEST,
+ controlLoop.getKey().asIdentifier() + " already defined");
+ }
+ }
+
+ toscaSavedNodeTemplate = controlLoopProvider.saveInstanceProperties(serviceTemplate);
+
+ controlLoopProvider.createControlLoops(controlLoops.getControlLoopList());
+
+ }
+
+ List<ToscaConceptIdentifier> affectedControlLoops = controlLoops.getControlLoopList().stream()
+ .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList());
+
+ List<ToscaConceptIdentifier> toscaAffectedProperties = toscaSavedNodeTemplate.values().stream()
+ .map(template -> template.getKey().asIdentifier()).collect(Collectors.toList());
+
+ response.setAffectedInstanceProperties(Stream.of(affectedControlLoops, toscaAffectedProperties)
+ .flatMap(Collection::stream).collect(Collectors.toList()));
+
+ return response;
+ }
+
+ /**
+ * Crates a new Control Loop instance.
+ * @param instanceName Control Loop Instance name
+ * @param controlLoop empty Control Loop
+ * @param controlLoopElements new Control Loop Element map
+ * @param template original Cloned Tosca Node Template
+ * @param newNodeTemplate new Tosca Node Template
+ */
+ private void crateNewControlLoopInstance(String instanceName, ControlLoop controlLoop,
+ Map<UUID, ControlLoopElement> controlLoopElements,
+ ToscaNodeTemplate template,
+ ToscaNodeTemplate newNodeTemplate) {
+ if (template.getType().equals(CONTROL_LOOP_NODE_TYPE)) {
+ controlLoop.setDefinition(getControlLoopDefinition(newNodeTemplate));
+ }
+
+ if (template.getType().contains(CONTROL_LOOP_NODE_ELEMENT_TYPE)) {
+ ControlLoopElement controlLoopElement = getControlLoopElement(instanceName, newNodeTemplate);
+ controlLoopElements.put(controlLoopElement.getId(), controlLoopElement);
}
+
+ controlLoop.setName("PMSH" + instanceName);
+ controlLoop.setVersion(template.getVersion());
+ controlLoop.setDescription("PMSH control loop " + instanceName);
+ controlLoop.setState(ControlLoopState.UNINITIALISED);
+ controlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
}
/**
+ * Get's the instance property name of the control loop.
+ *
+ * @param name the name of the control loop to get, null for all control loops
+ * @param version the version of the control loop to get, null for all control loops
+ * @return the instance name of the control loop instance properties
+ * @throws PfModelException on errors getting control loops
+ */
+ private String getInstancePropertyName(String name, String version) throws PfModelException {
+ List<String> toscaDefinitionsNames =
+ controlLoopProvider.getControlLoops(name, version).stream().map(ControlLoop::getDefinition)
+ .map(ToscaNameVersion::getName).collect(Collectors.toList());
+
+ return toscaDefinitionsNames.stream().reduce("", (s1, s2) -> {
+
+ if (s2.contains(INSTANCE_TEXT)) {
+ String[] instances = s2.split(INSTANCE_TEXT);
+
+ return INSTANCE_TEXT + instances[1];
+ }
+
+ return s1;
+ });
+ }
+
+ /**
* Generates Instance Name in sequential order and return it to append to the Node Template Name.
*
* @return instanceName
@@ -361,4 +501,61 @@ public class ControlLoopInstantiationProvider {
return INSTANCE_TEXT + (instanceNumber + 1);
}
+
+ /**
+ * Retrieves Control Loop Definition.
+ *
+ * @param template tosca node template
+ * @return control loop definition
+ */
+ private ToscaConceptIdentifier getControlLoopDefinition(ToscaNodeTemplate template) {
+ ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
+ definition.setName(template.getName());
+ definition.setVersion(template.getVersion());
+
+ return definition;
+ }
+
+ /**
+ * Retrieves Control Loop Element.
+ *
+ * @param instanceName instance name to be appended to participant name
+ * @param template tosca node template
+ * @return a control loop element
+ */
+ @SuppressWarnings("unchecked")
+ private ControlLoopElement getControlLoopElement(String instanceName, ToscaNodeTemplate template) {
+ ControlLoopElement controlLoopElement = new ControlLoopElement();
+ ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
+ definition.setName(template.getName());
+ definition.setVersion(template.getVersion());
+ controlLoopElement.setDefinition(definition);
+
+ LinkedTreeMap<String, Object> participantId = (LinkedTreeMap<String, Object>) template.getProperties()
+ .get(PARTICIPANT_ID_PROPERTY_KEY);
+
+ ToscaConceptIdentifier participantIdAndType = new ToscaConceptIdentifier();
+ participantIdAndType.setName(participantId.get(CL_ELEMENT_NAME) + instanceName);
+ participantIdAndType.setVersion(String.valueOf(participantId.get(CL_ELEMENT_VERSION)));
+
+ controlLoopElement.setParticipantType(participantIdAndType);
+ controlLoopElement.setParticipantId(participantIdAndType);
+
+ return controlLoopElement;
+ }
+
+ /**
+ * Deep clones ToscaNodeTemplate.
+ *
+ * @param serviceTemplate ToscaServiceTemplate
+ * @return a cloned Hash Map of ToscaNodeTemplate
+ */
+ private Map<String, ToscaNodeTemplate> deepCloneNodeTemplate(ToscaServiceTemplate serviceTemplate) {
+ String jsonString = GSON.toJson(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates());
+
+ Type type = new TypeToken<HashMap<String, ToscaNodeTemplate>>() {}.getType();
+
+ return GSON.fromJson(jsonString, type);
+ }
+
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java
index 47a99ca29..e3e34878f 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java
@@ -18,7 +18,6 @@
package org.onap.policy.clamp.controlloop.runtime.main.parameters;
-import java.util.concurrent.TimeUnit;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@@ -34,17 +33,11 @@ import org.springframework.validation.annotation.Validated;
@Validated
public class ParticipantParameters {
- /**
- * Default maximum message age, in milliseconds, that should be examined. Any message
- * older than this is discarded.
- */
- public static final long DEFAULT_MAX_AGE_MS = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
-
- @Min(1)
+ @Min(100)
private long heartBeatMs;
- @Min(1)
- private long maxMessageAgeMs = DEFAULT_MAX_AGE_MS;
+ @Min(100)
+ private long maxStatusWaitMs;
@Valid
@NotNull
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java
index 8102fe90e..c0b0480de 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java
@@ -34,13 +34,13 @@ public class ParticipantUpdateParameters {
/**
* Maximum number of times to re-send a request to a PDP.
*/
- @Min(value = 0)
+ @Min(value = 1)
private int maxRetryCount;
/**
* Maximum time to wait, in milliseconds, for a PDP response.
*/
- @Min(value = 0)
+ @Min(value = 100)
private long maxWaitMs;
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java
index 2c3a41e26..fcb5aed97 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java
@@ -121,7 +121,7 @@ public class CommissioningController extends AbstractRestController {
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ToscaServiceTemplate body)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
return ResponseEntity.ok().body(provider.createControlLoopDefinitions(body));
}
@@ -188,7 +188,7 @@ public class CommissioningController extends AbstractRestController {
@ApiParam(
value = "Control Loop definition version",
required = true) @RequestParam("version") String version)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
return ResponseEntity.ok().body(provider.deleteControlLoopDefinition(name, version));
}
@@ -385,6 +385,7 @@ public class CommissioningController extends AbstractRestController {
* @param version the version of the tosca service template to get
* @return the specified tosca service template or section Json Schema
* @throws PfModelException on errors getting the Common or Instance Properties
+ * @throws ControlLoopException on error getting the Common or Instance Properties
*/
// @formatter:off
@GetMapping(value = "/commission/getCommonOrInstanceProperties",
@@ -438,7 +439,7 @@ public class CommissioningController extends AbstractRestController {
@ApiParam(value = "Tosca service template version", required = false) @RequestParam(
value = "version",
required = false) String version)
- throws PfModelException {
+ throws PfModelException {
return ResponseEntity.ok().body(provider.getNodeTemplatesWithCommonOrInstanceProperties(common, name, version));
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java
index 5a8275f8a..91958f97a 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java
@@ -187,9 +187,76 @@ public class InstantiationController extends AbstractRestController {
@RequestHeader(
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body) {
+ @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body)
+ throws PfModelException {
+
+ return ResponseEntity.ok().body(provider.createInstanceProperties(body));
+ }
+
+ /**
+ * Deletes a control loop definition and instance properties.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param name the name of the control loop to delete
+ * @param version the version of the control loop to delete
+ * @return a response
+ * @throws PfModelException on errors deleting of control loop and instance properties
+ */
+ // @formatter:off
+ @DeleteMapping(value = "/instanceProperties",
+ produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
+ @ApiOperation(value = "Delete a control loop and instance properties",
+ notes = "Deletes a control loop and instance properties, returning optional error details",
+ response = InstantiationResponse.class,
+ tags = {TAGS},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(
+ name = VERSION_MINOR_NAME,
+ description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(
+ name = VERSION_PATCH_NAME,
+ description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(
+ name = VERSION_LATEST_NAME,
+ description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(
+ name = REQUEST_ID_NAME,
+ description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {
+ @Extension
+ (
+ name = EXTENSION_NAME,
+ properties = {
+ @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
+ }
+ )
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
+ }
+ )
+ // @formatter:on
+
+ public ResponseEntity<InstantiationResponse> deleteInstanceProperties(
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Control Loop definition name", required = true) @RequestParam("name") String name,
+ @ApiParam(value = "Control Loop definition version") @RequestParam(
+ value = "version",
+ required = true) String version) throws PfModelException {
- return ResponseEntity.ok().body(provider.saveInstanceProperties(body));
+ return ResponseEntity.ok().body(provider.deleteInstanceProperties(name, version));
}
/**
@@ -494,10 +561,10 @@ public class InstantiationController extends AbstractRestController {
@RequestHeader(
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
+ @ApiParam(value = "Control Loop name", required = false) @RequestParam(
value = "name",
required = false) String name,
- @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
+ @ApiParam(value = "Control Loop version", required = false) @RequestParam(
value = "version",
required = false) String version)
throws PfModelException {
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 65149a733..d13d66c5d 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
@@ -61,8 +61,6 @@ public class SupervisionScanner {
private final ParticipantStatusReqPublisher participantStatusReqPublisher;
private final ParticipantUpdatePublisher participantUpdatePublisher;
- private final long maxWaitMs;
-
/**
* Constructor for instantiating SupervisionScanner.
*
@@ -89,8 +87,7 @@ public class SupervisionScanner {
controlLoopCounter.setMaxRetryCount(
clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- controlLoopCounter
- .setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs());
+ controlLoopCounter.setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
participantUpdateCounter.setMaxRetryCount(
clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
@@ -99,10 +96,7 @@ public class SupervisionScanner {
participantStatusCounter.setMaxRetryCount(
clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- participantStatusCounter
- .setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs());
-
- maxWaitMs = clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs();
+ participantStatusCounter.setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
/**
@@ -131,6 +125,7 @@ public class SupervisionScanner {
} catch (PfModelException pfme) {
LOGGER.warn("error reading control loops from database", pfme);
}
+
if (counterCheck) {
scanParticipantUpdate();
}
@@ -145,7 +140,7 @@ public class SupervisionScanner {
if (participantUpdateCounter.isFault(id)) {
LOGGER.debug("report Participant Update fault");
- } else if (participantUpdateCounter.getDuration(id) > maxWaitMs) {
+ } else if (participantUpdateCounter.getDuration(id) > participantUpdateCounter.getMaxWaitMs()) {
if (participantUpdateCounter.count(id)) {
LOGGER.debug("retry message ParticipantUpdate");
@@ -166,7 +161,7 @@ public class SupervisionScanner {
LOGGER.debug("report Participant fault");
return;
}
- if (participantStatusCounter.getDuration(id) > maxWaitMs) {
+ if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs()) {
if (participantStatusCounter.count(id)) {
LOGGER.debug("retry message ParticipantStatusReq");
participantStatusReqPublisher.send(id);
@@ -243,17 +238,19 @@ public class SupervisionScanner {
return;
}
- if (controlLoopCounter.count(id)) {
- if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
- LOGGER.debug("retry message ControlLoopUpdate");
- controlLoopUpdatePublisher.send(controlLoop);
+ if (controlLoopCounter.getDuration(id) > controlLoopCounter.getMaxWaitMs()) {
+ if (controlLoopCounter.count(id)) {
+ if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
+ LOGGER.debug("retry message ControlLoopUpdate");
+ controlLoopUpdatePublisher.send(controlLoop);
+ } else {
+ LOGGER.debug("retry message ControlLoopStateChange");
+ controlLoopStateChangePublisher.send(controlLoop);
+ }
} else {
- LOGGER.debug("retry message ControlLoopStateChange");
- controlLoopStateChangePublisher.send(controlLoop);
+ LOGGER.debug("report ControlLoop fault");
+ controlLoopCounter.setFault(id);
}
- } else {
- LOGGER.debug("report ControlLoop fault");
- controlLoopCounter.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 d15a424b9..fe46297f1 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
@@ -25,14 +25,11 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
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.clamp.controlloop.models.controlloop.concepts.ParticipantUtils;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -50,8 +47,7 @@ import org.springframework.stereotype.Component;
public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<ParticipantUpdate> {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
- private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
- private static final Coder CODER = new StandardCoder();
+
private final PolicyModelsProvider modelsProvider;
/**
@@ -67,28 +63,27 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
message.setParticipantType(participantType);
message.setTimestamp(Instant.now());
- ToscaServiceTemplate toscaServiceTemplate;
+ ToscaServiceTemplate toscaServiceTemplate = null;
try {
- toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
+ var list = modelsProvider.getServiceTemplateList(null, null);
+ if (!list.isEmpty()) {
+ toscaServiceTemplate = list.get(0);
+ }
} catch (PfModelException pfme) {
LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
return;
}
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
- .getNodeTemplates().entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType =
- CODER.decode(toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
+ 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);
}
- prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
}
}
@@ -138,20 +133,4 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
return participantDefinition;
}
-
- private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
- ToscaServiceTemplate toscaServiceTemplate) {
- if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
- return true;
- } else {
- var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
- if (nodeType != null) {
- var derivedFrom = nodeType.getDerivedFrom();
- if (derivedFrom != null) {
- return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
- }
- }
- }
- return false;
- }
}