From 66ccb9814f2105b8c37a8ec47b9595fc09e4c5e7 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 26 Nov 2024 14:23:39 +0000 Subject: Fix undeploy issue after migration failure in ACM-R Issue-ID: POLICY-5177 Change-Id: Ic49dc15a9fd2a92f358eb60a440a8efb5080bbde Signed-off-by: FrancescoFioraEst --- .../intermediary/handler/CacheProvider.java | 26 +++++++++++++++++----- .../intermediary/handler/CacheProviderTest.java | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'participant/participant-intermediary') diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java index 3837ec629..b9e33c92d 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java @@ -45,6 +45,7 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType import org.onap.policy.clamp.models.acm.concepts.SubState; import org.onap.policy.models.base.PfUtils; 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.springframework.stereotype.Component; @@ -140,7 +141,8 @@ public class CacheProvider { var automationComposition = automationCompositions.get(instanceId); var map = acElementsDefinitions.get(automationComposition.getCompositionId()); var element = automationComposition.getElements().get(acElementId); - return map.get(element.getDefinition()).getAutomationCompositionElementToscaNodeTemplate().getProperties(); + return getAcElementDefinition(map, element.getDefinition()) + .getAutomationCompositionElementToscaNodeTemplate().getProperties(); } /** @@ -152,8 +154,20 @@ public class CacheProvider { */ public Map getCommonProperties(@NonNull UUID compositionId, @NonNull ToscaConceptIdentifier definition) { - return acElementsDefinitions.get(compositionId).get(definition) - .getAutomationCompositionElementToscaNodeTemplate().getProperties(); + return getAcElementDefinition(acElementsDefinitions.get(compositionId), definition) + .getAutomationCompositionElementToscaNodeTemplate().getProperties(); + } + + private AutomationCompositionElementDefinition getAcElementDefinition( + Map map, + ToscaConceptIdentifier definition) { + var nodeTemplate = map.get(definition); + if (nodeTemplate == null) { + nodeTemplate = new AutomationCompositionElementDefinition(); + nodeTemplate.setAutomationCompositionElementToscaNodeTemplate(new ToscaNodeTemplate()); + nodeTemplate.getAutomationCompositionElementToscaNodeTemplate().setProperties(new HashMap<>()); + } + return nodeTemplate; } /** @@ -273,8 +287,8 @@ public class CacheProvider { */ public CompositionElementDto createCompositionElementDto(UUID compositionId, AutomationCompositionElement element, Map compositionInProperties) { - var compositionOutProperties = getAcElementsDefinitions() - .get(compositionId).get(element.getDefinition()).getOutProperties(); + var compositionOutProperties = getAcElementDefinition(acElementsDefinitions + .get(compositionId), element.getDefinition()).getOutProperties(); return new CompositionElementDto(compositionId, element.getDefinition(), compositionInProperties, compositionOutProperties); } @@ -291,7 +305,7 @@ public class CacheProvider { var definitions = acElementsDefinitions.get(compositionId); Map map = new HashMap<>(); for (var element : automationComposition.getElements().values()) { - var definition = definitions.get(element.getDefinition()); + var definition = getAcElementDefinition(definitions, element.getDefinition()); var compositionElement = (definition != null) ? new CompositionElementDto(compositionId, element.getDefinition(), definition.getAutomationCompositionElementToscaNodeTemplate().getProperties(), diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java index ced2d81e8..96add2025 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java @@ -65,6 +65,8 @@ class CacheProviderTest { .isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> cacheProvider.getCommonProperties(instanceId, (UUID) null)) .isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cacheProvider.getCommonProperties(null, instanceId)) + .isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> cacheProvider.removeAutomationComposition(null)) .isInstanceOf(NullPointerException.class); -- cgit 1.2.3-korg