From f3b0ef4dc7cc21b273ea160781b5170b2d105e1a Mon Sep 17 00:00:00 2001 From: Adam Wudzinski Date: Fri, 15 Jan 2021 17:38:30 +0100 Subject: Map VSP PM_DICTIONARY Type to VF PM_DICTIONARY Type File defined in ZIP VSP package as PM_DICTIONARY will be now mapped to PM_DICTIONARY type in VF. Also PmDictionaryValidator is run on files with PM_DICTIONARY type in ZIP Manifest file, instead of file naming convention. Issue-ID: SDC-3390 Signed-off-by: Adam Wudzinski Change-Id: I2e21353b9e80b6bb68c4c6d408ad1ffa33314e7b --- .../CandidateServiceImpl.java | 8 +++ .../ManifestCreatorNamingConventionImpl.java | 50 ++++++++++++++- .../ManifestCreatorNamingConventionImplTest.java | 75 +++++++++++++++++++--- 3 files changed, 122 insertions(+), 11 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core') 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/filedatastructuremodule/CandidateServiceImpl.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/filedatastructuremodule/CandidateServiceImpl.java index 8bae5e8193..7c11fb65ab 100644 --- 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/filedatastructuremodule/CandidateServiceImpl.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/filedatastructuremodule/CandidateServiceImpl.java @@ -1,5 +1,6 @@ /* * Copyright © 2016-2018 European Support Limited + * Modifications copyright (c) 2021 Nokia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -362,6 +363,13 @@ public class CandidateServiceImpl implements CandidateService { .withMessage(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()).build()))); } + @Override + public String createManifestFromExisting(VspDetails vspDetails, FilesDataStructure structure, ManifestContent existingManifest) { + return JsonUtil.object2Json(manifestCreator.createManifestFromExisting(vspDetails, structure, existingManifest) + .orElseThrow(() -> new CoreException(new ErrorCode.ErrorCodeBuilder() + .withMessage(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()).build()))); + } + @Override public Optional createManifest(VspDetails vspDetails, FileContentHandler fileContentHandler, 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/filedatastructuremodule/ManifestCreatorNamingConventionImpl.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/filedatastructuremodule/ManifestCreatorNamingConventionImpl.java index 3f061b059c..54cc1fbf1c 100644 --- 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/filedatastructuremodule/ManifestCreatorNamingConventionImpl.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/filedatastructuremodule/ManifestCreatorNamingConventionImpl.java @@ -1,5 +1,6 @@ /* * Copyright © 2016-2017 European Support Limited + * Modifications copyright (c) 2021 Nokia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,10 +55,56 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { addModulesToManifestFileDataList(filesDataStructure, fileDataList); addNestedToManifest(filesDataStructure, fileDataList); addArtifactsToManifestFileDataList(filesDataStructure, fileDataList); + + ManifestContent manifestContent = createManifest(vspDetails, fileDataList); + return Optional.of(manifestContent); + } + + @Override + public Optional createManifestFromExisting(VspDetails vspDetails, FilesDataStructure filesDataStructure, ManifestContent existingManifest) { + if (Objects.isNull(filesDataStructure)) { + return Optional.empty(); + } + + List fileDataList = new ArrayList<>(); + addModulesToManifestFileDataList(filesDataStructure, fileDataList); + addNestedToManifest(filesDataStructure, fileDataList); + addArtifactsToManifestFileDataList(filesDataStructure, fileDataList, existingManifest); + ManifestContent manifestContent = createManifest(vspDetails, fileDataList); return Optional.of(manifestContent); } + private void addArtifactsToManifestFileDataList(FilesDataStructure filesDataStructure, List fileDataList, ManifestContent existingManifest) { + Collection forArtifacts = CollectionUtils + .union(filesDataStructure.getArtifacts(), filesDataStructure.getUnassigned()); + if (CollectionUtils.isNotEmpty(forArtifacts)) { + for (String artifact : forArtifacts) { + if (isCloudSpecificArtifact(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, artifact)); + } else if (isControllerBlueprintArchive(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact)); + } else if (isHelm(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.HELM, artifact)); + } else if (isPmDictionary(artifact, existingManifest)) { + fileDataList.add(createBaseFileData(FileData.Type.PM_DICTIONARY, artifact)); + } + else { + fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact)); + } + } + } + } + + private boolean isPmDictionary(String artifact, ManifestContent existingManifest) { + return existingManifest.getData() + .stream() + .filter(fileData -> fileData.getType() + .equals(FileData.Type.PM_DICTIONARY)) + .map(FileData::getFile) + .anyMatch(pmDictionaryFile -> pmDictionaryFile.equals(artifact)); + } + private void addNestedToManifest( FilesDataStructure filesDataStructure, List fileDataList) { if (CollectionUtils.isNotEmpty(filesDataStructure.getNested())) { @@ -172,8 +219,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator { fileDataList.add(createBaseFileData(FileData.Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact)); } else if (isHelm(artifact)) { fileDataList.add(createBaseFileData(FileData.Type.HELM, artifact)); - } - else { + } else { fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact)); } } 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/filedatastructuremodule/ManifestCreatorNamingConventionImplTest.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/filedatastructuremodule/ManifestCreatorNamingConventionImplTest.java index 1a9bc2aa4c..2cea0f73e3 100644 --- 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/filedatastructuremodule/ManifestCreatorNamingConventionImplTest.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/filedatastructuremodule/ManifestCreatorNamingConventionImplTest.java @@ -3,13 +3,14 @@ * SDC * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications copyright (c) 2021 Nokia * ================================================================================ * 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. @@ -20,15 +21,18 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.heat.datatypes.manifest.FileData; +import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; public class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNamingConventionImpl { @@ -37,13 +41,66 @@ public class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNami private static final String ARTIFACT_3 = "cloudtech_aws_configtemplate.zip"; private static final String ARTIFACT_4 = "k8s_charts.zip"; private static final String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip"; + private static final String PMDICT_YAML = "pmdict.yaml"; + @Test - public void testIsCloudSpecificArtifact() { + void testIsCloudSpecificArtifact() { assertTrue(isCloudSpecificArtifact(ARTIFACT_1)); assertTrue(isCloudSpecificArtifact(ARTIFACT_2)); assertTrue(isCloudSpecificArtifact(ARTIFACT_3)); assertFalse(isCloudSpecificArtifact(ARTIFACT_4)); assertFalse(isCloudSpecificArtifact(ARTIFACT_5)); } + + @Test + void shouldMapPmDictionaryTypeFromExistingManifestToPmDictionaryTypeInNewManifest() { + // given + VspDetails vspDetails = new VspDetails(); + FilesDataStructure fileDataStructure = new FilesDataStructure(); + fileDataStructure.setArtifacts(List.of(PMDICT_YAML)); + ManifestContent existingManifest = prepareManifestWithPmDictFileWithType(FileData.Type.PM_DICTIONARY); + + // when + Optional newManifest = new ManifestCreatorNamingConventionImpl() + .createManifestFromExisting(vspDetails, fileDataStructure, existingManifest); + + // then + assertTrue(newManifest.isPresent()); + assertTrue(newManifest.get() + .getData() + .stream() + .allMatch(fd -> fd.getType().equals(FileData.Type.PM_DICTIONARY) && + fd.getFile().equals(PMDICT_YAML))); + } + + @Test + void shouldMapPmDictionaryWithOtherTypeFromExistingManifestToOtherTypeInNewManifest() { + // given + VspDetails vspDetails = new VspDetails(); + FilesDataStructure fileDataStructure = new FilesDataStructure(); + fileDataStructure.setArtifacts(List.of(PMDICT_YAML)); + ManifestContent existingManifest = prepareManifestWithPmDictFileWithType(FileData.Type.OTHER); + + // when + Optional newManifest = new ManifestCreatorNamingConventionImpl() + .createManifestFromExisting(vspDetails, fileDataStructure, existingManifest); + + // then + assertTrue(newManifest.isPresent()); + assertTrue(newManifest.get() + .getData() + .stream() + .allMatch(fd -> fd.getType().equals(FileData.Type.OTHER) && + fd.getFile().equals(PMDICT_YAML))); + } + + private ManifestContent prepareManifestWithPmDictFileWithType(FileData.Type fileType) { + ManifestContent existingManifest = new ManifestContent(); + FileData fileData = new FileData(); + fileData.setFile(PMDICT_YAML); + fileData.setType(fileType); + existingManifest.setData(List.of(fileData)); + return existingManifest; + } } -- cgit 1.2.3-korg