diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-11-26 14:23:39 +0000 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-11-26 17:45:52 +0000 |
commit | 66ccb9814f2105b8c37a8ec47b9595fc09e4c5e7 (patch) | |
tree | 75099d312177d8e3080e13814e6063ac21fd0cf4 /participant | |
parent | 69486c769a936881a1d11d2ff1f0f11e7be7e9df (diff) |
Fix undeploy issue after migration failure in ACM-R
Issue-ID: POLICY-5177
Change-Id: Ic49dc15a9fd2a92f358eb60a440a8efb5080bbde
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant')
2 files changed, 22 insertions, 6 deletions
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<String, Object> 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<ToscaConceptIdentifier, AutomationCompositionElementDefinition> 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<String, Object> 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<UUID, CompositionElementDto> 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); |