aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main/java
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2023-10-02 11:02:10 +0100
committerRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>2023-10-02 10:27:20 +0000
commitc706398593f184301d38bd6cba86566da60bece6 (patch)
tree82368d0ea9c6397a7727a579083b42cf94b63e64 /models/src/main/java
parent573057bf622d0a671d9327f32ad096f58bc31cc1 (diff)
Handle TOSCA template with invalid element type
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
Diffstat (limited to 'models/src/main/java')
-rwxr-xr-xmodels/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
index 9f267d32d..a518c4908 100755
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
@@ -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);
}