summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java
diff options
context:
space:
mode:
authorsiddharth0905 <siddharth.singh4@amdocs.com>2018-02-28 17:41:34 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-03-04 09:36:14 +0000
commit5a3d729a49c1a62b0fef9530753c51e598a64c1f (patch)
tree36372a56642ec812f16f8a55c8e1efbfc8213d7c /openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java
parent4d3fef3e44d898ed9947c17fd6d20f15e19aa124 (diff)
Code change to support new global type
Code change to support new global type for VMI port Change-Id: I30427a8ec784c8d314c3df0e34178587dda0351c Issue-ID: SDC-1070 Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java186
1 files changed, 77 insertions, 109 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java
index 629868cb3a..eddbec3116 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java
@@ -1,18 +1,18 @@
/*
- * Copyright © 2016-2017 European Support Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright © 2016-2018 European Support Limited
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
package org.openecomp.sdc.enrichment.impl.tosca;
@@ -21,21 +21,15 @@ import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
import org.openecomp.sdc.enrichment.impl.tosca.model.PortMirroringConnectionPointDescription;
-import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.datatypes.model.CapabilityAssignment;
import org.openecomp.sdc.tosca.datatypes.model.Import;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
-import org.openecomp.sdc.tosca.datatypes.model.NodeType;
-import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
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.ToscaUtil;
-import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
@@ -83,7 +77,7 @@ public class PortMirroringEnricher {
//Collect all the ports across all the service templates
collectPorts(serviceTemplateEntry.getValue()));
//Collect External ports from the list of all ports collected above
- filterExternalPorts(toscaServiceModel);
+ filterExternalPorts();
//Handle external port changes
handleExternalPorts(toscaServiceModel);
return errors;
@@ -97,44 +91,53 @@ public class PortMirroringEnricher {
Map<String, NodeTemplate> serviceTemplatePortNodeTemplates = nodeTemplates.entrySet().stream()
.filter(nodeTemplateEntry -> (Objects.nonNull(nodeTemplateEntry.getValue()))
&& (isPortNodeTemplate(nodeTemplateEntry.getValue().getType())))
- .collect(Collectors.toMap(nodeTemplateEntry -> nodeTemplateEntry.getKey(),
- nodeTemplateEntry -> nodeTemplateEntry.getValue()));
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
portNodeTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate),
serviceTemplatePortNodeTemplates);
//Get all linked internal ports from abstract node template link requirements
- List<String> abstractLinkedPortNodeTemplates = new ArrayList<>();
- for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
- NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
- if (isSubstitutableNodeTemplate(nodeTemplate)) {
- List<Map<String, RequirementAssignment>> requirements = nodeTemplate.getRequirements();
- if (Objects.nonNull(requirements)) {
- for (Map<String, RequirementAssignment> requirement : requirements) {
- String requirementId = requirement.keySet().iterator().next();
- String abstractLinkRequirementIdPrefix = ToscaConstants.LINK_REQUIREMENT_ID + "_";
- if (requirementId.startsWith(abstractLinkRequirementIdPrefix)) {
- //Collect port node template ids from the link requirement ids in the abstract
- // node template
- abstractLinkedPortNodeTemplates.add(requirementId.substring(requirementId
- .indexOf("_") + 1));
- }
- }
- }
- if (CollectionUtils.isNotEmpty(abstractLinkedPortNodeTemplates)) {
- //Populate a map of the substitution service templates and list of internal ports
- addCollectedPortsToAbstractServiceTemplatePortMap(nodeTemplate,
- abstractLinkedPortNodeTemplates);
- }
+ collectLinkedInternalPorts(nodeTemplates);
+ }
+ }
+
+ private void collectLinkedInternalPorts(Map<String, NodeTemplate> nodeTemplates) {
+ List<String> abstractLinkedPortNodeTemplates = new ArrayList<>();
+ for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
+ NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
+ if (isSubstitutableNodeTemplate(nodeTemplate)) {
+ List<Map<String, RequirementAssignment>> requirements = nodeTemplate.getRequirements();
+ if (Objects.isNull(requirements)) {
+ return;
+ }
+
+ requirements.forEach(requirement -> addInternalPortToAbstractNode(requirement,
+ abstractLinkedPortNodeTemplates));
+
+ if (CollectionUtils.isNotEmpty(abstractLinkedPortNodeTemplates)) {
+ //Populate a map of the substitution service templates and list of internal ports
+ addCollectedPortsToAbstractServiceTemplatePortMap(nodeTemplate,
+ abstractLinkedPortNodeTemplates);
}
}
}
}
+ private void addInternalPortToAbstractNode(Map<String, RequirementAssignment> requirement,
+ List<String> abstractLinkedPortNodeTemplates) {
+ String requirementId = requirement.keySet().iterator().next();
+ String abstractLinkRequirementIdPrefix = ToscaConstants.LINK_REQUIREMENT_ID + "_";
+ if (requirementId.startsWith(abstractLinkRequirementIdPrefix)) {
+ //Collect port node template ids from the link requirement ids in the abstract
+ // node template
+ abstractLinkedPortNodeTemplates.add(requirementId.substring(requirementId
+ .indexOf("_") + 1));
+ }
+ }
+
private void addCollectedPortsToAbstractServiceTemplatePortMap(NodeTemplate nodeTemplate,
- List<String>
- abstractLinkedPortNodeTemplates) {
- String substitutionServiceTemplateName = null;
+ List<String> abstractLinkedPortNodeTemplates) {
+ String substitutionServiceTemplateName;
if (nodeTemplate.getProperties() != null) {
Map serviceTemplateFilter = (Map<String, Object>) nodeTemplate.getProperties()
.get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
@@ -154,7 +157,7 @@ public class PortMirroringEnricher {
}
}
- private void filterExternalPorts(ToscaServiceModel toscaServiceModel) {
+ private void filterExternalPorts() {
for (Map.Entry<String, Map<String, NodeTemplate>> portNodeTemplateEntry : portNodeTemplates
.entrySet()) {
Map<String, NodeTemplate> externalPorts = new HashMap<>();
@@ -163,7 +166,6 @@ public class PortMirroringEnricher {
for (Map.Entry<String, NodeTemplate> portNodeTemplate : portNodeTemplateMap.entrySet()) {
String nodeTemplateId = portNodeTemplate.getKey();
NodeTemplate nodeTemplate = portNodeTemplate.getValue();
- String newPortNodeType = nodeTemplate.getType();
if (!isInternalPort(serviceTemplateFileName, nodeTemplateId, nodeTemplate)) {
//External Port
externalPorts.putIfAbsent(nodeTemplateId, nodeTemplate);
@@ -173,19 +175,20 @@ public class PortMirroringEnricher {
}
}
- private void updateExternalPortNodeTemplate(NodeTemplate externalPortNodeTemplate,
- ToscaServiceModel toscaServiceModel) {
+ private void updateExternalPortNodeTemplate(NodeTemplate externalPortNodeTemplate) {
String currentPortNodeType = externalPortNodeTemplate.getType();
- if (currentPortNodeType.equals(ToscaNodeType.CONTRAIL_PORT)
- || currentPortNodeType.equals(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE)) {
+ if (currentPortNodeType.equals(ToscaNodeType.CONTRAIL_PORT)) {
//Set external contrail port node type
externalPortNodeTemplate.setType(ToscaNodeType.EXTERNAL_CONTRAIL_PORT);
- addPortMirroringCapability(externalPortNodeTemplate);
+ } else if (currentPortNodeType.equals(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE)) {
+ //Set external contrail VMI port node type
+ externalPortNodeTemplate.setType(ToscaNodeType.EXTERNAL_VMI_PORT);
} else if (currentPortNodeType.equals(ToscaNodeType.NEUTRON_PORT)) {
//Set external neutron port node type
externalPortNodeTemplate.setType(ToscaNodeType.EXTERNAL_NEUTRON_PORT);
- addPortMirroringCapability(externalPortNodeTemplate);
}
+
+ addPortMirroringCapability(externalPortNodeTemplate);
}
private void handleExternalPorts(ToscaServiceModel toscaServiceModel) {
@@ -196,53 +199,22 @@ public class PortMirroringEnricher {
ServiceTemplate serviceTemplate =
toscaServiceModel.getServiceTemplates().get(serviceTemplateName);
Map<String, NodeTemplate> externalNodeTemplates = entry.getValue();
- if (MapUtils.isNotEmpty(externalNodeTemplates)) {
- for (Map.Entry<String, NodeTemplate> externalNodeTemplate : externalNodeTemplates
- .entrySet()) {
- String externalPortNodeTemplateId = externalNodeTemplate.getKey();
- updateExternalPortNodeTemplate(externalNodeTemplate.getValue(), toscaServiceModel);
- if (serviceTemplate.getTopology_template().getSubstitution_mappings() != null) {
- //Add port mirroring capability to substitution mapping for external ports
- addPortMirroringSubstitutionMappingCapability(serviceTemplate,
- externalPortNodeTemplateId);
- }
- handleExternalPortProperties(externalNodeTemplate.getValue(), serviceTemplate, toscaServiceModel);
- }
- addGlobalTypeImport(serviceTemplate);
+ if (MapUtils.isEmpty(externalNodeTemplates)) {
+ return;
}
- }
- }
- private void handleExternalPortProperties(NodeTemplate portNodeTemplate,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel){
-
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- String externalPortType = portNodeTemplate.getType();
- Map<String, PropertyDefinition> globalTypesportProperties = new HashMap<>();
- NodeType flatNodeType =
- (NodeType) toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, externalPortType, serviceTemplate, toscaServiceModel);
- globalTypesportProperties.putAll(flatNodeType.getProperties());
-
- Map<String, Object> properties = portNodeTemplate.getProperties();
- Map<String, Object> filteredProperties = new HashMap<>();
-
- if(MapUtils.isEmpty(properties)){
- return;
- }
-
- for(Map.Entry<String, Object> propertyEntry: properties.entrySet()){
- if(globalTypesportProperties.containsKey(propertyEntry.getKey())){
- filteredProperties.put(propertyEntry.getKey(), propertyEntry.getValue());
+ for (Map.Entry<String, NodeTemplate> externalNodeTemplate : externalNodeTemplates
+ .entrySet()) {
+ String externalPortNodeTemplateId = externalNodeTemplate.getKey();
+ updateExternalPortNodeTemplate(externalNodeTemplate.getValue());
+ if (serviceTemplate.getTopology_template().getSubstitution_mappings() != null) {
+ //Add port mirroring capability to substitution mapping for external ports
+ addPortMirroringSubstitutionMappingCapability(serviceTemplate,
+ externalPortNodeTemplateId);
+ }
}
+ addGlobalTypeImport(serviceTemplate);
}
-
- if(!MapUtils.isEmpty(filteredProperties)) {
- portNodeTemplate.setProperties(filteredProperties);
- }else{
- portNodeTemplate.setProperties(null);
- }
-
}
private void addPortMirroringSubstitutionMappingCapability(ServiceTemplate serviceTemplate,
@@ -305,18 +277,16 @@ public class PortMirroringEnricher {
&& portNodeTypes.contains(nodeType);
}
- private Set<String> getPortNodeTypes(){
+ private Set<String> getPortNodeTypes() {
return new HashSet<>(Arrays.asList(ToscaNodeType.NEUTRON_PORT,
ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE,
ToscaNodeType.CONTRAIL_PORT));
}
private boolean isSubstitutableNodeTemplate(NodeTemplate nodeTemplate) {
- if (Objects.nonNull(nodeTemplate.getDirectives())) {
- return nodeTemplate.getDirectives().contains(ToscaConstants
- .NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
- }
- return false;
+ return Objects.nonNull(nodeTemplate.getDirectives())
+ && nodeTemplate.getDirectives()
+ .contains(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
}
private boolean isInternalPort(String serviceTemplateFileName, String nodeTemplateId,
@@ -327,10 +297,8 @@ public class PortMirroringEnricher {
private boolean isAbstractInternalPort(String serviceTemplateFileName, String nodeTemplateId) {
//Check if port corresponds to an abstract internal port
- if (portNodeTemplateIdsFromAbstract.containsKey(serviceTemplateFileName)) {
- return portNodeTemplateIdsFromAbstract.get(serviceTemplateFileName).contains(nodeTemplateId);
- }
- return false;
+ return portNodeTemplateIdsFromAbstract.containsKey(serviceTemplateFileName)
+ && portNodeTemplateIdsFromAbstract.get(serviceTemplateFileName).contains(nodeTemplateId);
}