diff options
author | kooper <sergey.sachkov@est.tech> | 2019-03-04 13:47:51 +0000 |
---|---|---|
committer | kooper <sergey.sachkov@est.tech> | 2019-03-04 13:47:51 +0000 |
commit | 11e9d33f2f50ad3990905fba184b7c10d255070a (patch) | |
tree | 32e1a0ba3d5da03a41202e9bf28c28f099601972 /openecomp-be/lib/openecomp-sdc-vendor-software-product-lib | |
parent | 7deb4e0e5f6cf06b7fbb27c6bda4e91f847f4075 (diff) |
Add manifest non mano set support
Issue-ID: SDC-2141
Change-Id: I056e8f7c1da8f17ce8583207660882f85a4d11a4
Signed-off-by: kooper <sergey.sachkov@est.tech>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib')
8 files changed, 360 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java new file mode 100644 index 0000000000..69ce97efc5 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019, Nordix Foundation. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.tosca.csar.Manifest; + + +public interface ETSIService { + /** + * Checks package structure is CSAR with TOSCA-Metadata directory according to SOL004 v2.5.1 + * and contains mandatory Entries in Tosca.meta + * @param handler contains csar artifacts + * @return true if all condition matched, false otherwise + */ + boolean isSol004WithToscaMetaDirectory(FileContentHandler handler); + + /** + * Update file structure. Moves non mano files to Artifacts/Deployment/non mano key location + * @param handler + * @param manifest + */ + void moveNonManoFileToArtifactFolder(FileContentHandler handler, Manifest manifest); +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml index 450acd6583..08e8a0881a 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml @@ -112,6 +112,11 @@ <artifactId>openecomp-sdc-vendor-license-api</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <scope>provided</scope> + </dependency> </dependencies> diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/Configuration.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/Configuration.java new file mode 100644 index 0000000000..e2f9a4efaf --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/Configuration.java @@ -0,0 +1,10 @@ +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; + +import java.util.Map; + +import lombok.Data; + +@Data +public class Configuration { + private Map<String, NonManoType> nonManoKeyFolderMapping; +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java new file mode 100644 index 0000000000..b3002abf6e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019, Nordix Foundation. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; + +import org.apache.commons.io.IOUtils; +import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter; +import org.openecomp.core.utilities.file.FileContentHandler; + + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.openecomp.sdc.tosca.csar.Manifest; + +import static org.openecomp.sdc.tosca.csar.CSARConstants.*; + +public class ETSIServiceImpl implements ETSIService { + + private Configuration configuration; + + public ETSIServiceImpl() throws IOException { + InputStream io = getClass().getClassLoader().getResourceAsStream("nonManoConfig.yaml"); + if(io == null){ + throw new IOException("Non Mano configuration not found"); + } + String data = IOUtils.toString(io, StandardCharsets.UTF_8); + YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); + configuration = yamlToObjectConverter.convertFromString(data, Configuration.class); + } + + public ETSIServiceImpl(Configuration configuration) { + this.configuration = configuration; + } + + @Override + public boolean isSol004WithToscaMetaDirectory(FileContentHandler handler) { + Map<String, byte[]> templates = handler.getFiles(); + return isMetaFilePresent(templates) && hasMetaMandatoryEntries(templates); + } + + @Override + public void moveNonManoFileToArtifactFolder(FileContentHandler handler, Manifest manifest) { + for (Map.Entry<String, List<String>> entry : manifest.getNonManoSources().entrySet()) { + String e = entry.getKey(); + List<String> k = entry.getValue(); + updateNonManoLocation(handler, e, k); + } + } + + private void updateNonManoLocation(FileContentHandler handler, String nonManoKey, List<String> sources) { + Map<String, byte[]> files = handler.getFiles(); + for (String key : sources) { + if (files.containsKey(key)) { + updateLocation(key, nonManoKey, files); + } + } + } + + private void updateLocation(String key, String nonManoKey, Map<String, byte[]> files){ + if (nonManoKey == null || nonManoKey.isEmpty()) { + return; + } + Map<String, NonManoType> map = configuration.getNonManoKeyFolderMapping(); + if (map.containsKey(nonManoKey)) { + NonManoType nonManoPair = map.get(nonManoKey); + String newLocation = nonManoPair.getType() + "/" + + nonManoPair.getLocation() + "/" + getFileName(key); + if (!files.containsKey(newLocation)) { + files.put(newLocation, files.remove(key)); + } + } + } + + + private String getFileName(String key) { + return key.substring(key.lastIndexOf('/') + 1); + } + + private boolean hasMetaMandatoryEntries(Map<String, byte[]> templates) { + Optional<byte[]> meta = templates.entrySet().stream().filter(e -> e.getKey().equals(TOSCA_META_PATH_FILE_NAME) + || e.getKey().equals(TOSCA_META_ORIG_PATH_FILE_NAME)).findFirst().map(Map.Entry::getValue); + if (!meta.isPresent()) { + return false; + } + String metaContent = new String(meta.get(), StandardCharsets.UTF_8); + return metaContent.contains(TOSCA_META_ENTRY_DEFINITIONS) && metaContent.contains(TOSCA_META_ENTRY_MANIFEST) + && metaContent.contains(TOSCA_META_ENTRY_CHANGE_LOG); + } + + private boolean isMetaFilePresent(Map<String, byte[]> handler) { + return handler.containsKey(TOSCA_META_PATH_FILE_NAME) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/NonManoType.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/NonManoType.java new file mode 100644 index 0000000000..e10c102593 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/NonManoType.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019, Nordix Foundation. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; + + +import lombok.Data; + +@Data +public class NonManoType { + private String location; + private String type; +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/resources/nonManoConfig.yaml b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/resources/nonManoConfig.yaml new file mode 100644 index 0000000000..c444e66c48 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/resources/nonManoConfig.yaml @@ -0,0 +1,19 @@ +nonManoKeyFolderMapping: + onap_ves_events: + location: VES_EVENTS + type: Deployment + onap_pm_dictionary: + location: PM_DICTIONARY + type: Deployment + onap_yang_modules: + location: YANG_MODULES + type: Deployment + onap_ansible_playbooks: + location: ANSIBLE_PLAYBOOK + type: Deployment + onap_scripts: + location: SCRIPTS + type: Deployment + onap_others: + location: OTHER + type: Informational
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java new file mode 100644 index 0000000000..ae69415f1d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java @@ -0,0 +1,133 @@ +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.tosca.csar.Manifest; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ETSIServiceImplTest { + private ETSIService etsiService; + private String sol004MetaFile = "TOSCA-Meta-Version: 1.0\n" + + "CSAR-Version: 1.0\n" + + "Created-By: Kuku\n" + + "Entry-Definitions: MainServiceTemplate.yaml\n" + + "Entry-Manifest: MainServiceTemplate.mf\n" + + "Entry-Change-Log: MainServiceTemplate.log"; + private String metaFile = "TOSCA-Meta-Version: 1.0\n" + + "CSAR-Version: 1.0\n" + + "Created-By: Kuku\n" + + "Entry-Definitions: MainServiceTemplate.yaml"; + + private String finalNonManoLocation = "Deployment/VES_EVENTS/test.xml"; + private String finalOtherNonManoLocation = "Informational/OTHER/test.xml"; + + @Before + public void setUp() throws IOException { + YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); + Configuration configuration = yamlToObjectConverter.convert("src/test/resources", + Configuration.class, "nonManoConfig.yaml"); + etsiService = new ETSIServiceImpl(configuration); + } + + @After + public void tearDown() { + etsiService = null; + } + + @Test + public void testIsSol004TrueOrigin() { + FileContentHandler fileContentHandler = new FileContentHandler(); + fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", sol004MetaFile.getBytes(StandardCharsets.UTF_8)); + assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); + } + + @Test + public void testIsSol004True() { + FileContentHandler fileContentHandler = new FileContentHandler(); + fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", sol004MetaFile.getBytes(StandardCharsets.UTF_8)); + assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); + } + + @Test + public void testIsSol004False() { + FileContentHandler fileContentHandler = new FileContentHandler(); + fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", metaFile.getBytes(StandardCharsets.UTF_8)); + assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); + } + + @Test + public void testIsSol004FalseWithNull() { + FileContentHandler fileContentHandler = new FileContentHandler(); + assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); + } + + @Test + public void testMoveNonManoFileToArtifactFolder() throws IOException { + Map<String, List<String>> nonManoSources = new HashMap<>(); + List<String> sources = new ArrayList<>(); + sources.add("Some/test.xml"); + nonManoSources.put("Some", sources); + FileContentHandler fileContentHandler = new FileContentHandler(); + fileContentHandler.addFile("Some/test.xml", new byte[1]); + Manifest manifest = mock(Manifest.class); + when(manifest.getNonManoSources()).thenReturn(nonManoSources); + etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest); + assertTrue(fileContentHandler.containsFile(finalNonManoLocation)); + } + + @Test + public void testMoveNonManoFileToArtifactFolderFileNotInFolder() throws IOException { + Map<String, List<String>> nonManoSources = new HashMap<>(); + List<String> sources = new ArrayList<>(); + sources.add("test.xml"); + nonManoSources.put("foo", sources); + FileContentHandler fileContentHandler = new FileContentHandler(); + fileContentHandler.addFile("test.xml", new byte[1]); + Manifest manifest = mock(Manifest.class); + when(manifest.getNonManoSources()).thenReturn(nonManoSources); + etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest); + assertFalse(fileContentHandler.containsFile(finalOtherNonManoLocation)); + } + + @Test + public void testMoveNonManoFileToArtifactFolderNoMove() throws IOException { + Map<String, List<String>> nonManoSources = new HashMap<>(); + List<String> sources = new ArrayList<>(); + sources.add(finalNonManoLocation); + nonManoSources.put("Some", sources); + FileContentHandler fileContentHandler = new FileContentHandler(); + fileContentHandler.addFile(finalNonManoLocation, new byte[1]); + Manifest manifest = mock(Manifest.class); + when(manifest.getNonManoSources()).thenReturn(nonManoSources); + etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest); + assertTrue(fileContentHandler.containsFile(finalNonManoLocation)); + } + + @Test + public void testMoveNonManoFileToArtifactFolderMoveToKeyFolder() throws IOException { + Map<String, List<String>> nonManoSources = new HashMap<>(); + List<String> sources = new ArrayList<>(); + sources.add("Artifacts/Deployment/test.xml"); + nonManoSources.put("Some", sources); + FileContentHandler fileContentHandler = new FileContentHandler(); + fileContentHandler.addFile("Artifacts/Deployment/test.xml", new byte[1]); + Manifest manifest = mock(Manifest.class); + when(manifest.getNonManoSources()).thenReturn(nonManoSources); + etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest); + assertTrue(fileContentHandler.containsFile(finalNonManoLocation)); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/nonManoConfig.yaml b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/nonManoConfig.yaml new file mode 100644 index 0000000000..32c6b1ce57 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/nonManoConfig.yaml @@ -0,0 +1,7 @@ +nonManoKeyFolderMapping: + Some: + location: VES_EVENTS + type: Deployment + Other: + location: VES_EVENTS + type: Informational
\ No newline at end of file |