summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/main/java/org
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2021-09-10 20:15:37 +0000
committerGerrit Code Review <gerrit@onap.org>2021-09-10 20:15:37 +0000
commit859749a4143c104f6bd63392c8d2cb2839408029 (patch)
tree56a7794cf8f70cdcc6144c8001930c86b8f6d01b /runtime-controlloop/src/main/java/org
parent09d8a86e2126ccc9a12456ddead12a5fe8f58697 (diff)
parent6b3c8bd96a66160714f768b185290ed765e23ec7 (diff)
Merge "Verify participant Simulator and messages"
Diffstat (limited to 'runtime-controlloop/src/main/java/org')
-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/supervision/SupervisionScanner.java35
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java51
4 files changed, 36 insertions, 67 deletions
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/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;
- }
}