From 871b9813322801509a566b49a1cdcc65c052de29 Mon Sep 17 00:00:00 2001 From: shikha0203 Date: Thu, 18 May 2023 14:11:03 +0100 Subject: Support import of service with no substitution mapping node type Issue-ID: SDC-4506 Signed-off-by: shikha0203 Change-Id: I7bc8f020418f2b9299be3454ffbc1e016a2d300e --- catalog-ui/src/app/utils/service-csar-reader.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'catalog-ui/src/app/utils') diff --git a/catalog-ui/src/app/utils/service-csar-reader.ts b/catalog-ui/src/app/utils/service-csar-reader.ts index 90de53b8c9..20dfe6ca6b 100644 --- a/catalog-ui/src/app/utils/service-csar-reader.ts +++ b/catalog-ui/src/app/utils/service-csar-reader.ts @@ -20,7 +20,7 @@ import {ServiceCsar, ToscaMetaEntry} from "../models"; import {load} from 'js-yaml'; -import { ComponentType } from "./constants"; +import {ComponentType} from "./constants"; export class ServiceCsarReader { @@ -35,8 +35,12 @@ export class ServiceCsarReader { this.readToscaMeta(toscaMetaFileContent); const entryDefinitionFileContent = await zip.file(this.serviceCsar.entryDefinitionFileName).async("string"); this.readServiceMetadata(entryDefinitionFileContent); - const interfaceDefinitionFileContent = await zip.file(this.serviceCsar.interfaceDefinitionFileName).async("string"); - this.readServiceSubstitutionNode(interfaceDefinitionFileContent); + if (zip.file(this.serviceCsar.interfaceDefinitionFileName) != null) { + const interfaceDefinitionFileContent = await zip.file(this.serviceCsar.interfaceDefinitionFileName).async("string"); + this.readSubstitutionNodeFromInterfaceDefinitionFile(interfaceDefinitionFileContent); + } else { + this.readSubstitutionNodeFromMainTemplateFile(entryDefinitionFileContent); + } resolve(this.serviceCsar); } catch (error) { reject(error); @@ -60,7 +64,6 @@ export class ServiceCsarReader { private readEntryDefinitionFileName() { this.serviceCsar.entryDefinitionFileName = this.serviceCsar.toscaMeta.getEntry(ToscaMetaEntry.ENTRY_DEFINITIONS); } - private readInterfaceDefinitionFileName() { let fileNameArray:Array = this.serviceCsar.entryDefinitionFileName.split("."); fileNameArray.splice(fileNameArray.length - 1, 0, "-interface."); @@ -72,12 +75,16 @@ export class ServiceCsarReader { this.setMetadata(metadata); } - private readServiceSubstitutionNode(interfaceDefinitionFileContent) { + private readSubstitutionNodeFromInterfaceDefinitionFile(interfaceDefinitionFileContent) { const nodeTypes = load(interfaceDefinitionFileContent).node_types; let nodeType = Object.keys(nodeTypes).values().next().value; this.serviceCsar.substitutionNodeType = nodeTypes[nodeType]["derived_from"]; } + private readSubstitutionNodeFromMainTemplateFile(entryDefinitionFileContent) { + this.serviceCsar.substitutionNodeType = load(entryDefinitionFileContent).topology_template.substitution_mappings.node_type; + } + private setMetadata = (metadata:object) : void => { let extraServiceMetadata: Map = new Map(); this.serviceCsar.serviceMetadata.componentType = ComponentType.SERVICE; -- cgit 1.2.3-korg