aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxuegao <xue.gao@intl.att.com>2021-02-11 15:16:36 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-02-20 07:07:06 +0000
commit6068ce140c9a65f13a0bd245c9b9a50befaddc32 (patch)
treecf045f20386163e6f771ead735c02bccf5fb1f5b
parentfee0f29212b10c940ec4b19fc8f4794d06964eee (diff)
Fix pnf csar package issue
Generate the dependencies and imports even derivedFrom list is empty. Issue-ID: SDC-3391 Signed-off-by: xuegao <xue.gao@intl.att.com> Change-Id: Ia07d1d6a73a1e08fb8f5ba1678b15e71aecd54b0 Signed-off-by: xuegao <xue.gao@intl.att.com>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java66
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java43
2 files changed, 80 insertions, 29 deletions
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 70834fd39a..ddea498c6f 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
@@ -561,7 +561,7 @@ public class ToscaExportHandler {
final List<Triple<String, String, Component>> dependencies,
final ComponentInstance componentInstance) {
log.debug("createDependency componentCache {}", componentCache);
- final Component componentRI = componentCache.get(componentInstance.getComponentUid());
+ Component componentRI = componentCache.get(componentInstance.getComponentUid());
if (componentRI == null || componentInstance.getOriginType() == OriginTypeEnum.ServiceSubstitution) {
// all resource must be only once!
final Either<Component, StorageOperationStatus> resource = toscaOperationFacade
@@ -572,15 +572,15 @@ public class ToscaExportHandler {
return;
}
final Component fetchedComponent = resource.left().value();
- setComponentCache(componentCache, componentInstance, fetchedComponent);
- addDependencies(imports, dependencies, fetchedComponent);
+ componentRI = setComponentCache(componentCache, componentInstance, fetchedComponent);
+ addDependencies(imports, dependencies, componentRI);
}
}
/**
* Sets a componentCache from the given component/resource.
*/
- private void setComponentCache(final Map<String, Component> componentCache,
+ private Component setComponentCache(final Map<String, Component> componentCache,
final ComponentInstance componentInstance,
final Component fetchedComponent) {
componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent);
@@ -594,7 +594,9 @@ public class ToscaExportHandler {
}
final Component fetchedSource = sourceService.left().value();
componentCache.put(fetchedSource.getUniqueId(), fetchedSource);
+ return fetchedSource;
}
+ return fetchedComponent;
}
/**
@@ -609,7 +611,7 @@ public class ToscaExportHandler {
final Optional<Map<String, String>> derivedFromMapOfIdToName = getDerivedFromMapOfIdToName(fetchedComponent,
componentsList);
- if (derivedFromMapOfIdToName.isPresent()) {
+ if (derivedFromMapOfIdToName.isPresent() && !derivedFromMapOfIdToName.get().isEmpty()) {
derivedFromMapOfIdToName.get().entrySet().forEach(entry -> {
log.debug("Started entry.getValue() : {}", entry.getValue());
if (!NATIVE_ROOT.equals(entry.getValue())) {
@@ -620,8 +622,11 @@ public class ToscaExportHandler {
}
}
});
+ setImports(imports, dependencies, componentsList);
+ } else {
+ setImports(imports, dependencies, fetchedComponent);
}
- setImports(imports, dependencies, componentsList);
+
}
}
@@ -658,30 +663,33 @@ public class ToscaExportHandler {
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) {
- final Map<String, String> files = new HashMap<>();
- final String artifactName = artifactDefinition.getArtifactName();
- files.put(IMPORTS_FILE_KEY, artifactName);
- final StringBuilder keyNameBuilder = new StringBuilder();
- keyNameBuilder.append(component.getComponentType().toString().toLowerCase());
- keyNameBuilder.append("-");
- 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");
- addImports(imports, keyNameBuilder, interfaceFiles);
- }
+ componentsList.forEach(component -> setImports(imports, dependencies, component));
+ }
+
+ private void setImports(final List<Map<String, Map<String, String>>> imports,
+ final List<Triple<String, String, Component>> dependencies,
+ final Component component) {
+ final Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ final ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE);
+ if (artifactDefinition != null) {
+ final Map<String, String> files = new HashMap<>();
+ final String artifactName = artifactDefinition.getArtifactName();
+ files.put(IMPORTS_FILE_KEY, artifactName);
+ final StringBuilder keyNameBuilder = new StringBuilder();
+ keyNameBuilder.append(component.getComponentType().toString().toLowerCase());
+ keyNameBuilder.append("-");
+ 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");
+ addImports(imports, keyNameBuilder, interfaceFiles);
}
- });
+ }
}
/**
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index a87460fa93..71a43acdb4 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -37,6 +37,8 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType.PROPERTY;
@@ -46,6 +48,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.LinkedList;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -72,6 +75,7 @@ import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.exception.ToscaExportException;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
@@ -329,6 +333,45 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
}
@Test
+ public void testSetImports() throws Exception {
+ Resource resource = new Resource();
+ resource.setResourceType(ResourceTypeEnum.PNF);
+
+ Component component = resource;
+ component.setName("TestResourceName");
+ Map<String, ArtifactDefinition> artifactList = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("name.name2");
+ artifactList.put("assettoscatemplate", artifact);
+ component.setArtifacts(artifactList);
+ component.setToscaArtifacts(artifactList);
+ ToscaTemplate toscaTemplate = new ToscaTemplate("");
+
+
+ ComponentInstance ci = new ComponentInstance();
+ ci.setComponentUid("name");
+ ci.setOriginType(OriginTypeEnum.PNF);
+ ci.setSourceModelUid("modelName");
+ List<ComponentInstance> componentInstanceList = new LinkedList<>();
+ componentInstanceList.add(ci);
+ component.setComponentInstances(componentInstanceList);
+
+ when(toscaOperationFacade.getToscaFullElement(eq("name"))).thenReturn(Either.left(component));
+
+ Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> result;
+ result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate);
+
+ verify(toscaOperationFacade, times(1)).getToscaFullElement("name");
+ Assert.assertTrue(result.isLeft());
+ ToscaTemplate toscaTemplateRes = result.left().value().left;
+ Assert.assertTrue(toscaTemplateRes.getImports().size() == 8);
+ Assert.assertNotNull(toscaTemplateRes.getImports().get(6).get("resource-TestResourceName-interface"));
+ Assert.assertNotNull(toscaTemplateRes.getImports().get(7).get("resource-TestResourceName"));
+ Assert.assertTrue(toscaTemplateRes.getDependencies().size() == 1);
+ Assert.assertNotNull(toscaTemplateRes.getDependencies().get(0).getLeft().equals("name.name2"));
+ }
+
+ @Test
public void testConvertToscaTemplate() throws Exception {
Component component = getNewResource();