aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-controlloop/src')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java34
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java11
-rw-r--r--runtime-controlloop/src/main/resources/application.yaml2
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java32
4 files changed, 58 insertions, 21 deletions
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 d13d66c5d..0c49ce14f 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
@@ -29,6 +29,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils;
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.runtime.main.parameters.ClRuntimeParameterGroup;
@@ -37,7 +38,10 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpd
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusReqPublisher;
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.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -55,6 +59,7 @@ public class SupervisionScanner {
new HandleCounter<>();
private final ControlLoopProvider controlLoopProvider;
+ private final PolicyModelsProvider modelsProvider;
private final ControlLoopStateChangePublisher controlLoopStateChangePublisher;
private final ControlLoopUpdatePublisher controlLoopUpdatePublisher;
private final ParticipantProvider participantProvider;
@@ -65,6 +70,7 @@ public class SupervisionScanner {
* Constructor for instantiating SupervisionScanner.
*
* @param controlLoopProvider the provider to use to read control loops from the database
+ * @param modelsProvider the Policy Models Provider
* @param controlLoopStateChangePublisher the ControlLoop StateChange Publisher
* @param controlLoopUpdatePublisher the ControlLoopUpdate Publisher
* @param participantProvider the Participant Provider
@@ -72,13 +78,14 @@ public class SupervisionScanner {
* @param participantUpdatePublisher the Participant Update Publisher
* @param clRuntimeParameterGroup the parameters for the control loop runtime
*/
- public SupervisionScanner(final ControlLoopProvider controlLoopProvider,
+ public SupervisionScanner(final ControlLoopProvider controlLoopProvider, PolicyModelsProvider modelsProvider,
final ControlLoopStateChangePublisher controlLoopStateChangePublisher,
ControlLoopUpdatePublisher controlLoopUpdatePublisher, ParticipantProvider participantProvider,
ParticipantStatusReqPublisher participantStatusReqPublisher,
ParticipantUpdatePublisher participantUpdatePublisher,
final ClRuntimeParameterGroup clRuntimeParameterGroup) {
this.controlLoopProvider = controlLoopProvider;
+ this.modelsProvider = modelsProvider;
this.controlLoopStateChangePublisher = controlLoopStateChangePublisher;
this.controlLoopUpdatePublisher = controlLoopUpdatePublisher;
this.participantProvider = participantProvider;
@@ -119,8 +126,13 @@ public class SupervisionScanner {
}
try {
- for (ControlLoop controlLoop : controlLoopProvider.getControlLoops(null, null)) {
- scanControlLoop(controlLoop, counterCheck);
+ var list = modelsProvider.getServiceTemplateList(null, null);
+ if (list != null && !list.isEmpty()) {
+ ToscaServiceTemplate toscaServiceTemplate = list.get(0);
+
+ for (ControlLoop controlLoop : controlLoopProvider.getControlLoops(null, null)) {
+ scanControlLoop(controlLoop, toscaServiceTemplate, counterCheck);
+ }
}
} catch (PfModelException pfme) {
LOGGER.warn("error reading control loops from database", pfme);
@@ -190,7 +202,8 @@ public class SupervisionScanner {
participantUpdateCounter.remove(id);
}
- private void scanControlLoop(final ControlLoop controlLoop, boolean counterCheck) throws PfModelException {
+ private void scanControlLoop(final ControlLoop controlLoop, ToscaServiceTemplate toscaServiceTemplate,
+ boolean counterCheck) throws PfModelException {
LOGGER.debug("scanning control loop {} . . .", controlLoop.getKey().asIdentifier());
if (controlLoop.getState().equals(controlLoop.getOrderedState().asState())) {
@@ -202,11 +215,16 @@ public class SupervisionScanner {
}
var completed = true;
+ var minSpNotCompleted = 1000; // min startPhase not completed
for (ControlLoopElement element : controlLoop.getElements().values()) {
if (!element.getState().equals(element.getOrderedState().asState())) {
completed = false;
- break;
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
+ minSpNotCompleted = Math.min(minSpNotCompleted, startPhase);
}
+
}
if (completed) {
@@ -222,7 +240,7 @@ public class SupervisionScanner {
LOGGER.debug("control loop scan: transition from state {} to {} not completed", controlLoop.getState(),
controlLoop.getOrderedState());
if (counterCheck) {
- handleCounter(controlLoop);
+ handleCounter(controlLoop, minSpNotCompleted);
}
}
}
@@ -231,7 +249,7 @@ public class SupervisionScanner {
controlLoopCounter.clear(controlLoop.getKey().asIdentifier());
}
- private void handleCounter(ControlLoop controlLoop) {
+ private void handleCounter(ControlLoop controlLoop, int startPhase) {
ToscaConceptIdentifier id = controlLoop.getKey().asIdentifier();
if (controlLoopCounter.isFault(id)) {
LOGGER.debug("report ControlLoop fault");
@@ -242,7 +260,7 @@ public class SupervisionScanner {
if (controlLoopCounter.count(id)) {
if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
LOGGER.debug("retry message ControlLoopUpdate");
- controlLoopUpdatePublisher.send(controlLoop);
+ controlLoopUpdatePublisher.send(controlLoop, startPhase);
} else {
LOGGER.debug("retry message ControlLoopStateChange");
controlLoopStateChangePublisher.send(controlLoop);
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
index d68a643d2..74d987240 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
@@ -58,7 +58,18 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con
* @param controlLoop the ControlLoop
*/
public void send(ControlLoop controlLoop) {
+ send(controlLoop, 0);
+ }
+
+ /**
+ * Send ControlLoopUpdate to Participant.
+ *
+ * @param controlLoop the ControlLoop
+ * @param startPhase the Start Phase
+ */
+ public void send(ControlLoop controlLoop, int startPhase) {
var controlLoopUpdateMsg = new ControlLoopUpdate();
+ controlLoopUpdateMsg.setStartPhase(startPhase);
controlLoopUpdateMsg.setControlLoopId(controlLoop.getKey().asIdentifier());
controlLoopUpdateMsg.setMessageId(UUID.randomUUID());
controlLoopUpdateMsg.setTimestamp(Instant.now());
diff --git a/runtime-controlloop/src/main/resources/application.yaml b/runtime-controlloop/src/main/resources/application.yaml
index 96c340491..50c063fb3 100644
--- a/runtime-controlloop/src/main/resources/application.yaml
+++ b/runtime-controlloop/src/main/resources/application.yaml
@@ -26,7 +26,7 @@ runtime:
heartBeatMs: 20000
maxStatusWaitMs: 100000
updateParameters:
- maxRetryCount: 3
+ maxRetryCount: 4
maxWaitMs: 20000
databaseProviderParameters:
name: PolicyProviderParameterGroup
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
index 2ba321d36..bc1a3b70a 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
@@ -46,13 +46,16 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantSta
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
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.ToscaServiceTemplate;
class SupervisionScannerTest {
@Test
void testScannerOrderedStateEqualsToState() throws PfModelException {
var controlLoopProvider = mock(ControlLoopProvider.class);
+ var modelsProvider = mock(PolicyModelsProvider.class);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var participantProvider = mock(ParticipantProvider.class);
@@ -63,9 +66,9 @@ class SupervisionScannerTest {
var controlLoop = new ControlLoop();
when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
- var supervisionScanner = new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher,
- controlLoopUpdatePublisher, participantProvider, participantStatusReqPublisher,
- participantUpdatePublisher, clRuntimeParameterGroup);
+ var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider,
+ controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider,
+ participantStatusReqPublisher, participantUpdatePublisher, clRuntimeParameterGroup);
supervisionScanner.run(false);
verify(controlLoopProvider, times(0)).updateControlLoop(any(ControlLoop.class));
@@ -87,9 +90,12 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher,
- controlLoopUpdatePublisher, participantProvider, participantStatusReqPublisher,
- participantUpdatePublisher, clRuntimeParameterGroup);
+ var modelsProvider = mock(PolicyModelsProvider.class);
+ when(modelsProvider.getServiceTemplateList(null, null)).thenReturn(List.of(new ToscaServiceTemplate()));
+
+ var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider,
+ controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider,
+ participantStatusReqPublisher, participantUpdatePublisher, clRuntimeParameterGroup);
supervisionScanner.run(false);
verify(controlLoopProvider, times(1)).updateControlLoop(any(ControlLoop.class));
@@ -107,15 +113,16 @@ class SupervisionScannerTest {
participant.setVersion("1.0.0");
when(participantProvider.getParticipants(null, null)).thenReturn(List.of(participant));
+ var modelsProvider = mock(PolicyModelsProvider.class);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher,
- controlLoopUpdatePublisher, participantProvider, participantStatusReqPublisher,
- participantUpdatePublisher, clRuntimeParameterGroup);
+ var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider,
+ controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider,
+ participantStatusReqPublisher, participantUpdatePublisher, clRuntimeParameterGroup);
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);
@@ -142,14 +149,15 @@ class SupervisionScannerTest {
var participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider.updateParticipants(List.of(participant));
+ var modelsProvider = mock(PolicyModelsProvider.class);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
- var supervisionScanner = new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher,
- controlLoopUpdatePublisher, participantProvider, participantStatusReqPublisher,
- participantUpdatePublisher, clRuntimeParameterGroup);
+ var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider,
+ controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider,
+ participantStatusReqPublisher, participantUpdatePublisher, clRuntimeParameterGroup);
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);