aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--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.java128
-rw-r--r--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.java45
2 files changed, 97 insertions, 76 deletions
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 48601a28a7..f55447cc38 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
@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData.Type;
import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.services.HeatFileAnalyzer;
@@ -44,10 +45,13 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
protected static final Logger logger = LoggerFactory.getLogger(ManifestCreatorNamingConventionImpl.class);
private static final String CLOUD_SPECIFIC_FIXED_KEY_WORD = "cloudtech";
- private static final String[][] CLOUD_SPECIFIC_KEY_WORDS = {{"k8s", "azure", "aws"}, /* cloud specific technology */
- {"charts", "day0", "configtemplate"} /*cloud specific sub type*/};
+ private static final String[][] CLOUD_SPECIFIC_KEY_WORDS = {
+ {"k8s", "azure", "aws"}, // cloud specific technology
+ {"charts", "day0", "configtemplate"} // cloud specific subtype
+ };
private static final String CONTROLLER_BLUEPRINT_ARCHIVE_FIXED_KEY_WORD = "CBA";
private static final String HELM_KEY_WORD = "HELM";
+ private static final String PM_DICTIONARY = "PM_DICTIONARY";
@Override
public Optional<ManifestContent> createManifest(VspDetails vspDetails, FilesDataStructure filesDataStructure) {
@@ -58,8 +62,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
addModulesToManifestFileDataList(filesDataStructure, fileDataList);
addNestedToManifest(filesDataStructure, fileDataList);
addArtifactsToManifestFileDataList(filesDataStructure, fileDataList);
- ManifestContent manifestContent = createManifest(vspDetails, fileDataList);
- return Optional.of(manifestContent);
+ return Optional.of(createManifest(vspDetails, fileDataList));
}
@Override
@@ -72,8 +75,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
addModulesToManifestFileDataList(filesDataStructure, fileDataList);
addNestedToManifest(filesDataStructure, fileDataList);
addArtifactsToManifestFileDataList(filesDataStructure, fileDataList, existingManifest);
- ManifestContent manifestContent = createManifest(vspDetails, fileDataList);
- return Optional.of(manifestContent);
+ return Optional.of(createManifest(vspDetails, fileDataList));
}
private void addArtifactsToManifestFileDataList(FilesDataStructure filesDataStructure, List<FileData> fileDataList,
@@ -81,30 +83,35 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
Collection<String> 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));
+ List<FileData> manifestData = existingManifest.getData();
+ if (isCloudSpecificArtifact(artifact, manifestData)) {
+ fileDataList.add(createBaseFileData(Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, artifact));
+ } else if (isControllerBlueprintArchive(artifact, manifestData)) {
+ fileDataList.add(createBaseFileData(Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact));
+ } else if (isHelm(artifact, manifestData)) {
+ fileDataList.add(createBaseFileData(Type.HELM, artifact));
+ } else if (isPmDictionary(artifact, manifestData)) {
+ fileDataList.add(createBaseFileData(Type.PM_DICTIONARY, artifact));
} else {
- fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact));
+ fileDataList.add(createBaseFileData(Type.OTHER, artifact));
}
}
}
}
- private boolean isPmDictionary(String artifact, ManifestContent existingManifest) {
- return existingManifest.getData().stream().filter(fileData -> FileData.Type.PM_DICTIONARY.equals(fileData.getType())).map(FileData::getFile)
- .anyMatch(pmDictionaryFile -> pmDictionaryFile.equals(artifact));
+ private boolean isPmDictionary(String artifact, List<FileData> data) {
+ if (CollectionUtils.isNotEmpty(data) && data.stream()
+ .anyMatch(fileData -> fileData.getFile().equals(artifact) && Type.PM_DICTIONARY.equals(fileData.getType()))) {
+ return true;
+ } else {
+ return artifact.toUpperCase().contains(PM_DICTIONARY);
+ }
}
private void addNestedToManifest(FilesDataStructure filesDataStructure, List<FileData> fileDataList) {
if (CollectionUtils.isNotEmpty(filesDataStructure.getNested())) {
for (String nested : filesDataStructure.getNested()) {
- fileDataList.add(createBaseFileData(FileData.Type.HEAT, nested));
+ fileDataList.add(createBaseFileData(Type.HEAT, nested));
}
}
}
@@ -147,11 +154,11 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
fileDataList.add(createModuleFileData(fileName, false, processedFiles, fileContentHandler.getFileList(), fileDataList));
} else {
if (HeatFileAnalyzer.isYamlFile(fileName)) {
- fileDataList.add(createBasicFileData(fileName, FileData.Type.HEAT, null));
+ fileDataList.add(createBasicFileData(fileName, Type.HEAT, null));
} else if (HeatFileAnalyzer.isEnvFile(fileName)) {
- fileDataList.add(createBasicFileData(fileName, FileData.Type.HEAT_ENV, null));
+ fileDataList.add(createBasicFileData(fileName, Type.HEAT_ENV, null));
} else {
- fileDataList.add(createBasicFileData(fileName, FileData.Type.OTHER, null));
+ fileDataList.add(createBasicFileData(fileName, Type.OTHER, null));
}
}
}
@@ -167,39 +174,56 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
return Pattern.matches(Constants.BASE_HEAT_REGEX, fileName) && !isVolFile(fileName);
}
- protected boolean isCloudSpecificArtifact(String artifact) {
- if (artifact.contains(CLOUD_SPECIFIC_FIXED_KEY_WORD)) {
- for (int i = 0; i < CLOUD_SPECIFIC_KEY_WORDS.length; i++) {
- if (Arrays.stream(CLOUD_SPECIFIC_KEY_WORDS[i]).noneMatch(str -> artifact.contains(str))) {
- return false;
- }
- }
+ protected boolean isCloudSpecificArtifact(String artifact, List<FileData> data) {
+ if (CollectionUtils.isNotEmpty(data) && data.stream()
+ .anyMatch(fileData -> fileData.getFile().equals(artifact) && Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT.equals(fileData.getType()))) {
return true;
} else {
- return false;
+ if (artifact.contains(CLOUD_SPECIFIC_FIXED_KEY_WORD)) {
+ for (final String[] cloudSpecificKeyWord : CLOUD_SPECIFIC_KEY_WORDS) {
+ if (Arrays.stream(cloudSpecificKeyWord).noneMatch(artifact::contains)) {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
}
}
- private boolean isControllerBlueprintArchive(String artifact) {
- return artifact.toUpperCase().contains(CONTROLLER_BLUEPRINT_ARCHIVE_FIXED_KEY_WORD);
+ private boolean isControllerBlueprintArchive(String artifact, List<FileData> data) {
+ if (CollectionUtils.isNotEmpty(data) && data.stream()
+ .anyMatch(fileData -> fileData.getFile().equals(artifact) && Type.CONTROLLER_BLUEPRINT_ARCHIVE.equals(fileData.getType()))) {
+ return true;
+ } else {
+ return artifact.toUpperCase().contains(CONTROLLER_BLUEPRINT_ARCHIVE_FIXED_KEY_WORD);
+ }
}
- private boolean isHelm(String artifact) {
- return artifact.toUpperCase().contains(HELM_KEY_WORD);
+ private boolean isHelm(String artifact, List<FileData> data) {
+ if (CollectionUtils.isNotEmpty(data) && data.stream()
+ .anyMatch(fileData -> fileData.getFile().equals(artifact) && Type.HELM.equals(fileData.getType()))) {
+ return true;
+ } else {
+ return artifact.toUpperCase().contains(HELM_KEY_WORD);
+ }
}
private void addArtifactsToManifestFileDataList(FilesDataStructure filesDataStructure, List<FileData> fileDataList) {
Collection<String> 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));
+ if (isCloudSpecificArtifact(artifact, null)) {
+ fileDataList.add(createBaseFileData(Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, artifact));
+ } else if (isControllerBlueprintArchive(artifact, null)) {
+ fileDataList.add(createBaseFileData(Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact));
+ } else if (isHelm(artifact, null)) {
+ fileDataList.add(createBaseFileData(Type.HELM, artifact));
+ } else if (isPmDictionary(artifact, null)) {
+ fileDataList.add(createBaseFileData(Type.PM_DICTIONARY, artifact));
} else {
- fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact));
+ fileDataList.add(createBaseFileData(Type.OTHER, artifact));
}
}
}
@@ -208,9 +232,9 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
private void addModulesToManifestFileDataList(FilesDataStructure filesDataStructure, List<FileData> fileDataList) {
if (CollectionUtils.isNotEmpty(filesDataStructure.getModules())) {
for (Module module : filesDataStructure.getModules()) {
- FileData.Type type = module.getType();
+ Type type = module.getType();
if (type == null) {
- type = FileData.Type.HEAT;
+ type = Type.HEAT;
}
FileData fileData = createBaseFileData(type, module.getYaml());
fileData.setBase(module.getIsBase());
@@ -223,7 +247,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
private void addEnv(Module module, FileData fileData) {
if (Objects.nonNull(module.getEnv())) {
- FileData env = createBaseFileData(FileData.Type.HEAT_ENV, module.getEnv());
+ FileData env = createBaseFileData(Type.HEAT_ENV, module.getEnv());
fileData.addFileData(env);
}
}
@@ -231,15 +255,15 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
private void addVolume(Module module, FileData fileData) {
String volModule = module.getVol();
if (Objects.nonNull(volModule)) {
- FileData vol = createBaseFileData(FileData.Type.HEAT_VOL, volModule);
+ FileData vol = createBaseFileData(Type.HEAT_VOL, volModule);
if (Objects.nonNull(module.getVolEnv())) {
- vol.addFileData(createBaseFileData(FileData.Type.HEAT_ENV, module.getVolEnv()));
+ vol.addFileData(createBaseFileData(Type.HEAT_ENV, module.getVolEnv()));
}
fileData.addFileData(vol);
}
}
- private FileData createBaseFileData(FileData.Type heat, String yaml) {
+ private FileData createBaseFileData(Type heat, String yaml) {
FileData fileData = new FileData();
fileData.setType(heat);
fileData.setFile(yaml);
@@ -248,17 +272,17 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
private FileData createModuleFileData(String moduleFileName, boolean isBase, Set<String> processedFiles, Set<String> fileNames,
List<FileData> fileDataList) {
- FileData moduleFileData = createBasicFileData(moduleFileName, FileData.Type.HEAT, isBase);
+ FileData moduleFileData = createBasicFileData(moduleFileName, Type.HEAT, isBase);
Optional<String> volFile = fetchRelatedVolume(moduleFileName, fileNames);
volFile.ifPresent(vol -> {
markFileAsProcessed(vol, processedFiles);
removeFromFileDataListIfAlreadyProcessed(fileDataList, vol);
- FileData volFileData = createBasicFileData(vol, FileData.Type.HEAT_VOL, null);
+ FileData volFileData = createBasicFileData(vol, Type.HEAT_VOL, null);
Optional<String> envFile = fetchRelatedEnv(vol, fileNames);
envFile.ifPresent(env -> {
markFileAsProcessed(env, processedFiles);
removeFromFileDataListIfAlreadyProcessed(fileDataList, env);
- FileData envFileData = createBasicFileData(env, FileData.Type.HEAT_ENV, null);
+ FileData envFileData = createBasicFileData(env, Type.HEAT_ENV, null);
volFileData.addFileData(envFileData);
});
moduleFileData.addFileData(volFileData);
@@ -266,7 +290,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
Optional<String> envFile = fetchRelatedEnv(moduleFileName, fileNames);
envFile.ifPresent(env -> {
markFileAsProcessed(env, processedFiles);
- FileData envFileData = createBasicFileData(env, FileData.Type.HEAT_ENV, null);
+ FileData envFileData = createBasicFileData(env, Type.HEAT_ENV, null);
moduleFileData.addFileData(envFileData);
});
return moduleFileData;
@@ -276,7 +300,7 @@ public class ManifestCreatorNamingConventionImpl implements ManifestCreator {
fileDataList.removeIf(fileData -> fileData.getFile().equals(vol));
}
- private FileData createBasicFileData(String fileName, FileData.Type type, Boolean isBase) {
+ private FileData createBasicFileData(String fileName, Type type, Boolean isBase) {
FileData fileData = new FileData();
if (isBase != null) {
fileData.setBase(isBase);
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 2cea0f73e3..b58a1f90d8 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
@@ -21,20 +21,18 @@
package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Optional;
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.List;
-import java.util.Optional;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-
-public class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNamingConventionImpl {
+class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNamingConventionImpl {
private static final String ARTIFACT_1 = "cloudtech_k8s_charts.zip";
private static final String ARTIFACT_2 = "cloudtech_azure_day0.zip";
@@ -43,14 +41,13 @@ public class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNami
private static final String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip";
private static final String PMDICT_YAML = "pmdict.yaml";
-
@Test
void testIsCloudSpecificArtifact() {
- assertTrue(isCloudSpecificArtifact(ARTIFACT_1));
- assertTrue(isCloudSpecificArtifact(ARTIFACT_2));
- assertTrue(isCloudSpecificArtifact(ARTIFACT_3));
- assertFalse(isCloudSpecificArtifact(ARTIFACT_4));
- assertFalse(isCloudSpecificArtifact(ARTIFACT_5));
+ assertTrue(isCloudSpecificArtifact(ARTIFACT_1, null));
+ assertTrue(isCloudSpecificArtifact(ARTIFACT_2, null));
+ assertTrue(isCloudSpecificArtifact(ARTIFACT_3, null));
+ assertFalse(isCloudSpecificArtifact(ARTIFACT_4, null));
+ assertFalse(isCloudSpecificArtifact(ARTIFACT_5, null));
}
@Test
@@ -63,15 +60,15 @@ public class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNami
// when
Optional<ManifestContent> newManifest = new ManifestCreatorNamingConventionImpl()
- .createManifestFromExisting(vspDetails, fileDataStructure, existingManifest);
+ .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)));
+ .getData()
+ .stream()
+ .allMatch(fd -> fd.getType().equals(FileData.Type.PM_DICTIONARY) &&
+ fd.getFile().equals(PMDICT_YAML)));
}
@Test
@@ -84,15 +81,15 @@ public class ManifestCreatorNamingConventionImplTest extends ManifestCreatorNami
// when
Optional<ManifestContent> newManifest = new ManifestCreatorNamingConventionImpl()
- .createManifestFromExisting(vspDetails, fileDataStructure, existingManifest);
+ .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)));
+ .getData()
+ .stream()
+ .allMatch(fd -> fd.getType().equals(FileData.Type.OTHER) &&
+ fd.getFile().equals(PMDICT_YAML)));
}
private ManifestContent prepareManifestWithPmDictFileWithType(FileData.Type fileType) {