summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java209
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java161
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java97
-rw-r--r--catalog-be/src/test/resources/sdc.zipbin0 -> 28382 bytes
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java176
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/NodeType.java48
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java30
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java75
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java19
9 files changed, 481 insertions, 334 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index 2721fda2c5..e50523854d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -22,14 +22,36 @@ package org.openecomp.sdc.be.tosca;
import fj.data.Either;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.lang.WordUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
+import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -45,6 +67,7 @@ import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Product;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
@@ -57,6 +80,7 @@ import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
import org.openecomp.sdc.be.utils.CommonBeUtils;
+import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
@@ -69,26 +93,7 @@ import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.common.zip.ZipUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
+import org.yaml.snakeyaml.Yaml;
/**
* @author tg851x
@@ -290,16 +295,16 @@ public class CsarUtils {
Either<byte[], ResponseFormat> latestSchemaFilesFromCassandra = getLatestSchemaFilesFromCassandra();
if(latestSchemaFilesFromCassandra.isRight()){
- log.error("Error retrieving SDC Schema files from cassandra" );
+ log.error("Error retrieving SDC Schema files from cassandra");
return Either.right(latestSchemaFilesFromCassandra.right().value());
}
- //add files from retrieved SDC.zip to Definitions folder in CSAR
- Either<ZipOutputStream, ResponseFormat> addSchemaFilesFromCassandra = addSchemaFilesFromCassandra(zip, latestSchemaFilesFromCassandra.left().value());
+ final byte[] schemaFileZip = latestSchemaFilesFromCassandra.left().value();
- if(addSchemaFilesFromCassandra.isRight()){
- return addSchemaFilesFromCassandra;
- }
+ final List<String> nodesFromPackage = findNonRootNodesFromPackage(dependencies);
+
+ //add files from retrieved SDC.zip to Definitions folder in CSAR
+ addSchemaFilesFromCassandra(zip, schemaFileZip, nodesFromPackage);
Either<CsarDefinition, ResponseFormat> collectedComponentCsarDefinition = collectComponentCsarDefinition(component);
@@ -311,8 +316,8 @@ public class CsarUtils {
for (CsarEntryGenerator generator: generators) {
log.debug("Invoking CsarEntryGenerator: {}", generator.getClass().getName());
for (Entry<String, byte[]> pluginGeneratedFile : generator.generateCsarEntries(component).entrySet()) {
- zip.putNextEntry(new ZipEntry(pluginGeneratedFile.getKey()));
- zip.write(pluginGeneratedFile.getValue());
+ zip.putNextEntry(new ZipEntry(pluginGeneratedFile.getKey()));
+ zip.write(pluginGeneratedFile.getValue());
}
}
}
@@ -320,6 +325,84 @@ public class CsarUtils {
return writeAllFilesToCsar(component, collectedComponentCsarDefinition.left().value(), zip, isInCertificationRequest);
}
+ /**
+ * Create a list of all derived nodes found on the package
+ *
+ * @param dependencies all node dependencies
+ * @return a list of nodes
+ */
+ private List<String> findNonRootNodesFromPackage(final List<Triple<String, String, Component>> dependencies) {
+ final List<String> nodes = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(dependencies)) {
+ final String NATIVE_ROOT = "tosca.nodes.Root";
+ dependencies.forEach(dependency -> {
+ if (dependency.getRight() instanceof Resource) {
+ final Resource resource = (Resource) dependency.getRight();
+ if (CollectionUtils.isNotEmpty(resource.getDerivedList())) {
+ resource.getDerivedList().stream()
+ .filter(node -> !nodes.contains(node) && !NATIVE_ROOT.equalsIgnoreCase(node))
+ .forEach(node -> nodes.add(node));
+ }
+ }
+ });
+ }
+ return nodes;
+ }
+
+ /**
+ * Writes a new zip entry
+ *
+ * @param zipInputStream the zip entry to be read
+ * @return a map of the given zip entry
+ */
+ private Map<String, Object> readYamlZipEntry(final ZipInputStream zipInputStream) throws IOException {
+ final int initSize = 2048;
+ final StringBuilder zipEntry = new StringBuilder();
+ final byte[] buffer = new byte[initSize];
+ int read = 0;
+ while ((read = zipInputStream.read(buffer, 0, initSize)) >= 0) {
+ zipEntry.append(new String(buffer, 0, read));
+ }
+
+ return (Map<String, Object>) new Yaml().load(zipEntry.toString());
+ }
+
+ /**
+ * Filters and removes all duplicated nodes found
+ *
+ * @param nodesFromPackage a List of all derived nodes found on the given package
+ * @param nodesFromArtifactFile represents the nodes.yml file stored in Cassandra
+ * @return a nodes Map updated
+ */
+ private Map<String, Object> updateNodeYml(final List<String> nodesFromPackage,
+ final Map<String, Object> nodesFromArtifactFile) {
+
+ if (MapUtils.isNotEmpty(nodesFromArtifactFile)) {
+ final String nodeTypeBlock = ToscaTagNamesEnum.NODE_TYPES.getElementName();
+ final Map<String, Object> nodeTypes = (Map<String, Object>) nodesFromArtifactFile.get(nodeTypeBlock);
+ nodesFromPackage.stream()
+ .filter(nodeTypes::containsKey)
+ .forEach(nodeTypes::remove);
+
+ nodesFromArtifactFile.replace(nodeTypeBlock, nodeTypes);
+ }
+
+ return nodesFromArtifactFile;
+ }
+
+ /**
+ * Updates the zip entry from the given parameters
+ *
+ * @param byteArrayOutputStream an output stream in which the data is written into a byte array.
+ * @param nodesYaml a Map of nodes to be written
+ */
+ private void updateZipEntry(final ByteArrayOutputStream byteArrayOutputStream,
+ final Map<String, Object> nodesYaml) throws IOException {
+ if (MapUtils.isNotEmpty(nodesYaml)) {
+ byteArrayOutputStream.write(new YamlUtil().objectToYaml(nodesYaml).getBytes());
+ }
+ }
+
private Either<ZipOutputStream, ResponseFormat> getZipOutputStreamResponseFormatEither(ZipOutputStream zip, List<Triple<String, String, Component>> dependencies, Map<String, ImmutableTriple<String, String, Component>> innerComponentsCache) throws IOException {
String fileName;
if (dependencies != null && !dependencies.isEmpty()) {
@@ -374,43 +457,57 @@ public class CsarUtils {
return null;
}
- private Either<ZipOutputStream, ResponseFormat> addSchemaFilesFromCassandra(ZipOutputStream zip, byte[] schemaFileZip) {
-
- final int initSize = 2048;
-
- log.debug("Starting copy from Schema file zip to CSAR zip");
- try (final ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(schemaFileZip));
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final BufferedOutputStream bos = new BufferedOutputStream(out, initSize)) {
-
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- ZipUtils.checkForZipSlipInRead(entry);
- final String entryName = entry.getName();
- int readSize = initSize;
- final byte[] entryData = new byte[initSize];
-
+ private void addSchemaFilesFromCassandra(final ZipOutputStream zip,
+ final byte[] schemaFileZip,
+ final List<String> nodesFromPackage) {
+ final int initSize = 2048;
+ log.debug("Starting copy from Schema file zip to CSAR zip");
+ try (final ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(schemaFileZip));
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final BufferedOutputStream bos = new BufferedOutputStream(out, initSize)) {
+
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ ZipUtils.checkForZipSlipInRead(entry);
+ final String entryName = entry.getName();
+ int readSize = initSize;
+ final byte[] entryData = new byte[initSize];
+ if (entryName.equalsIgnoreCase("nodes.yml")) {
+ handleNode(zipStream, out, nodesFromPackage);
+ } else {
while ((readSize = zipStream.read(entryData, 0, readSize)) != -1) {
bos.write(entryData, 0, readSize);
}
-
bos.flush();
- out.flush();
- zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + entryName));
- zip.write(out.toByteArray());
- zip.flush();
- out.reset();
}
- } catch (final Exception e) {
- log.error("Error while writing the SDC schema file to the CSAR", e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ out.flush();
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + entryName));
+ zip.write(out.toByteArray());
+ zip.flush();
+ out.reset();
}
-
- log.debug("Finished coppy from Schema file zip to CSAR zip");
- return Either.left(zip);
+ } catch (final Exception e) {
+ log.error("Error while writing the SDC schema file to the CSAR", e);
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
+ log.debug("Finished copy from Schema file zip to CSAR zip");
+ }
+ /**
+ * Handles the nodes.yml zip entry, updating the nodes.yml to avoid duplicated nodes on it.
+ *
+ * @param zipInputStream the zip entry to be read
+ * @param byteArrayOutputStream an output stream in which the data is written into a byte array.
+ * @param nodesFromPackage list of all nodes found on the onboarded package
+ */
+ private void handleNode(final ZipInputStream zipInputStream,
+ final ByteArrayOutputStream byteArrayOutputStream,
+ final List<String> nodesFromPackage) throws IOException {
+ final Map<String, Object> nodesFromArtifactFile = readYamlZipEntry(zipInputStream);
+ final Map<String, Object> nodesYaml = updateNodeYml(nodesFromPackage, nodesFromArtifactFile);
+ updateZipEntry(byteArrayOutputStream, nodesYaml);
+ }
private void addInnerComponentsToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache,
Component childComponent) {
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 976842136f..64afee7904 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
@@ -163,7 +163,8 @@ public class ToscaExportHandler {
private static final String FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION = "convertToToscaTemplate - failed to get Default Imports section from configuration";
private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
private static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS = ConfigurationManager
- .getConfigurationManager().getConfiguration().getDefaultImports();
+ .getConfigurationManager().getConfiguration().getDefaultImports();
+ private static final String NATIVE_ROOT = "tosca.nodes.Root";
private static YamlUtil yamlUtil = new YamlUtil();
public ToscaExportHandler(){}
@@ -505,60 +506,142 @@ public class ToscaExportHandler {
return Either.left(new ImmutablePair<>(toscaTemplate, componentCache));
}
- private void createDependency(Map<String, Component> componentCache, List<Map<String, Map<String, String>>> imports,
- List<Triple<String, String, Component>> dependecies, ComponentInstance ci) {
- Map<String, String> files = new HashMap<>();
- Map<String, Map<String, String>> importsListMember = new HashMap<>();
- StringBuilder keyNameBuilder;
-
- Component componentRI = componentCache.get(ci.getComponentUid());
+ private void createDependency(final Map<String, Component> componentCache,
+ final List<Map<String, Map<String, String>>> imports,
+ final List<Triple<String, String, Component>> dependencies,
+ final ComponentInstance componentInstance) {
+ log.debug("createDependency componentCache {}",componentCache);
+ final Component componentRI = componentCache.get(componentInstance.getComponentUid());
if (componentRI == null) {
// all resource must be only once!
- Either<Component, StorageOperationStatus> resource = toscaOperationFacade
- .getToscaFullElement(ci.getComponentUid());
+ final Either<Component, StorageOperationStatus> resource = toscaOperationFacade
+ .getToscaFullElement(componentInstance.getComponentUid());
if ((resource.isRight()) && (log.isDebugEnabled())) {
- log.debug("Failed to fetch resource with id {} for instance {}",ci.getComponentUid() ,ci.getUniqueId());
+ log.debug("Failed to fetch resource with id {} for instance {}", componentInstance.getComponentUid(),
+ componentInstance.getUniqueId());
return ;
}
+ final Component fetchedComponent = resource.left().value();
+ setComponentCache(componentCache, componentInstance, fetchedComponent);
+ addDependencies(imports, dependencies, fetchedComponent);
+ }
+ }
- Component fetchedComponent = resource.left().value();
- componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent);
+ /**
+ * Sets a componentCache from the given component/resource.
+ */
+ private void setComponentCache(final Map<String, Component> componentCache,
+ final ComponentInstance componentInstance,
+ final Component fetchedComponent) {
+ componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent);
+ if (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
+ final Either<Component, StorageOperationStatus> sourceService = toscaOperationFacade
+ .getToscaFullElement(componentInstance.getSourceModelUid());
+ if (sourceService.isRight() && (log.isDebugEnabled())) {
+ log.debug("Failed to fetch source service with id {} for proxy {}",
+ componentInstance.getSourceModelUid(), componentInstance.getUniqueId());
+ }
+ final Component fetchedSource = sourceService.left().value();
+ componentCache.put(fetchedSource.getUniqueId(), fetchedSource);
+ }
+ }
- if (ci.getOriginType() == OriginTypeEnum.ServiceProxy){
- Either<Component, StorageOperationStatus> sourceService = toscaOperationFacade
- .getToscaFullElement(ci.getSourceModelUid());
- if (sourceService.isRight() && (log.isDebugEnabled())) {
- log.debug("Failed to fetch source service with id {} for proxy {}", ci.getSourceModelUid(), ci.getUniqueId());
- }
- Component fetchedSource = sourceService.left().value();
- componentCache.put(fetchedSource.getUniqueId(), fetchedSource);
+ /**
+ * Retrieves all derived_from nodes and stores it in a predictable order.
+ */
+ private void addDependencies(final List<Map<String, Map<String, String>>> imports,
+ final List<Triple<String, String, Component>> dependencies,
+ final Component fetchedComponent) {
+ final Set<Component> componentsList = new LinkedHashSet<>();
+ if (fetchedComponent instanceof Resource) {
+ log.debug("fetchedComponent is a resource {}",fetchedComponent);
+
+ final Optional<Map<String, String>> derivedFromMapOfIdToName = getDerivedFromMapOfIdToName(fetchedComponent, componentsList);
+ if (derivedFromMapOfIdToName.isPresent()) {
+ derivedFromMapOfIdToName.get().entrySet().forEach(entry -> {
+ log.debug("Started entry.getValue() : {}",entry.getValue());
+ if (!NATIVE_ROOT.equals(entry.getValue())) {
+ Either<Resource, StorageOperationStatus> resourcefetched = toscaOperationFacade
+ .getToscaElement(entry.getKey());
+ if (resourcefetched != null && resourcefetched.isLeft()) {
+ componentsList.add(resourcefetched.left().value());
+ }
+ }
+ });
}
+ setImports(imports, dependencies, componentsList);
+ }
+ }
- componentRI = fetchedComponent;
+ /**
+ * Returns all derived_from nodes found.
+ */
+ private Optional<Map<String, String>> getDerivedFromMapOfIdToName(final Component fetchedComponent,
+ final Set<Component> componentsList) {
+ final Resource parentResource = (Resource) fetchedComponent;
+ Map<String, String> derivedFromMapOfIdToName = new HashMap<>();
+ if(CollectionUtils.isNotEmpty(parentResource.getComponentInstances())) {
+ componentsList.add(fetchedComponent);
+ for (final ComponentInstance componentInstance : parentResource.getComponentInstances()) {
+ final Either<Resource, StorageOperationStatus> resourcefetched = toscaOperationFacade
+ .getToscaElement(componentInstance.getComponentUid());
+ if (resourcefetched != null && resourcefetched.isLeft()) {
+ final Map<String, String> derivedWithId = resourcefetched.left().value().getDerivedFromMapOfIdToName();
+ if (MapUtils.isNotEmpty(derivedWithId)) {
+ derivedFromMapOfIdToName.putAll(derivedWithId);
+ }
+ }
+ }
+ } else {
+ derivedFromMapOfIdToName = parentResource.getDerivedFromMapOfIdToName();
+ }
+ log.debug("Started derivedFromMapOfIdToName: {}", derivedFromMapOfIdToName);
+ return Optional.ofNullable(derivedFromMapOfIdToName);
+ }
- Map<String, ArtifactDefinition> toscaArtifacts = componentRI.getToscaArtifacts();
- ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE);
+ /**
+ * Creates a resource map and adds it to the import list.
+ */
+ private void setImports(final List<Map<String, Map<String, String>>> imports,
+ final List<Triple<String, String, Component>> dependencies,
+ final Set<Component> componentsList) {
+ componentsList.forEach(component -> {
+ final Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ final ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE);
if (artifactDefinition != null) {
- String artifactName = artifactDefinition.getArtifactName();
+ final Map<String, String> files = new HashMap<>();
+ final String artifactName = artifactDefinition.getArtifactName();
files.put(IMPORTS_FILE_KEY, artifactName);
- keyNameBuilder = new StringBuilder();
- keyNameBuilder.append(fetchedComponent.getComponentType().toString().toLowerCase());
+ final StringBuilder keyNameBuilder = new StringBuilder();
+ keyNameBuilder.append(component.getComponentType().toString().toLowerCase());
keyNameBuilder.append("-");
- keyNameBuilder.append(ci.getComponentName());
- importsListMember.put(keyNameBuilder.toString(), files);
- imports.add(importsListMember);
- dependecies.add(new ImmutableTriple<>(artifactName,
- artifactDefinition.getEsId(), fetchedComponent));
-
- if (!ModelConverter.isAtomicComponent(componentRI)) {
- importsListMember = new HashMap<>();
- Map<String, String> interfaceFiles = new HashMap<>();
+ keyNameBuilder.append(component.getName());
+ addImports(imports, keyNameBuilder, files);
+ dependencies
+ .add(new ImmutableTriple<String, String, Component>(artifactName, artifactDefinition.getEsId(),
+ component));
+
+ if (!ModelConverter.isAtomicComponent(component)) {
+ final Map<String, String> interfaceFiles = new HashMap<>();
interfaceFiles.put(IMPORTS_FILE_KEY, getInterfaceFilename(artifactName));
keyNameBuilder.append("-interface");
- importsListMember.put(keyNameBuilder.toString(), interfaceFiles);
- imports.add(importsListMember);
+ addImports(imports, keyNameBuilder, interfaceFiles);
}
}
+ });
+ }
+
+ /**
+ * Adds the found resource to the import definition list.
+ */
+ private void addImports(final List<Map<String, Map<String, String>>> imports,
+ final StringBuilder keyNameBuilder,
+ final Map<String, String> files) {
+ final String mapKey = keyNameBuilder.toString();
+ if (imports.stream().allMatch(stringMapMap -> stringMapMap.get(mapKey) == null)) {
+ final Map<String, Map<String, String>> importsListMember = new HashMap<>();
+ importsListMember.put(keyNameBuilder.toString(), files);
+ imports.add(importsListMember);
}
}
@@ -952,7 +1035,7 @@ public class ToscaExportHandler {
toscaNodeType.setDescription(component.getDescription());
} else {
String derivedFrom = null != component.getDerivedFromGenericType() ? component.getDerivedFromGenericType()
- : "tosca.nodes.Root";
+ : NATIVE_ROOT;
toscaNodeType.setDerived_from(derivedFrom);
}
return toscaNodeType;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
index a838ded853..cdea369fe8 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
@@ -20,12 +20,34 @@
package org.openecomp.sdc.be.tosca;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import fj.data.Either;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import mockit.Deencapsulation;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -60,23 +82,6 @@ import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
public class CsarUtilsTest extends BeConfDependentTest {
@InjectMocks
@@ -107,6 +112,8 @@ public class CsarUtilsTest extends BeConfDependentTest {
}
+ private final List<String> nodesFromPackage = Arrays.asList("tosca.nodes.Root", "tosca.nodes.Container.Application");
+
private NonMetaArtifactInfo createNonMetaArtifactInfoTestSubject() {
return new CsarUtils.NonMetaArtifactInfo("mock", "mock", ArtifactTypeEnum.AAI_SERVICE_MODEL,
ArtifactGroupTypeEnum.DEPLOYMENT, new byte[0], "mock", true);
@@ -475,27 +482,6 @@ public class CsarUtilsTest extends BeConfDependentTest {
}
}
-
- @Test
- public void testAddSchemaFilesFromCassandra() throws IOException {
- try (ByteArrayOutputStream out = new ByteArrayOutputStream();
- ZipOutputStream zip = new ZipOutputStream(out);
- ByteArrayOutputStream outMockStream = new ByteArrayOutputStream();
- ZipOutputStream outMock = new ZipOutputStream(outMockStream);) {
-
- outMock.putNextEntry(new ZipEntry("mock1"));
- outMock.write(new byte[1]);
- outMock.putNextEntry(new ZipEntry("mock2"));
- outMock.write(new byte[3]);
- outMock.close();
- byte[] byteArray = outMockStream.toByteArray();
- Deencapsulation.invoke(testSubject, "addSchemaFilesFromCassandra", zip, byteArray);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
@Test
public void testAddInnerComponentsToCache() {
Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
@@ -957,4 +943,39 @@ public class CsarUtilsTest extends BeConfDependentTest {
assertTrue(eitherNonMetaArtifact.isRight());
assertTrue(!collectedWarningMessages.isEmpty());
}
+
+ @Test(expected = IOException.class)
+ public void testAddSchemaFilesFromCassandraAddingDuplicatedEntry() throws IOException {
+ final String rootPath = System.getProperty("user.dir");
+ final Path path = Paths.get(rootPath + "/src/test/resources/sdc.zip");
+ try {
+ final byte[] data = Files.readAllBytes(path);
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final ZipOutputStream zip = new ZipOutputStream(out);) {
+ Deencapsulation.invoke(testSubject, "addSchemaFilesFromCassandra",
+ zip, data, nodesFromPackage);
+ zip.putNextEntry(new ZipEntry("Definitions/nodes.yml"));
+ zip.finish();
+ }
+ } catch (final IOException e) {
+ Assert.assertTrue("duplicate entry: Definitions/nodes.yml".equals(e.getMessage()));
+ throw new IOException("Could not add Schema Files From Cassandra", e);
+ }
+ }
+
+ @Test
+ public void testFindNonRootNodesFromPackage() {
+ final Resource resource = new Resource();
+ resource.setDerivedList(nodesFromPackage);
+ final Component component = resource;
+ final List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+ final Triple<String, String, Component> triple = Triple.of("fileName", "cassandraId", component);
+ dependencies.add(triple);
+ final List<String> expectedResult = Arrays.asList("tosca.nodes.Container.Application");
+ final List<String> result = Deencapsulation.invoke(testSubject,
+ "findNonRootNodesFromPackage", dependencies);
+ assertTrue(CollectionUtils.isNotEmpty(result));
+ assertEquals(expectedResult, result);
+ }
+
}
diff --git a/catalog-be/src/test/resources/sdc.zip b/catalog-be/src/test/resources/sdc.zip
new file mode 100644
index 0000000000..55a351508f
--- /dev/null
+++ b/catalog-be/src/test/resources/sdc.zip
Binary files differ
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 8100f988a2..a38095a3ce 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
@@ -20,6 +20,14 @@
package org.openecomp.sdc.be.model;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
@@ -27,18 +35,26 @@ import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
+@Getter
+@Setter
+@EqualsAndHashCode
+@ToString
public class Resource extends Component {
+ /**
+ * Please note that more than one "derivedFrom" resource is not currently supported by the app. The first list
+ * element is always addressed.
+ */
private List<String> derivedFrom;
+ /**
+ * The derivedList is a chain of derivedFrom. e.g. if resource C is derived from resource B that is derived from
+ * resource A - then A, B is the "DerivedList" of resource C
+ */
private List<String> derivedList;
+ private Map<String, String> derivedFromMapOfIdToName;
+
private List<PropertyDefinition> attributes;
private Map<String, InterfaceInstanceDataDefinition> instInterfaces;
@@ -48,7 +64,7 @@ public class Resource extends Component {
public Resource() {
super(new ResourceMetadataDefinition());
this.getComponentMetadataDefinition().getMetadataDataDefinition()
- .setComponentType(ComponentTypeEnum.RESOURCE);
+ .setComponentType(ComponentTypeEnum.RESOURCE);
}
public Resource(ComponentMetadataDefinition componentMetadataDefinition) {
@@ -59,82 +75,30 @@ public class Resource extends Component {
this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE);
}
- /**
- * Please note that more than one "derivedFrom" resource is not currently
- * supported by the app. The first list element is always addressed.
- *
- * @return
- */
- public List<String> getDerivedFrom() {
- return derivedFrom;
- }
-
- public void setDerivedFrom(List<String> derivedFrom) {
- this.derivedFrom = derivedFrom;
- }
-
- /**
- * The derivedList is a chain of derivedFrom. e.g. if resource C is derived
- * from resource B that is derived from resource A - then A, B is the
- * "DerivedList" of resource C
- *
- * @return
- */
- public List<String> getDerivedList() {
- return derivedList;
- }
-
- public void setDerivedList(List<String> derivedList) {
- this.derivedList = derivedList;
- }
-
+ @Override
public List<PropertyDefinition> getProperties() {
return properties;
}
+ @Override
public void setProperties(List<PropertyDefinition> properties) {
this.properties = properties;
}
- public List<PropertyDefinition> getAttributes() {
- return attributes;
- }
-
- public void setAttributes(List<PropertyDefinition> attributes) {
- this.attributes = attributes;
- }
-
- public Map<String, InterfaceInstanceDataDefinition> getInstInterfaces() {
- return instInterfaces;
- }
-
- public void setInstInterfaces(
- Map<String, InterfaceInstanceDataDefinition> instInterfaces) {
- this.instInterfaces = instInterfaces;
- }
-
public Boolean isAbstract() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition()
- .getMetadataDataDefinition())
- .isAbstract();
+ .getMetadataDataDefinition())
+ .isAbstract();
}
public void setAbstract(Boolean isAbstract) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setAbstract(isAbstract);
- }
-
- public List<String> getDefaultCapabilities() {
- return defaultCapabilities;
- }
-
- public void setDefaultCapabilities(List<String> defaultCapabilities) {
- this.defaultCapabilities = defaultCapabilities;
+ .setAbstract(isAbstract);
}
public String getCost() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getCost();
+ .getCost();
}
public void setCost(String cost) {
@@ -143,103 +107,72 @@ public class Resource extends Component {
public String getLicenseType() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getLicenseType();
+ .getLicenseType();
}
public void setLicenseType(String licenseType) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setLicenseType(licenseType);
+ .setLicenseType(licenseType);
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + super.hashCode();
- result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
- result = prime * result + ((defaultCapabilities == null) ? 0 : defaultCapabilities.hashCode());
- result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode());
- result = prime * result + ((properties == null) ? 0 : properties.hashCode());
- result = prime * result + ((derivedList == null) ? 0 : derivedList.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- if (!super.equals(o)) return false;
- Resource resource = (Resource) o;
- return Objects.equals(derivedFrom, resource.derivedFrom) &&
- Objects.equals(derivedList, resource.derivedList) &&
- Objects.equals(properties, resource.properties) &&
- Objects.equals(attributes, resource.attributes) &&
- Objects.equals(defaultCapabilities, resource.defaultCapabilities);
- }
-
-
- @Override
- public String toString() {
- return "Resource [derivedFrom=" + derivedFrom + ", properties=" + properties + ", attributes=" + attributes
- + ", defaultCapabilities=" + defaultCapabilities + ", additionalInformation=" + additionalInformation
- + "Metadata [" + getComponentMetadataDefinition().getMetadataDataDefinition().toString() + "]";
- }
public String getToscaResourceName() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getToscaResourceName();
+ .getToscaResourceName();
}
public void setToscaResourceName(String toscaResourceName) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setToscaResourceName(toscaResourceName);
+ .setToscaResourceName(toscaResourceName);
}
public ResourceTypeEnum getResourceType() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getResourceType();
+ .getResourceType();
}
public void setResourceType(ResourceTypeEnum resourceType) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setResourceType(resourceType);
+ .setResourceType(resourceType);
}
public void setVendorName(String vendorName) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setVendorName(vendorName);
+ .setVendorName(vendorName);
}
public void setVendorRelease(String vendorRelease) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setVendorRelease(vendorRelease);
+ .setVendorRelease(vendorRelease);
}
public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).
- setResourceVendorModelNumber(resourceVendorModelNumber);
+ setResourceVendorModelNumber(resourceVendorModelNumber);
}
public String getVendorName() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getVendorName();
+ .getVendorName();
}
public String getVendorRelease() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getVendorRelease();
+ .getVendorRelease();
}
public String getResourceVendorModelNumber() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getResourceVendorModelNumber();
+ .getResourceVendorModelNumber();
}
@Override
public String fetchGenericTypeToscaNameFromConfig() {
String result = super.fetchGenericTypeToscaNameFromConfig();
- if (null == result)
- result = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes().get(ResourceTypeEnum.VFC.getValue());
+ if (null == result) {
+ result = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes()
+ .get(ResourceTypeEnum.VFC.getValue());
+ }
return result;
}
@@ -249,24 +182,23 @@ public class Resource extends Component {
}
@Override
- public boolean shouldGenerateInputs(){
+ public boolean shouldGenerateInputs() {
return !(this.getResourceType().isAtomicType());
}
@Override
public boolean deriveFromGeneric() {
- return this.shouldGenerateInputs() || (derivedFrom != null && derivedFrom.contains(fetchGenericTypeToscaNameFromConfig()));
+ return this.shouldGenerateInputs() || (derivedFrom != null && derivedFrom
+ .contains(fetchGenericTypeToscaNameFromConfig()));
}
public Map<String, List<RequirementCapabilityRelDef>> groupRelationsFromCsarByInstanceName(Resource resource) {
- List<RequirementCapabilityRelDef> componentInstanceRelationsFromCsar = resource.getComponentInstancesRelations().stream().filter(r->!r.isOriginUI()).collect(Collectors.toList());
- Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId = MapUtil.groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode);
- return MapUtil.convertMapKeys(relationsByInstanceId, instId -> getInstanceInvariantNameFromInstanceId(resource, instId));
- }
-
- private String getInstanceNameFromInstanceId(Resource resource, String instId) {
- Optional<ComponentInstance> componentInstanceById = resource.getComponentInstanceById(instId);
- return componentInstanceById.isPresent() ? componentInstanceById.get().getName() : null;
+ List<RequirementCapabilityRelDef> componentInstanceRelationsFromCsar = resource.getComponentInstancesRelations()
+ .stream().filter(r -> !r.isOriginUI()).collect(Collectors.toList());
+ Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId = MapUtil
+ .groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode);
+ return MapUtil
+ .convertMapKeys(relationsByInstanceId, instId -> getInstanceInvariantNameFromInstanceId(resource, instId));
}
private String getInstanceInvariantNameFromInstanceId(Resource resource, String instId) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/NodeType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/NodeType.java
index 9c3b76d556..296e80b674 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/NodeType.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/NodeType.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.
@@ -20,12 +20,16 @@
package org.openecomp.sdc.be.model.jsonjanusgraph.datamodel;
-import org.openecomp.sdc.be.datatypes.elements.*;
-
import java.util.List;
import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-public class NodeType extends ToscaElement{
+@Getter
+@Setter
+public class NodeType extends ToscaElement {
public NodeType() {
super(ToscaElementTypeEnum.NODE_TYPE);
@@ -33,39 +37,7 @@ public class NodeType extends ToscaElement{
private List<String> derivedFrom;
private List<String> derivedList;
+ private Map<String, String> derivedFromMapOfIdToName;
private Map<String, PropertyDataDefinition> attributes;
private Map<String, InterfaceDataDefinition> interfaceArtifacts;
-
- public List<String> getDerivedList() {
- return derivedList;
- }
-
- public void setDerivedList(List<String> derivedList) {
- this.derivedList = derivedList;
- }
-
- public List<String> getDerivedFrom() {
- return derivedFrom;
- }
-
- public void setDerivedFrom(List<String> derivedFrom) {
- this.derivedFrom = derivedFrom;
- }
-
- public Map<String, PropertyDataDefinition> getAttributes() {
- return attributes;
- }
-
- public void setAttributes(Map<String, PropertyDataDefinition> attributes) {
- this.attributes = attributes;
- }
-
- public Map<String, InterfaceDataDefinition> getInterfaceArtifacts() {
- return interfaceArtifacts;
- }
-
- public void setInterfaceArtifacts(Map<String, InterfaceDataDefinition> interfaceArtifacts) {
- this.interfaceArtifacts = interfaceArtifacts;
- }
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
index 96242e32a3..9a70e9c837 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
@@ -321,42 +321,48 @@ public class NodeTypeOperation extends ToscaElementOperation {
return JanusGraphOperationStatus.OK;
}
- private JanusGraphOperationStatus setResourceDerivedFromGraph(GraphVertex componentV, NodeType toscaElement) {
- List<String> derivedFromList = new ArrayList<>();
+ private JanusGraphOperationStatus setResourceDerivedFromGraph(final GraphVertex componentV,
+ final NodeType toscaElement) {
+ final List<String> derivedFromList = new ArrayList<>();
+ final Map<String, String> derivedFromMapOfIdToName = new LinkedHashMap<>();
- JanusGraphOperationStatus
- listFromGraphStatus = findResourcesPathRecursively(componentV, derivedFromList);
+ final JanusGraphOperationStatus listFromGraphStatus = findResourcesPathRecursively(componentV, derivedFromList,
+ derivedFromMapOfIdToName);
if (JanusGraphOperationStatus.OK != listFromGraphStatus) {
return listFromGraphStatus;
}
if (!derivedFromList.isEmpty()) {
if (derivedFromList.size() > 1) {
- List<String> lastDerivedFrom = new ArrayList<>();
+ final List<String> lastDerivedFrom = new ArrayList<>();
lastDerivedFrom.add(derivedFromList.get(1));
toscaElement.setDerivedFrom(lastDerivedFrom);
- toscaElement.setDerivedList(derivedFromList);
} else {
toscaElement.setDerivedFrom(null);
- toscaElement.setDerivedList(derivedFromList);
}
-
+ toscaElement.setDerivedList(derivedFromList);
+ toscaElement.setDerivedFromMapOfIdToName(derivedFromMapOfIdToName);
}
return JanusGraphOperationStatus.OK;
}
- protected JanusGraphOperationStatus findResourcesPathRecursively(GraphVertex nodeTypeV, List<String> resourcesPathList) {
+ private JanusGraphOperationStatus findResourcesPathRecursively(final GraphVertex nodeTypeV,
+ final List<String> resourcesPathList,
+ final Map<String, String> derivedFromMapOfIdToName) {
Either<GraphVertex, JanusGraphOperationStatus> parentResourceRes = janusGraphDao
.getChildVertex(nodeTypeV, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.NoParse);
resourcesPathList.add((String) nodeTypeV.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME));
+ derivedFromMapOfIdToName.put(nodeTypeV.getUniqueId(),
+ (String) nodeTypeV.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME));
while (parentResourceRes.isLeft()) {
-
- GraphVertex parent = parentResourceRes.left().value();
+ final GraphVertex parent = parentResourceRes.left().value();
resourcesPathList.add((String) parent.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME));
+ derivedFromMapOfIdToName
+ .put(parent.getUniqueId(), (String) parent.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME));
parentResourceRes = janusGraphDao
.getChildVertex(parent, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.NoParse);
}
- JanusGraphOperationStatus operationStatus = parentResourceRes.right().value();
+ final JanusGraphOperationStatus operationStatus = parentResourceRes.right().value();
if (operationStatus != JanusGraphOperationStatus.NOT_FOUND) {
return operationStatus;
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 39d3548279..c16c8a98e5 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
@@ -22,6 +22,18 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.utils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.BooleanUtils;
@@ -34,14 +46,60 @@ import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
+import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ProductMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RelationshipInstDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
-import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFieldsExtractor;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFieldsExtractor;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceInterface;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.MapInterfaceInstanceDataDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RelationshipImpl;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
@@ -54,16 +112,6 @@ import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
public class ModelConverter {
public static final String CAP_PROP_DELIM = "#";
private static final Logger log = Logger.getLogger(ModelConverter.class);
@@ -196,6 +244,7 @@ public class ModelConverter {
NodeType nodeType = (NodeType) toscaElement;
resource.setDerivedFrom(nodeType.getDerivedFrom());
resource.setDerivedList(nodeType.getDerivedList());
+ resource.setDerivedFromMapOfIdToName(nodeType.getDerivedFromMapOfIdToName());
resource.setAbstract((Boolean) nodeType.getMetadataValue(JsonPresentationFields.IS_ABSTRACT));
convertAttributes(nodeType, resource);
convertCapabilities(nodeType, resource);
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 790ce10653..c53e4e00bb 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
@@ -20,16 +20,14 @@
package org.openecomp.sdc.be.model;
-import mockit.Deencapsulation;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
public class ResourceTest extends ModelConfDependentTest{
private Resource createTestSubject() {
@@ -447,15 +445,4 @@ public class ResourceTest extends ModelConfDependentTest{
result = testSubject.groupRelationsFromCsarByInstanceName(resource);
}
- @Test
- public void testGetInstanceNameFromInstanceId() throws Exception {
- Resource testSubject;
- Resource resource = new Resource();
- String instId = "mock";
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "getInstanceNameFromInstanceId", resource, instId);
- }
}