From 7ac38590a5c6d80f2aa4d7697ce3735f4a1a8132 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Fri, 22 Oct 2021 13:52:24 +0100 Subject: Add support startPhase in all state transitions Issue-ID: POLICY-3785 Change-Id: I1b5821cc42cdbb63e3172596431dc561ced09c55 Signed-off-by: FrancescoFioraEst --- .../controlloop/concepts/ParticipantUtils.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'models/src/main/java/org') diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java index 4c3dd4b06..c05311892 100644 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java @@ -56,6 +56,30 @@ public final class ParticipantUtils { return null; } + /** + * Get the First StartPhase + * it depend of the state of the Control Loop + * and also from the all startPhase defined into the ToscaServiceTemplate. + * @param controlLoop the ControlLoop + * @param toscaServiceTemplate the ToscaServiceTemplate + * @return the First StartPhase + */ + public static int getFirstStartPhase(ControlLoop controlLoop, ToscaServiceTemplate toscaServiceTemplate) { + var minStartPhase = 1000; + var maxStartPhase = 0; + for (var element : controlLoop.getElements().values()) { + ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates() + .get(element.getDefinition().getName()); + int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()); + minStartPhase = Math.min(minStartPhase, startPhase); + maxStartPhase = Math.max(maxStartPhase, startPhase); + } + + return ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState()) + || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? minStartPhase + : maxStartPhase; + } + /** * Finds startPhase from a map of properties. * -- cgit 1.2.3-korg