aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2021-10-06 16:58:35 +0100
committerMichael Morris <michael.morris@est.tech>2021-10-08 12:51:10 +0000
commitc65452a519e4c64fe23e42251d8237ada676f81c (patch)
tree263a97b46f7cb3a476d5f1f6be616c9bf35cc17e /catalog-be/src
parente6346f60e877671547b6619d42088ea1a3b47b4d (diff)
Allow importing service with no instances
Issue-ID: SDC-3751 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Change-Id: I383d9fd8901b9c3e968ba18bfc31a520a490be0b
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java19
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java8
3 files changed, 20 insertions, 18 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index 0006f833b2..51794a3350 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -274,15 +274,18 @@ public class YamlTemplateParsingHandler {
private Map<String, UploadComponentInstanceInfo> getInstances(String yamlName, Map<String, Object> toscaJson,
Map<String, String> createdNodesToscaResourceNames) {
- Map<String, Object> nodeTemlates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES).left().on(err -> failIfNoNodeTemplates(yamlName));
- return getInstances(toscaJson, createdNodesToscaResourceNames, nodeTemlates);
+ Map<String, Object> nodeTemplates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES).left().on(err -> new HashMap<>());
+ if (nodeTemplates.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ return getInstances(toscaJson, createdNodesToscaResourceNames, nodeTemplates);
}
private Map<String, UploadComponentInstanceInfo> getInstances(Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames,
- Map<String, Object> nodeTemlates) {
+ Map<String, Object> nodeTemplates) {
Map<String, UploadComponentInstanceInfo> moduleComponentInstances;
Map<String, Object> substitutionMappings = getSubstitutionMappings(toscaJson);
- moduleComponentInstances = nodeTemlates.entrySet().stream()
+ moduleComponentInstances = nodeTemplates.entrySet().stream()
.map(node -> buildModuleComponentInstanceInfo(node, substitutionMappings, createdNodesToscaResourceNames))
.collect(Collectors.toMap(UploadComponentInstanceInfo::getName, i -> i));
return moduleComponentInstances;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index 0c5accad09..8a855e0031 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -251,9 +251,6 @@ public class ServiceImportBusinessLogic {
try {
ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic
.getParsedToscaYamlInfo(topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, nodeName, service);
- if (MapUtils.isEmpty(parsedToscaYamlInfo.getInstances())) {
- throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- }
log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", service.getName());
csfyp.setYamlName(yamlName);
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
@@ -1294,13 +1291,15 @@ public class ServiceImportBusinessLogic {
log.debug("************* Going to create all nodes {}", yamlName);
handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, nodeName);
- log.debug("************* Going to create all resource instances {}", yamlName);
- service = createServiceInstances(yamlName, service, uploadComponentInstanceInfoMap, csarInfo.getCreatedNodes());
- log.debug("************* Going to create all relations {}", yamlName);
- service = createServiceInstancesRelations(csarInfo.getModifier(), yamlName, service, uploadComponentInstanceInfoMap);
- log.debug("************* Going to create positions {}", yamlName);
- compositionBusinessLogic.setPositionsForComponentInstances(service, csarInfo.getModifier().getUserId());
- log.debug("************* Finished to set positions {}", yamlName);
+ if (!MapUtils.isEmpty(uploadComponentInstanceInfoMap)) {
+ log.debug("************* Going to create all resource instances {}", yamlName);
+ service = createServiceInstances(yamlName, service, uploadComponentInstanceInfoMap, csarInfo.getCreatedNodes());
+ log.debug("************* Going to create all relations {}", yamlName);
+ service = createServiceInstancesRelations(csarInfo.getModifier(), yamlName, service, uploadComponentInstanceInfoMap);
+ log.debug("************* Going to create positions {}", yamlName);
+ compositionBusinessLogic.setPositionsForComponentInstances(service, csarInfo.getModifier().getUserId());
+ log.debug("************* Finished to set positions {}", yamlName);
+ }
return service;
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
index adfd5de888..6fcdd1373c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
@@ -1131,10 +1131,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap,
- topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
- csarInfo, nodeTypesArtifactsToCreate, nodeName));
+ Assertions.assertNotNull(sIB1
+ .createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap,
+ topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
+ csarInfo, nodeTypesArtifactsToCreate, nodeName));
}
@Test