From 1a64c83fc436e17f93e468f7d46ff9f5fcb081ce Mon Sep 17 00:00:00 2001 From: vasraz Date: Fri, 7 Feb 2020 10:14:06 +0000 Subject: Add support for simple yaml profile 1.2 Change-Id: I735d25c6b6c3344c4b742f09b3aeaf4d03c2d17c Signed-off-by: Vasyl Razinkov Issue-ID: SDC-2738 --- .../sdc/asdctool/main/SdcSchemaFileImport.java | 6 +- .../be/components/impl/ResourceImportManager.java | 19 +- .../be/servlets/AbstractValidationsServlet.java | 8 +- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 27 +- .../java/org/openecomp/sdc/be/model/Resource.java | 45 +- .../jsonjanusgraph/datamodel/ToscaElement.java | 147 +--- .../operations/ToscaElementOperation.java | 19 +- .../model/jsonjanusgraph/utils/ModelConverter.java | 8 + .../org/openecomp/sdc/be/model/ResourceTest.java | 744 +++++++++------------ .../be/datatypes/enums/JsonPresentationFields.java | 5 +- .../core/converter/datatypes/Constants.java | 1 - .../services/ServiceTemplateReaderServiceImpl.java | 3 +- .../services/impl/ToscaAnalyzerServiceImpl.java | 5 +- .../services/impl/ToscaValidationServiceImpl.java | 14 +- 14 files changed, 441 insertions(+), 610 deletions(-) diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java index 47a08ea70e..676c3b45c0 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java @@ -28,6 +28,7 @@ import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao; import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.impl.FSConfigurationSource; @@ -174,9 +175,8 @@ public class SdcSchemaFileImport { yaml.setName(fileName); //Initialize the yaml contents - Map data = new LinkedHashMap<>(); - - data.put("tosca_definitions_version", TOSCA_VERSION); + final Map data = new LinkedHashMap<>(); + data.put(ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), TOSCA_VERSION); if (importFileList.length > 0) { data.put("imports", importFileList); 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 categories = resourceMetaData.getCategories(); + + final String payloadData = resourceMetaData.getPayloadData(); + if (payloadData != null) { + resource.setToscaVersion(getToscaVersion(payloadData)); + } + + final List categories = resourceMetaData.getCategories(); calculateResourceIsAbstract(resource, categories); } + private String getToscaVersion(final String payloadData) { + final String decodedPayload = new String(Base64.decodeBase64(payloadData)); + final Map mappedToscaTemplate = (Map) new Yaml().load(decodedPayload); + final Either findFirstToscaStringElement = + ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION); + return findFirstToscaStringElement.left().value(); + } + private void calculateResourceIsAbstract(Resource resource, List 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 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 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 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 exportComponentInterface(Component component, - boolean isAssociatedComponent) { + public Either 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 nodeTypes = new HashMap<>(); - Either toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, - toscaTemplate, nodeTypes, isAssociatedComponent); + final Map nodeTypes = new HashMap<>(); + final Either 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 convertToToscaTemplate(Component component) { + private Either 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 nodeTypes = new HashMap<>(); + final Map nodeTypes = new HashMap<>(); if (ModelConverter.isAtomicComponent(component)) { log.trace("convert component as node type"); return convertNodeType(new HashMap<>(), component, toscaTemplate, nodeTypes); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java index a38095a3ce..e9756b6c4e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java @@ -57,9 +57,7 @@ public class Resource extends Component { private List attributes; - private Map instInterfaces; - - private List defaultCapabilities; + private String toscaVersion; public Resource() { super(new ResourceMetadataDefinition()); @@ -75,16 +73,6 @@ public class Resource extends Component { this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE); } - @Override - public List getProperties() { - return properties; - } - - @Override - public void setProperties(List properties) { - this.properties = properties; - } - public Boolean isAbstract() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition() .getMetadataDataDefinition()) @@ -115,7 +103,6 @@ public class Resource extends Component { .setLicenseType(licenseType); } - public String getToscaResourceName() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) .getToscaResourceName(); @@ -136,36 +123,36 @@ public class Resource extends Component { .setResourceType(resourceType); } - public void setVendorName(String vendorName) { - ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setVendorName(vendorName); - } - - public void setVendorRelease(String vendorRelease) { - ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setVendorRelease(vendorRelease); - } - - public void setResourceVendorModelNumber(String resourceVendorModelNumber) { - ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()). - setResourceVendorModelNumber(resourceVendorModelNumber); - } - public String getVendorName() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) .getVendorName(); } + public void setVendorName(String vendorName) { + ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) + .setVendorName(vendorName); + } + public String getVendorRelease() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) .getVendorRelease(); } + public void setVendorRelease(String vendorRelease) { + ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) + .setVendorRelease(vendorRelease); + } + public String getResourceVendorModelNumber() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) .getResourceVendorModelNumber(); } + public void setResourceVendorModelNumber(String resourceVendorModelNumber) { + ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()). + setResourceVendorModelNumber(resourceVendorModelNumber); + } + @Override public String fetchGenericTypeToscaNameFromConfig() { String result = super.fetchGenericTypeToscaNameFromConfig(); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java index 28efb308b6..d6d3347000 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java @@ -20,6 +20,12 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.datamodel; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import lombok.Getter; +import lombok.Setter; import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; @@ -35,25 +41,21 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation; import org.openecomp.sdc.common.log.api.ILogConfiguration; import org.slf4j.MDC; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - +@Getter +@Setter public abstract class ToscaElement { protected Map metadata; protected List categories; protected Map toscaArtifacts; + protected ToscaElementTypeEnum toscaType; private Map artifacts; private Map deploymentArtifacts; private Map additionalInformation; private Map properties; private Map capabilities; - private Map capabiltiesProperties; + private Map capabilitiesProperties; private Map requirements; - - protected ToscaElementTypeEnum toscaType; // User private String creatorUserId; private String creatorFullName; @@ -61,101 +63,12 @@ public abstract class ToscaElement { private String lastUpdaterFullName; private Map allVersions; + private String toscaVersion; public ToscaElement(ToscaElementTypeEnum toscaType){ this.toscaType = toscaType; } - public Map getMetadata() { - return metadata; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - - public List getCategories() { - return categories; - } - - public void setCategories(List categories) { - this.categories = categories; - } - public Map getToscaArtifacts() { - return toscaArtifacts; - } - - public void setToscaArtifacts(Map toscaArtifacts) { - this.toscaArtifacts = toscaArtifacts; - } - - public ToscaElementTypeEnum getToscaType() { - return toscaType; - } - - public void setToscaType(ToscaElementTypeEnum toscaType) { - this.toscaType = toscaType; - } - public Map getArtifacts() { - return artifacts; - } - - public void setArtifacts(Map artifacts) { - this.artifacts = artifacts; - } - - public Map getDeploymentArtifacts() { - return deploymentArtifacts; - } - - public void setDeploymentArtifacts(Map deploymentArtifacts) { - this.deploymentArtifacts = deploymentArtifacts; - } - public Map getAdditionalInformation() { - return additionalInformation; - } - public void setAdditionalInformation(Map additionalInformation) { - this.additionalInformation = additionalInformation; - } - public Map getProperties() { - return properties; - } - public void setProperties(Map properties) { - this.properties = properties; - } - - public Map getAllVersions() { - return allVersions; - } - - public void setAllVersions(Map allVersions) { - this.allVersions = allVersions; - } - - public Map getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map capabilities) { - this.capabilities = capabilities; - } - - public Map getRequirements() { - return requirements; - } - - public void setRequirements(Map requirements) { - this.requirements = requirements; - } - - public Map getCapabilitiesProperties() { - return capabiltiesProperties; - } - - public void setCapabilitiesProperties(Map capabiltiesProperties) { - this.capabiltiesProperties = capabiltiesProperties; - } - // metadata properties // ---------------------------- public Object getMetadataValue(JsonPresentationFields name) { @@ -294,42 +207,16 @@ public abstract class ToscaElement { return (Long)archiveTime; } - public void setArchiveTime(Long archiveTime) { setMetadataValue(JsonPresentationFields.ARCHIVE_TIME, archiveTime); } - - public Boolean isVspArchived() { return (Boolean) getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED); } - - public void setVspArchived(Boolean vspArchived) { setMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED, vspArchived); } - - public String getCreatorUserId() { - return creatorUserId; - } - - public void setCreatorUserId(String creatorUserId) { - this.creatorUserId = creatorUserId; - } - - public String getCreatorFullName() { - return creatorFullName; - } - - public void setCreatorFullName(String creatorFullName) { - this.creatorFullName = creatorFullName; - } - - public String getLastUpdaterUserId() { - return lastUpdaterUserId; - } - - public void setLastUpdaterUserId(String lastUpdaterUserId) { - this.lastUpdaterUserId = lastUpdaterUserId; + public void setArchiveTime(Long archiveTime) { + setMetadataValue(JsonPresentationFields.ARCHIVE_TIME, archiveTime); } - public String getLastUpdaterFullName() { - return lastUpdaterFullName; + public Boolean isVspArchived() { + return (Boolean) getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED); } - public void setLastUpdaterFullName(String lastUpdaterFullName) { - this.lastUpdaterFullName = lastUpdaterFullName; + public void setVspArchived(Boolean vspArchived) { + setMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED, vspArchived); } public void generateUUID() { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java index e973400963..ec1185a706 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java @@ -24,7 +24,6 @@ import java.lang.reflect.Type; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; - import org.apache.commons.collections.CollectionUtils; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; @@ -60,6 +59,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.jsongraph.util.CommonUtility; import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -170,7 +170,7 @@ public abstract class ToscaElementOperation extends BaseOperation { } if (result == null) { createdToscaElementVertex = createNextVersionRes.left().value(); - Map properties = new HashMap<>(); + final Map properties = new EnumMap<>(EdgePropertyEnum.class); properties.put(EdgePropertyEnum.STATE, createdToscaElementVertex.getMetadataProperty(GraphPropertyEnum.STATE)); status = janusGraphDao .createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.STATE, properties); @@ -321,7 +321,10 @@ public abstract class ToscaElementOperation extends BaseOperation { nodeTypeVertex.setUniqueId(toscaElement.getUniqueId()); nodeTypeVertex.setType(toscaElement.getComponentType()); - + final String toscaVersion = toscaElement.getToscaVersion(); + if (toscaVersion != null) { + nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.TOSCA_DEFINITIONS_VERSION, toscaVersion); + } } protected StorageOperationStatus assosiateToUsers(GraphVertex nodeTypeVertex, ToscaElement toscaElement) { @@ -729,7 +732,7 @@ public abstract class ToscaElementOperation extends BaseOperation { List components = new ArrayList<>(); List componentsPerUser; - HashSet ids = new HashSet(); + final Set ids = new HashSet<>(); Either, JanusGraphOperationStatus> childrenVertecies = janusGraphDao.getChildrenVertices(userV, EdgeLabelEnum.STATE, JsonParseFlagEnum.NoParse); if (childrenVertecies.isRight() && childrenVertecies.right().value() != JanusGraphOperationStatus.NOT_FOUND) { log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.STATE, childrenVertecies.right().value()); @@ -918,9 +921,15 @@ public abstract class ToscaElementOperation extends BaseOperation { break; } - Map jsonMetada = componentV.getMetadataJson(); if (toscaElement != null) { + final Map jsonMetada = componentV.getMetadataJson(); toscaElement.setMetadata(jsonMetada); + if (jsonMetada != null) { + final Object toscaVersion = jsonMetada.get(ToscaTagNamesEnum.TOSCA_VERSION.getElementName()); + if (toscaVersion != null) { + toscaElement.setToscaVersion((String) toscaVersion); + } + } } return (T) toscaElement; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java index c16c8a98e5..ae854254c2 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java @@ -246,6 +246,10 @@ public class ModelConverter { resource.setDerivedList(nodeType.getDerivedList()); resource.setDerivedFromMapOfIdToName(nodeType.getDerivedFromMapOfIdToName()); resource.setAbstract((Boolean) nodeType.getMetadataValue(JsonPresentationFields.IS_ABSTRACT)); + final String toscaVersion = nodeType.getToscaVersion(); + if (toscaVersion != null) { + resource.setToscaVersion(toscaVersion); + } convertAttributes(nodeType, resource); convertCapabilities(nodeType, resource); convertRequirements(nodeType, resource); @@ -798,6 +802,10 @@ public class ModelConverter { nodeType.setDerivedFrom(resource.getDerivedFrom()); nodeType.setDerivedList(resource.getDerivedList()); nodeType.setResourceType(resource.getResourceType()); + final String toscaVersion = resource.getToscaVersion(); + if (toscaVersion != null) { + nodeType.setToscaVersion(toscaVersion); + } convertCommonToscaData(component, nodeType); convertAdditionalInformation(component, nodeType); convertArtifacts(resource, nodeType); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java index c53e4e00bb..bb72c53033 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,421 +28,329 @@ import org.junit.Test; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest; -public class ResourceTest extends ModelConfDependentTest{ - - private Resource createTestSubject() { - return new Resource(); - } - - @Test - public void testCtor() throws Exception { - ComponentMetadataDefinition componentMetadataDefinition = new ResourceMetadataDefinition(); - new Resource(componentMetadataDefinition); - } - - @Test - public void testGetDerivedFrom() throws Exception { - Resource testSubject; - List result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDerivedFrom(); - } - - - @Test - public void testSetDerivedFrom() throws Exception { - Resource testSubject; - List derivedFrom = null; - - // default test - testSubject = createTestSubject(); - testSubject.setDerivedFrom(derivedFrom); - } - - - @Test - public void testGetDerivedList() throws Exception { - Resource testSubject; - List result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDerivedList(); - } - - - @Test - public void testSetDerivedList() throws Exception { - Resource testSubject; - List derivedList = null; - - // default test - testSubject = createTestSubject(); - testSubject.setDerivedList(derivedList); - } - - - @Test - public void testGetProperties() throws Exception { - Resource testSubject; - List result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getProperties(); - } - - - @Test - public void testSetProperties() throws Exception { - Resource testSubject; - List properties = null; - - // default test - testSubject = createTestSubject(); - testSubject.setProperties(properties); - } - - - @Test - public void testGetAttributes() throws Exception { - Resource testSubject; - List result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAttributes(); - } - - - @Test - public void testSetAttributes() throws Exception { - Resource testSubject; - List attributes = null; - - // default test - testSubject = createTestSubject(); - testSubject.setAttributes(attributes); - } - - - @Test - public void testGetInterfaces() throws Exception { - Resource testSubject; - Map result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getInterfaces(); - } - - - @Test - public void testSetInterfaces() throws Exception { - Resource testSubject; - Map interfaces = null; - - // default test - testSubject = createTestSubject(); - testSubject.setInterfaces(interfaces); - } - - - @Test - public void testIsAbstract() throws Exception { - Resource testSubject; - Boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.isAbstract(); - } - - - @Test - public void testSetAbstract() throws Exception { - Resource testSubject; - Boolean isAbstract = null; - - // default test - testSubject = createTestSubject(); - testSubject.setAbstract(isAbstract); - } - - - @Test - public void testGetDefaultCapabilities() throws Exception { - Resource testSubject; - List result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDefaultCapabilities(); - } - - - @Test - public void testSetDefaultCapabilities() throws Exception { - Resource testSubject; - List defaultCapabilities = null; - - // default test - testSubject = createTestSubject(); - testSubject.setDefaultCapabilities(defaultCapabilities); - } - - - @Test - public void testGetCost() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getCost(); - } - - - @Test - public void testSetCost() throws Exception { - Resource testSubject; - String cost = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setCost(cost); - } - - - @Test - public void testGetLicenseType() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getLicenseType(); - } - - - @Test - public void testSetLicenseType() throws Exception { - Resource testSubject; - String licenseType = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setLicenseType(licenseType); - } - - - @Test - public void testHashCode() throws Exception { - Resource testSubject; - int result; - - // default test - testSubject = createTestSubject(); - result = testSubject.hashCode(); - } - - - @Test - public void testEquals() throws Exception { - Resource testSubject; - Object obj = null; - boolean result; - - // test 1 - testSubject = createTestSubject(); - result = testSubject.equals(obj); - Assert.assertEquals(false, result); - obj = new Object(); - result = testSubject.equals(obj); - Assert.assertEquals(false, result); - result = testSubject.equals(testSubject); - Assert.assertEquals(true, result); - - Resource testSubject2 = createTestSubject(); - result = testSubject.equals(testSubject2); - Assert.assertEquals(true, result); - } - - - @Test - public void testToString() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); - } - - - @Test - public void testGetToscaResourceName() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getToscaResourceName(); - } - - - @Test - public void testSetToscaResourceName() throws Exception { - Resource testSubject; - String toscaResourceName = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setToscaResourceName(toscaResourceName); - } - - - @Test - public void testGetResourceType() throws Exception { - Resource testSubject; - ResourceTypeEnum result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResourceType(); - } - - - @Test - public void testSetResourceType() throws Exception { - Resource testSubject; - ResourceTypeEnum resourceType = null; - - // default test - testSubject = createTestSubject(); - testSubject.setResourceType(resourceType); - } - - - @Test - public void testSetVendorName() throws Exception { - Resource testSubject; - String vendorName = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setVendorName(vendorName); - } - - - @Test - public void testSetVendorRelease() throws Exception { - Resource testSubject; - String vendorRelease = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setVendorRelease(vendorRelease); - } - - - @Test - public void testSetResourceVendorModelNumber() throws Exception { - Resource testSubject; - String resourceVendorModelNumber = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setResourceVendorModelNumber(resourceVendorModelNumber); - } - - - @Test - public void testGetVendorName() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getVendorName(); - } - - - @Test - public void testGetVendorRelease() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getVendorRelease(); - } - - - @Test - public void testGetResourceVendorModelNumber() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResourceVendorModelNumber(); - } - - @Test - public void testFetchGenericTypeToscaNameFromConfig() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.fetchGenericTypeToscaNameFromConfig(); - } - - @Test - public void testAssetType() throws Exception { - Resource testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.assetType(); - } - - - @Test - public void testShouldGenerateInputs() throws Exception { - Resource testSubject; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.shouldGenerateInputs(); - } - - - @Test - public void testDeriveFromGeneric() throws Exception { - Resource testSubject; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.deriveFromGeneric(); - } - - @Test - public void testGroupRelationsByInstanceName() throws Exception { - Resource testSubject; - Map> result; - - // default test - testSubject = createTestSubject(); - Resource resource = new Resource(); - resource.setComponentInstancesRelations(new LinkedList()); - result = testSubject.groupRelationsFromCsarByInstanceName(resource); - } +public class ResourceTest extends ModelConfDependentTest { + + private Resource createTestSubject() { + return new Resource(); + } + + @Test + public void testCtor() throws Exception { + ComponentMetadataDefinition componentMetadataDefinition = new ResourceMetadataDefinition(); + new Resource(componentMetadataDefinition); + } + + @Test + public void testGetProperties() throws Exception { + Resource testSubject; + List result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getProperties(); + } + + @Test + public void testSetProperties() throws Exception { + Resource testSubject; + List properties = null; + + // default test + testSubject = createTestSubject(); + testSubject.setProperties(properties); + } + + @Test + public void testGetAttributes() throws Exception { + Resource testSubject; + List result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getAttributes(); + } + + @Test + public void testSetAttributes() throws Exception { + Resource testSubject; + List attributes = null; + + // default test + testSubject = createTestSubject(); + testSubject.setAttributes(attributes); + } + + @Test + public void testGetInterfaces() throws Exception { + Resource testSubject; + Map result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getInterfaces(); + } + + @Test + public void testSetInterfaces() throws Exception { + Resource testSubject; + Map interfaces = null; + + // default test + testSubject = createTestSubject(); + testSubject.setInterfaces(interfaces); + } + + @Test + public void testIsAbstract() throws Exception { + Resource testSubject; + Boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.isAbstract(); + } + + @Test + public void testSetAbstract() throws Exception { + Resource testSubject; + Boolean isAbstract = null; + + // default test + testSubject = createTestSubject(); + testSubject.setAbstract(isAbstract); + } + + @Test + public void testGetCost() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getCost(); + } + + @Test + public void testSetCost() throws Exception { + Resource testSubject; + String cost = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setCost(cost); + } + + @Test + public void testGetLicenseType() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getLicenseType(); + } + + @Test + public void testSetLicenseType() throws Exception { + Resource testSubject; + String licenseType = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setLicenseType(licenseType); + } + + @Test + public void testHashCode() throws Exception { + Resource testSubject; + int result; + + // default test + testSubject = createTestSubject(); + result = testSubject.hashCode(); + } + + @Test + public void testEquals() throws Exception { + Resource testSubject; + Object obj = null; + boolean result; + + // test 1 + testSubject = createTestSubject(); + result = testSubject.equals(obj); + Assert.assertEquals(false, result); + obj = new Object(); + result = testSubject.equals(obj); + Assert.assertEquals(false, result); + result = testSubject.equals(testSubject); + Assert.assertEquals(true, result); + + Resource testSubject2 = createTestSubject(); + result = testSubject.equals(testSubject2); + Assert.assertEquals(true, result); + } + + @Test + public void testToString() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.toString(); + } + + @Test + public void testGetToscaResourceName() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getToscaResourceName(); + } + + @Test + public void testSetToscaResourceName() throws Exception { + Resource testSubject; + String toscaResourceName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setToscaResourceName(toscaResourceName); + } + + @Test + public void testGetResourceType() throws Exception { + Resource testSubject; + ResourceTypeEnum result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResourceType(); + } + + @Test + public void testSetResourceType() throws Exception { + Resource testSubject; + ResourceTypeEnum resourceType = null; + + // default test + testSubject = createTestSubject(); + testSubject.setResourceType(resourceType); + } + + @Test + public void testSetVendorName() throws Exception { + Resource testSubject; + String vendorName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setVendorName(vendorName); + } + + @Test + public void testSetVendorRelease() throws Exception { + Resource testSubject; + String vendorRelease = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setVendorRelease(vendorRelease); + } + + @Test + public void testSetResourceVendorModelNumber() throws Exception { + Resource testSubject; + String resourceVendorModelNumber = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setResourceVendorModelNumber(resourceVendorModelNumber); + } + + @Test + public void testGetVendorName() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getVendorName(); + } + + @Test + public void testGetVendorRelease() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getVendorRelease(); + } + + @Test + public void testGetResourceVendorModelNumber() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResourceVendorModelNumber(); + } + + @Test + public void testFetchGenericTypeToscaNameFromConfig() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.fetchGenericTypeToscaNameFromConfig(); + } + + @Test + public void testAssetType() throws Exception { + Resource testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.assetType(); + } + + @Test + public void testShouldGenerateInputs() throws Exception { + Resource testSubject; + boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.shouldGenerateInputs(); + } + + @Test + public void testDeriveFromGeneric() throws Exception { + Resource testSubject; + boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.deriveFromGeneric(); + } + + @Test + public void testGroupRelationsByInstanceName() throws Exception { + Resource testSubject; + Map> result; + + // default test + testSubject = createTestSubject(); + Resource resource = new Resource(); + resource.setComponentInstancesRelations(new LinkedList()); + result = testSubject.groupRelationsFromCsarByInstanceName(resource); + } } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java index b84baff861..027519500f 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java @@ -246,7 +246,10 @@ public enum JsonPresentationFields { GET_PROPERTY("get_property", null), GET_INPUT("get_input", null), - GET_OPERATION_OUTPUT("get_operation_output", null); + GET_OPERATION_OUTPUT("get_operation_output", null), + + TOSCA_DEFINITIONS_VERSION("tosca_definitions_version", null); + private String presentation; private GraphPropertyEnum storedAs; diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java index 18e6a49aa5..c9f5548681 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java @@ -26,7 +26,6 @@ public class Constants { public static final String metadataFile = "TOSCA-Metadata/TOSCA.meta"; - public static final String definitionVersion = "tosca_definitions_version"; private static final String DEFAULT_NAMESPACE = "tosca_default_namespace"; private static final String TEMPLATE_NAME = "template_name"; public static final String topologyTemplate = "topology_template"; diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java index f41caff349..9b1c0126c7 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import static org.openecomp.core.converter.datatypes.Constants.*; @@ -69,7 +70,7 @@ public class ServiceTemplateReaderServiceImpl implements ServiceTemplateReaderSe @Override public Object getToscaVersion() { - return this.readServiceTemplate.get(definitionVersion); + return this.readServiceTemplate.get(ToscaTagNamesEnum.TOSCA_VERSION.getElementName()); } @Override diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java index 1bc547aed7..3ce9badea0 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java @@ -56,6 +56,7 @@ import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.SdcRuntimeException; import org.openecomp.sdc.common.zip.ZipUtils; @@ -192,8 +193,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { } private boolean isToscaYamlFile(byte[] fileContent) { - Map fileMap = new YamlUtil().yamlToObject(new String(fileContent), Map.class); - return fileMap.containsKey("tosca_definitions_version"); + final Map fileMap = new YamlUtil().yamlToObject(new String(fileContent), Map.class); + return fileMap.containsKey(ToscaTagNamesEnum.TOSCA_VERSION.getElementName()); } private void updateMinMaxOccurencesForNodeTypeRequirement(Map.Entry entry, diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java index 0394073e57..9f3dd0790f 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java @@ -26,6 +26,7 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.logging.api.Logger; @@ -55,7 +56,6 @@ public class ToscaValidationServiceImpl implements ToscaValidationService { private static final String SDCPARSER_JTOSCA_VALIDATIONISSUE_CONFIG = "SDCParser_jtosca-validation-issue-configuration.yaml"; private static final String SDCPARSER_ERROR_CONFIG = "SDCParser_error-configuration.yaml"; - private static final String TOSCA_DEFINITION_VERSION = "tosca_definitions_version"; static { // Override default SDC Parser configuration @@ -119,17 +119,17 @@ public class ToscaValidationServiceImpl implements ToscaValidationService { .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private boolean isToscaYaml(String filePath) { + private boolean isToscaYaml(final String filePath) { boolean retValue = false; - try (InputStream input = new BufferedInputStream(new FileInputStream(new File(filePath)));) { - Yaml yaml = new Yaml(); - LinkedHashMap data = (LinkedHashMap) yaml.load(input); - if(data.get(TOSCA_DEFINITION_VERSION) != null) { + try (final InputStream input = new BufferedInputStream(new FileInputStream(new File(filePath)));) { + final Yaml yaml = new Yaml(); + final LinkedHashMap data = (LinkedHashMap) yaml.load(input); + if(data.get(ToscaTagNamesEnum.TOSCA_VERSION.getElementName()) != null) { retValue = true; } } - catch(Exception e){ + catch(final Exception e){ LOGGER.info("Ignore the exception as the input file may not be a Tosca Yaml; let the " + "default value return", e); } -- cgit 1.2.3-korg