diff options
author | vasraz <vasyl.razinkov@est.tech> | 2020-02-07 10:14:06 +0000 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-03-22 12:47:42 +0000 |
commit | 1a64c83fc436e17f93e468f7d46ff9f5fcb081ce (patch) | |
tree | 835abbeb362b01216df6549233d48745b9c19bb4 /catalog-be/src/main/java | |
parent | 6329f959f27920179604e1a015003a0f6614bd97 (diff) |
Add support for simple yaml profile 1.2
Change-Id: I735d25c6b6c3344c4b742f09b3aeaf4d03c2d17c
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-2738
Diffstat (limited to 'catalog-be/src/main/java')
3 files changed, 41 insertions, 13 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index dfd7c6c58d..7e26cb329f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.auditing.api.AuditEventFactory; @@ -752,13 +753,27 @@ public class ResourceImportManager { } - private void setMetaDataFromJson(UploadResourceInfo resourceMetaData, Resource resource) { + private void setMetaDataFromJson(final UploadResourceInfo resourceMetaData, final Resource resource) { this.populateResourceMetadata(resourceMetaData, resource); resource.setCreatorUserId(resourceMetaData.getContactId()); - List<CategoryDefinition> categories = resourceMetaData.getCategories(); + + final String payloadData = resourceMetaData.getPayloadData(); + if (payloadData != null) { + resource.setToscaVersion(getToscaVersion(payloadData)); + } + + final List<CategoryDefinition> categories = resourceMetaData.getCategories(); calculateResourceIsAbstract(resource, categories); } + private String getToscaVersion(final String payloadData) { + final String decodedPayload = new String(Base64.decodeBase64(payloadData)); + final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(decodedPayload); + final Either<String, ResultStatusEnum> findFirstToscaStringElement = + ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION); + return findFirstToscaStringElement.left().value(); + } + private void calculateResourceIsAbstract(Resource resource, List<CategoryDefinition> categories) { if (categories != null && !categories.isEmpty()) { CategoryDefinition categoryDef = categories.get(0); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java index 580fb737ec..fb1290310d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java @@ -87,7 +87,13 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(AbstractValidationsServlet.class); private static final String TOSCA_SIMPLE_YAML_PREFIX = "tosca_simple_yaml_"; - private static final List<String> TOSCA_DEFINITION_VERSIONS = Arrays.asList(TOSCA_SIMPLE_YAML_PREFIX + "1_0_0", TOSCA_SIMPLE_YAML_PREFIX + "1_1_0", "tosca_simple_profile_for_nfv_1_0_0", TOSCA_SIMPLE_YAML_PREFIX + "1_0", TOSCA_SIMPLE_YAML_PREFIX + "1_1"); + private static final List<String> TOSCA_DEFINITION_VERSIONS = Arrays.asList( + TOSCA_SIMPLE_YAML_PREFIX + "1_0_0", + TOSCA_SIMPLE_YAML_PREFIX + "1_1_0", + "tosca_simple_profile_for_nfv_1_0_0", + TOSCA_SIMPLE_YAML_PREFIX + "1_0", + TOSCA_SIMPLE_YAML_PREFIX + "1_1", + TOSCA_SIMPLE_YAML_PREFIX + "1_2"); private static final List<String> TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(".yml", ".yaml", ".csar"); protected ServletUtils servletUtils; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 64afee7904..1ca087d38a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -181,18 +181,22 @@ public class ToscaExportHandler { return Either.left(toscaRepresentation); } - public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component, - boolean isAssociatedComponent) { + public Either<ToscaRepresentation, ToscaError> exportComponentInterface(final Component component, + final boolean isAssociatedComponent) { if (null == DEFAULT_IMPORTS) { log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION); return Either.right(ToscaError.GENERAL_ERROR); } - ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION); + String toscaVersion = null; + if (component instanceof Resource) { + toscaVersion = ((Resource) component).getToscaVersion(); + } + ToscaTemplate toscaTemplate = new ToscaTemplate(toscaVersion != null ? toscaVersion : TOSCA_VERSION); toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS)); - Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); - Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, - toscaTemplate, nodeTypes, isAssociatedComponent); + final Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); + final Either<ToscaTemplate, ToscaError> toscaTemplateRes = + convertInterfaceNodeType(new HashMap<>(), component, toscaTemplate, nodeTypes, isAssociatedComponent); if (toscaTemplateRes.isRight()) { return Either.right(toscaTemplateRes.right().value()); } @@ -240,18 +244,21 @@ public class ToscaExportHandler { return Either.left(fillImports.left().value().left); } - private Either<ToscaTemplate, ToscaError> convertToToscaTemplate(Component component) { + private Either<ToscaTemplate, ToscaError> convertToToscaTemplate(final Component component) { if (null == DEFAULT_IMPORTS) { log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION); return Either.right(ToscaError.GENERAL_ERROR); } log.trace("start tosca export for {}", component.getUniqueId()); - ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION); - + String toscaVersion = null; + if (component instanceof Resource) { + toscaVersion = ((Resource) component).getToscaVersion(); + } + final ToscaTemplate toscaTemplate = new ToscaTemplate(toscaVersion != null ? toscaVersion : TOSCA_VERSION); toscaTemplate.setMetadata(convertMetadata(component)); toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS)); - Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); + final Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); if (ModelConverter.isAtomicComponent(component)) { log.trace("convert component as node type"); return convertNodeType(new HashMap<>(), component, toscaTemplate, nodeTypes); |