diff options
author | ojasdubey <ojas.dubey@amdocs.com> | 2018-03-29 11:41:55 +0530 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-03-29 11:55:39 +0000 |
commit | a26e2683d10fdd4484d67bb8b7d6a2e0a41ab753 (patch) | |
tree | 3ab830c719cfe867ce1028da75e8c1566ea69898 /openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main | |
parent | 589c480ce6c51e92f8e22ae9c0d4548067a37948 (diff) |
Component Dependency create VF bug fix
1. Fixed create VF issues for scenarios where
dependencies were added from the UI
2. Added supporting tests and fixed existing
Change-Id: Ib8bb0074183567c263855f8723028646c9629038
Issue-ID: SDC-1184
Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java | 99 |
1 files changed, 61 insertions, 38 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java index fbd0d225a5..e414b31b76 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java @@ -1,12 +1,32 @@ package org.openecomp.sdc.enrichment.impl.tosca; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_FUNCTION; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VM_TYPE_TAG; +import static org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType.NATIVE_NODE; +import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE; +import static org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType.NATIVE_DEPENDS_ON; +import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.ABSTRACT_NODE_TEMPLATE_ID_PREFIX; + +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; +import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; import org.openecomp.sdc.versioning.dao.types.Version; @@ -14,22 +34,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_FUNCTION; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VM_TYPE_TAG; -import static org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType.NATIVE_NODE; -import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE; -import static org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType.NATIVE_DEPENDS_ON; -import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; -import static org.openecomp.sdc.translator.services.heattotosca.Constants.ABSTRACT_NODE_TEMPLATE_ID_PREFIX; - public class AbstractSubstituteToscaEnricher { private ToscaAnalyzerService toscaAnalyzerService ; private ComponentQuestionnaireData componentQuestionnaireData; @@ -123,7 +130,7 @@ public class AbstractSubstituteToscaEnricher { } enrichRequirements(sourceToTargetDependencies, componentDisplayName, nodeTemplate, - componentDisplayNameToNodeTempalteIds); + componentDisplayNameToNodeTempalteIds, serviceTemplate, toscaModel); } }); return errors; @@ -168,35 +175,51 @@ public class AbstractSubstituteToscaEnricher { private void enrichRequirements(Map<String, List<String>> sourceToTargetDependencies, String componentDisplayName, NodeTemplate nodeTemplate, - Map<String, List<String>> componentDisplayNameToNodeTempalteIds) { - List<Map<String, RequirementAssignment>> requirements = - nodeTemplate.getRequirements(); - - if(requirements == null) { - requirements = new ArrayList<Map<String, RequirementAssignment>>(); + Map<String, List<String>> componentDisplayNameToNodeTempalteIds, + ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) { + final List<String> targets = sourceToTargetDependencies.get(componentDisplayName); + if (CollectionUtils.isEmpty(targets)) { + return; } - final List<String> targets = sourceToTargetDependencies.get(componentDisplayName); - if(targets != null) { - for (String target : targets) { - List<String> targetNodeTemplateIds = componentDisplayNameToNodeTempalteIds.get(target); - if(targetNodeTemplateIds != null) { - for (String targetNodeTemplateId : targetNodeTemplateIds) { - Map<String, RequirementAssignment> requirement = new HashMap<String, - RequirementAssignment>(); - RequirementAssignment requirementAssignment = new RequirementAssignment(); - requirementAssignment.setCapability(NATIVE_NODE); - requirementAssignment.setRelationship(NATIVE_DEPENDS_ON); - requirementAssignment.setNode(targetNodeTemplateId); - requirement.put("dependency", requirementAssignment); - requirements.add(requirement); - } + for (String target : targets) { + List<String> targetNodeTemplateIds = componentDisplayNameToNodeTempalteIds.get(target); + if (CollectionUtils.isEmpty(targetNodeTemplateIds)) { + continue; + } + for (String targetNodeTemplateId : targetNodeTemplateIds) { + Optional<String> dependencyRequirementKey = + getDependencyRequirementKey(serviceTemplate, componentDisplayName, nodeTemplate, toscaServiceModel); + if (dependencyRequirementKey.isPresent()) { + RequirementAssignment requirementAssignment = new RequirementAssignment(); + requirementAssignment.setCapability(NATIVE_NODE); + requirementAssignment.setRelationship(NATIVE_DEPENDS_ON); + requirementAssignment.setNode(targetNodeTemplateId); + DataModelUtil.addRequirementAssignment(nodeTemplate, dependencyRequirementKey.get(), requirementAssignment); } } } + } - if (!requirements.isEmpty()) - nodeTemplate.setRequirements(requirements); + private Optional<String> getDependencyRequirementKey(ServiceTemplate serviceTemplate, + String componentDisplayName, + NodeTemplate nodeTemplate, + ToscaServiceModel toscaServiceModel) { + String nodeType = nodeTemplate.getType(); + NodeType flatNodeType = (NodeType) toscaAnalyzerService + .getFlatEntity(ToscaElementTypes.NODE_TYPE, nodeType, serviceTemplate, toscaServiceModel); + List<Map<String, RequirementDefinition>> flatNodeTypeRequirements = flatNodeType.getRequirements(); + if (Objects.isNull(flatNodeTypeRequirements)) { + return Optional.empty() ; + } + for (Map<String, RequirementDefinition> requirementDefinitionMap : flatNodeTypeRequirements) { + String requirementKey = requirementDefinitionMap.keySet().iterator().next(); + String expectedKey = ToscaConstants.DEPENDS_ON_REQUIREMENT_ID + "_" + componentDisplayName; + if (requirementKey.equals(expectedKey)) { + return Optional.of(requirementKey); + } + } + return Optional.empty(); } private String getComponentDisplayName(String nodeTemplateId, NodeTemplate nodeTemplate) { |