diff options
11 files changed, 482 insertions, 520 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java index a3a76a561b..34177bbcff 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-api/src/main/java/org/openecomp/core/enrichment/types/ComponentMonitoringUploadInfo.java @@ -31,30 +31,21 @@ public class ComponentMonitoringUploadInfo { private Map<MonitoringUploadType, MonitoringArtifactInfo> infoByType = new HashMap<>(); - //todo as part of ATTASDC-4503 - public MonitoringArtifactInfo getSnmpTrap() { return infoByType.get(SNMP_TRAP); } - public void setSnmpTrap(MonitoringArtifactInfo snmpTrapInfo) { - infoByType.put(SNMP_TRAP, snmpTrapInfo); - } - public MonitoringArtifactInfo getSnmpPoll() { return infoByType.get(SNMP_POLL); } - public void setSnmpPoll(MonitoringArtifactInfo snmpPollInfo) { - infoByType.put(SNMP_POLL, snmpPollInfo); - } - public MonitoringArtifactInfo getVesEvent() { return infoByType.get(VES_EVENTS); } - public void setVesEvent(MonitoringArtifactInfo snmpPollInfo) { - infoByType.put(VES_EVENTS, snmpPollInfo); + public void setMonitoringArtifactFile(MonitoringUploadType type, + MonitoringArtifactInfo monitoringArtifactInfo) { + infoByType.put(type, monitoringArtifactInfo); } } diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java index 57c1d19f03..e55ad880e9 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ExternalArtifactEnricher.java @@ -28,6 +28,7 @@ import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import java.lang.reflect.Constructor; import java.util.Collection; @@ -38,9 +39,6 @@ import java.util.Map; public class ExternalArtifactEnricher extends Enricher { private MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private static String EXTERNAL_ARTIFACT_ENRICH_CONF_FILE = "ExternalArtifactConfiguration.json"; - private static final String EXTERNAL_ARTIFACT_ENRICH_ERROR = "ERROR_CREATING_EXTERNAL_ARTIFACTS"; - private static final String EXTERNAL_ARTIFACT_ENRICH_ERROR_MSG = - "An Error has occured during enrichment of external artifacts "; private static Collection<String> implementingClasses = getExternalArtifactEnrichedImplClassesList(); private static Logger logger = LoggerFactory.getLogger(ExternalArtifactEnricher.class); @@ -57,21 +55,21 @@ public class ExternalArtifactEnricher extends Enricher { public Map<String, List<ErrorMessage>> enrich() { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); Map<String, List<ErrorMessage>> errors = new HashMap<>(); try { for (String implementingClassName : implementingClasses) { ExternalArtifactEnricherInterface externalArtifactEnricherInstance = getExternalArtifactEnricherInstance(implementingClassName); - externalArtifactEnricherInstance.enrich(this.data); + externalArtifactEnricherInstance.enrich(this.data, (ToscaServiceModel) this.model); } } catch (Exception e) { logger.debug("",e); logger.error(e.getMessage()); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return errors; } diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java index ff0e9b4838..f15d83cd55 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java @@ -37,7 +37,10 @@ import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; -import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.Directive; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; @@ -49,28 +52,37 @@ import org.openecomp.sdc.versioning.dao.types.Version; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; +import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; +import static org.openecomp.sdc.tosca.services.ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME; + public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface { private EnrichedServiceModelDao enrichedServiceModelDao; private ComponentDao componentDao; private ComponentArtifactDao componentArtifactDao; private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private static final String COMPONENT_PREFIX = "org.openecomp.resource.vfc."; + + private final Logger LOG = LoggerFactory.getLogger(this.getClass().getName()); - private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); /** * Enrich map. * * @param enrichmentInfo the enrichmentInfo * @return the map */ - public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo) { + public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo, + ToscaServiceModel serviceModel) { Map<String, List<ErrorMessage>> errors = new HashMap<>(); String vspId = enrichmentInfo.getKey(); @@ -79,33 +91,115 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface Collection<ComponentEntity> components = getComponentDao().list(new ComponentEntity(vspId, version, null)); components - .forEach(componentEntry -> errors.putAll(enrichComponent(componentEntry, vspId, version))); + .forEach(componentEntry -> errors.putAll(enrichComponent(vspId, version, componentEntry, + serviceModel))); return errors; } - Map<String, List<ErrorMessage>> enrichComponent(ComponentEntity componentEntry, String vspId, - Version version) { + private Map<String, List<ErrorMessage>> enrichComponent(String vspId, + Version version, + ComponentEntity component, + ToscaServiceModel serviceModel) { + Set<String> abstractNodeTypes = + extractAbstractTypesFromSameTypeFromServiceModel(component, serviceModel); + return enrichComponent(vspId, version, component, abstractNodeTypes); + } + + private Set<String> extractAbstractTypesFromSameTypeFromServiceModel(ComponentEntity component, + ToscaServiceModel serviceModel) { + Set<String> abstractNodeTypes = new HashSet<>(); + Map<String, ServiceTemplate> serviceTemplates = serviceModel.getServiceTemplates(); + String typeToCheck = + getComponentVfcTypeToCheck(component.getComponentCompositionData().getName()); + + for (ServiceTemplate serviceTemplate : serviceTemplates.values()) { + collectAllAbstractNodeTypesPointingToType( + typeToCheck, serviceTemplate, serviceTemplates, abstractNodeTypes); + } + + return abstractNodeTypes; + } + + private String getComponentVfcTypeToCheck(String type) { + return Objects.isNull(type) ? "" + : type.replace(COMPONENT_PREFIX, COMPONENT_PREFIX + "compute."); + } + + private void collectAllAbstractNodeTypesPointingToType(String typeToCheck, + ServiceTemplate serviceTemplate, + Map<String, ServiceTemplate> serviceTemplates, + Set<String> abstractNodeTypes) { + Map<String, NodeTemplate> nodeTemplates = + DataModelUtil.getNodeTemplates(serviceTemplate); + + for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) { + handleNodeTemplate(nodeTemplateEntry.getValue(), typeToCheck, + serviceTemplates, abstractNodeTypes); + } + } + + private void handleNodeTemplate(NodeTemplate nodeTemplate, + String typeToCheck, + Map<String, ServiceTemplate> serviceTemplates, + Set<String> abstractNodeTypes) { + List<String> directives = DataModelUtil.getDirectives(nodeTemplate); + if (directives.contains(Directive.SUBSTITUTABLE.getDisplayName())) { + handleSubstitutionServiceTemplate(typeToCheck, nodeTemplate, serviceTemplates, + abstractNodeTypes); + } + } + + private void handleSubstitutionServiceTemplate(String typeToCheck, + NodeTemplate nodeTemplate, + Map<String, ServiceTemplate> serviceTemplates, + Set<String> abstractNodeTypes) { + Object serviceTemplateFilter = + DataModelUtil.getPropertyValue(nodeTemplate, SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); + if (Objects.nonNull(serviceTemplateFilter) && serviceTemplateFilter instanceof Map) { + String substituteServiceTemplateName = + (String) ((Map<String, Object>) serviceTemplateFilter) + .get(SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME); + ServiceTemplate substituteServiceTemplate = + serviceTemplates.get(substituteServiceTemplateName); + if (doesNodeTypeExistInSubServiceTemplate(typeToCheck, substituteServiceTemplate)) { + abstractNodeTypes.add(nodeTemplate.getType()); + } + } + } + + private boolean doesNodeTypeExistInSubServiceTemplate(String nodeTypeId, + ServiceTemplate substituteServiceTemplate) { + return Objects + .nonNull(DataModelUtil.getNodeType(substituteServiceTemplate, nodeTypeId)); + } + + Map<String, List<ErrorMessage>> enrichComponent(String vspId, + Version version, + ComponentEntity componentEntry, + Set<String> abstractNodeTypes) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); Map<String, List<ErrorMessage>> errors = new HashMap<>(); - ComponentMonitoringUploadInfo componentMonitoringUploadInfo = - extractComponentMibInfo(componentEntry, vspId, version, errors); - enrichComponentMib(componentMonitoringUploadInfo, vspId, version, errors); - mdcDataDebugMessage.debugExitMessage(null, null); + List<ComponentMonitoringUploadInfo> componentMonitoringUploadInfoList = + extractComponentMibInfo(vspId, version, componentEntry, abstractNodeTypes); + + componentMonitoringUploadInfoList.forEach( + componentUploadInfo -> enrichComponentMib(vspId, version, componentUploadInfo, errors)); + + mdcDataDebugMessage.debugExitMessage(null); return errors; } - private ComponentMonitoringUploadInfo extractComponentMibInfo(ComponentEntity componentEntity, - String vspId, - Version version, - Map<String, List<ErrorMessage>> errors) { + private List<ComponentMonitoringUploadInfo> extractComponentMibInfo(String vspId, Version version, + ComponentEntity componentEntity, + Set<String> abstractNodeTypes) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); String componentId = componentEntity.getId(); ComponentMonitoringUploadEntity entity = new ComponentMonitoringUploadEntity(); @@ -113,79 +207,70 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface entity.setVspId(vspId); entity.setVersion(version); entity.setComponentId(componentId); - String componentName = componentEntity.getComponentCompositionData().getName(); - ComponentMonitoringUploadInfo componentMonitoringUploadInfo = - new ComponentMonitoringUploadInfo(); - for (MonitoringUploadType monitoringUploadType : MonitoringUploadType.values()) { - updComponentMibInfoByType(componentName, monitoringUploadType, entity, - componentMonitoringUploadInfo, - errors); - } -// updComponentMibInfoByType(componentName, MonitoringUploadType.SNMP_POLL, entity, -// componentMonitoringUploadInfo, -// errors); -// updComponentMibInfoByType(componentName, MonitoringUploadType.SNMP_TRAP, entity, -// componentMonitoringUploadInfo, -// errors); - - mdcDataDebugMessage.debugExitMessage(null, null); - return componentMonitoringUploadInfo; + List<ComponentMonitoringUploadInfo> componentMonitoringUploadInfoList = new ArrayList<>(); + + abstractNodeTypes.forEach(unifiedComponentNodeType -> componentMonitoringUploadInfoList + .add(updComponentMibInfoByType(unifiedComponentNodeType, entity))); + + mdcDataDebugMessage.debugExitMessage(null); + return componentMonitoringUploadInfoList; } - private void updComponentMibInfoByType(String componentName, MonitoringUploadType type, - ComponentMonitoringUploadEntity componentMonitoringUploadEntity, - ComponentMonitoringUploadInfo componentMonitoringUploadInfo, - Map<String, List<ErrorMessage>> errors) { + private ComponentMonitoringUploadInfo updComponentMibInfoByType(String componentName, + ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); - String path; - componentMonitoringUploadEntity.setType(type); - Optional<ComponentMonitoringUploadEntity> artifact = - getComponentArtifactDao().getByType(componentMonitoringUploadEntity); + ComponentMonitoringUploadInfo componentMonitoringUploadInfo = + new ComponentMonitoringUploadInfo(); - if (!artifact.isPresent()) { - return; + for (MonitoringUploadType type : MonitoringUploadType.values()) { + componentMonitoringUploadEntity.setType(type); + Optional<ComponentMonitoringUploadEntity> artifact = + getComponentArtifactDao().getByType(componentMonitoringUploadEntity); + + if (!artifact.isPresent()) { + continue; + } + ComponentMonitoringUploadEntity mibArtifact = artifact.get(); + updateComponentMonitoringUploadInfoWithMib(getArtifactPath(type, componentName), type, + mibArtifact, + componentMonitoringUploadInfo); } - String unifiedComponentNodeType = - ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + DataModelUtil.getNamespaceSuffix(componentName); - path = unifiedComponentNodeType + File.separator + ArtifactCategory.DEPLOYMENT.getDisplayName() + + mdcDataDebugMessage.debugExitMessage(null); + return componentMonitoringUploadInfo; + } + + private String getArtifactPath(MonitoringUploadType type, String unifiedComponentNodeType) { + return unifiedComponentNodeType + File.separator + ArtifactCategory.DEPLOYMENT.getDisplayName() + File.separator + type.name(); + } + + private void updateComponentMonitoringUploadInfoWithMib(String path, + MonitoringUploadType type, + ComponentMonitoringUploadEntity mibArtifact, + ComponentMonitoringUploadInfo componentMonitoringUploadInfo) { MonitoringArtifactInfo monitoringArtifactInfo = new MonitoringArtifactInfo(); monitoringArtifactInfo.setName(path); - monitoringArtifactInfo.setContent(artifact.get().getArtifact().array()); - switch (type) { //todo as part of ATTASDC-4503 - case SNMP_POLL: - componentMonitoringUploadInfo.setSnmpPoll(monitoringArtifactInfo); - break; - case SNMP_TRAP: - componentMonitoringUploadInfo.setSnmpTrap(monitoringArtifactInfo); - break; - case VES_EVENTS: - componentMonitoringUploadInfo.setVesEvent(monitoringArtifactInfo); - break; - default: - break; - } - - mdcDataDebugMessage.debugExitMessage(null, null); + monitoringArtifactInfo.setContent(mibArtifact.getArtifact().array()); + componentMonitoringUploadInfo.setMonitoringArtifactFile(type, monitoringArtifactInfo); } - private void enrichComponentMib(ComponentMonitoringUploadInfo componentMonitoringUploadInfo, - String vspId, + private void enrichComponentMib(String vspId, Version version, + ComponentMonitoringUploadInfo componentUploadInfo, Map<String, List<ErrorMessage>> errors) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); ServiceArtifact mibServiceArtifact = new ServiceArtifact(); mibServiceArtifact.setVspId(vspId); mibServiceArtifact.setVersion(version); - enrichMibFiles(mibServiceArtifact, componentMonitoringUploadInfo, errors); + enrichMibFiles(mibServiceArtifact, componentUploadInfo, errors); + - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } private void enrichMibFiles(ServiceArtifact monitoringArtifact, @@ -193,12 +278,11 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface Map<String, List<ErrorMessage>> errors) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (componentMonitoringUploadInfo == null) { return; } - //todo fix as part of ATTASDC-4503 enrichMibByType(componentMonitoringUploadInfo.getSnmpTrap(), MonitoringUploadType.SNMP_TRAP, monitoringArtifact, errors); @@ -209,7 +293,7 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface monitoringArtifact, errors); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } private void enrichMibByType(MonitoringArtifactInfo monitoringArtifactInfo, @@ -218,7 +302,7 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface Map<String, List<ErrorMessage>> errors) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (monitoringArtifactInfo == null) { return; @@ -228,7 +312,7 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface mibs = FileUtils .getFileContentMapFromZip(FileUtils.toByteArray(monitoringArtifactInfo.getContent())); } catch (IOException ioException) { - log.debug("",ioException); + LOG.debug("", ioException); ErrorMessage.ErrorMessageUtil .addMessage(mibServiceArtifact.getName() + "." + type.name(), errors) .add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); @@ -241,7 +325,7 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface getEnrichedServiceModelDao().storeExternalArtifact(mibServiceArtifact); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } private EnrichedServiceModelDao getEnrichedServiceModelDao() { diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java index 828de7244c..089cfe7a82 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java @@ -10,6 +10,7 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.enrichment.EnrichmentInfo; import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface; import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; @@ -29,13 +30,13 @@ import java.util.Map; public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterface { private ComponentDao componentDao; - //private ProcessArtifactDao processArtifactDao; private ProcessDao processDao; private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private EnrichedServiceModelDao enrichedServiceModelDao; @Override - public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo) throws IOException { + public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo, + ToscaServiceModel serviceModel) throws IOException { Map<String, List<ErrorMessage>> errors = new HashMap<>(); String vspId = enrichmentInfo.getKey(); Version version = enrichmentInfo.getVersion(); @@ -72,18 +73,11 @@ public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterfac ProcessEntity processEntity = new ProcessEntity(vspId, version, componentId, null); final Collection<ProcessEntity> processes = getProcessDao().list(processEntity); - /*processes.stream() - .filter(entity -> entity.getType().equals(ProcessType.Lifecycle_Operations)) - .forEach(entity -> { - ProcessArtifactEntity artifactEntity = new ProcessArtifactEntity(vspId, version, - componentId, entity.getId());*/ - processes.forEach(entity -> { ProcessEntity artifactEntity = new ProcessEntity(vspId, version, componentId, entity.getId()); ProcessEntity artifactProcessEntity = getProcessDao().get(artifactEntity); - //ProcessArtifactEntity artifact = getProcessArtifactDao().get(artifactEntity); if (artifactProcessEntity != null && ProcessType.Lifecycle_Operations.equals( artifactProcessEntity.getType()) && artifactProcessEntity.getArtifactName() != null ) { @@ -99,7 +93,7 @@ public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterfac ServiceArtifact processServiceArtifact = new ServiceArtifact(); processServiceArtifact.setVspId(vspId); processServiceArtifact.setVersion(version); - enrichServiceArtifact(componentProcessInfo, processServiceArtifact, errors); + enrichServiceArtifact(componentProcessInfo, processServiceArtifact); } }); @@ -107,8 +101,7 @@ public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterfac } void enrichServiceArtifact(ComponentProcessInfo componentProcessInfo, - ServiceArtifact processServiceArtifact, - Map<String, List<ErrorMessage>> errors) { + ServiceArtifact processServiceArtifact) { mdcDataDebugMessage.debugEntryMessage(null); diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java index 9e46a5c33d..3836796420 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/VspInformationArtifactEnricher.java @@ -31,6 +31,7 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.enrichment.EnrichmentInfo; import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface; import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; @@ -63,14 +64,13 @@ public class VspInformationArtifactEnricher implements ExternalArtifactEnricherI public VspInformationArtifactEnricher() { } - public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo) + public Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo, + ToscaServiceModel serviceModel) throws IOException { String vspId = enrichmentInfo.getKey(); Version version = enrichmentInfo.getVersion(); - Map<String, List<ErrorMessage>> errors = enrichInformationArtifact(vspId, version); - - return errors; + return enrichInformationArtifact(vspId, version); } private Map<String, List<ErrorMessage>> enrichInformationArtifact(String vspId, Version version) @@ -88,7 +88,6 @@ public class VspInformationArtifactEnricher implements ExternalArtifactEnricherI errorList.add(new ErrorMessage(ErrorLevel.ERROR, String.format( "Cannot enrich information artifact for vendor software product with id %s and version %s", vspId, version.toString()))); - //TODO: add error to map (what is the key?) mdcDataDebugMessage.debugExitMessage(null); return errors; diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/ExternalArtifactEnricherInterface.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/ExternalArtifactEnricherInterface.java index bd250bb8f4..dd1f13d034 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/ExternalArtifactEnricherInterface.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/inter/ExternalArtifactEnricherInterface.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.enrichment.inter; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.enrichment.EnrichmentInfo; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import java.io.IOException; import java.util.List; @@ -32,5 +33,6 @@ import java.util.Map; * Created by Talio on 11/24/2016. */ public interface ExternalArtifactEnricherInterface { - Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo) throws IOException; + Map<String, List<ErrorMessage>> enrich(EnrichmentInfo enrichmentInfo, + ToscaServiceModel serviceModel) throws IOException; } diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricherTest.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricherTest.java index c01f986ab1..65444b9c46 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricherTest.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricherTest.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.enrichment.impl.external.artifact; +import org.apache.commons.collections4.CollectionUtils; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -32,7 +33,11 @@ import org.openecomp.core.model.types.ServiceArtifact; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.enrichment.EnrichmentInfo; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; @@ -43,10 +48,18 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.atLeastOnce; @@ -73,20 +86,23 @@ public class MonitoringMibEnricherTest { @Test public void testEnrichComponent() throws Exception { String vspId = "123"; - String componentId = "1111111111"; + String componentId = "1"; Version version = new Version(); version.setMajor(1); version.setMinor(0); - ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId); - setMockToEnrichComponent(vspId, componentId, version); - monitoringMibEnricher.enrichComponent(componentEntity, vspId, version); - + ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId, vspId + + "enrichMib_server"); + setMockToEnrichComponent(vspId, version, componentId); String componentName = componentEntity.getComponentCompositionData().getName(); String unifiedComponentName = ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + DataModelUtil.getNamespaceSuffix(componentName); + ArgumentCaptor<ServiceArtifact> expectedServiceArtifact = ArgumentCaptor.forClass(ServiceArtifact.class); + monitoringMibEnricher.enrichComponent(vspId, version, componentEntity, + Stream.of(unifiedComponentName).collect(Collectors.toSet())); + Mockito.verify(enrichedServiceModelDaoMock, atLeastOnce()) .storeExternalArtifact(expectedServiceArtifact.capture()); Assert.assertEquals(expectedServiceArtifact.getValue().getName() @@ -98,7 +114,7 @@ public class MonitoringMibEnricherTest { } @Test - public void testEnrich() throws Exception { + public void testEnrichmentOfTwoComponentsFromSameType() throws IOException { EnrichmentInfo enrichmentInfo = new EnrichmentInfo(); Version version = new Version(); version.setMajor(1); @@ -106,24 +122,43 @@ public class MonitoringMibEnricherTest { String vspId = "123"; enrichmentInfo.setKey(vspId); enrichmentInfo.setVersion(version); - String componentId1 = "1111111111"; - String componentId2 = "2222222222"; + String componentId1 = "1"; + String componentId2 = "2"; + String abstType = "org.openecomp.resource.abstract.nodes.pd_server"; + String abstType1 = "org.openecomp.resource.abstract.nodes.pd_server_1"; + + List<ComponentEntity> returnedComponents = new ArrayList<>(); + returnedComponents.add(getComponentEntity(vspId, version, componentId1, + "pd_server")); + returnedComponents.add(getComponentEntity(vspId, version, componentId2, + "pd_server")); + Mockito.when(componentDaoMock.list(anyObject())) + .thenReturn(returnedComponents); + setMockToEnrichComponent(vspId, version, componentId1); + ToscaServiceModel mockServiceModel = + getMockServiceModel("/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType"); - Collection<ComponentEntity> returnedComponents = new ArrayList<>(); - returnedComponents.add(getComponentEntity(vspId, version, componentId1)); - returnedComponents.add(getComponentEntity(vspId, version, componentId2)); + ArgumentCaptor<ServiceArtifact> expectedServiceArtifact = + ArgumentCaptor.forClass(ServiceArtifact.class); + monitoringMibEnricher.enrich(enrichmentInfo, mockServiceModel); - Mockito.when(componentDaoMock.list(anyObject())) - .thenReturn(returnedComponents); - setMockToEnrichComponent(vspId, componentId1, version); + Mockito.verify(enrichedServiceModelDaoMock, times(24)) + .storeExternalArtifact(expectedServiceArtifact.capture()); + + Set<String> prefixes = getAllMibDirectoryPrefixes(expectedServiceArtifact.getAllValues()); - monitoringMibEnricher.enrich(enrichmentInfo); - Mockito.verify(enrichedServiceModelDaoMock, times(12)).storeExternalArtifact(anyObject()); + validateExpectedAbstractTypes(Stream.of(abstType, abstType1).collect(Collectors.toSet()), prefixes); + } + private void validateExpectedAbstractTypes(Set<String> expectedAbstractTypes, + Set<String> prefixes) { + for(String abstType : expectedAbstractTypes){ + Assert.assertTrue(prefixes.contains(abstType)); + } } - private void setMockToEnrichComponent(String vspId, String componentId, Version version) { + private void setMockToEnrichComponent(String vspId, Version version, String componentId) { ComponentMonitoringUploadEntity returnedArtifact = new ComponentMonitoringUploadEntity(); returnedArtifact.setVspId(vspId); returnedArtifact.setVersion(version); @@ -137,16 +172,18 @@ public class MonitoringMibEnricherTest { Mockito.doNothing().when(enrichedServiceModelDaoMock).storeExternalArtifact(anyObject()); } - private ComponentEntity getComponentEntity(String vspId, Version version, String componentId) { + private ComponentEntity getComponentEntity(String vspId, + Version version, + String componentId, + String componentNameSuffix) { ComponentEntity componentEntity = new ComponentEntity(); componentEntity.setId(componentId); componentEntity.setVspId(vspId); componentEntity.setVersion(version); - String componentName = vspId + "enrichMib_server"; String compositionData = "{\n" + - " \"name\": \"org.openecomp.resource.vfc.nodes.heat." + componentName + "\",\n" + - " \"displayName\": \"" + componentName + "\"\n" + + " \"name\": \"org.openecomp.resource.vfc.nodes.heat." + componentNameSuffix + "\",\n" + + " \"displayName\": \"" + componentNameSuffix + "\"\n" + "}"; componentEntity.setCompositionData(compositionData); return componentEntity; @@ -154,8 +191,42 @@ public class MonitoringMibEnricherTest { private ByteBuffer getMibByteBuffer(String fileName) { byte[] mibBytes = FileUtils.readViaInputStream(this.getClass().getResource(fileName), - stream -> FileUtils.toByteArray(stream)); + FileUtils::toByteArray); return ByteBuffer.wrap(mibBytes); } + private ToscaServiceModel getMockServiceModel(String serviceTemplatesDirectory) + throws IOException { + File directory = new File(this.getClass().getResource(serviceTemplatesDirectory).getFile()); + ToscaServiceModel serviceModel = new ToscaServiceModel(); + Map<String, ServiceTemplate> serviceTemplates = new HashMap<>(); + + for (final File serviceTemplateFile : directory.listFiles()) { + byte[] content = FileUtils + .readViaInputStream(this.getClass().getResource(serviceTemplatesDirectory + File + .separator + serviceTemplateFile.getName()), + FileUtils::toByteArray); + ServiceTemplate serviceTemplate = + new YamlUtil().yamlToObject(new String(content), ServiceTemplate.class); + serviceTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate); + } + + serviceModel.setServiceTemplates(serviceTemplates); + return serviceModel; + } + + private Set<String> getAllMibDirectoryPrefixes(List<ServiceArtifact> serviceArtifacts) { + if(CollectionUtils.isEmpty(serviceArtifacts)){ + return new HashSet<>(); + } + + Set<String> prefixes = new HashSet<>(); + for(ServiceArtifact serviceArtifact : serviceArtifacts){ + String absolutePath = serviceArtifact.getName(); + prefixes.add(absolutePath.split(Pattern.quote(File.separator))[0]); + } + + return prefixes; + } + } diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/MainServiceTemplate.yaml b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/MainServiceTemplate.yaml new file mode 100644 index 0000000000..afd5b4afd0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/MainServiceTemplate.yaml @@ -0,0 +1,39 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Main +imports: +- openecomp_heat_index: + file: openecomp-heat/_index.yml +- GlobalSubstitutionTypes: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.nodes.heat.pd_server: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + pd_flavor_name: + type: string + description: flavor name of PD instance + default: m3.xlarge + availabilityzone_name: + type: string + description: availabilityzone name + default: nova + + node_templates: + abstract_pd_server_0: + type: org.openecomp.resource.abstract.nodes.pd_server + directives: + - substitutable + properties: + service_template_filter: + substitute_service_template: Nested_pd_serverServiceTemplate.yaml + count: 1 + abstract_pd_server_1: + type: org.openecomp.resource.abstract.nodes.pd_server_1 + directives: + - substitutable + properties: + service_template_filter: + substitute_service_template: Nested_pd_1serverServiceTemplate.yaml + count: 1 diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_1serverServiceTemplate.yaml b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_1serverServiceTemplate.yaml new file mode 100644 index 0000000000..1b8f9636ec --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_1serverServiceTemplate.yaml @@ -0,0 +1,20 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Nested_pd_1server +imports: +- openecomp_heat_index: + file: openecomp-heat/_index.yml +- GlobalSubstitutionTypes: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.compute.nodes.heat.pd_server: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + index_value: + type: integer + description: Index value of this substitution service template runtime instance + required: false + default: 0 + constraints: + - greater_or_equal: 0 diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_serverServiceTemplate.yaml b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_serverServiceTemplate.yaml new file mode 100644 index 0000000000..61dae4b1fa --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_serverServiceTemplate.yaml @@ -0,0 +1,20 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Nested_pd_server +imports: +- openecomp_heat_index: + file: openecomp-heat/_index.yml +- GlobalSubstitutionTypes: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.compute.nodes.heat.pd_server: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + index_value: + type: integer + description: Index value of this substitution service template runtime instance + required: false + default: 0 + constraints: + - greater_or_equal: 0 diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java index 7c1dfdcafd..04df2ae587 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java @@ -39,7 +39,6 @@ import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType; import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition; import org.openecomp.sdc.tosca.datatypes.model.CapabilityAssignment; import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; -import org.openecomp.sdc.tosca.datatypes.model.CapabilityType; import org.openecomp.sdc.tosca.datatypes.model.Constraint; import org.openecomp.sdc.tosca.datatypes.model.EntrySchema; import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition; @@ -68,7 +67,6 @@ import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -86,8 +84,10 @@ public class DataModelUtil { * Add substitution mapping. */ - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private static final MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private static final Logger logger = LoggerFactory.getLogger(DataModelUtil.class); + private static final String SERVICE_TEMPLATE = "Service Template"; + private static final String NODE_TYPE = "Node Type"; /** * Add substitution mapping. @@ -97,14 +97,14 @@ public class DataModelUtil { */ public static void addSubstitutionMapping(ServiceTemplate serviceTemplate, SubstitutionMapping substitutionMapping) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", "Service Template") + new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE) .build()); } @@ -113,7 +113,16 @@ public class DataModelUtil { } serviceTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); + } + + public static List<String> getDirectives(NodeTemplate nodeTemplate) { + if (Objects.isNull(nodeTemplate) + || Objects.isNull(nodeTemplate.getDirectives())) { + return Collections.emptyList(); + } + + return nodeTemplate.getDirectives(); } /** @@ -128,7 +137,7 @@ public class DataModelUtil { List<String> substitutionMappingRequirementList) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, @@ -136,7 +145,7 @@ public class DataModelUtil { LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements", - "Service Template").build()); + SERVICE_TEMPLATE).build()); } if (serviceTemplate.getTopology_template() == null) { @@ -154,7 +163,7 @@ public class DataModelUtil { serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements() .put(substitutionMappingRequirementId, substitutionMappingRequirementList); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** @@ -169,7 +178,7 @@ public class DataModelUtil { List<String> substitutionMappingCapabilityList) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, @@ -177,7 +186,7 @@ public class DataModelUtil { LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities", - "Service Template").build()); + SERVICE_TEMPLATE).build()); } if (serviceTemplate.getTopology_template() == null) { @@ -195,13 +204,13 @@ public class DataModelUtil { serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities() .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } - public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate){ + public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate) { if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getTopology_template()) - || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())){ + || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())) { return new HashMap<>(); } @@ -219,14 +228,14 @@ public class DataModelUtil { NodeTemplate nodeTemplate) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Node Template", "Service Template").build()); + new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { @@ -238,33 +247,8 @@ public class DataModelUtil { } topologyTemplate.getNode_templates().put(nodeTemplateId, nodeTemplate); - mdcDataDebugMessage.debugExitMessage(null, null); - - } - - /** - * Add capability def. - * - * @param nodeType the node type - * @param capabilityId the capability id - * @param capabilityDefinition the capability definition - */ - public static void addCapabilityDef(NodeType nodeType, String capabilityId, - CapabilityDefinition capabilityDefinition) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - if (nodeType == null) { - throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Capability Definition", "Node Type").build()); - } - if (Objects.isNull(nodeType.getCapabilities())) { - nodeType.setCapabilities(new HashMap<>()); - } - nodeType.getCapabilities().put(capabilityId, capabilityDefinition); + mdcDataDebugMessage.debugExitMessage(null); - mdcDataDebugMessage.debugExitMessage(null, null); } /** @@ -275,15 +259,15 @@ public class DataModelUtil { */ public static void addNodeTypeCapabilitiesDef(NodeType nodeType, Map<String, CapabilityDefinition> capabilities) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); - if (capabilities == null || capabilities.entrySet().size() == 0) { + if (MapUtils.isEmpty(capabilities) || capabilities.entrySet().isEmpty()) { return; } if (nodeType == null) { throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Capability Definition", "Node Type").build()); + new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE).build()); } if (MapUtils.isEmpty(nodeType.getCapabilities())) { @@ -296,7 +280,7 @@ public class DataModelUtil { nodeType.getCapabilities().put(entry.getKey(), entry.getValue()); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** @@ -310,14 +294,14 @@ public class DataModelUtil { PolicyDefinition policyDefinition) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Policy Definition", "Service Template") + new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE) .build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); @@ -330,7 +314,7 @@ public class DataModelUtil { } topologyTemplate.getPolicies().put(policyId, policyDefinition); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** @@ -344,38 +328,38 @@ public class DataModelUtil { NodeType nodeType) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Node Type", "Service Template").build()); + new InvalidAddActionNullEntityErrorBuilder(NODE_TYPE, SERVICE_TEMPLATE).build()); } if (serviceTemplate.getNode_types() == null) { serviceTemplate.setNode_types(new HashMap<>()); } serviceTemplate.getNode_types().put(nodeTypeId, nodeType); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } public static void removeNodeType(ServiceTemplate serviceTemplate, - String nodeTypeId){ + String nodeTypeId) { if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Node Type", "Service Template").build()); + new InvalidAddActionNullEntityErrorBuilder(NODE_TYPE, SERVICE_TEMPLATE).build()); } if (serviceTemplate.getNode_types() == null) { serviceTemplate.setNode_types(new HashMap<>()); } serviceTemplate.getNode_types().remove(nodeTypeId); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** @@ -390,14 +374,14 @@ public class DataModelUtil { RelationshipTemplate relationshipTemplate) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Relationship Template", "Service Template") + new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE) .build()); } if (serviceTemplate.getTopology_template() == null) { @@ -409,7 +393,7 @@ public class DataModelUtil { serviceTemplate.getTopology_template().getRelationship_templates() .put(relationshipTemplateId, relationshipTemplate); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** @@ -423,7 +407,7 @@ public class DataModelUtil { RequirementAssignment requirementAssignment) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (nodeTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, @@ -447,7 +431,7 @@ public class DataModelUtil { requirement.put(requirementId, requirementAssignment); nodeTemplate.getRequirements().add(requirement); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** @@ -460,7 +444,7 @@ public class DataModelUtil { public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null || serviceTemplate.getTopology_template() == null @@ -468,7 +452,7 @@ public class DataModelUtil { return null; } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId); } @@ -482,12 +466,12 @@ public class DataModelUtil { public static NodeType getNodeType(ServiceTemplate serviceTemplate, String nodeTypeId) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null || serviceTemplate.getNode_types() == null) { return null; } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return serviceTemplate.getNode_types().get(nodeTypeId); } @@ -503,7 +487,7 @@ public class DataModelUtil { String requirementDefinitionId) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (nodeType == null || nodeType.getRequirements() == null || requirementDefinitionId == null) { return Optional.empty(); @@ -514,32 +498,32 @@ public class DataModelUtil { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return Optional.empty(); } /** - * get requirement defenition from requirement defenition list by req key. + * get requirement definition from requirement definition list by req key. * - * @param requirementsDefinitionList requirement defenition list + * @param requirementsDefinitionList requirement definition list * @param requirementKey requirement key */ public static Optional<RequirementDefinition> getRequirementDefinition( List<Map<String, RequirementDefinition>> requirementsDefinitionList, String requirementKey) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (CollectionUtils.isEmpty(requirementsDefinitionList)) { return Optional.empty(); } for (Map<String, RequirementDefinition> requirementMap : requirementsDefinitionList) { if (requirementMap.containsKey(requirementKey)) { - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return Optional.of(requirementMap.get(requirementKey)); } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return Optional.empty(); } @@ -555,13 +539,13 @@ public class DataModelUtil { String capabilityDefinitionId) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) { return Optional.empty(); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return Optional.ofNullable(nodeType.getCapabilities().get(capabilityDefinitionId)); } @@ -576,14 +560,14 @@ public class DataModelUtil { String groupName, GroupDefinition group) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Group Definition", "Service Template") + new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE) .build()); } @@ -601,44 +585,7 @@ public class DataModelUtil { } serviceTemplate.getTopology_template().getGroups().put(groupName, group); - mdcDataDebugMessage.debugExitMessage(null, null); - } - - /** - * Create property definition property definition. - * - * @param type the type - * @param description the description - * @param required the required - * @param constraints the constraints - * @param status the status - * @param entrySchema the entry schema - * @param defaultVal the default val - * @return the property definition - */ - public static PropertyDefinition createPropertyDefinition(String type, String description, - boolean required, - List<Constraint> constraints, - Status status, - EntrySchema entrySchema, - Object defaultVal) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - PropertyDefinition propDef = new PropertyDefinition(); - propDef.setType(type); - propDef.setDescription(description); - propDef.setRequired(required); - propDef.setConstraints(constraints); - if (status != null) { - propDef.setStatus(status); - } - propDef.setEntry_schema(entrySchema); - propDef.set_default(defaultVal); - - mdcDataDebugMessage.debugExitMessage(null, null); - return propDef; + mdcDataDebugMessage.debugExitMessage(null); } /** @@ -662,7 +609,7 @@ public class DataModelUtil { Object defaultVal) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); ParameterDefinition paramDef = new ParameterDefinition(); paramDef.setType(type); @@ -676,7 +623,7 @@ public class DataModelUtil { paramDef.setEntry_schema(entrySchema == null ? null : entrySchema.clone()); paramDef.set_default(defaultVal); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return paramDef; } @@ -693,7 +640,7 @@ public class DataModelUtil { String relationship, Object[] occurrences) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); RequirementDefinition requirementDefinition = new RequirementDefinition(); requirementDefinition.setCapability(capability); @@ -703,87 +650,11 @@ public class DataModelUtil { requirementDefinition.setOccurrences(occurrences); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return requirementDefinition; } /** - * Create attribute definition attribute definition. - * - * @param type the type - * @param description the description - * @param status the status - * @param entrySchema the entry schema - * @param defaultVal the default val - * @return the attribute definition - */ - public static AttributeDefinition createAttributeDefinition(String type, String description, - Status status, - EntrySchema entrySchema, - Object defaultVal) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - AttributeDefinition attributeDef = new AttributeDefinition(); - attributeDef.setType(type); - - if (description != null) { - attributeDef.setDescription(description); - } - if (status != null) { - attributeDef.setStatus(status); - } - attributeDef.setEntry_schema(entrySchema); - attributeDef.set_default(defaultVal); - - mdcDataDebugMessage.debugExitMessage(null, null); - return attributeDef; - } - - /** - * Create valid values constraint constraint. - * - * @param values the values - * @return the constraint - */ - public static Constraint createValidValuesConstraint(Object... values) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - Constraint validValues = new Constraint(); - for (Object value : values) { - validValues.addValidValue(value); - } - - mdcDataDebugMessage.debugExitMessage(null, null); - return validValues; - } - - /** - * Create metadata metadata. - * - * @param templateName the template name - * @param templateVersion the template version - * @param templateAuthor the template author - * @return the metadata - */ - public static Map<String, String> createMetadata(String templateName, String templateVersion, - String templateAuthor) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - Map<String, String> metadata = new HashMap<>(); - metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, templateName); - metadata.put("template_version", templateVersion); - metadata.put("template_author", templateAuthor); - - mdcDataDebugMessage.debugExitMessage(null, null); - return metadata; - } - - /** * Create entry schema entry schema. * * @param type the type @@ -795,9 +666,10 @@ public class DataModelUtil { List<Constraint> constraints) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); - if(Objects.isNull(type) && Objects.isNull(description) && CollectionUtils.isEmpty(constraints)){ + if (Objects.isNull(type) && Objects.isNull(description) && + CollectionUtils.isEmpty(constraints)) { return null; } @@ -806,59 +678,11 @@ public class DataModelUtil { entrySchema.setDescription(description); entrySchema.setConstraints(constraints); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return entrySchema; } /** - * Create valid values constraints list list. - * - * @param values the values - * @return the list - */ - public static List<Constraint> createValidValuesConstraintsList(String... values) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - List<Constraint> constraints; - Constraint validValues; - constraints = new ArrayList<>(); - validValues = DataModelUtil.createValidValuesConstraint(values); - constraints.add(validValues); - - mdcDataDebugMessage.debugExitMessage(null, null); - return constraints; - } - - /** - * Create greater or equal constrain constraint. - * - * @param value the value - * @return the constraint - */ - public static Constraint createGreaterOrEqualConstrain(Object value) { - mdcDataDebugMessage.debugEntryMessage(null, null); - - Constraint constraint = new Constraint(); - constraint.setGreater_or_equal(value); - - mdcDataDebugMessage.debugExitMessage(null, null); - return constraint; - } - - /** - * Gets constrain list. - * - * @param constrains the constrains - * @return the constrain list - */ - public static List<Constraint> getConstrainList(Constraint... constrains) { - return Arrays.asList(constrains); - - } - - /** * Create get input property value from list parameter map. * * @param inputPropertyListName the input property list name @@ -871,7 +695,7 @@ public class DataModelUtil { String... nestedPropertyName) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); List propertyList = new ArrayList<>(); propertyList.add(inputPropertyListName); @@ -882,7 +706,7 @@ public class DataModelUtil { Map getInputProperty = new HashMap<>(); getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), propertyList); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return getInputProperty; } @@ -896,7 +720,7 @@ public class DataModelUtil { PropertyDefinition propertyDefinition) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (propertyDefinition == null) { return null; @@ -914,7 +738,7 @@ public class DataModelUtil { parameterDefinition.setHidden(false); parameterDefinition.setImmutable(false); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return parameterDefinition; } @@ -929,7 +753,7 @@ public class DataModelUtil { AttributeDefinition attributeDefinition, Map<String, List> outputValue) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (attributeDefinition == null) { return null; @@ -938,85 +762,10 @@ public class DataModelUtil { parameterDefinition.setDescription(attributeDefinition.getDescription()); parameterDefinition.setValue(outputValue); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return parameterDefinition; } - /** - * Convert capability type to capability definition capability definition. - * - * @param capabilityTypeId the capability type id - * @param capabilityType the capability type - * @param properties the properties - * @return the capability definition - */ - public static CapabilityDefinition convertCapabilityTypeToCapabilityDefinition( - String capabilityTypeId, CapabilityType capabilityType, Map<String, Object> properties) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); - capabilityDefinition.setAttributes(cloneAttributeDefinitionMap(capabilityType.getAttributes())); - capabilityDefinition.setProperties(clonePropertyDefinitionMap(capabilityType.getProperties())); - capabilityDefinition.setDescription(capabilityType.getDescription()); - capabilityDefinition.setType(capabilityTypeId); - - capabilityDefinition.getProperties() - .entrySet() - .stream() - .filter(entry -> properties.containsKey(entry.getKey())) - .forEach(entry -> entry.getValue() - .set_default(properties.get(entry.getKey()))); - - mdcDataDebugMessage.debugExitMessage(null, null); - return capabilityDefinition; - } - - /** - * Clone property definition map map. - * - * @param propertyDefinitionMap the property definition map - * @return the map - */ - public static Map clonePropertyDefinitionMap( - Map<String, PropertyDefinition> propertyDefinitionMap) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - Map outMap = new HashMap<>(); - for (String propertyDefKey : propertyDefinitionMap.keySet()) { - PropertyDefinition propertyDefValue = propertyDefinitionMap.get(propertyDefKey); - outMap.put(new String(propertyDefKey), propertyDefValue.clone()); - } - - mdcDataDebugMessage.debugExitMessage(null, null); - return outMap; - } - - /** - * Clone attribute definition map map. - * - * @param attributeDefinitionMap the attribute definition map - * @return the map - */ - public static Map cloneAttributeDefinitionMap( - Map<String, AttributeDefinition> attributeDefinitionMap) { - - - mdcDataDebugMessage.debugEntryMessage(null, null); - - Map outMap = new HashMap<>(); - for (String attributeDefKey : attributeDefinitionMap.keySet()) { - AttributeDefinition attributeDefinition = attributeDefinitionMap.get(attributeDefKey); - outMap.put(new String(attributeDefKey), attributeDefinition.clone()); - } - - mdcDataDebugMessage.debugExitMessage(null, null); - return outMap; - } - public static boolean isNodeTemplate(String entryId, ServiceTemplate serviceTemplate) { return serviceTemplate.getTopology_template().getNode_templates() != null && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null; @@ -1034,7 +783,7 @@ public class DataModelUtil { ParameterDefinition parameterDefinition) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (Objects.isNull(serviceTemplate)) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, @@ -1042,7 +791,7 @@ public class DataModelUtil { LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter", - "Service Template").build()); + SERVICE_TEMPLATE).build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { @@ -1054,7 +803,7 @@ public class DataModelUtil { } topologyTemplate.getInputs().put(parameterDefinitionId, parameterDefinition); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } @@ -1070,15 +819,15 @@ public class DataModelUtil { ParameterDefinition parameterDefinition) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (Objects.isNull(serviceTemplate)) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION); throw new CoreException( - new InvalidAddActionNullEntityErrorBuilder("Topology Template Ouput Parameter", - "Service Template").build()); + new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter", + SERVICE_TEMPLATE).build()); } TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); if (Objects.isNull(topologyTemplate)) { @@ -1090,7 +839,7 @@ public class DataModelUtil { } topologyTemplate.getOutputs().put(parameterDefinitionId, parameterDefinition); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } @@ -1106,7 +855,7 @@ public class DataModelUtil { return; } if (requirementList == null) { - requirementList = new ArrayList<Map<String, RequirementDefinition>>(); + requirementList = new ArrayList<>(); } for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) { @@ -1121,7 +870,7 @@ public class DataModelUtil { */ public static Map<String, RequirementAssignment> getNodeTemplateRequirements( NodeTemplate nodeTemplate) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (Objects.isNull(nodeTemplate)) { return null; @@ -1144,7 +893,7 @@ public class DataModelUtil { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return nodeTemplateRequirementsAssignment; } @@ -1156,7 +905,7 @@ public class DataModelUtil { */ public static List<Map<String, RequirementAssignment>> getNodeTemplateRequirementList( NodeTemplate nodeTemplate) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); //Creating concrete objects List<Map<String, RequirementAssignment>> requirements = nodeTemplate.getRequirements(); @@ -1181,21 +930,21 @@ public class DataModelUtil { requirements.addAll(concreteRequirementList); nodeTemplate.setRequirements(requirements); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return concreteRequirementList; } /** * get requirement assignment from requirement assignment list by req key. * - * @param requirementsAssignmentList requirement defenition list + * @param requirementsAssignmentList requirement definition list * @param requirementKey requirement key */ public static Optional<List<RequirementAssignment>> getRequirementAssignment( List<Map<String, RequirementAssignment>> requirementsAssignmentList, String requirementKey) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (CollectionUtils.isEmpty(requirementsAssignmentList)) { return Optional.empty(); } @@ -1211,20 +960,20 @@ public class DataModelUtil { } } - mdcDataDebugMessage.debugExitMessage(null, null); - return Optional.ofNullable(matchRequirementAssignmentList); + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of(matchRequirementAssignmentList); } /** - * remove requirement defenition from requirement defenition list by req key. + * remove requirement definition from requirement definition list by req key. * - * @param requirementsDefinitionList requirement defenition list + * @param requirementsDefinitionList requirement definition list * @param requirementKey requirement key */ public static void removeRequirementsDefinition( List<Map<String, RequirementDefinition>> requirementsDefinitionList, String requirementKey) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (requirementsDefinitionList == null) { return; } @@ -1240,11 +989,11 @@ public class DataModelUtil { requirementsDefinitionList.remove(removeMap); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** - * remove requirement assignment from requirement defenition list by req key. + * remove requirement assignment from requirement definition list by req key. * * @param requirementsAssignmentList requirement Assignment list * @param requirementKey requirement key @@ -1252,7 +1001,7 @@ public class DataModelUtil { public static void removeRequirementsAssignment( List<Map<String, RequirementAssignment>> requirementsAssignmentList, String requirementKey) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (requirementsAssignmentList == null) { return; } @@ -1268,7 +1017,7 @@ public class DataModelUtil { requirementsAssignmentList.remove(removeMap); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } @@ -1283,7 +1032,7 @@ public class DataModelUtil { NodeTemplate nodeTemplate, String requirementKey, RequirementAssignment requirementAssignmentToBeDeleted) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate .getRequirements(); @@ -1291,7 +1040,6 @@ public class DataModelUtil { return; } - Map<String, RequirementAssignment> mapToBeRemoved = new HashMap<>(); ListIterator<Map<String, RequirementAssignment>> iter = nodeTemplateRequirements.listIterator(); while (iter.hasNext()) { Map<String, RequirementAssignment> reqMap = iter.next(); @@ -1308,12 +1056,11 @@ public class DataModelUtil { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } /** - * Return the suffix of the input namespace - * For an exmpale - for abc.sdf.vsrx, retrun vsrx + * Return the suffix of the input namespace For an exampale - for abc.sdf.vsrx, return vsrx * * @param namespace namespace * @return String namespace suffix @@ -1334,7 +1081,7 @@ public class DataModelUtil { * * @param imports namespace * @param importId namespace - * @return true if exist, flase if not exist + * @return true if exist, false if not exist */ public static boolean isImportAddedToServiceTemplate(List<Map<String, Import>> imports, String importId) { @@ -1355,7 +1102,7 @@ public class DataModelUtil { */ public static ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate, String outputParameterId) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null || serviceTemplate.getTopology_template() == null @@ -1363,7 +1110,7 @@ public class DataModelUtil { return null; } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return serviceTemplate.getTopology_template().getOutputs().get(outputParameterId); } @@ -1408,27 +1155,27 @@ public class DataModelUtil { */ public static Object getPropertyValue(NodeTemplate nodeTemplate, String propertyId) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (nodeTemplate == null || nodeTemplate.getProperties() == null) { return null; } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return nodeTemplate.getProperties().get(propertyId); } /** * Get node template properties according to the input node template id. * - * @param serviceTemplate service template - * @param nodeTemplateId node template id + * @param serviceTemplate service template + * @param nodeTemplateId node template id * @return node template properties */ public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate, String nodeTemplateId) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null || serviceTemplate.getTopology_template() == null @@ -1437,7 +1184,7 @@ public class DataModelUtil { return null; } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) .getProperties(); } @@ -1449,7 +1196,7 @@ public class DataModelUtil { * @return the substitution mappings */ public static SubstitutionMapping getSubstitutionMappings(ServiceTemplate serviceTemplate) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (serviceTemplate == null || serviceTemplate.getTopology_template() == null @@ -1457,7 +1204,7 @@ public class DataModelUtil { return null; } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return serviceTemplate.getTopology_template().getSubstitution_mappings(); } @@ -1465,18 +1212,15 @@ public class DataModelUtil { /** * Compare two requirement assignment objects for equality. * - * @param first the first requirement assignement object - * @param second the second requirement assignement object + * @param first the first requirement assignment object + * @param second the second requirement assignment object * @return true if objects are equal and false otherwise */ public static boolean compareRequirementAssignment(RequirementAssignment first, RequirementAssignment second) { - if (first.getCapability().equals(second.getCapability()) + return (first.getCapability().equals(second.getCapability()) && first.getNode().equals(second.getNode()) - && first.getRelationship().equals(second.getRelationship())) { - return true; - } - return false; + && first.getRelationship().equals(second.getRelationship())); } /** @@ -1552,21 +1296,21 @@ public class DataModelUtil { NodeTemplate portNodeTemplate) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); RequirementAssignment requirementAssignment = new RequirementAssignment(); requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE); requirementAssignment.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO); requirementAssignment.setNode(computeNodeTemplateId); addRequirementAssignment(portNodeTemplate, ToscaConstants.BINDING_REQUIREMENT_ID, requirementAssignment); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } public static SubstitutionMapping createSubstitutionTemplateSubMapping( String nodeTypeKey, NodeType substitutionNodeType, Map<String, Map<String, List<String>>> mapping) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); SubstitutionMapping substitutionMapping = new SubstitutionMapping(); substitutionMapping.setNode_type(nodeTypeKey); substitutionMapping.setCapabilities( @@ -1575,7 +1319,7 @@ public class DataModelUtil { manageRequirementMapping(substitutionNodeType.getRequirements(), mapping.get("requirement"))); - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return substitutionMapping; } @@ -1606,7 +1350,7 @@ public class DataModelUtil { private static Map<String, List<String>> manageRequirementMapping( List<Map<String, RequirementDefinition>> requirementList, Map<String, List<String>> requirementSubstitutionMapping) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (requirementList == null) { return null; @@ -1622,17 +1366,17 @@ public class DataModelUtil { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return requirementMapping; } private static Map<String, List<String>> manageCapabilityMapping( Map<String, CapabilityDefinition> capabilities, Map<String, List<String>> capabilitySubstitutionMapping) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); if (capabilities == null) { - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return null; } @@ -1645,7 +1389,7 @@ public class DataModelUtil { capabilityMapping.put(capabilityKey, capabilityMap); } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); return capabilityMapping; } @@ -1653,9 +1397,9 @@ public class DataModelUtil { List<Map<String, RequirementDefinition>> requirementsList, String templateName) { - mdcDataDebugMessage.debugEntryMessage(null, null); + mdcDataDebugMessage.debugEntryMessage(null); - if (requirementsList == null || requirementsList.size() == 0) { + if (CollectionUtils.isEmpty(requirementsList)) { return; } @@ -1671,11 +1415,12 @@ public class DataModelUtil { } } - mdcDataDebugMessage.debugExitMessage(null, null); + mdcDataDebugMessage.debugExitMessage(null); } - public static boolean isNodeTemplateSectionMissingFromServiceTemplate(ServiceTemplate serviceTemplate){ - return Objects.isNull(serviceTemplate.getTopology_template() ) + public static boolean isNodeTemplateSectionMissingFromServiceTemplate( + ServiceTemplate serviceTemplate) { + return Objects.isNull(serviceTemplate.getTopology_template()) || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates()); } } |