From 644017cb3edd5b7a077a634ffd5daf2fee6bc088 Mon Sep 17 00:00:00 2001 From: az2497 Date: Thu, 10 Aug 2017 17:49:40 +0300 Subject: [SDC] OnBoard with enabled tests and features Change-Id: I4c1bbf6e1c854cf97a3561c736f83da44b58b7c0 Signed-off-by: az2497 [SDC] OnBoard with enabled tests and features. Change-Id: Icd52f039aee4dd393a1404d530bb9fdd0b20e604 Signed-off-by: az2497 --- .../src/main/resources/healingConfiguration.json | 3 +- .../healing/healers/ValidationStructureHealer.java | 273 +++++++++++++++++++++ 2 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ValidationStructureHealer.java (limited to 'openecomp-be/lib/openecomp-healing-lib') diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/healingConfiguration.json b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/healingConfiguration.json index 105dbe5875..9f83296a71 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/healingConfiguration.json +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/resources/healingConfiguration.json @@ -7,5 +7,6 @@ "NIC_DATA_HEALER" : "org.openecomp.sdc.healing.healers.NicDataHealer", "COMPONENT_QUESTIONNAIRE_HEALER" : "org.openecomp.sdc.healing.healers.ComponentQuestionnaireHealer", "HEAT_TOSCA_TRANSLATION_HEALER" : "org.openecomp.sdc.healing.healers.HeatToToscaTranslationHealer", - "VLM_VERSION_HEALER" : "org.openecomp.sdc.healing.healers.VlmVersionHealer" + "VLM_VERSION_HEALER" : "org.openecomp.sdc.healing.healers.VlmVersionHealer", + "VALIDATION_STRUCTURE_HEALER" : "org.openecomp.sdc.healing.healers.ValidationStructureHealer" } \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ValidationStructureHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ValidationStructureHealer.java new file mode 100644 index 0000000000..f92fbd1730 --- /dev/null +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ValidationStructureHealer.java @@ -0,0 +1,273 @@ +package org.openecomp.sdc.healing.healers; + +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.healing.interfaces.Healer; +import org.openecomp.sdc.heat.datatypes.manifest.FileData; +import org.openecomp.sdc.heat.datatypes.structure.Artifact; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +/** + * Created by Talio on 7/30/2017. + */ +public class ValidationStructureHealer implements Healer { + + private static final VendorSoftwareProductInfoDao vspInfoDao = + VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); + private static final OrchestrationTemplateDao orchestrationTemplateDao = + OrchestrationTemplateDaoFactory.getInstance().createInterface(); + + @Override + public Object heal(Map healingParams) throws Exception { + + String vspId = (String) healingParams.get(SdcCommon.VSP_ID); + Version version = (Version) healingParams.get(SdcCommon.VERSION); + + VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version)); + UploadDataEntity orchestrationTemplate = + orchestrationTemplateDao.getOrchestrationTemplate(vspId, version); + + OldValidationStructureTree oldValidationStructureTree; + try{ + oldValidationStructureTree = + JsonUtil.json2Object(orchestrationTemplate.getValidationData(), OldValidationStructureTree + .class); + } catch (Exception e){ + return Optional.empty(); + } + + Optional newHeatStructureTreeFromOldStructureTree = + createNewHeatStructureTreeFromOldStructureTree(oldValidationStructureTree.getImportStructure()); + + if(newHeatStructureTreeFromOldStructureTree.isPresent()){ + ValidationStructureList validationData = new ValidationStructureList + (newHeatStructureTreeFromOldStructureTree.get()); + vspDetails.setValidationDataStructure(validationData); + + updateValuesInDb(vspId, vspDetails, orchestrationTemplate, validationData); + } + return newHeatStructureTreeFromOldStructureTree; + + } + + private void updateValuesInDb(String vspId, VspDetails vspDetails, + UploadDataEntity orchestrationTemplate, + ValidationStructureList validationData) { + vspInfoDao.update(vspDetails); + UploadData uploadData = getUpdatedUploadData(orchestrationTemplate, validationData); + orchestrationTemplateDao.updateOrchestrationTemplateData(vspId, uploadData); + } + + private UploadData getUpdatedUploadData(UploadDataEntity orchestrationTemplate, + ValidationStructureList validationData) { + UploadData uploadData = new UploadData(); + uploadData.setValidationDataStructure(validationData); + uploadData.setValidationData(JsonUtil.object2Json(validationData)); + uploadData.setContentData(orchestrationTemplate.getContentData()); + uploadData.setId(orchestrationTemplate.getId()); + uploadData.setPackageName(orchestrationTemplate.getPackageName()); + uploadData.setPackageVersion(orchestrationTemplate.getPackageVersion()); + return uploadData; + } + + + private Optional createNewHeatStructureTreeFromOldStructureTree(OldHeatStructureTree + oldHeatStructureTree){ + + HeatStructureTree heatStructureTree = new HeatStructureTree(); + + if(Objects.isNull(oldHeatStructureTree)){ + return Optional.empty(); + } + + mapOldHeatStructureTreeValues(oldHeatStructureTree, heatStructureTree); + + Set heat = + oldHeatStructureTree.getHeat() == null ? new HashSet<>() : oldHeatStructureTree.getHeat(); + Set volume = + oldHeatStructureTree.getVolume() == null ? new HashSet<>() : oldHeatStructureTree.getVolume(); + Set nested = + oldHeatStructureTree.getNested() == null ? new HashSet<>() : oldHeatStructureTree.getNested(); + Set network = + oldHeatStructureTree.getNetwork() == null ? new HashSet<>() : oldHeatStructureTree.getNetwork(); + + + heatStructureTree.setHeat(createHeatStructureTreeSetFromOld(heat)); + heatStructureTree.setVolume(createHeatStructureTreeSetFromOld(volume)); + heatStructureTree.setNested(createHeatStructureTreeSetFromOld(nested)); + heatStructureTree.setNetwork(createHeatStructureTreeSetFromOld(network)); + + + return Optional.of(heatStructureTree); + + } + + private void mapOldHeatStructureTreeValues( + OldHeatStructureTree oldHeatStructureTree, + HeatStructureTree heatStructureTree) { + heatStructureTree.setFileName(oldHeatStructureTree.getFileName()); + heatStructureTree.setBase(oldHeatStructureTree.getBase()); + heatStructureTree.setType(oldHeatStructureTree.getType()); + heatStructureTree.setArtifacts(oldHeatStructureTree.getArtifacts()); + heatStructureTree.setErrors(oldHeatStructureTree.getErrors()); + + if(Objects.nonNull(oldHeatStructureTree.getEnv())) { + heatStructureTree.setEnv(new HeatStructureTree(oldHeatStructureTree.getEnv(), false)); + } + } + + private Set createHeatStructureTreeSetFromOld(Set + oldHeatStructureTreeSet){ + if(CollectionUtils.isEmpty(oldHeatStructureTreeSet)){ + return null; + } + Set newHeatStructureSet = new HashSet<>(); + + for(OldHeatStructureTree old : oldHeatStructureTreeSet){ + Optional newHeatStructureTree = + createNewHeatStructureTreeFromOldStructureTree(old); + if(newHeatStructureTree.isPresent()){ + newHeatStructureSet.add(newHeatStructureTree.get()); + } + } + + return newHeatStructureSet; + } + + private class OldValidationStructureTree{ + private OldHeatStructureTree importStructure; + + public OldHeatStructureTree getImportStructure() { + return importStructure; + } + + public void setImportStructure( + OldHeatStructureTree importStructure) { + this.importStructure = importStructure; + } + } + + private class OldHeatStructureTree{ + private String fileName; + private FileData.Type type; + private Boolean isBase; + private String env; + private List errors; + private Set heat; + private Set volume; + private Set network; + private Set nested; + private Set other; + private Set artifacts; + + public OldHeatStructureTree() { + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public FileData.Type getType() { + return type; + } + + public void setType(FileData.Type type) { + this.type = type; + } + + public Boolean getBase() { + return isBase; + } + + public void setBase(Boolean base) { + isBase = base; + } + + public String getEnv() { + return env; + } + + public void setEnv(String env) { + this.env = env; + } + + public List getErrors() { + return errors; + } + + public void setErrors(List errors) { + this.errors = errors; + } + + public Set getHeat() { + return heat; + } + + public void setHeat(Set heat) { + this.heat = heat; + } + + public Set getVolume() { + return volume; + } + + public void setVolume(Set volume) { + this.volume = volume; + } + + public Set getNetwork() { + return network; + } + + public void setNetwork( + Set network) { + this.network = network; + } + + public Set getNested() { + return nested; + } + + public void setNested(Set nested) { + this.nested = nested; + } + + public Set getOther() { + return other; + } + + public void setOther(Set other) { + this.other = other; + } + + public Set getArtifacts() { + return artifacts; + } + + public void setArtifacts(Set artifacts) { + this.artifacts = artifacts; + } +} +} -- cgit 1.2.3-korg