diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-02-02 15:42:56 +0000 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-02-03 09:25:32 +0000 |
commit | 4ad78088b7d1098f5529611eff15b1d61fc66a04 (patch) | |
tree | 7babd109983b2ac320eb5890342905b6397d7766 /models/src/main | |
parent | 26814a2d839be880fa56c658f0d88940d957e872 (diff) |
Handle AC Element Instance Deployment and undeployment on ACM-R
Part of the implementation related to Deployment and undeployment,
missing part will be implemented in POLICY-4509.
push-upstream: POLICY-4506
Change-Id: Ie7ad2da6c0a3286938fc4993d70ee71caee833ba
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main')
4 files changed, 52 insertions, 27 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java index 18a62ae94..363668619 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -53,13 +53,10 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut private DeployState deployState = DeployState.UNDEPLOYED; @NonNull - private LockState lockState = LockState.LOCKED; + private LockState lockState = LockState.NONE; private Map<UUID, AutomationCompositionElement> elements; - @NonNull - private Boolean primed = false; - /** * Copy contructor, does a deep copy. * @@ -74,7 +71,6 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut this.deployState = otherAutomationComposition.deployState; this.lockState = otherAutomationComposition.lockState; this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new); - this.primed = otherAutomationComposition.primed; } @Override diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java index 00f83122d..2aacc74b6 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java @@ -100,9 +100,6 @@ public class JpaAutomationComposition extends Validated @Column private String description; - @Column(columnDefinition = "TINYINT DEFAULT 1") - private Boolean primed; - @NotNull @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn(name = "instanceId", foreignKey = @ForeignKey(name = "ac_element_fk")) @@ -155,7 +152,6 @@ public class JpaAutomationComposition extends Validated this.lockState = copyConcept.lockState; this.description = copyConcept.description; this.elements = PfUtils.mapList(copyConcept.elements, JpaAutomationCompositionElement::new); - this.primed = copyConcept.primed; } /** @@ -180,7 +176,6 @@ public class JpaAutomationComposition extends Validated automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); automationComposition.setDescription(description); - automationComposition.setPrimed(primed); automationComposition.setElements(new LinkedHashMap<>(this.elements.size())); for (var element : this.elements) { automationComposition.getElements().put(UUID.fromString(element.getElementId()), element.toAuthorative()); @@ -200,7 +195,6 @@ public class JpaAutomationComposition extends Validated this.deployState = automationComposition.getDeployState(); this.lockState = automationComposition.getLockState(); this.description = automationComposition.getDescription(); - this.primed = automationComposition.getPrimed(); this.elements = new ArrayList<>(automationComposition.getElements().size()); for (var elementEntry : automationComposition.getElements().entrySet()) { @@ -264,11 +258,6 @@ public class JpaAutomationComposition extends Validated if (result != 0) { return result; } - - result = ObjectUtils.compare(primed, other.primed); - if (result != 0) { - return result; - } return PfUtils.compareObjects(elements, other.elements); } } 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 21efc66d3..197955d3a 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -30,8 +30,11 @@ import javax.ws.rs.core.Response.Status; import lombok.AllArgsConstructor; import lombok.NonNull; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository; +import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.springframework.data.domain.Example; @@ -97,6 +100,7 @@ public class AutomationCompositionProvider { */ public AutomationComposition createAutomationComposition(final AutomationComposition automationComposition) { automationComposition.setInstanceId(UUID.randomUUID()); + AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE); var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition, JpaAutomationComposition::new, "automation composition")); @@ -110,7 +114,9 @@ public class AutomationCompositionProvider { * @param automationComposition the automation composition to update * @return the updated automation composition */ - public AutomationComposition updateAutomationComposition(final AutomationComposition automationComposition) { + public AutomationComposition updateAutomationComposition( + @NonNull final AutomationComposition automationComposition) { + AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE); var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition, JpaAutomationComposition::new, "automation composition")); @@ -154,6 +160,8 @@ public class AutomationCompositionProvider { example.setInstanceId(null); example.setElements(null); example.setState(null); + example.setDeployState(null); + example.setLockState(null); return Example.of(example); } 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 7d1e80f54..af29deb3f 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 @@ -39,6 +39,8 @@ import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; @@ -97,25 +99,23 @@ public final class AcmUtils { } /** - * Set the Policy information in the service template for the automation composition element. + * Get the Policy information in the service template for the deploy message to participants. * - * @param acElement automation composition element * @param toscaServiceTemplate ToscaServiceTemplate */ - public static void setAcPolicyInfo(AutomationCompositionElement acElement, - ToscaServiceTemplate toscaServiceTemplate) { + public static ToscaServiceTemplate getToscaServiceTemplateFragment(ToscaServiceTemplate toscaServiceTemplate) { // Pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment if (toscaServiceTemplate.getPolicyTypes() == null && toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() == null) { - return; + return new ToscaServiceTemplate(); } - ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate(); + var toscaServiceTemplateFragment = new ToscaServiceTemplate(); toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes()); - ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate(); + var toscaTopologyTemplate = new ToscaTopologyTemplate(); toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies()); toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate); toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes()); - acElement.setToscaServiceTemplateFragment(toscaServiceTemplateFragment); + return toscaServiceTemplateFragment; } /** @@ -196,7 +196,7 @@ public final class AcmUtils { public static List<Entry<String, ToscaNodeTemplate>> extractAcElementsFromServiceTemplate( ToscaServiceTemplate serviceTemplate) { return serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet().stream().filter( - nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), + nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), serviceTemplate)) .collect(Collectors.toList()); } @@ -308,4 +308,36 @@ public final class AcmUtils { .collect(Collectors.toList()); // @formatter:on } + + + /** + * Return true if DeployState and LockState are in a Transitional State. + * + * @return true if DeployState and LockState are in a Transitional State + */ + public static boolean isInTransitionalState(DeployState deployState, LockState lockState) { + return DeployState.DEPLOYING.equals(deployState) || DeployState.UNDEPLOYING.equals(deployState) + || LockState.LOCKING.equals(lockState) || LockState.UNLOCKING.equals(lockState); + } + + /** + * Set the states on the automation composition and on all its automation composition elements. + * + * @param deployState the DeployState we want the automation composition to transition to + * @param lockState the LockState we want the automation composition to transition to + */ + public static void setCascadedState(final AutomationComposition automationComposition, + final DeployState deployState, final LockState lockState) { + automationComposition.setDeployState(deployState); + automationComposition.setLockState(lockState); + + if (MapUtils.isEmpty(automationComposition.getElements())) { + return; + } + + for (var element : automationComposition.getElements().values()) { + element.setDeployState(deployState); + element.setLockState(lockState); + } + } } |