From 80085205609fce24a44fe034fecf59beab83515a Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Wed, 7 Oct 2020 13:20:38 +0100 Subject: Fixing vulnerabilities and code smells and increasing code coverage Change-Id: If345b669433f754aedfbc81bef9c9b8a7686e92f Issue-ID: SO-2867 Signed-off-by: waqas.ikram --- .../so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml | 6 + .../exceptions/NsRequestProcessingException.java | 3 +- ...atalogPackageManagementServiceProviderImpl.java | 2 +- .../etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java | 5 +- .../nfvo/ns/lcm/bpmn/flows/nsd/FileParser.java | 32 ---- .../flows/nsd/NetworkServiceDescriptorParser.java | 209 -------------------- .../ns/lcm/bpmn/flows/nsd/ToscaMetadataParser.java | 67 ------- .../nfvo/ns/lcm/bpmn/flows/nsd/YamlFileParser.java | 39 ---- .../ns/lcm/bpmn/flows/nsd/parser/FileParser.java | 33 ++++ .../nsd/parser/NetworkServiceDescriptorParser.java | 213 +++++++++++++++++++++ .../bpmn/flows/nsd/parser/ToscaMetadataParser.java | 70 +++++++ .../lcm/bpmn/flows/nsd/parser/YamlFileParser.java | 40 ++++ .../bpmn/flows/tasks/CreateInstantiateVnfTask.java | 21 +- .../ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java | 38 +--- .../ns/lcm/bpmn/flows/tasks/TerminateNsTask.java | 11 +- .../bpmn/flows/utils/LocalDateTimeTypeAdapter.java | 15 +- .../nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java | 63 ++++++ .../nsd/NetworkServiceDescriptorParserTest.java | 87 --------- .../parser/NetworkServiceDescriptorParserTest.java | 89 +++++++++ .../lcm/rest/NsLifecycleManagementController.java | 8 +- 20 files changed, 560 insertions(+), 491 deletions(-) delete mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileParser.java delete mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParser.java delete mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/ToscaMetadataParser.java delete mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/YamlFileParser.java create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/FileParser.java create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParser.java create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/ToscaMetadataParser.java create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/YamlFileParser.java create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java delete mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParserTest.java create mode 100644 so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java (limited to 'so-etsi-nfvo') diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml index 1c13ecac25..3178b28502 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml @@ -102,5 +102,11 @@ ${hamcrest-version} test + + nl.jqno.equalsverifier + equalsverifier + ${equalsverifier-version} + test + \ No newline at end of file diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java index 0dcadfd4d8..0901f077d2 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java @@ -31,10 +31,11 @@ import org.springframework.web.bind.annotation.ResponseStatus; public class NsRequestProcessingException extends RuntimeException { private static final long serialVersionUID = 66862444537194516L; - private InlineResponse400 problemDetails; + private final InlineResponse400 problemDetails; public NsRequestProcessingException(final String message) { super(message); + problemDetails = null; } public NsRequestProcessingException(final String message, final InlineResponse400 problemDetails) { diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java index 75dd7107a7..097db5c153 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java @@ -25,7 +25,7 @@ import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model. import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.EtsiCatalogManagerRequestFailureException; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptorParser; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser.NetworkServiceDescriptorParser; import org.onap.so.rest.service.HttpRestServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java index 58ca2507bd..cfe5b94859 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java @@ -22,6 +22,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.Arrays; import java.util.Objects; /** @@ -82,7 +83,7 @@ public class FileEntry { @Override public int hashCode() { - return Objects.hash(isDirectory, filePath, fileContent); + return Objects.hash(isDirectory, filePath) + Arrays.hashCode(fileContent); } @Override @@ -90,7 +91,7 @@ public class FileEntry { if (obj instanceof FileEntry) { final FileEntry other = (FileEntry) obj; return Objects.equals(isDirectory, other.isDirectory) && Objects.equals(filePath, other.filePath) - && Objects.equals(fileContent, other.fileContent); + && Arrays.equals(fileContent, other.fileContent); } return false; } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileParser.java deleted file mode 100644 index 9df5262302..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileParser.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; - -import java.util.Map; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public interface FileParser { - - Map getFileContent(final FileEntry entryDefinitionFileEntry); - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParser.java deleted file mode 100644 index 33737f4c17..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParser.java +++ /dev/null @@ -1,209 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@Service -public class NetworkServiceDescriptorParser { - public static final String NS_NODE_TYPE = "tosca.nodes.nfv.NS"; - private static final String NODE_TYPE = "node_type"; - private static final String SUBSTITUTION_MAPPINGS = "substitution_mappings"; - private static final Logger logger = LoggerFactory.getLogger(NetworkServiceDescriptorParser.class); - private static final String VNF_TYPE = "tosca.nodes.nfv.VNF"; - private static final String PROPERTIES = "properties"; - private static final String TYPE = "type"; - private static final String NODE_TEMPLATES = "node_templates"; - private static final String TOPOLOGY_TEMPLATE = "topology_template"; - private static final String ENTRY_DEFINITIONS = "Entry-Definitions"; - private static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta"; - private final ToscaMetadataParser toscaMetadataParser; - private final FileParser fileParser; - - @Autowired - public NetworkServiceDescriptorParser(final ToscaMetadataParser toscaMetadataParser, final FileParser fileParser) { - this.toscaMetadataParser = toscaMetadataParser; - this.fileParser = fileParser; - } - - public Optional parse(final byte[] zipBytes) { - try { - final Map files = getZipContent(zipBytes); - if (isMetaFilePresent(files)) { - final Optional optional = - toscaMetadataParser.parse(files.get(TOSCA_META_PATH_FILE_NAME)); - if (optional.isPresent()) { - final ToscaMetadata toscaMetadata = optional.get(); - logger.info("Parsed ToscaMetadata {}", toscaMetadata); - final String entryDefinitionFile = toscaMetadata.getEntry(ENTRY_DEFINITIONS); - if (entryDefinitionFile != null && files.containsKey(entryDefinitionFile)) { - final Map fileContent = - fileParser.getFileContent(files.get(entryDefinitionFile)); - final Map topologyTemplates = getTopologyTemplates(fileContent); - final Map nodeTemplates = getNodeTemplates(topologyTemplates); - - final Optional nsdOptional = - getNetworkServiceDescriptor(topologyTemplates);; - if (nsdOptional.isPresent()) { - final NetworkServiceDescriptor networkServiceDescriptor = nsdOptional.get(); - networkServiceDescriptor.setVnfs(getVirtualNetworkFunctions(nodeTemplates)); - return Optional.of(networkServiceDescriptor); - } - - } - } - - } - - } catch (final Exception exception) { - logger.error("Unable to parser nsd zip content", exception); - } - logger.error("Unable to parser nsd zip content"); - return Optional.empty(); - } - - @SuppressWarnings("unchecked") - private Optional getNetworkServiceDescriptor( - final Map topologyTemplates) { - final Map substitutionMappings = - (Map) topologyTemplates.get(SUBSTITUTION_MAPPINGS); - final Object nodeType = substitutionMappings.get(NODE_TYPE); - if (substitutionMappings != null && nodeType != null && NS_NODE_TYPE.equals(nodeType)) { - final NetworkServiceDescriptor networkServiceDescriptor = new NetworkServiceDescriptor(); - networkServiceDescriptor.setType(nodeType.toString()); - networkServiceDescriptor.setProperties((Map) substitutionMappings.get(PROPERTIES)); - return Optional.of(networkServiceDescriptor); - } - logger.error("No {} found in fileContent: {}", SUBSTITUTION_MAPPINGS, topologyTemplates); - - return Optional.empty(); - } - - private List getVirtualNetworkFunctions(final Map nodeTemplates) { - final List vnfs = new ArrayList<>(); - for (final Entry entry : nodeTemplates.entrySet()) { - @SuppressWarnings("unchecked") - final Map entryValue = (Map) entry.getValue(); - final Object type = entryValue.get(TYPE); - if (type != null && type.equals(VNF_TYPE)) { - @SuppressWarnings("unchecked") - final Map vnfProperties = (Map) entryValue.get(PROPERTIES); - final VirtualNetworkFunction vnf = new VirtualNetworkFunction(); - vnf.setVnfName(entry.getKey()); - - if (vnfProperties != null && !vnfProperties.isEmpty()) { - final Object vnfDescriptorId = vnfProperties.get("descriptor_id"); - @SuppressWarnings("unchecked") - final List vnfmInfoList = (List) vnfProperties.get("vnfm_info"); - if (vnfDescriptorId != null && vnfmInfoList != null) { - vnf.setVnfmInfoList(vnfmInfoList); - vnf.setVnfdId(vnfDescriptorId.toString()); - vnf.setProperties(vnfProperties); - vnfs.add(vnf); - } else { - logger.warn("descriptor_id missing {}", entryValue); - } - } - } - - } - return vnfs; - } - - private Map getNodeTemplates(final Map topologyTemplates) { - @SuppressWarnings("unchecked") - final Map nodeTemplates = (Map) topologyTemplates.get(NODE_TEMPLATES); - if (nodeTemplates != null) { - logger.debug("Found nodeTemplates: {}", topologyTemplates); - return nodeTemplates; - } - logger.error("No {} found in fileContent: {}", NODE_TEMPLATES, topologyTemplates); - return Collections.emptyMap(); - } - - private Map getTopologyTemplates(final Map fileContent) { - @SuppressWarnings("unchecked") - final Map topologyTemplates = (Map) fileContent.get(TOPOLOGY_TEMPLATE); - if (topologyTemplates != null) { - logger.debug("Found {}: {}", TOPOLOGY_TEMPLATE, topologyTemplates); - - return topologyTemplates; - } - logger.error("No {} found in fileContent: {}", TOPOLOGY_TEMPLATE, fileContent); - return Collections.emptyMap(); - } - - private boolean isMetaFilePresent(final Map files) { - return files.containsKey(TOSCA_META_PATH_FILE_NAME); - } - - private Map getZipContent(final byte[] zipBytes) { - final Map files = new HashMap<>(); - try (final ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(zipBytes));) { - ZipEntry zipEntry; - while ((zipEntry = inputZipStream.getNextEntry()) != null) { - logger.info("{} : {}", zipEntry.getName(), zipEntry.isDirectory()); - if (files.get(zipEntry.getName()) != null) { - logger.warn("{} File entry already exists ...", zipEntry.getName()); - } else { - final FileEntry fileEntry = new FileEntry().filePath(zipEntry.getName()) - .fileContent(getBytes(inputZipStream)).isDirectory(zipEntry.isDirectory()); - files.put(zipEntry.getName(), fileEntry); - - } - - } - return files; - } catch (final Exception exception) { - logger.error("Unable to parser nsd zip content", exception); - return Collections.emptyMap(); - } - } - - private byte[] getBytes(final ZipInputStream inputZipStream) throws IOException { - try { - return IOUtils.toByteArray(inputZipStream); - } catch (final IOException exception) { - logger.error("Could not read bytes from file", exception); - throw exception; - } - } - - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/ToscaMetadataParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/ToscaMetadataParser.java deleted file mode 100644 index fe23f5ef8d..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/ToscaMetadataParser.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; - -import static org.apache.commons.lang3.StringUtils.isNotBlank; -import java.util.List; -import java.util.Optional; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@Service -public class ToscaMetadataParser { - private static final String ATTRIBUTE_VALUE_SEPARATOR = ":"; - private static final Logger logger = LoggerFactory.getLogger(ToscaMetadataParser.class); - - public Optional parse(final FileEntry toscaMetaFile) { - try { - final ToscaMetadata toscaMetadata = new ToscaMetadata(); - final List lines = IOUtils.readLines(toscaMetaFile.getFileContentAsStream(), "utf-8"); - for (final String line : lines) { - final String trimmedLine = line.trim(); - if (!trimmedLine.isEmpty() && trimmedLine.contains(ATTRIBUTE_VALUE_SEPARATOR)) { - final String[] entry = trimmedLine.split(ATTRIBUTE_VALUE_SEPARATOR); - if (entry.length >= 2 && isNotBlank(entry[0]) && isNotBlank(entry[1])) { - toscaMetadata.addEntry(entry[0].trim(), entry[1].trim()); - } else { - logger.warn("Unexpected line in metadata file: {}", line); - } - } else { - logger.warn("Unexpected line does not contain valid separator {} in metadata file: {}", - ATTRIBUTE_VALUE_SEPARATOR, line); - } - - } - return Optional.of(toscaMetadata); - - } catch (final Exception exception) { - logger.error("Unable to parser metadata file content", exception); - } - return Optional.empty(); - } - - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/YamlFileParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/YamlFileParser.java deleted file mode 100644 index ac8f782a99..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/YamlFileParser.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; - -import java.util.Map; -import org.springframework.stereotype.Service; -import org.yaml.snakeyaml.Yaml; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@Service -public class YamlFileParser implements FileParser { - - @Override - public Map getFileContent(final FileEntry entryDefinitionFileEntry) { - final Yaml yaml = new Yaml(); - return yaml.load(entryDefinitionFileEntry.getFileContentAsStream()); - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/FileParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/FileParser.java new file mode 100644 index 0000000000..2a37922e9b --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/FileParser.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; + +import java.util.Map; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface FileParser { + + Map getFileContent(final FileEntry entryDefinitionFileEntry); + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParser.java new file mode 100644 index 0000000000..7df2e6973d --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParser.java @@ -0,0 +1,213 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import org.apache.commons.io.IOUtils; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.ToscaMetadata; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.VirtualNetworkFunction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class NetworkServiceDescriptorParser { + public static final String NS_NODE_TYPE = "tosca.nodes.nfv.NS"; + private static final String NODE_TYPE = "node_type"; + private static final String SUBSTITUTION_MAPPINGS = "substitution_mappings"; + private static final Logger logger = LoggerFactory.getLogger(NetworkServiceDescriptorParser.class); + private static final String VNF_TYPE = "tosca.nodes.nfv.VNF"; + private static final String PROPERTIES = "properties"; + private static final String TYPE = "type"; + private static final String NODE_TEMPLATES = "node_templates"; + private static final String TOPOLOGY_TEMPLATE = "topology_template"; + private static final String ENTRY_DEFINITIONS = "Entry-Definitions"; + private static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta"; + private final ToscaMetadataParser toscaMetadataParser; + private final FileParser fileParser; + + @Autowired + public NetworkServiceDescriptorParser(final ToscaMetadataParser toscaMetadataParser, final FileParser fileParser) { + this.toscaMetadataParser = toscaMetadataParser; + this.fileParser = fileParser; + } + + public Optional parse(final byte[] zipBytes) { + try { + final Map files = getZipContent(zipBytes); + if (isMetaFilePresent(files)) { + final Optional optional = + toscaMetadataParser.parse(files.get(TOSCA_META_PATH_FILE_NAME)); + if (optional.isPresent()) { + final ToscaMetadata toscaMetadata = optional.get(); + logger.info("Parsed ToscaMetadata {}", toscaMetadata); + final String entryDefinitionFile = toscaMetadata.getEntry(ENTRY_DEFINITIONS); + if (entryDefinitionFile != null && files.containsKey(entryDefinitionFile)) { + final Map fileContent = + fileParser.getFileContent(files.get(entryDefinitionFile)); + final Map topologyTemplates = getTopologyTemplates(fileContent); + final Map nodeTemplates = getNodeTemplates(topologyTemplates); + + final Optional nsdOptional = + getNetworkServiceDescriptor(topologyTemplates); + if (nsdOptional.isPresent()) { + final NetworkServiceDescriptor networkServiceDescriptor = nsdOptional.get(); + networkServiceDescriptor.setVnfs(getVirtualNetworkFunctions(nodeTemplates)); + return Optional.of(networkServiceDescriptor); + } + + } + } + + } + + logger.error("Unable to find {} file in {}", TOSCA_META_PATH_FILE_NAME, files); + } catch (final Exception exception) { + logger.error("Unable to parse nsd zip content", exception); + } + return Optional.empty(); + } + + @SuppressWarnings("unchecked") + private Optional getNetworkServiceDescriptor( + final Map topologyTemplates) { + final Map substitutionMappings = + (Map) topologyTemplates.get(SUBSTITUTION_MAPPINGS); + final Object nodeType = substitutionMappings.get(NODE_TYPE); + if (substitutionMappings != null && nodeType != null && NS_NODE_TYPE.equals(nodeType)) { + final NetworkServiceDescriptor networkServiceDescriptor = new NetworkServiceDescriptor(); + networkServiceDescriptor.setType(nodeType.toString()); + networkServiceDescriptor.setProperties((Map) substitutionMappings.get(PROPERTIES)); + return Optional.of(networkServiceDescriptor); + } + logger.error("No {} found in fileContent: {}", SUBSTITUTION_MAPPINGS, topologyTemplates); + + return Optional.empty(); + } + + private List getVirtualNetworkFunctions(final Map nodeTemplates) { + final List vnfs = new ArrayList<>(); + for (final Entry entry : nodeTemplates.entrySet()) { + @SuppressWarnings("unchecked") + final Map entryValue = (Map) entry.getValue(); + final Object type = entryValue.get(TYPE); + if (type != null && type.equals(VNF_TYPE)) { + @SuppressWarnings("unchecked") + final Map vnfProperties = (Map) entryValue.get(PROPERTIES); + final VirtualNetworkFunction vnf = new VirtualNetworkFunction(); + vnf.setVnfName(entry.getKey()); + + if (vnfProperties != null && !vnfProperties.isEmpty()) { + final Object vnfDescriptorId = vnfProperties.get("descriptor_id"); + @SuppressWarnings("unchecked") + final List vnfmInfoList = (List) vnfProperties.get("vnfm_info"); + if (vnfDescriptorId != null && vnfmInfoList != null) { + vnf.setVnfmInfoList(vnfmInfoList); + vnf.setVnfdId(vnfDescriptorId.toString()); + vnf.setProperties(vnfProperties); + vnfs.add(vnf); + } else { + logger.warn("descriptor_id missing {}", entryValue); + } + } + } + + } + return vnfs; + } + + private Map getNodeTemplates(final Map topologyTemplates) { + @SuppressWarnings("unchecked") + final Map nodeTemplates = (Map) topologyTemplates.get(NODE_TEMPLATES); + if (nodeTemplates != null) { + logger.debug("Found nodeTemplates: {}", topologyTemplates); + return nodeTemplates; + } + logger.error("No {} found in fileContent: {}", NODE_TEMPLATES, topologyTemplates); + return Collections.emptyMap(); + } + + private Map getTopologyTemplates(final Map fileContent) { + @SuppressWarnings("unchecked") + final Map topologyTemplates = (Map) fileContent.get(TOPOLOGY_TEMPLATE); + if (topologyTemplates != null) { + logger.debug("Found {}: {}", TOPOLOGY_TEMPLATE, topologyTemplates); + + return topologyTemplates; + } + logger.error("No {} found in fileContent: {}", TOPOLOGY_TEMPLATE, fileContent); + return Collections.emptyMap(); + } + + private boolean isMetaFilePresent(final Map files) { + return files.containsKey(TOSCA_META_PATH_FILE_NAME); + } + + private Map getZipContent(final byte[] zipBytes) { + final Map files = new HashMap<>(); + try (final ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(zipBytes));) { + ZipEntry zipEntry; + while ((zipEntry = inputZipStream.getNextEntry()) != null) { + logger.info("{} : {}", zipEntry.getName(), zipEntry.isDirectory()); + if (files.get(zipEntry.getName()) != null) { + logger.warn("{} File entry already exists ...", zipEntry.getName()); + } else { + final FileEntry fileEntry = new FileEntry().filePath(zipEntry.getName()) + .fileContent(getBytes(inputZipStream)).isDirectory(zipEntry.isDirectory()); + files.put(zipEntry.getName(), fileEntry); + + } + + } + return files; + } catch (final Exception exception) { + logger.error("Unable to parse nsd zip content", exception); + return Collections.emptyMap(); + } + } + + private byte[] getBytes(final ZipInputStream inputZipStream) throws IOException { + try { + return IOUtils.toByteArray(inputZipStream); + } catch (final IOException exception) { + logger.error("Could not read bytes from file", exception); + throw exception; + } + } + + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/ToscaMetadataParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/ToscaMetadataParser.java new file mode 100644 index 0000000000..746416c8e4 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/ToscaMetadataParser.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import java.util.List; +import java.util.Optional; +import org.apache.commons.io.IOUtils; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.ToscaMetadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class ToscaMetadataParser { + private static final String ATTRIBUTE_VALUE_SEPARATOR = ":"; + private static final Logger logger = LoggerFactory.getLogger(ToscaMetadataParser.class); + + public Optional parse(final FileEntry toscaMetaFile) { + try { + final ToscaMetadata toscaMetadata = new ToscaMetadata(); + final List lines = IOUtils.readLines(toscaMetaFile.getFileContentAsStream(), UTF_8); + for (final String line : lines) { + final String trimmedLine = line.trim(); + if (!trimmedLine.isEmpty() && trimmedLine.contains(ATTRIBUTE_VALUE_SEPARATOR)) { + final String[] entry = trimmedLine.split(ATTRIBUTE_VALUE_SEPARATOR); + if (entry.length >= 2 && isNotBlank(entry[0]) && isNotBlank(entry[1])) { + toscaMetadata.addEntry(entry[0].trim(), entry[1].trim()); + } else { + logger.warn("Unexpected line in metadata file: {}", line); + } + } else { + logger.warn("Unexpected line does not contain valid separator {} in metadata file: {}", + ATTRIBUTE_VALUE_SEPARATOR, line); + } + + } + return Optional.of(toscaMetadata); + + } catch (final Exception exception) { + logger.error("Unable to parser metadata file content", exception); + } + return Optional.empty(); + } + + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/YamlFileParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/YamlFileParser.java new file mode 100644 index 0000000000..eab6974252 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/YamlFileParser.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; + +import java.util.Map; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; +import org.springframework.stereotype.Service; +import org.yaml.snakeyaml.Yaml; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class YamlFileParser implements FileParser { + + @Override + public Map getFileContent(final FileEntry entryDefinitionFileEntry) { + final Yaml yaml = new Yaml(); + return yaml.load(entryDefinitionFileEntry.getFileContentAsStream()); + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java index bfeaf49daa..fcebea59f2 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java @@ -47,6 +47,7 @@ import org.springframework.stereotype.Component; */ @Component public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { + private static final String CREATE_INSTANTIATE_REQUEST_PARAM_NAME = "request"; private static final Logger logger = LoggerFactory.getLogger(CreateInstantiateVnfTask.class); private static final String NF_INST_ID_PARAM_NAME = "NF_INST_ID"; public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; @@ -64,7 +65,8 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { public void checkIfNfInstanceExistsInDb(final DelegateExecution execution) { logger.info("Executing checkIfNfInstanceInDb"); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); logger.info("request: {}", request); setJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Checking if NF Instance record exists in database for " @@ -79,7 +81,8 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { public void createNfInstanceInDb(final DelegateExecution execution) { logger.info("Executing createNfInstanceInDb"); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); logger.info("request: {}", request); setJobStatus(execution, IN_PROGRESS, "Creating NF Instance record in database for " + request.getVnfName()); @@ -104,7 +107,8 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { public void createGenericVnfInAai(final DelegateExecution execution) { logger.info("Executing createGenericVnfInAai"); try { - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); setJobStatus(execution, IN_PROGRESS, "Creating GenericVnf record in AAI for " + request.getVnfName()); @@ -140,7 +144,8 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { logger.info("Executing invokeCreateInstantiationRequest"); try { - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); logger.info("request: {}", request); setJobStatus(execution, IN_PROGRESS, @@ -180,7 +185,8 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { logger.info("Executing updateNfInstanceStatusToInstantiated"); updateNfInstanceStatus(execution, State.INSTANTIATED); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); setJobStatus(execution, FINISHED, "Successfully created and Instantiated VNF: " + request.getVnfName() + " will set status to " + State.INSTANTIATED); @@ -192,7 +198,8 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { logger.info("Executing updateNfInstanceStatusToActive"); updateNfInstanceStatus(execution, State.FAILED); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); setJobStatus(execution, ERROR, "Failed to create and instantiate VNF: " + request.getVnfName() + " will set status to " + State.FAILED); @@ -204,7 +211,7 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { final String nfInstId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME); final Optional optional = databaseServiceProvider.getNfvoNfInst(nfInstId); - if (!optional.isPresent()) { + if (optional.isEmpty()) { final String message = "Unable to find NfvoNfInst record in database using nfInstId: " + nfInstId; logger.error(message); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java index 1d9e09e74b..f3dbf37f6a 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java @@ -240,12 +240,20 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); - final String nsPackageId = nfvoNsInst.getNsPackageId(); - final NsdInfo nsdInfo = getNsdInfo(execution, nsPackageId); final Map vnfdIdToVnfPkgIdMapping = new HashMap<>(); try { + final Optional nsdInfoOptional = + etsiCatalogPackageManagementServiceProvider.getNSPackageModel(nsPackageId); + + if (nsdInfoOptional.isEmpty()) { + final String message = "Unable to find NS package using NS package id: " + nsPackageId; + logger.error(message); + abortOperation(execution, message); + } + + final NsdInfo nsdInfo = nsdInfoOptional.get(); for (final String vnfPkgId : nsdInfo.getVnfPkgIds()) { final Optional optional = etsiCatalogPackageManagementServiceProvider.getVnfPkgInfo(vnfPkgId); @@ -290,32 +298,6 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { setJobStatusToError(execution, "Instantiate NS workflow process failed"); } - private NsdInfo getNsdInfo(final DelegateExecution execution, final String nsPackageId) { - try { - final Optional optional = - etsiCatalogPackageManagementServiceProvider.getNSPackageModel(nsPackageId); - - if (optional.isPresent()) { - final NsdInfo packageModel = optional.get(); - logger.info("NS Package exists {}", packageModel); - return packageModel; - } - - } catch (final EtsiCatalogManagerRequestFailureException failureException) { - final String message = - "Unexpected exception occured while getting ns package using nsPackageId: " + nsPackageId; - logger.error(message, failureException); - - abortOperation(execution, message); - } - - final String message = "Unable to find NS package using NS package id: " + nsPackageId; - logger.error(message); - abortOperation(execution, message); - return null; - - } - private Optional getTenant(final Map additionalParams) { final String vimId = (String) additionalParams.get("vim_id"); if (vimId != null) { diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java index 2baa2845a5..23a239e3b1 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java @@ -109,9 +109,8 @@ public class TerminateNsTask extends AbstractNetworkServiceTask { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); final List nfInstances = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstId); if (nfInstances != null) { - nfInstances.stream().forEach(instance -> { - logger.info("Current status {} of vnf: {}", instance.getStatus(), instance.getName()); - }); + nfInstances.stream().forEach( + instance -> logger.info("Current status {} of vnf: {}", instance.getStatus(), instance.getName())); } } @@ -120,16 +119,14 @@ public class TerminateNsTask extends AbstractNetworkServiceTask { logger.info("Getting NfvoNfInstList using nsInstId: {}", nsInstId); final List nfvoNfInstList = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstId); - if (nfvoNfInstList.size() == 0) { + if (nfvoNfInstList == null || nfvoNfInstList.size() == 0) { final String message = "Unable to find NF Instances in database using id: " + nsInstId; abortOperation(execution, message); } final List vnfIdsList = new ArrayList<>(); - nfvoNfInstList.stream().forEach(nfvoNfInst -> { - vnfIdsList.add(nfvoNfInst.getNfInstId()); - }); + nfvoNfInstList.stream().forEach(nfvoNfInst -> vnfIdsList.add(nfvoNfInst.getNfInstId())); return vnfIdsList; } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java index 34959ee0f0..9f21d2b449 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java @@ -24,6 +24,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; /** @@ -45,14 +46,14 @@ public class LocalDateTimeTypeAdapter extends TypeAdapter { @Override public LocalDateTime read(final JsonReader in) throws IOException { - switch (in.peek()) { - case NULL: - in.nextNull(); - return null; - default: - final String dateTime = in.nextString(); - return LocalDateTime.parse(dateTime, FORMATTER); + if (JsonToken.NULL == in.peek()) { + in.nextNull(); + return null; + } + final String dateTime = in.nextString(); + return LocalDateTime.parse(dateTime, FORMATTER); + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java new file mode 100644 index 0000000000..edfb20afd2 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows; + +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.ToscaMetadata; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.VirtualNetworkFunction; +import org.onap.so.openpojo.rules.ToStringTester; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class PojoClassesTests { + + @Test + public void test_nsd_parser_pojo_classes() throws ClassNotFoundException { + + final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()) + .with(new ToStringTester()).build(); + validator.validate(FileEntry.class.getPackageName(), new FilterPackageInfo()); + } + + + @Test + public void test_nsd_parser_pojo_classes_equalAndHashMethod() throws ClassNotFoundException { + final List> classes = Arrays.asList(FileEntry.class, NetworkServiceDescriptor.class, + ToscaMetadata.class, VirtualNetworkFunction.class); + for (final Class clazz : classes) { + EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, + Warning.INHERITED_DIRECTLY_FROM_OBJECT).verify(); + } + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParserTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParserTest.java deleted file mode 100644 index 2bebf1c30a..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParserTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Map; -import java.util.Optional; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.TestApplication; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -public class NetworkServiceDescriptorParserTest { - - private static final String VALID_ETSI_NSD_FILE = "src/test/resources/ns.csar"; - private static final String INVALID_ETSI_NSD_FILE = "src/test/resources/invalid_ns.csar"; - - @Autowired - private NetworkServiceDescriptorParser objUnderTest; - - @Test - public void testValidEtsiNsd_ableToParseIt() throws IOException { - final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(VALID_ETSI_NSD_FILE))); - final Optional optional = objUnderTest.parse(zipBytes); - assertTrue(optional.isPresent()); - final NetworkServiceDescriptor actualNsd = optional.get(); - assertEquals(NetworkServiceDescriptorParser.NS_NODE_TYPE, actualNsd.getType()); - assertFalse(actualNsd.getProperties().isEmpty()); - - final Map actualNsdProperties = actualNsd.getProperties(); - assertEquals(5, actualNsdProperties.size()); - assertEquals("ffdddc5d-a44b-45ae-8fc3-e6551cce350f", actualNsdProperties.get("descriptor_id")); - assertEquals(5, actualNsd.getVnfs().size()); - - } - - @Test - public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException { - assertFalse(objUnderTest.parse(new byte[] {}).isPresent()); - } - - @Test - public void testInvalidEtsiNsd_returnEmptyOptional() throws IOException { - final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(INVALID_ETSI_NSD_FILE))); - assertFalse(objUnderTest.parse(zipBytes).isPresent()); - } - - private String getAbsolutePath(final String path) { - final File file = new File(path); - return file.getAbsolutePath(); - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java new file mode 100644 index 0000000000..4a8c715e5c --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Map; +import java.util.Optional; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.TestApplication; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser.NetworkServiceDescriptorParser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class NetworkServiceDescriptorParserTest { + + private static final String VALID_ETSI_NSD_FILE = "src/test/resources/ns.csar"; + private static final String INVALID_ETSI_NSD_FILE = "src/test/resources/invalid_ns.csar"; + + @Autowired + private NetworkServiceDescriptorParser objUnderTest; + + @Test + public void testValidEtsiNsd_ableToParseIt() throws IOException { + final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(VALID_ETSI_NSD_FILE))); + final Optional optional = objUnderTest.parse(zipBytes); + assertTrue(optional.isPresent()); + final NetworkServiceDescriptor actualNsd = optional.get(); + assertEquals(NetworkServiceDescriptorParser.NS_NODE_TYPE, actualNsd.getType()); + assertFalse(actualNsd.getProperties().isEmpty()); + + final Map actualNsdProperties = actualNsd.getProperties(); + assertEquals(5, actualNsdProperties.size()); + assertEquals("ffdddc5d-a44b-45ae-8fc3-e6551cce350f", actualNsdProperties.get("descriptor_id")); + assertEquals(5, actualNsd.getVnfs().size()); + + } + + @Test + public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException { + assertFalse(objUnderTest.parse(new byte[] {}).isPresent()); + } + + @Test + public void testInvalidEtsiNsd_returnEmptyOptional() throws IOException { + final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(INVALID_ETSI_NSD_FILE))); + assertFalse(objUnderTest.parse(zipBytes).isPresent()); + } + + private String getAbsolutePath(final String path) { + final File file = new File(path); + return file.getAbsolutePath(); + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java index 78ab9e96cc..2390cef564 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java @@ -77,7 +77,7 @@ public class NsLifecycleManagementController { */ @PostMapping(value = "/ns_instances", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity createNs( + public ResponseEntity createNs( @RequestHeader(value = HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME, required = true) final String globalCustomerId, @RequestHeader(value = HTTP_SERVICETYPE_HEADER_PARM_NAME, required = false, @@ -106,7 +106,7 @@ public class NsLifecycleManagementController { */ @DeleteMapping(value = "/ns_instances/{nsInstanceId}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity deleteNs(@PathVariable("nsInstanceId") final String nsInstanceId) { + public ResponseEntity deleteNs(@PathVariable("nsInstanceId") final String nsInstanceId) { logger.debug("Received delete NS request for nsInstanceId: {}", nsInstanceId); nsLifeCycleManager.deleteNs(nsInstanceId); logger.info("Successfully deleted NS for nsInstanceId: {}", nsInstanceId); @@ -124,7 +124,7 @@ public class NsLifecycleManagementController { @PostMapping(value = "/ns_instances/{nsInstanceId}/instantiate", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId, + public ResponseEntity instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId, @RequestBody final InstantiateNsRequest instantiateNsRequest) { logger.debug("Received instantiate NS request: {}\n with nsInstanceId: {}", instantiateNsRequest, nsInstanceId); final URI resourceUri = nsLifeCycleManager.instantiateNs(nsInstanceId, instantiateNsRequest); @@ -144,7 +144,7 @@ public class NsLifecycleManagementController { @PostMapping(value = "/ns_instances/{nsInstanceId}/terminate", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity terminateNs(@PathVariable("nsInstanceId") final String nsInstanceId, + public ResponseEntity terminateNs(@PathVariable("nsInstanceId") final String nsInstanceId, @RequestBody final TerminateNsRequest terminateNsRequest) { logger.debug("Received terminate NS request: {}\n with nsInstanceId: {}", terminateNsRequest, nsInstanceId); final URI resourceUri = nsLifeCycleManager.terminateNs(nsInstanceId, terminateNsRequest); -- cgit 1.2.3-korg