diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-07-26 11:22:52 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-07-26 11:54:36 +0000 |
commit | 6cb378c883742a170218b0c40b5c2f62ab1fc49a (patch) | |
tree | 8d36d7575a7e93f97271160a96e89b0fcf625297 /models/src/main/java/org | |
parent | 37195c69c99b5987f037a018859b4421cbcbadf2 (diff) |
Allow migration to be performed in stages in ACM model
Issue-ID: POLICY-5089
Change-Id: I5192028cc4c7bc8a5744be0675fdea422dc49c1e
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java/org')
7 files changed, 62 insertions, 6 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java index 16398e54b..7d3acaa52 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java @@ -58,6 +58,8 @@ public class AutomationCompositionElement { @NonNull private SubState subState = SubState.NONE; + private Integer stage; + private String operationalState; private String useState; private String description; @@ -87,6 +89,7 @@ public class AutomationCompositionElement { this.subState = otherElement.subState; this.operationalState = otherElement.operationalState; this.useState = otherElement.useState; + this.stage = otherElement.stage; this.message = otherElement.message; } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java index d6079d0e7..9c827d701 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,11 @@ package org.onap.policy.clamp.models.acm.concepts; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -50,8 +54,26 @@ public final class ParticipantUtils { } return DeployState.DEPLOYING.equals(automationComposition.getDeployState()) - || LockState.UNLOCKING.equals(automationComposition.getLockState()) ? minStartPhase - : maxStartPhase; + || LockState.UNLOCKING.equals(automationComposition.getLockState()) ? minStartPhase : maxStartPhase; + } + + /** + * Get the First Stage. + * + * @param automationComposition the automation composition + * @param toscaServiceTemplate the ToscaServiceTemplate + * @return the First stage + */ + public static int getFirstStage( + AutomationComposition automationComposition, ToscaServiceTemplate toscaServiceTemplate) { + Set<Integer> minStage = new HashSet<>(); + for (var element : automationComposition.getElements().values()) { + var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates() + .get(element.getDefinition().getName()); + var stage = ParticipantUtils.findStageSet(toscaNodeTemplate.getProperties()); + minStage.addAll(stage); + } + return minStage.stream().min(Integer::compare).orElse(0); } /** @@ -63,8 +85,25 @@ public final class ParticipantUtils { public static int findStartPhase(Map<String, Object> properties) { var objStartPhase = properties.get("startPhase"); if (objStartPhase != null) { - return Integer.valueOf(objStartPhase.toString()); + return Integer.parseInt(objStartPhase.toString()); } return 0; } + + + /** + * Finds stage from a map of properties. + * + * @param properties Map of properties + * @return stage + */ + public static Set<Integer> findStageSet(Map<String, Object> properties) { + var objStage = properties.get("stage"); + if (objStage instanceof List<?> stageSet) { + return stageSet.stream() + .map(obj -> Integer.valueOf(obj.toString())) + .collect(Collectors.toSet()); + } + return Set.of(0); + } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java index 2c7d51fe7..9807ff9ca 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java @@ -41,7 +41,7 @@ import org.onap.policy.models.base.PfUtils; public class AutomationCompositionDeployAck extends ParticipantAckMessage { private UUID automationCompositionId; - private Integer startPhase; + private Integer stage; // A map with AutomationCompositionElementID as its key, and a pair of result and message as value per // AutomationCompositionElement. @@ -63,7 +63,7 @@ public class AutomationCompositionDeployAck extends ParticipantAckMessage { public AutomationCompositionDeployAck(final AutomationCompositionDeployAck source) { super(source); this.automationCompositionId = source.automationCompositionId; - this.startPhase = source.startPhase; + this.stage = source.stage; this.automationCompositionResultMap = PfUtils.mapMap(source.automationCompositionResultMap, UnaryOperator.identity()); } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java index 6ae812cf4..2d7608afd 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java @@ -38,6 +38,7 @@ public class AutomationCompositionMigration extends ParticipantMessage { private List<ParticipantDeploy> participantUpdatesList = new ArrayList<>(); private Boolean precheck = false; + private Integer stage = 0; public AutomationCompositionMigration() { super(ParticipantMessageType.AUTOMATION_COMPOSITION_MIGRATION); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java index 79ca9612e..e511ba1fc 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java @@ -105,6 +105,9 @@ public class JpaAutomationCompositionElement extends Validated private String useState; @Column + private Integer stage; + + @Column private String description; @Column @@ -185,6 +188,7 @@ public class JpaAutomationCompositionElement extends Validated this.subState = copyConcept.subState; this.operationalState = copyConcept.operationalState; this.useState = copyConcept.useState; + this.stage = copyConcept.stage; this.message = copyConcept.message; } @@ -213,6 +217,7 @@ public class JpaAutomationCompositionElement extends Validated element.setSubState(subState); element.setOperationalState(operationalState); element.setUseState(useState); + element.setStage(stage); element.setMessage(message); return element; @@ -231,6 +236,7 @@ public class JpaAutomationCompositionElement extends Validated this.subState = element.getSubState(); this.operationalState = element.getOperationalState(); this.useState = element.getUseState(); + this.stage = element.getStage(); this.message = element.getMessage(); } @@ -288,6 +294,11 @@ public class JpaAutomationCompositionElement extends Validated return result; } + result = ObjectUtils.compare(stage, other.stage); + if (result != 0) { + return result; + } + result = ObjectUtils.compare(operationalState, other.operationalState); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java index 9b736483d..2d532b420 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java @@ -262,6 +262,7 @@ public class AutomationCompositionProvider { jpaAcElement.setDeployState(element.getDeployState()); jpaAcElement.setLockState(element.getLockState()); jpaAcElement.setSubState(element.getSubState()); + jpaAcElement.setStage(element.getStage()); jpaAcElement.setRestarting(element.getRestarting()); ProviderUtils.validate(element, jpaAcElement, "AutomationCompositionElement"); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java index 50b8d14ad..aaf41ddeb 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -413,6 +413,7 @@ public final class AcmUtils { element.setLockState(lockState); element.setSubState(subState); element.setMessage(null); + element.setStage(null); } } |