diff options
Diffstat (limited to 'openecomp-be/lib')
2 files changed, 61 insertions, 101 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java index e3701743ec..6fc8cfef61 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java @@ -21,6 +21,8 @@ package org.openecomp.sdc.healing.healers; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.dao.ServiceModelDaoFactory; import org.openecomp.core.model.types.ServiceElement; @@ -114,72 +116,36 @@ public class CompositionDataHealer implements Healer { Collection<NetworkEntity> networkEntities = networkDao.list(new NetworkEntity(vspId, version, null)); - Optional<ToscaServiceModel> serviceModelForHealing = getServiceModelForHealing(vspId, version); + Optional<Pair<ToscaServiceModel, ToscaServiceModel>> serviceModels = + getServiceModelForHealing(vspId, version); CompositionData compositionData = null; - if (!doesVspNeedCompositionDataHealing(vspId, version, componentEntities, networkEntities, - nicEntities)) { + if (!doesVspNeedCompositionDataHealing(componentEntities, networkEntities, nicEntities)) { updateComponentsDisplayNames(componentEntities); mdcDataDebugMessage.debugExitMessage(null, null); - //return Optional.empty(); } else { - if (!serviceModelForHealing.isPresent()) { + if (!serviceModels.isPresent()) { mdcDataDebugMessage.debugExitMessage(null, null); return Optional.empty(); } - compositionData = healCompositionData(vspId, version, serviceModelForHealing); + compositionData = serviceModels.isPresent() ? healCompositionData(vspId, version, + serviceModels.get()) : null; } - compositionData = - getCompositionDataForHealing(vspId, version, serviceModelForHealing.get()); - HealNfodData(vspId, version, compositionData); - mdcDataDebugMessage.debugExitMessage(null, null); - return Optional.of(compositionData); - } - - private boolean doesVspNeedCompositionDataHealing(String vspId, Version version, - Collection<ComponentEntity> componentEntities, - Collection<NetworkEntity> networkEntities, - Collection<NicEntity> nicEntities) { - - return (CollectionUtils.isEmpty(componentEntities) && CollectionUtils.isEmpty(nicEntities) && - CollectionUtils.isEmpty(networkEntities) ); - -// mdcDataDebugMessage.debugEntryMessage(null, null); -// -//// ToscaServiceModel toscaServiceModel; -// -// ByteBuffer contentData = uploadData.getContentData(); -// FileContentHandler fileContentHandler = CommonUtil.validateAndUploadFileContent(uploadData -// .getContentData().array()); -// -// -// -// TranslatorOutput translatorOutput = -// HeatToToscaUtil.loadAndTranslateTemplateData(fileContentHandler); -// ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); -// -//// toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version); -// -// mdcDataDebugMessage.debugExitMessage(null, null); -// return toscaServiceModel; + if(serviceModels.isPresent()) { + compositionData = + getCompositionDataForHealing(vspId, version, serviceModels.get()); + HealNfodData(vspId, version, compositionData); + } + mdcDataDebugMessage.debugExitMessage(null, null); + return Optional.ofNullable(compositionData); } private void HealNfodData(String vspId, Version version, CompositionData compositionData) { Collection<ComponentEntity> componentEntities; - /*componentEntities = - vendorSoftwareProductDao.listComponents(vspId, version);*/ componentEntities = componentDao.list(new ComponentEntity(vspId, version, null)); - /*Collection<ComputeEntity> computeEntities=vendorSoftwareProductDao.listComputesByVsp(vspId, - version); - Collection<ImageEntity> imageEntities =vendorSoftwareProductDao.listImagesByVsp(vspId, version); - Collection<DeploymentFlavorEntity> deploymentFlavorEntities =vendorSoftwareProductDao - .listDeploymentFlavors(vspId, version);*/ - Collection<ComputeEntity> computeEntities = computeDao.listByVsp(vspId, version); Collection<ImageEntity> imageEntities = imageDao.listByVsp(vspId, version); - //Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deloymentFlavorDao.list(new - //DeploymentFlavorEntity(vspId, version, null)); if (CollectionUtils.isEmpty(computeEntities) && CollectionUtils.isEmpty(imageEntities)) { for (Component component : compositionData.getComponents()) { @@ -198,17 +164,12 @@ public class CompositionDataHealer implements Healer { } } - - /*if (CollectionUtils.isEmpty(deploymentFlavorEntities)) { - compositionEntityDataManager.saveDeploymentFlavors(vspId,version,compositionData); - }*/ } private CompositionData healCompositionData(String vspId, Version version, - Optional<ToscaServiceModel> serviceModelForHealing) { - ToscaServiceModel toscaServiceModel = serviceModelForHealing.get(); + Pair<ToscaServiceModel, ToscaServiceModel> toscaServiceModels) { CompositionData compositionData = - getCompositionDataForHealing(vspId, version, toscaServiceModel); + getCompositionDataForHealing(vspId, version, toscaServiceModels); compositionEntityDataManager.saveCompositionData(vspId, version, compositionData); return compositionData; } @@ -222,19 +183,16 @@ public class CompositionDataHealer implements Healer { } private CompositionData getCompositionDataForHealing(String vspId, Version version, - ToscaServiceModel toscaServiceModel) { + Pair<ToscaServiceModel, ToscaServiceModel> toscaServiceModels) { mdcDataDebugMessage.debugEntryMessage(null); - if (Objects.isNull(toscaServiceModel)) { + if (Objects.isNull(toscaServiceModels)) { return null; } - CompositionData compositionData = new CompositionData(); - if (Objects.nonNull(toscaServiceModel)) { - compositionData = compositionDataExtractor - .extractServiceCompositionData(toscaServiceModel); - serviceModelDao.storeServiceModel(vspId, version, toscaServiceModel); - } + CompositionData compositionData = compositionDataExtractor + .extractServiceCompositionData(toscaServiceModels.getRight()); + serviceModelDao.storeServiceModel(vspId, version, toscaServiceModels.getLeft()); mdcDataDebugMessage.debugExitMessage(null); return compositionData; @@ -269,12 +227,12 @@ public class CompositionDataHealer implements Healer { } - private Optional<ToscaServiceModel> getServiceModelForHealing(String vspId, Version version) + private Optional<Pair<ToscaServiceModel, ToscaServiceModel>> getServiceModelForHealing(String + vspId, Version + version) throws IOException { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); - /*UploadDataEntity uploadData = - vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version));*/ UploadDataEntity uploadData = orchestrationTemplateDataDao.getOrchestrationTemplate(vspId, version); @@ -297,7 +255,8 @@ public class CompositionDataHealer implements Healer { } mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return Optional.of(translatorOutput.getToscaServiceModel()); + return Optional.of(new ImmutablePair<>(translatorOutput.getToscaServiceModel(), translatorOutput + .getNonUnifiedToscaServiceModel())); } private TranslatorOutput getTranslatorOutputForHealing(UploadDataEntity uploadData) { diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java index 69fa33aae7..348739e780 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java @@ -36,7 +36,7 @@ public class ToscaConverterImpl implements ToscaConverter { @Override public ToscaServiceModel convert(FileContentHandler fileContentHandler) - throws IOException { + throws IOException { Map<String, byte[]> csarFiles = new HashMap<>(fileContentHandler.getFiles()); ToscaServiceModel toscaServiceModel = new ToscaServiceModel(); Map<String, ServiceTemplate> serviceTemplates = new HashMap<>(); @@ -88,9 +88,9 @@ public class ToscaConverterImpl implements ToscaConverter { } } catch (YAMLException ye) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() - .withMessage("Invalid YAML content in file " + key + ". reason - " - + ye.getMessage()) - .withCategory(ErrorCategory.APPLICATION).build()); + .withMessage("Invalid YAML content in file " + key + ". reason - " + + ye.getMessage()) + .withCategory(ErrorCategory.APPLICATION).build()); } } @@ -100,7 +100,7 @@ public class ToscaConverterImpl implements ToscaConverter { GlobalSubstitutionServiceTemplate globalSubstitutionServiceTemplate, Map<String, byte[]> csarFiles) { Collection<ServiceTemplate> globalServiceTemplates = - GlobalTypesGenerator.getGlobalTypesServiceTemplate().values(); + GlobalTypesGenerator.getGlobalTypesServiceTemplate().values(); addGlobalServiceTemplates(globalServiceTemplates, serviceTemplates); toscaServiceModel.setEntryDefinitionServiceTemplate(mainStName); toscaServiceModel.setServiceTemplates(serviceTemplates); @@ -125,10 +125,10 @@ public class ToscaConverterImpl implements ToscaConverter { String fileName, Map<String, byte[]> csarFiles, Map<String, ServiceTemplate> serviceTemplates) { Optional<ServiceTemplate> serviceTemplate = - getServiceTemplateFromCsar(fileName, csarFiles); + getServiceTemplateFromCsar(fileName, csarFiles); serviceTemplate.ifPresent( - serviceTemplate1 -> addServiceTemplate(serviceTemplateName, serviceTemplate1, - serviceTemplates)); + serviceTemplate1 -> addServiceTemplate(serviceTemplateName, serviceTemplate1, + serviceTemplates)); } private void addServiceTemplate(String serviceTemplateName, @@ -160,7 +160,7 @@ public class ToscaConverterImpl implements ToscaConverter { ServiceTemplate serviceTemplate = new ServiceTemplate(); try { ServiceTemplateReaderService readerService = - new ServiceTemplateReaderServiceImpl(fileContent); + new ServiceTemplateReaderServiceImpl(fileContent); convertMetadata(serviceTemplateName, serviceTemplate, readerService); convertToscaVersion(serviceTemplate, readerService); convertImports(serviceTemplate); @@ -169,9 +169,9 @@ public class ToscaConverterImpl implements ToscaConverter { } catch (YAMLException ye) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() - .withMessage("Invalid YAML content in file" + serviceTemplateName + ". reason - " - + ye.getMessage()) - .withCategory(ErrorCategory.APPLICATION).build()); + .withMessage("Invalid YAML content in file" + serviceTemplateName + ". reason - " + + ye.getMessage()) + .withCategory(ErrorCategory.APPLICATION).build()); } @@ -187,7 +187,7 @@ public class ToscaConverterImpl implements ToscaConverter { private void convertImports(ServiceTemplate serviceTemplate) { serviceTemplate.setImports(new ArrayList<>()); serviceTemplate.getImports() - .add(createImportMap(openecompHeatIndex, "openecomp-heat/_index.yml")); + .add(createImportMap(openecompHeatIndex, "openecomp-heat/_index.yml")); serviceTemplate.getImports().add(createImportMap(globalSubstitution, globalStName)); } @@ -210,7 +210,7 @@ public class ToscaConverterImpl implements ToscaConverter { if (MapUtils.isNotEmpty(metadataToConvert)) { for (Map.Entry<String, Object> metadataEntry : metadataToConvert.entrySet()) { if (Objects.isNull(metadataEntry.getValue()) || - !(metadataEntry.getValue() instanceof String)) { + !(metadataEntry.getValue() instanceof String)) { continue; } finalMetadata.put(metadataEntry.getKey(), (String) metadataEntry.getValue()); @@ -229,9 +229,9 @@ public class ToscaConverterImpl implements ToscaConverter { for (Map.Entry<String, Object> nodeTypeEntry : nodeTypes.entrySet()) { DataModelUtil - .addNodeType(serviceTemplate, nodeTypeEntry.getKey(), - (NodeType) createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), - NodeType.class)); + .addNodeType(serviceTemplate, nodeTypeEntry.getKey(), + (NodeType) createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), + NodeType.class)); } } @@ -265,10 +265,10 @@ public class ToscaConverterImpl implements ToscaConverter { for (Map.Entry<String, Object> entry : mapToConvert.entrySet()) { ParameterDefinition parameterDefinition = - (ParameterDefinition) createObjectFromClass( - entry.getKey(), entry.getValue(), ParameterDefinition.class); + (ParameterDefinition) createObjectFromClass( + entry.getKey(), entry.getValue(), ParameterDefinition.class); addToServiceTemplateAccordingToSection( - serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition); + serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition); } } @@ -279,11 +279,11 @@ public class ToscaConverterImpl implements ToscaConverter { switch (inputsOrOutputs) { case inputs: DataModelUtil - .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); break; case outputs: DataModelUtil - .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); } } @@ -315,15 +315,15 @@ public class ToscaConverterImpl implements ToscaConverter { substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType)); substitutionMapping.setCapabilities( - convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(capabilities))); + convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(capabilities))); substitutionMapping.setRequirements( - convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(requirements))); + convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(requirements))); return substitutionMapping; } private Map<String, List<String>> convertSubstitutionMappingsSections( - Map<String, Object> sectionToConvert) { + Map<String, Object> sectionToConvert) { Map<String, List<String>> convertedSection = new HashMap<>(); if (MapUtils.isEmpty(sectionToConvert)) { return null; @@ -345,7 +345,7 @@ public class ToscaConverterImpl implements ToscaConverter { return CsarFileTypes.globalServiceTemplate; } else if (isDefinitions(fileName)) { return CsarFileTypes.definitionsFile; - } else if (isMetadataFile(metadataFile)) { + } else if (isMetadataFile(fileName)) { return CsarFileTypes.toscaMetadata; } return CsarFileTypes.externalFile; @@ -373,14 +373,14 @@ public class ToscaConverterImpl implements ToscaConverter { nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description")); nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives")); nodeTemplate.setInterfaces( - (Map<String, InterfaceDefinition>) nodeTemplateAsMap.get("interfaces")); + (Map<String, InterfaceDefinition>) nodeTemplateAsMap.get("interfaces")); nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter")); nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties")); nodeTemplate.setRequirements( - (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements")); + (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements")); nodeTemplate.setType((String) nodeTemplateAsMap.get("type")); nodeTemplate.setCapabilities( - convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities"))); + convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities"))); return nodeTemplate; } @@ -393,8 +393,8 @@ public class ToscaConverterImpl implements ToscaConverter { for (Map.Entry<String, Object> capabilityAssignmentEntry : capabilities.entrySet()) { Map<String, CapabilityAssignment> tempMap = new HashMap<>(); tempMap.put(capabilityAssignmentEntry.getKey(), - (CapabilityAssignment) createObjectFromClass - (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), CapabilityAssignment.class)); + (CapabilityAssignment) createObjectFromClass + (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), CapabilityAssignment.class)); convertedCapabilities.add(tempMap); } return convertedCapabilities; @@ -408,8 +408,9 @@ public class ToscaConverterImpl implements ToscaConverter { } catch (Exception e) { //todo - return error to user? throw new CoreException(new ErrorCode.ErrorCodeBuilder() - .withCategory(ErrorCategory.APPLICATION) - .withMessage("Can't create Node Type from " + nodeTypeId).build()); + .withCategory(ErrorCategory.APPLICATION) + .withMessage("Can't create " + classToCreate.getSimpleName() + " from " + + nodeTypeId).build()); } } |