Handle TOSCA template with invalid element type 71/136071/1
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>
Mon, 2 Oct 2023 10:02:10 +0000 (11:02 +0100)
committerRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>
Mon, 2 Oct 2023 10:27:20 +0000 (10:27 +0000)
Tosca node templates should have elements with valid element type and
composition type. Invalid elements will be ignored, throws error if
there are no single valid element present.

Issue-ID: POLICY-4830
Signed-off-by: rameshiyer27 <ramesh.murugan.iyer@est.tech>
Change-Id: I4c6c88eee7c8017dfd4877e154062fca42e660ed

models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java

index 9f267d3..a518c49 100755 (executable)
@@ -66,6 +66,10 @@ public class AcDefinitionProvider {
         serviceTemplate.getMetadata().put("compositionId", compositionId);
         acmDefinition.setServiceTemplate(serviceTemplate);
         var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, toscaElementName);
+        if (acElements.isEmpty()) {
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+                    "NodeTemplate with element type " + toscaElementName + " must exist!");
+        }
         acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
         var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new,
                 "AutomationCompositionDefinition");
@@ -94,6 +98,10 @@ public class AcDefinitionProvider {
         acmDefinition.setServiceTemplate(serviceTemplate);
         var acElements =
                 AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, toscaElementName);
+        if (acElements.isEmpty()) {
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+                    "NodeTemplate with element type " + toscaElementName + " must exist!");
+        }
         acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
         updateAcDefinition(acmDefinition, toscaCompositionName);
     }