From 6b3c8bd96a66160714f768b185290ed765e23ec7 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Fri, 3 Sep 2021 17:22:30 +0100 Subject: Verify participant Simulator and messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing ControlLoopElementHandler in participant Simulator and fix some message issues. Issue-ID: POLICY-3628 Change-Id: I9f058c19aa18e070bac6ccaf98fdf7600d66d71e Signed-off-by: FrancescoFioraEst --- .../main/parameters/ParticipantParameters.java | 13 +--- .../parameters/ParticipantUpdateParameters.java | 4 +- .../runtime/supervision/SupervisionScanner.java | 35 +++++----- .../comm/ParticipantUpdatePublisher.java | 51 +++++---------- .../src/main/resources/application.yaml | 6 +- .../supervision/SupervisionScannerTest.java | 4 +- .../supervision/comm/SupervisionMessagesTest.java | 74 +++++++--------------- .../src/test/resources/application_test.properties | 9 ++- .../test/resources/parameters/TestParameters.json | 5 +- 9 files changed, 70 insertions(+), 131 deletions(-) (limited to 'runtime-controlloop') 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 { 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 participantDefinitionUpdates = new ArrayList<>(); - for (Map.Entry 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 participants = participantProvider.getParticipants(null, null); assertThat(participants.get(0).getHealthStatus()).isEqualTo(ParticipantHealthStatus.NOT_HEALTHY); - supervisionScanner.run(true); supervisionScanner.run(true); participants = participantProvider.getParticipants(null, null); assertThat(participants.get(0).getHealthStatus()).isEqualTo(ParticipantHealthStatus.OFF_LINE); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java index 14de34d1c..bcc3a701c 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java @@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; 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.ClElementStatisticsProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; @@ -53,9 +54,6 @@ import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData; import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; -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.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; @@ -77,8 +75,6 @@ class SupervisionMessagesTest extends CommonRestController { private static PolicyModelsProvider modelsProvider; private static ParticipantProvider participantProvider; private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement"; - private static final Coder CODER = new StandardCoder(); /** * setup Db Provider Parameters. @@ -133,7 +129,7 @@ class SupervisionMessagesTest extends CommonRestController { // List listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null); commissioningProvider.createControlLoopDefinitions(serviceTemplate); assertThatCode(() -> participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } } @@ -160,9 +156,10 @@ class SupervisionMessagesTest extends CommonRestController { synchronized (lockit) { ParticipantDeregisterListener participantDeregisterListener = - new ParticipantDeregisterListener(supervisionHandler); - assertThatCode(() -> participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, - participantDeregisterMsg)).doesNotThrowAnyException(); + new ParticipantDeregisterListener(supervisionHandler); + assertThatCode( + () -> participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, participantDeregisterMsg)) + .doesNotThrowAnyException(); } } @@ -191,59 +188,36 @@ class SupervisionMessagesTest extends CommonRestController { ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(null, null); List participantDefinitionUpdates = new ArrayList<>(); - for (Map.Entry 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); - } + for (Map.Entry 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); + toscaInputEntry.getValue(), participantDefinitionUpdates); } } participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates); synchronized (lockit) { - ParticipantUpdatePublisher participantUpdatePublisher = - new ParticipantUpdatePublisher(modelsProvider); + ParticipantUpdatePublisher participantUpdatePublisher = new ParticipantUpdatePublisher(modelsProvider); participantUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); assertThatCode(() -> participantUpdatePublisher.send(participantUpdateMsg)).doesNotThrowAnyException(); } } - 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; - } - private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey, - ToscaNodeTemplate entryValue, List participantDefinitionUpdates) { + ToscaNodeTemplate entryValue, List participantDefinitionUpdates) { var clDefinition = new ControlLoopElementDefinition(); - clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier( - entryKey, entryValue.getVersion())); + clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion())); clDefinition.setControlLoopElementToscaNodeTemplate(entryValue); List controlLoopElementDefinitionList = new ArrayList<>(); if (participantDefinitionUpdates.isEmpty()) { - participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType, - controlLoopElementDefinitionList)); + participantDefinitionUpdates + .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); } else { boolean participantExists = false; for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) { @@ -253,15 +227,15 @@ class SupervisionMessagesTest extends CommonRestController { } } if (!participantExists) { - participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType, - controlLoopElementDefinitionList)); + participantDefinitionUpdates.add( + getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); } } } private ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition, - ToscaConceptIdentifier clParticipantType, - List controlLoopElementDefinitionList) { + ToscaConceptIdentifier clParticipantType, + List controlLoopElementDefinitionList) { ParticipantDefinition participantDefinition = new ParticipantDefinition(); participantDefinition.setParticipantType(clParticipantType); controlLoopElementDefinitionList.add(clDefinition); @@ -280,9 +254,9 @@ class SupervisionMessagesTest extends CommonRestController { synchronized (lockit) { ParticipantUpdateAckListener participantUpdateAckListener = - new ParticipantUpdateAckListener(supervisionHandler); + new ParticipantUpdateAckListener(supervisionHandler); assertThatCode(() -> participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } } diff --git a/runtime-controlloop/src/test/resources/application_test.properties b/runtime-controlloop/src/test/resources/application_test.properties index 0074d9f95..61557879d 100644 --- a/runtime-controlloop/src/test/resources/application_test.properties +++ b/runtime-controlloop/src/test/resources/application_test.properties @@ -9,11 +9,10 @@ server.error.path=/error runtime.supervisionScannerIntervalSec=1000 runtime.participantClUpdateIntervalSec=1000 runtime.participantClStateChangeIntervalSec=1000 -runtime.participantParameters.heartBeatMs=120000 -runtime.participantParameters.updateParameters.maxRetryCount=1 -runtime.participantParameters.updateParameters.maxWaitMs=30000 -runtime.participantParameters.stateChangeParameters.maxRetryCount=1 -runtime.participantParameters.stateChangeParameters.maxWaitMs=30000 +runtime.participantParameters.heartBeatMs=20000 +runtime.participantParameters.maxStatusWaitMs=100000 +runtime.participantParameters.updateParameters.maxRetryCount=3 +runtime.participantParameters.updateParameters.maxWaitMs=20000 runtime.databaseProviderParameters.name=PolicyProviderParameterGroup runtime.databaseProviderParameters.implementation=org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl runtime.databaseProviderParameters.databaseDriver=org.h2.Driver diff --git a/runtime-controlloop/src/test/resources/parameters/TestParameters.json b/runtime-controlloop/src/test/resources/parameters/TestParameters.json index 99fc43d21..6d16f4853 100644 --- a/runtime-controlloop/src/test/resources/parameters/TestParameters.json +++ b/runtime-controlloop/src/test/resources/parameters/TestParameters.json @@ -5,13 +5,10 @@ "participantClStateChangeIntervalSec": 1000, "participantParameters": { "heartBeatMs": 120000, + "maxStatusWaitMs": 100000, "updateParameters": { "maxRetryCount": 1, "maxWaitMs": 30000 - }, - "stateChangeParameters": { - "maxRetryCount": 1, - "maxWaitMs": 30000 } }, "databaseProviderParameters": { -- cgit 1.2.3-korg