summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/main/java/org/onap
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2021-10-22 13:52:24 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2021-10-22 13:44:03 +0000
commit7ac38590a5c6d80f2aa4d7697ce3735f4a1a8132 (patch)
tree739c19376b36a460be4e44771f1da7499e2ec6a9 /runtime-controlloop/src/main/java/org/onap
parent962a9d16895c9ae75230cad5c7d8a1d4e453f2ad (diff)
Add support startPhase in all state transitions
Issue-ID: POLICY-3785 Change-Id: I1b5821cc42cdbb63e3172596431dc561ced09c55 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-controlloop/src/main/java/org/onap')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java22
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java32
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java4
3 files changed, 45 insertions, 13 deletions
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
index 960cb4304..2a1f9082f 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
@@ -36,6 +37,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
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.ParticipantState;
+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.models.messages.dmaap.participant.ControlLoopAck;
@@ -51,7 +53,10 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDer
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -75,6 +80,7 @@ public class SupervisionHandler {
private final ControlLoopProvider controlLoopProvider;
private final ParticipantProvider participantProvider;
private final MonitoringProvider monitoringProvider;
+ private final PolicyModelsProvider modelsProvider;
// Publishers for participant communication
private final ControlLoopUpdatePublisher controlLoopUpdatePublisher;
@@ -350,7 +356,7 @@ public class SupervisionHandler {
case UNINITIALISED2PASSIVE:
case PASSIVE:
controlLoop.setState(ControlLoopState.PASSIVE2UNINITIALISED);
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, getFirstStartPhase(controlLoop));
break;
case PASSIVE2UNINITIALISED:
@@ -384,7 +390,7 @@ public class SupervisionHandler {
case RUNNING:
controlLoop.setState(ControlLoopState.RUNNING2PASSIVE);
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, getFirstStartPhase(controlLoop));
break;
default:
@@ -408,7 +414,7 @@ public class SupervisionHandler {
case PASSIVE:
controlLoop.setState(ControlLoopState.PASSIVE2RUNNING);
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, getFirstStartPhase(controlLoop));
break;
default:
@@ -418,6 +424,16 @@ public class SupervisionHandler {
}
}
+ private int getFirstStartPhase(ControlLoop controlLoop) {
+ ToscaServiceTemplate toscaServiceTemplate = null;
+ try {
+ toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
+ } catch (PfModelException e) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, "Canont load ToscaServiceTemplate from DB", e);
+ }
+ return ParticipantUtils.getFirstStartPhase(controlLoop, toscaServiceTemplate);
+ }
+
private void checkParticipant(ParticipantMessage participantMessage, ParticipantState participantState,
ParticipantHealthStatus healthStatus) throws ControlLoopException, PfModelException {
if (participantMessage.getParticipantId() == null) {
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 5147aa241..48e06010d 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
@@ -220,13 +220,19 @@ public class SupervisionScanner {
var completed = true;
var minSpNotCompleted = 1000; // min startPhase not completed
+ var maxSpNotCompleted = 0; // max startPhase not completed
+ var defaultMin = 1000; // min startPhase
+ var defaultMax = 0; // max startPhase
for (ControlLoopElement element : controlLoop.getElements().values()) {
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
+ defaultMin = Math.min(defaultMin, startPhase);
+ defaultMax = Math.max(defaultMax, startPhase);
if (!element.getState().equals(element.getOrderedState().asState())) {
completed = false;
- ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
- .get(element.getDefinition().getName());
- int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
minSpNotCompleted = Math.min(minSpNotCompleted, startPhase);
+ maxSpNotCompleted = Math.max(maxSpNotCompleted, startPhase);
}
}
@@ -243,12 +249,20 @@ public class SupervisionScanner {
LOGGER.debug("control loop scan: transition from state {} to {} not completed", controlLoop.getState(),
controlLoop.getOrderedState());
- if (minSpNotCompleted != phaseMap.getOrDefault(controlLoop.getKey().asIdentifier(), 0)
- && ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
- phaseMap.put(controlLoop.getKey().asIdentifier(), minSpNotCompleted);
- sendControlLoopMsg(controlLoop, minSpNotCompleted);
+ var nextSpNotCompleted = ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())
+ || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? minSpNotCompleted
+ : maxSpNotCompleted;
+
+ var firstStartPhase = ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())
+ || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? defaultMin
+ : defaultMax;
+
+ if (nextSpNotCompleted != phaseMap.getOrDefault(controlLoop.getKey().asIdentifier(), firstStartPhase)) {
+ phaseMap.put(controlLoop.getKey().asIdentifier(), nextSpNotCompleted);
+ sendControlLoopMsg(controlLoop, nextSpNotCompleted);
} else if (counterCheck) {
- handleCounter(controlLoop, minSpNotCompleted);
+ phaseMap.put(controlLoop.getKey().asIdentifier(), nextSpNotCompleted);
+ handleCounter(controlLoop, nextSpNotCompleted);
}
}
}
@@ -282,7 +296,7 @@ public class SupervisionScanner {
controlLoopUpdatePublisher.send(controlLoop, startPhase);
} else {
LOGGER.debug("retry message ControlLoopStateChange");
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, startPhase);
}
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
index 79d113c14..69d7b73d0 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
@@ -36,12 +36,14 @@ public class ControlLoopStateChangePublisher
* Send ControlLoopStateChange to Participant.
*
* @param controlLoop the ControlLoop
+ * @param startPhase the startPhase
*/
- public void send(ControlLoop controlLoop) {
+ public void send(ControlLoop controlLoop, int startPhase) {
var clsc = new ControlLoopStateChange();
clsc.setControlLoopId(controlLoop.getKey().asIdentifier());
clsc.setMessageId(UUID.randomUUID());
clsc.setOrderedState(controlLoop.getOrderedState());
+ clsc.setStartPhase(startPhase);
super.send(clsc);
}