aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main/java
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2023-09-22 15:46:30 +0100
committerRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>2023-09-27 13:49:20 +0000
commit5a92f5dc2d2066635d59a0b986ec77487198a821 (patch)
tree4ea39827c5cbc183b4e52c2d28f051b2ceedae90 /models/src/main/java
parent3398b96f53bd1c5f9926a88db996abbbfe1da500 (diff)
Allow customisation in element and composition names in TOSCA
User defined values can be provided in the spring properties file for runtime-acm. The same values will be expected from the TOSCA template. If not configured in application properties, default values will be used. Issue-ID: POLICY-4827 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: I17bfe811c2531c65e90679e95de9732129b54898
Diffstat (limited to 'models/src/main/java')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java23
-rwxr-xr-xmodels/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java2
-rwxr-xr-xmodels/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java28
-rwxr-xr-xmodels/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java18
4 files changed, 41 insertions, 30 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
index c265e6458..ff580c7c2 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@ import lombok.NonNull;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaEntity;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaTopologyTemplate;
-import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.Validated;
@@ -39,8 +38,6 @@ import org.onap.policy.models.base.Validated;
public final class ToscaServiceTemplateValidation {
private static final String ROOT_KEY_NAME_SUFFIX = ".Root";
- private static final String AC_NODE_TYPE_NOT_PRESENT =
- "NodeTemplate with type " + AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE + " must exist!";
/**
* validate a serviceTemplate.
@@ -48,7 +45,8 @@ public final class ToscaServiceTemplateValidation {
* @param result the result
* @param serviceTemplate the serviceTemplate to validate
*/
- public static void validate(final BeanValidationResult result, DocToscaServiceTemplate serviceTemplate) {
+ public static void validate(final BeanValidationResult result, DocToscaServiceTemplate serviceTemplate,
+ String toscaCompositionName) {
var references = DocUtil.getToscaReferences(serviceTemplate);
@@ -66,7 +64,7 @@ public final class ToscaServiceTemplateValidation {
}
}
- validateToscaTopologyTemplate(result, serviceTemplate.getToscaTopologyTemplate());
+ validateToscaTopologyTemplate(result, serviceTemplate.getToscaTopologyTemplate(), toscaCompositionName);
if (serviceTemplate.getToscaTopologyTemplate() != null) {
validEntityTypeAncestors(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(),
@@ -98,21 +96,24 @@ public final class ToscaServiceTemplateValidation {
* @param topologyTemplate the ToscaServiceTemplate
*/
public static void validateToscaTopologyTemplate(BeanValidationResult result,
- DocToscaTopologyTemplate topologyTemplate) {
+ DocToscaTopologyTemplate topologyTemplate, String toscaCompositionName) {
+ String acNodeTypeNotPresent =
+ "NodeTemplate with type " + toscaCompositionName + " must exist!";
+
if (topologyTemplate != null && topologyTemplate.getNodeTemplates() != null) {
var nodeTemplates = topologyTemplate.getNodeTemplates();
var acNumber = nodeTemplates.values().stream().filter(
- nodeTemplate -> AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType()))
+ nodeTemplate -> toscaCompositionName.equals(nodeTemplate.getType()))
.count();
if (acNumber == 0) {
- result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT);
+ result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, acNodeTypeNotPresent);
}
if (acNumber > 1) {
result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, "NodeTemplate with type "
- + AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE + " not allowed to be more than one!");
+ + toscaCompositionName + " not allowed to be more than one!");
}
} else {
- result.addResult("TopologyTemplate", topologyTemplate, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT);
+ result.addResult("TopologyTemplate", topologyTemplate, ValidationStatus.INVALID, acNodeTypeNotPresent);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
index 641c9ad15..4069d7bb1 100755
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
@@ -138,8 +138,6 @@ public class JpaAutomationCompositionDefinition extends Validated
@Override
public BeanValidationResult validate(@NonNull String fieldName) {
var result = super.validate(fieldName);
- ToscaServiceTemplateValidation.validate(result, serviceTemplate);
-
if (!result.isValid()) {
return result;
}
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 588039b07..9f267d32d 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
@@ -28,10 +28,12 @@ import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.data.domain.Example;
@@ -53,7 +55,7 @@ public class AcDefinitionProvider {
* @return the created ACM Definition
*/
public AutomationCompositionDefinition createAutomationCompositionDefinition(
- final ToscaServiceTemplate serviceTemplate) {
+ final ToscaServiceTemplate serviceTemplate, final String toscaElementName, String toscaCompositionName) {
var acmDefinition = new AutomationCompositionDefinition();
var compositionId = UUID.randomUUID();
acmDefinition.setCompositionId(compositionId);
@@ -63,10 +65,16 @@ public class AcDefinitionProvider {
}
serviceTemplate.getMetadata().put("compositionId", compositionId);
acmDefinition.setServiceTemplate(serviceTemplate);
- var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate);
+ var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, toscaElementName);
acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new,
"AutomationCompositionDefinition");
+ var validationResult = new BeanValidationResult("AutomationCompositionDefinition", acmDefinition);
+ ToscaServiceTemplateValidation.validate(validationResult, jpaAcmDefinition.getServiceTemplate(),
+ toscaCompositionName);
+ if (! validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ }
var result = acmDefinitionRepository.save(jpaAcmDefinition);
return result.toAuthorative();
@@ -78,14 +86,16 @@ public class AcDefinitionProvider {
* @param compositionId The UUID of the automation composition definition to delete
* @param serviceTemplate the service template to be created
*/
- public void updateServiceTemplate(UUID compositionId, ToscaServiceTemplate serviceTemplate) {
+ public void updateServiceTemplate(UUID compositionId, ToscaServiceTemplate serviceTemplate, String toscaElementName,
+ String toscaCompositionName) {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(compositionId);
acmDefinition.setState(AcTypeState.COMMISSIONED);
acmDefinition.setServiceTemplate(serviceTemplate);
- var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate);
+ var acElements =
+ AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, toscaElementName);
acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
- updateAcDefinition(acmDefinition);
+ updateAcDefinition(acmDefinition, toscaCompositionName);
}
/**
@@ -93,9 +103,15 @@ public class AcDefinitionProvider {
*
* @param acDefinition the AutomationCompositionDefinition to be updated
*/
- public void updateAcDefinition(AutomationCompositionDefinition acDefinition) {
+ public void updateAcDefinition(AutomationCompositionDefinition acDefinition, String toscaCompositionName) {
var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acDefinition, JpaAutomationCompositionDefinition::new,
"AutomationCompositionDefinition");
+ var validationResult = new BeanValidationResult("AutomationCompositionDefinition", acDefinition);
+ ToscaServiceTemplateValidation.validate(validationResult, jpaAcmDefinition.getServiceTemplate(),
+ toscaCompositionName);
+ if (! validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ }
acmDefinitionRepository.save(jpaAcmDefinition);
acmDefinitionRepository.flush();
}
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 fe44050d5..c3d8fc4a4 100755
--- 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
@@ -65,10 +65,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AcmUtils {
-
- public static final String AUTOMATION_COMPOSITION_ELEMENT =
- "org.onap.policy.clamp.acm.AutomationCompositionElement";
- public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
public static final String ENTRY = "entry ";
/**
@@ -99,15 +95,15 @@ public final class AcmUtils {
* @return true if the NodeTemplate is an AutomationCompositionElement
*/
public static boolean checkIfNodeTemplateIsAutomationCompositionElement(ToscaNodeTemplate nodeTemplate,
- ToscaServiceTemplate toscaServiceTemplate) {
- if (nodeTemplate.getType().contains(AUTOMATION_COMPOSITION_ELEMENT)) {
+ ToscaServiceTemplate toscaServiceTemplate, String toscaElementName) {
+ if (nodeTemplate.getType().contains(toscaElementName)) {
return true;
} else {
var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
if (nodeType != null) {
var derivedFrom = nodeType.getDerivedFrom();
if (derivedFrom != null) {
- return derivedFrom.contains(AUTOMATION_COMPOSITION_ELEMENT);
+ return derivedFrom.contains(toscaElementName);
}
}
}
@@ -167,10 +163,10 @@ public final class AcmUtils {
* @return the list of Entry of AutomationCompositionElement
*/
public static List<Entry<String, ToscaNodeTemplate>> extractAcElementsFromServiceTemplate(
- ToscaServiceTemplate serviceTemplate) {
+ ToscaServiceTemplate serviceTemplate, String toscaElementName) {
return serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet().stream().filter(
nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(),
- serviceTemplate))
+ serviceTemplate, toscaElementName))
.toList();
}
@@ -203,13 +199,13 @@ public final class AcmUtils {
* @return the result of validation
*/
public static BeanValidationResult validateAutomationComposition(AutomationComposition automationComposition,
- ToscaServiceTemplate serviceTemplate) {
+ ToscaServiceTemplate serviceTemplate, String toscaCompositionName) {
var result = new BeanValidationResult(ENTRY + automationComposition.getName(), automationComposition);
var map = getMapToscaNodeTemplates(serviceTemplate);
var nodeTemplateGet = map.values().stream()
- .filter(nodeTemplate -> AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType())).findFirst();
+ .filter(nodeTemplate -> toscaCompositionName.equals(nodeTemplate.getType())).findFirst();
if (nodeTemplateGet.isEmpty()) {
result.addResult(new ObjectValidationResult("ToscaServiceTemplate", serviceTemplate.getName(),