diff options
author | rameshiyer27 <ramesh.murugan.iyer@est.tech> | 2022-02-07 17:07:38 +0000 |
---|---|---|
committer | rameshiyer27 <ramesh.murugan.iyer@est.tech> | 2022-02-10 14:20:42 +0000 |
commit | 45b653fc5a8d641452247eca5c80cf580609e9bf (patch) | |
tree | 06cfd4529db05dc23cbd63d2fe2e53799eb07bdf /models-tosca/src/main/java | |
parent | 303d42453fbfcf2381f810b10a496b69aa8bc34b (diff) |
Add policy metadataSet handling as node templates
Each metadataSet is represented as a 'node_template' in Tosca
mapped to a specific node type.
Support added for db operations of node templates as
independent entities.
Detailed documentation available here :
https://wiki.onap.org/display/DW/Enable+Handling+of+Policy+Type+Metadata
Issue-ID: POLICY-3832
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: I6c189142b1778ba858aae27cd92d4f136d950208
Diffstat (limited to 'models-tosca/src/main/java')
6 files changed, 416 insertions, 9 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java index 919d187de..c339f721e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ public class ToscaEntity implements PfNameVersion { @SerializedName("derived_from") private String derivedFrom; - private Map<String, String> metadata; + private Map<String, Object> metadata; private String description; /** @@ -67,7 +67,7 @@ public class ToscaEntity implements PfNameVersion { if (copyObject.metadata != null) { metadata = new LinkedHashMap<>(); - for (final Entry<String, String> metadataEntry : copyObject.metadata.entrySet()) { + for (final Entry<String, Object> metadataEntry : copyObject.metadata.entrySet()) { metadata.put(metadataEntry.getKey(), metadataEntry.getValue()); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java index 8171b7d78..2ec9ee2c8 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2022 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +35,8 @@ import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -549,6 +551,125 @@ public class AuthorativeToscaProvider { } /** + * Create tosca node templates. + * + * @param dao the DAO to use to access the database + * @param toscaServiceTemplate the template with node templates entities to be created. + * @return the toscaServiceTemplate with node templates that were created + * @throws PfModelException on errors creating node templates + */ + public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final PfDao dao, + @NonNull final ToscaServiceTemplate toscaServiceTemplate) + throws PfModelException { + LOGGER.debug("createToscaNodeTemplates ={}", toscaServiceTemplate); + ToscaServiceTemplate createdServiceTemplate; + + synchronized (providerLockObject) { + createdServiceTemplate = new SimpleToscaProvider() + .createToscaNodeTemplates(dao, new JpaToscaServiceTemplate(toscaServiceTemplate)).toAuthorative(); + } + + LOGGER.debug("<-createToscaNodeTemplates: createdServiceTemplate={}", createdServiceTemplate); + return createdServiceTemplate; + } + + /** + * Update tosca node templates. + * + * @param dao the DAO to use to access the database + * @param serviceTemplate the service template containing the definitions of the nodeTemplates to be updated. + * @return the TOSCA service template containing the nodeTemplates that were updated + * @throws PfModelRuntimeException on errors updating node templates + */ + public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final PfDao dao, + @NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { + LOGGER.debug("->updateToscaNodeTemplates: serviceTemplate={}", serviceTemplate); + ToscaServiceTemplate updatedServiceTemplate; + + synchronized (providerLockObject) { + updatedServiceTemplate = new SimpleToscaProvider() + .updateToscaNodeTemplates(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + } + + LOGGER.debug("<-updateToscaNodeTemplates: updatedServiceTemplate={}", updatedServiceTemplate); + return updatedServiceTemplate; + } + + + /** + * Delete a tosca node template. + * + * @param dao the DAO to use to access the database + * @param name the name of the node template to delete. + * @param version the version of the node template to delete. + * @return the TOSCA service template containing the node template that was deleted + * @throws PfModelException on errors deleting node template + */ + public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final PfDao dao, @NonNull final String name, + @NonNull final String version) throws PfModelException { + LOGGER.debug("->deleteToscaNodeTemplate: name={}, version={}", name, version); + ToscaServiceTemplate deletedServiceTemplate; + + synchronized (providerLockObject) { + deletedServiceTemplate = + new SimpleToscaProvider().deleteToscaNodeTemplate(dao, new PfConceptKey(name, version)).toAuthorative(); + } + LOGGER.debug("<-deleteToscaNodeTemplate: name={}, version={}, deletedServiceTemplate={}", name, version, + deletedServiceTemplate); + return deletedServiceTemplate; + } + + /** + * Get node template metadataSet. + * + * @param dao the DAO to use to access the database + * @param name the name of the metadataSet to get, null to get all metadataSets + * @param version the version of the metadataSet to get, null to get all versions of a metadataSets + * @return the metadataSets found + * @throws PfModelException on errors getting policy metadataSet + */ + public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSet( + @NonNull final PfDao dao, final String name, final String version) + throws PfModelException { + LOGGER.debug("->getNodeTemplateMetadataSet: name={}, version={}", name, version); + List<Map<ToscaEntityKey, Map<String, Object>>> metadataSets; + + synchronized (providerLockObject) { + metadataSets = new SimpleToscaProvider().getNodeTemplateMetadata(dao, name, version); + } + LOGGER.debug("<-getNodeTemplateMetadataSet: name={}, version={}, metadataSets={}", name, version, + metadataSets); + return metadataSets; + } + + /** + * Get tosca node templates. + * + * @param dao the DAO to use to access the database + * @param name the name of the node template to get, null to get all node templates + * @param version the version of the node template to get, null to get all versions of node template + * @return the node templates found + * @throws PfModelException on errors getting tosca node templates + */ + public List<Map<PfConceptKey, ToscaNodeTemplate>> getToscaNodeTemplate( + @NonNull final PfDao dao, final String name, final String version) + throws PfModelException { + LOGGER.debug("->getNodeTemplate: name={}, version={}", name, version); + List<Map<PfConceptKey, ToscaNodeTemplate>> nodeTemplates = new ArrayList<>(); + + synchronized (providerLockObject) { + new SimpleToscaProvider().getToscaNodeTemplates(dao, name, version) + .getConceptMap().forEach((key, value) -> nodeTemplates.add(Map.of(key, value.toAuthorative()))); + } + + LOGGER.debug("<-getNodeTemplate: name={}, version={}, nodeTemplates={}", name, version, + nodeTemplates); + return nodeTemplates; + } + + + /** * Return the contents of a list of maps as a plain list. * * @param listOfMaps the list of maps diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java index 2416bab69..84381fb50 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2020,2022 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.EmbeddedId; +import javax.persistence.Lob; import javax.persistence.MappedSuperclass; import lombok.Data; import lombok.EqualsAndHashCode; @@ -66,6 +67,7 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme private PfConceptKey derivedFrom; @ElementCollection + @Lob private Map<@NotNull @NotBlank String, @NotNull @NotBlank String> metadata; @Column @@ -156,7 +158,7 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme description = toscaEntity.getDescription(); } - metadata = PfUtils.mapMap(toscaEntity.getMetadata(), item -> item); + metadata = PfUtils.mapMap(toscaEntity.getMetadata(), Object::toString); } @Override diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index 862108b15..e2f61c464 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2020,2022 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,6 +24,8 @@ package org.onap.policy.models.tosca.simple.provider; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.Optional; import javax.ws.rs.core.Response; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; @@ -36,9 +38,15 @@ import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTypes; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; @@ -641,6 +649,195 @@ public class SimpleToscaProvider { return deletedServiceTemplate; } + + /** + * Get metadata of tosca node templates. + * + * @param dao the DAO to use to access the database + * @param name the name of the nodeTemplate to get, set to null to get all node templates + * @param version the version of the metadataSet to get, set to null to get all versions + * @return the list of maps with node template key and metadata values found + * @throws PfModelException on errors getting metadataSets + */ + public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadata( + @NonNull final PfDao dao, final String name, final String version) + throws PfModelException { + LOGGER.debug("->getNodeTemplateMetadataSet: name={}, version={}", name, version); + + List<Map<ToscaEntityKey, Map<String, Object>>> metadataSets = new ArrayList<>(); + + JpaToscaServiceTemplate dbServiceTemplate = getServiceTemplate(dao); + + //Return empty list if no node templates present in db + if (!ToscaUtils.doNodeTemplatesExist(dbServiceTemplate)) { + return metadataSets; + } + var returnServiceTemplate = new JpaToscaServiceTemplate(dbServiceTemplate); + List<ToscaNodeTemplate> toscaNodeTemplates = new ArrayList<>(); + returnServiceTemplate.getTopologyTemplate() + .getNodeTemplates().getConceptMap().forEach((key, value) -> toscaNodeTemplates.add(value + .toAuthorative())); + + //Filter metadataSet for specific node template + if (name != null && version != null) { + var filterKey = new ToscaEntityKey(name, version); + toscaNodeTemplates.removeIf(entity -> !entity.getKey().equals(filterKey)); + } + toscaNodeTemplates.forEach(e -> metadataSets.add(Map.of(e.getKey(), e.getMetadata()))); + LOGGER.debug("<-getNodeTemplateMetadataSet: name={}, version={}, metadataSets={}", name, version, + metadataSets); + + return metadataSets; + } + + /** + * Get tosca node templates. + * + * @param dao the DAO to use to access the database + * @param name the name of the node template to get, set to null to get all node templates + * @param version the version of the node template to get, set to null to get all versions + * @return the node templates with the specified key + * @throws PfModelException on errors getting node templates + */ + public JpaToscaNodeTemplates getToscaNodeTemplates(@NonNull final PfDao dao, final String name, + final String version) + throws PfModelException { + LOGGER.debug("->getNodeTemplate: name={}, version={}", name, version); + + var nodeTemplates = new JpaToscaNodeTemplates(); + + JpaToscaServiceTemplate dbServiceTemplate = getServiceTemplate(dao); + + //Return empty if no nodeTemplates present in db + if (!ToscaUtils.doNodeTemplatesExist(dbServiceTemplate)) { + return nodeTemplates; + } + var returnServiceTemplate = new JpaToscaServiceTemplate(dbServiceTemplate); + nodeTemplates = returnServiceTemplate.getTopologyTemplate().getNodeTemplates(); + + //Filter specific nodeTemplates + if (name != null && version != null) { + var filterKey = new PfConceptKey(name, version); + nodeTemplates.getConceptMap().entrySet().removeIf(entity -> !entity.getKey().equals(filterKey)); + } + LOGGER.debug("<-getNodeTemplateMetadataSet: name={}, version={}, nodeTemplates={}", name, version, + nodeTemplates); + + return nodeTemplates; + } + + + /** + * Update tosca node template. + * + * @param dao the DAO to use to access the database + * @param serviceTemplate the service template containing the definitions of the node templates to be updated. + * @return the TOSCA service template containing the node templates that were updated + * @throws PfModelRuntimeException on errors updating node templates + */ + public JpaToscaServiceTemplate updateToscaNodeTemplates(@NonNull final PfDao dao, + @NonNull final JpaToscaServiceTemplate serviceTemplate) + throws PfModelException { + LOGGER.debug("->updateToscaNodeTemplates: serviceTemplate={}", serviceTemplate); + + ToscaUtils.assertNodeTemplatesExist(serviceTemplate); + for (JpaToscaNodeTemplate nodeTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplates() + .getAll(null)) { + + //verify if the node template is referenced in the metadata of created policies + assertNodeTemplateNotUsedInPolicy(dao, nodeTemplate.getName(), nodeTemplate.getVersion()); + verifyNodeTypeInDbTemplate(dao, nodeTemplate); + + dao.update(nodeTemplate); + } + // Return the service template with updated node templates + var updatedNodeTemplates = new JpaToscaNodeTemplates(); + updatedNodeTemplates.setKey(serviceTemplate.getTopologyTemplate().getNodeTemplates().getKey()); + + for (PfConceptKey metadataSetKey : serviceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap() + .keySet()) { + updatedNodeTemplates.getConceptMap().put(metadataSetKey, dao.get(JpaToscaNodeTemplate.class, + metadataSetKey)); + } + serviceTemplate.getTopologyTemplate().setNodeTemplates(updatedNodeTemplates); + + LOGGER.debug("<-updatedToscaNodeTemplates: serviceTemplate={}", serviceTemplate); + return serviceTemplate; + } + + /** + * Delete a tosca node template. + * + * @param dao the DAO to use to access the database + * @param nodeTemplateKey the node template key + * @return the TOSCA service template containing the node templates that were deleted + * @throws PfModelException on errors deleting node templates + */ + public JpaToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final PfDao dao, + @NonNull final PfConceptKey nodeTemplateKey) + throws PfModelException { + LOGGER.debug("->deleteToscaNodeTemplate: key={}", nodeTemplateKey); + + JpaToscaServiceTemplate dbServiceTemplate = getServiceTemplate(dao); + + if (!ToscaUtils.doNodeTemplatesExist(dbServiceTemplate)) { + throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "no node templates found"); + } + JpaToscaNodeTemplate nodeTemplate4Deletion = dbServiceTemplate.getTopologyTemplate().getNodeTemplates() + .get(nodeTemplateKey); + if (nodeTemplate4Deletion == null) { + throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "node template " + nodeTemplateKey.getId() + + NOT_FOUND); + } + + //Verify if the node template is referenced in the metadata of created policies + assertNodeTemplateNotUsedInPolicy(dao, nodeTemplateKey.getName(), nodeTemplateKey.getVersion()); + + dbServiceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap().remove(nodeTemplateKey); + new SimpleToscaServiceTemplateProvider().write(dao, dbServiceTemplate); + dao.delete(nodeTemplate4Deletion); + + var deletedServiceTemplate = new JpaToscaServiceTemplate(); + deletedServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + deletedServiceTemplate.getTopologyTemplate().setNodeTemplates(new JpaToscaNodeTemplates()); + deletedServiceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap() + .put(nodeTemplateKey, nodeTemplate4Deletion); + + LOGGER.debug("<-deleteToscaNodeTemplate: key={}, serviceTemplate={}", nodeTemplateKey, deletedServiceTemplate); + return deletedServiceTemplate; + } + + /** + * Write a node template to the database. + * + * @param dao the DAO to use to access the database + * @param serviceTemplate the service template to be written + * @return the service template created by this method + * @throws PfModelException on errors writing the metadataSets + */ + public JpaToscaServiceTemplate createToscaNodeTemplates(@NonNull final PfDao dao, + @NonNull final JpaToscaServiceTemplate serviceTemplate) + throws PfModelException { + + LOGGER.debug("->write: tosca nodeTemplates={}", serviceTemplate); + + ToscaUtils.assertNodeTemplatesExist(serviceTemplate); + + Optional<JpaToscaNodeTypes> nodeTypes = Optional.ofNullable(serviceTemplate.getNodeTypes()); + for (JpaToscaNodeTemplate nodeTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplates() + .getAll(null)) { + + // verify node types in the db if mismatch/empty entities in the template + if (! (nodeTypes.isPresent() && nodeTypes.get().getKeys().contains(nodeTemplate.getType()))) { + verifyNodeTypeInDbTemplate(dao, nodeTemplate); + } + } + JpaToscaServiceTemplate writtenServiceTemplate = appendToServiceTemplate(dao, serviceTemplate); + LOGGER.debug("<-createdToscaNodeTemplates: writtenServiceTemplate={}", writtenServiceTemplate); + + return serviceTemplate; + } + /** * Verify the policy type for a policy exists. * @@ -670,6 +867,28 @@ public class SimpleToscaProvider { } /** + * Verify the node type for a toscaNodeTemplate metadataSet. + * + * @param dao the DAO to use to access toscaNodeTemplate types in the database + * @param toscaNodeTemplate the toscaNodeTemplate to check the toscaNodeTemplate type for + */ + private void verifyNodeTypeInDbTemplate(final PfDao dao, final JpaToscaNodeTemplate toscaNodeTemplate) throws + PfModelException { + PfConceptKey nodeTypeKey = toscaNodeTemplate.getType(); + + JpaToscaNodeType nodeType = null; + + nodeType = dao.get(JpaToscaNodeType.class, nodeTypeKey); + + if (nodeType == null) { + String errorMessage = + "NODE_TYPE " + nodeTypeKey + " for toscaNodeTemplate " + toscaNodeTemplate.getId() + + " does not exist"; + throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage); + } + } + + /** * Get the latest version of the policy type for the given policy type name. * * @param dao the DAO to use to access policy types in the database @@ -699,4 +918,31 @@ public class SimpleToscaProvider { return (JpaToscaPolicyType) filterdPolicyTypeList.get(0); } + + /** + * Assert that the node template is not referenced in any Tosca policy. + * + * @param name the name of node template + * @param version the version of node template + * @throws PfModelException if node template referenced in a policy + */ + private void assertNodeTemplateNotUsedInPolicy(PfDao dao, String name, String version) + throws PfModelException { + JpaToscaServiceTemplate dbTemplate; + try { + //Retrieve all the policies from db, return if policies doesn't exist + dbTemplate = getPolicies(dao, null, null); + } catch (PfModelRuntimeException e) { + LOGGER.debug("Could not verify the node template reference in created policies ", e); + return; + } + for (JpaToscaPolicy policy : dbTemplate.getTopologyTemplate().getPolicies().getConceptMap().values()) { + if (policy.getMetadata().getOrDefault("metadataSetName", "").equals(name) + && policy.getMetadata().getOrDefault("metadataSetVersion", "").equals(version)) { + throw new PfModelException(Response.Status.NOT_ACCEPTABLE, + "Node template is in use, it is referenced in Tosca Policy " + policy.getName() + " version " + + policy.getVersion()); + } + } + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java index 7f6fbb2f3..6f4b2993f 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020,2022 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -67,6 +67,8 @@ public final class ToscaServiceTemplateUtils { addFragmentEntitites(compositeTemplate.getDataTypes(), fragmentTemplate.getDataTypes(), result)); compositeTemplate.setPolicyTypes( addFragmentEntitites(compositeTemplate.getPolicyTypes(), fragmentTemplate.getPolicyTypes(), result)); + compositeTemplate.setNodeTypes( + addFragmentEntitites(compositeTemplate.getNodeTypes(), fragmentTemplate.getNodeTypes(), result)); if (originalTemplate.getTopologyTemplate() != null && fragmentTemplate.getTopologyTemplate() != null) { if (originalTemplate.getTopologyTemplate() @@ -74,6 +76,9 @@ public final class ToscaServiceTemplateUtils { compositeTemplate.getTopologyTemplate() .setPolicies(addFragmentEntitites(compositeTemplate.getTopologyTemplate().getPolicies(), fragmentTemplate.getTopologyTemplate().getPolicies(), result)); + compositeTemplate.getTopologyTemplate() + .setNodeTemplates(addFragmentEntitites(compositeTemplate.getTopologyTemplate().getNodeTemplates(), + fragmentTemplate.getTopologyTemplate().getNodeTemplates(), result)); } else { Validated.addResult(result, "topology template", originalTemplate.getTopologyTemplate().getKey(), diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java index 5ec8247ac..be0d41d9b 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2022 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -107,6 +107,15 @@ public final class ToscaUtils { } /** + * Assert that node templates have been specified correctly. + * + * @param serviceTemplate the service template containing node templates to be checked + */ + public static void assertNodeTemplatesExist(final JpaToscaServiceTemplate serviceTemplate) { + assertExist(serviceTemplate, ToscaUtils::checkNodeTemplateExist); + } + + /** * Check that data types have been specified correctly. * * @param serviceTemplate the service template containing data types to be checked @@ -135,6 +144,16 @@ public final class ToscaUtils { } /** + * Check that tosca node templates have been specified correctly. + * + * @param serviceTemplate the service template containing node templates to be checked + */ + public static boolean doNodeTemplatesExist(final JpaToscaServiceTemplate serviceTemplate) { + + return doExist(serviceTemplate, ToscaUtils::checkNodeTemplateExist); + } + + /** * Assert that something have been specified correctly. * * @param serviceTemplate the service template containing policy types to be checked @@ -207,6 +226,20 @@ public final class ToscaUtils { } /** + * Check if node templates have been specified correctly. + */ + public static String checkNodeTemplateExist(final JpaToscaServiceTemplate serviceTemplate) { + if (serviceTemplate.getTopologyTemplate().getNodeTemplates() == null) { + return "node templates not present on the service template"; + } + + if (serviceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap().isEmpty()) { + return "no parameters present on the node templates"; + } + return null; + } + + /** * getLatestPolicyTypeVersion Find all the ancestors of an entity type. * * @param entityTypes the set of entity types that exist |