aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authoreleonorali <eleonoral@amdocs.com>2018-05-22 16:26:35 +0300
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-05-31 11:49:42 +0000
commitba61c887dbcb1b81e31e15b18a44f68ff344b2fb (patch)
treedd31ec8b358392c3309b680f045003d0350abf5b /openecomp-be
parent5bf62dca8740c67fd7b7492874808fe152514fc3 (diff)
TOSCA Consolidation Data - Refactoring Part 2
Refactor get Compute/Port/Nested/SubInterface Consolidation Data APIs Change-Id: Ibce3abcd766555fe0eeaaf2f728d3a384935877d Issue-ID: SDC-1330 Signed-off-by: eleonorali <eleonoral@amdocs.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java181
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.java99
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java65
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java120
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java46
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java11
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java107
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileNestedConsolidationData.java102
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java138
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java97
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java57
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java110
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java79
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java176
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java39
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java108
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java48
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java108
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java111
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataTest.java57
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java170
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java98
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java89
23 files changed, 1399 insertions, 817 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
index c1a4168a74..df6bad594d 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
@@ -35,8 +35,9 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedSubstitutionData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
+import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.*;
import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
+import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType;
import org.openecomp.sdc.translator.services.heattotosca.Constants;
import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
@@ -54,50 +55,52 @@ import java.util.Set;
public class TranslationContext {
+ private ManifestFile manifest;
+
+
+ private static final Map<String, Map<String, Map<String, String>>> translationMapping;
+ private static final Map<String, ServiceTemplate> globalServiceTemplates;
+ private static final Map<String, ImplementationConfiguration> nameExtractorImplMap;
+ private static final List<String> vfcGroupSubInterfaceExposedProperties;
+ private static final List<String> enrichPortResourceProperties;
+ private static final ImplementationConfiguration vfcInstanceGroupConfiguration;
- private static Map<String, Map<String, Map<String, String>>> translationMapping;
- private static Map<String, ServiceTemplate> globalServiceTemplates;
- private static Map<String, ImplementationConfiguration> nameExtractorImplMap;
private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
- private static List<String> vfcGroupSubInterfaceExposedProperties;
- private static List<String> enrichPortResourceProperties;
- private static ImplementationConfiguration vfcInstanceGroupConfiguration;
- private ManifestFile manifest;
- private FileContentHandler files = new FileContentHandler();
- private Map<String, FileData.Type> manifestFiles = new HashMap<>();
+
+ private final FileContentHandler files = new FileContentHandler();
+ private final Map<String, FileData.Type> manifestFiles = new HashMap<>();
//Key - file name, value - file type
- private Set<String> nestedHeatsFiles = new HashSet<>();
- private FileContentHandler externalArtifacts = new FileContentHandler();
+ private final Set<String> nestedHeatsFiles = new HashSet<>();
+ private final FileContentHandler externalArtifacts = new FileContentHandler();
// Key - heat file name,value - set of heat resource ids which were translated
- private Map<String, Set<String>> translatedResources = new HashMap<>();
+ private final Map<String, Set<String>> translatedResources = new HashMap<>();
// Key - heat file name, value - translated Node template id
- private Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
+ private final Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
// Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
- private Map<String, Map<String, String>> translatedIds = new HashMap<>();
+ private final Map<String, Map<String, String>> translatedIds = new HashMap<>();
// key - service template type, value - translated service templates
- private Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
+ private final Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
//key - heat param name, value - shared resource data
- private Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
+ private final Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
//key - translated substitute service template file name, value - source nested heat file name
- private Map<String, String> nestedHeatFileName = new HashMap<>();
+ private final Map<String, String> nestedHeatFileName = new HashMap<>();
//Key - heat file name,value - Map eith key - heat pseudo param name,
// value - translated tosca parameter name
- private Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
+ private final Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
//Consolidation data gathered for Unified TOSCA model
private ConsolidationData consolidationData = new ConsolidationData();
private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
- private Set<String> unifiedHandledServiceTemplates = new HashSet<>();
+ private final Set<String> unifiedHandledServiceTemplates = new HashSet<>();
- private Map<String, Map<String, Map<String, Integer>>>
- requirementIdAppearanceInNodeTemplate = new HashMap<>();
+ private final Map<String, Map<String, Map<String, Integer>>> requirementIdAppearanceInNodeTemplate = new HashMap<>();
- private Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
+ private final Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
- private Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
+ private final Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
//Key - service template name, value - Map of key: node template id, value: properties with %index%
- private Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
+ private final Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
static {
Configuration config = ConfigurationManager.lookup();
@@ -111,27 +114,23 @@ public class TranslationContext {
}
nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
- supportedConsolidationComputeResources = config.populateMap(ConfigConstants
- .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
- .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
- supportedConsolidationPortResources = config.populateMap(ConfigConstants
- .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
- .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
- enrichPortResourceProperties = config.getAsStringValues(ConfigConstants
- .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
- .ENRICH_PORT_RESOURCE_PROP);
+ supportedConsolidationComputeResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
+ ConfigConstants.SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
+ supportedConsolidationPortResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
+ ConfigConstants.SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
+ enrichPortResourceProperties = config.getAsStringValues(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
+ ConfigConstants.ENRICH_PORT_RESOURCE_PROP);
vfcInstanceGroupConfiguration = getVfcInstanceGroupConfiguration(config);
- vfcGroupSubInterfaceExposedProperties = config.getAsStringValues(ConfigConstants
- .UNIFIED_MODEL_NAMESPACE, ConfigConstants.FULL_EXPOSED_PROPERTIES_KEY);
+ vfcGroupSubInterfaceExposedProperties = config.getAsStringValues(ConfigConstants.UNIFIED_MODEL_NAMESPACE,
+ ConfigConstants.FULL_EXPOSED_PROPERTIES_KEY);
}
private static ImplementationConfiguration getVfcInstanceGroupConfiguration(Configuration config) {
Map<String, ImplementationConfiguration> supportedUnifiedModelProperties =
- config.populateMap(ConfigConstants.UNIFIED_MODEL_NAMESPACE, ConfigConstants.UNIFIED_MODEL_IMPL_KEY,
- ImplementationConfiguration.class);
- return MapUtils.isEmpty(supportedUnifiedModelProperties) ? null :
- supportedUnifiedModelProperties.get(ConfigConstants.VFC_INSTANCE_GROUP_KEY);
+ config.populateMap(ConfigConstants.UNIFIED_MODEL_NAMESPACE, ConfigConstants.UNIFIED_MODEL_IMPL_KEY,
+ ImplementationConfiguration.class);
+ return MapUtils.isEmpty(supportedUnifiedModelProperties) ? null : supportedUnifiedModelProperties.get(ConfigConstants.VFC_INSTANCE_GROUP_KEY);
}
public static boolean isVfcInstanceGroupingEnabled() {
@@ -146,23 +145,19 @@ public class TranslationContext {
return enrichPortResourceProperties;
}
- public static Map<String, ImplementationConfiguration>
- getSupportedConsolidationComputeResources() {
+ public static Map<String, ImplementationConfiguration> getSupportedConsolidationComputeResources() {
return supportedConsolidationComputeResources;
}
- public static void setSupportedConsolidationComputeResources(
- Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
- TranslationContext.supportedConsolidationComputeResources =
- supportedConsolidationComputeResources;
+ public static void setSupportedConsolidationComputeResources(Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
+ TranslationContext.supportedConsolidationComputeResources = supportedConsolidationComputeResources;
}
public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
return supportedConsolidationPortResources;
}
- public static void setSupportedConsolidationPortResources(
- Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
+ public static void setSupportedConsolidationPortResources(Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
}
@@ -173,8 +168,7 @@ public class TranslationContext {
* @return implemetation class instance
*/
public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
- String nameExtractorImplClassName =
- nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
+ String nameExtractorImplClassName = nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
}
@@ -183,74 +177,54 @@ public class TranslationContext {
return unifiedSubstitutionData;
}
- public void setUnifiedSubstitutionData(
- Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
+ public void setUnifiedSubstitutionData(Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
this.unifiedSubstitutionData = unifiedSubstitutionData;
}
- public void addCleanedNodeTemplate(String serviceTemplateName,
- String nodeTemplateId,
- UnifiedCompositionEntity unifiedCompositionEntity,
- NodeTemplate nodeTemplate) {
+ public void addCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId, UnifiedCompositionEntity unifiedCompositionEntity,
+ NodeTemplate nodeTemplate) {
this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
- this.unifiedSubstitutionData
- .get(serviceTemplateName)
- .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
+ this.unifiedSubstitutionData.get(serviceTemplateName)
+ .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
}
- public Optional<List<String>> getIndexVarProperties(String serviceTemplateName,
- String nodeTemplateId) {
- ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties
- .get(serviceTemplateName);
+ public Optional<List<String>> getIndexVarProperties(String serviceTemplateName, String nodeTemplateId) {
+ ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties.get(serviceTemplateName);
if (Objects.nonNull(serviceTemplateIndexVarProperties)) {
return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId));
}
return Optional.empty();
}
- public void addIndexVarProperties(String serviceTemplateName,
- String nodeTemplateId,
- List<String> indexVarProperties) {
+ public void addIndexVarProperties(String serviceTemplateName, String nodeTemplateId, List<String> indexVarProperties) {
this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create());
- this.indexVarProperties
- .get(serviceTemplateName)
- .putAll(nodeTemplateId, indexVarProperties);
+ this.indexVarProperties.get(serviceTemplateName).putAll(nodeTemplateId, indexVarProperties);
}
- public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName,
- String nodeTemplateId) {
- return this.unifiedSubstitutionData.get(serviceTemplateName)
- .getCleanedNodeTemplate(nodeTemplateId);
+ public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId) {
+ return this.unifiedSubstitutionData.get(serviceTemplateName).getCleanedNodeTemplate(nodeTemplateId);
}
- public void addUnifiedNestedNodeTemplateId(String serviceTemplateName,
- String nestedNodeTemplateId,
- String unifiedNestedNodeTemplateId) {
+ public void addUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId, String unifiedNestedNodeTemplateId) {
this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
this.unifiedSubstitutionData.get(serviceTemplateName)
- .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
+ .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
}
- public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName,
- String nestedNodeTemplateId) {
- return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
- : this.unifiedSubstitutionData.get(serviceTemplateName)
- .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
+ public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId) {
+ return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() :
+ this.unifiedSubstitutionData.get(serviceTemplateName).getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
}
- public void addUnifiedNestedNodeTypeId(String serviceTemplateName,
- String nestedNodeTypeId,
- String unifiedNestedNodeTypeId) {
+ public void addUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTypeId, String unifiedNestedNodeTypeId) {
this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
this.unifiedSubstitutionData.get(serviceTemplateName)
- .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
+ .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
}
- public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName,
- String nestedNodeTemplateId) {
- return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
- : this.unifiedSubstitutionData.get(serviceTemplateName)
- .getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
+ public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTemplateId) {
+ return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() :
+ this.unifiedSubstitutionData.get(serviceTemplateName).getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
}
public ConsolidationData getConsolidationData() {
@@ -261,6 +235,26 @@ public class TranslationContext {
this.consolidationData = consolidationData;
}
+ public Optional<ConsolidationDataHandler> getConsolidationDataHandler(ConsolidationEntityType type) {
+ return consolidationData.getConsolidationDataHandler(type);
+ }
+
+ public ComputeConsolidationDataHandler getComputeConsolidationDataHandler() {
+ return consolidationData.getComputeConsolidationDataHandler();
+ }
+
+ public PortConsolidationDataHandler getPortConsolidationDataHandler() {
+ return consolidationData.getPortConsolidationDataHandler();
+ }
+
+ public NestedConsolidationDataHandler getNestedConsolidationDataHandler() {
+ return consolidationData.getNestedConsolidationDataHandler();
+ }
+
+ public SubInterfaceConsolidationDataHandler getSubInterfaceComputeConsolidationDataHandler() {
+ return consolidationData.getSubInterfaceConsolidationDataHandler();
+ }
+
public void addManifestFile(String fileName, FileData.Type fileType) {
this.manifestFiles.put(fileName, fileType);
}
@@ -558,10 +552,7 @@ public class TranslationContext {
public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
- if (unifiedHandledServiceTemplates.contains(serviceTemplateFileName)) {
- return true;
- }
- return false;
+ return unifiedHandledServiceTemplates.contains(serviceTemplateFileName)? true:false;
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.java
index d2f6083d23..fe0bf24d76 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.java
@@ -1,52 +1,65 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-/**
- * The type Compute consolidation data.
- */
public class ComputeConsolidationData {
- //Key - Service template file name
- private Map<String, FileComputeConsolidationData> fileComputeConsolidationData;
-
- /**
- * Instantiates a new Compute consolidation data.
- */
- public ComputeConsolidationData() {
- fileComputeConsolidationData = new HashMap<>();
- }
-
- /**
- * Gets all files.
- *
- * @return the all files
- */
- public Set<String> getAllServiceTemplateFileNames() {
- return fileComputeConsolidationData.keySet();
- }
-
- /**
- * Gets file compute consolidation data.
- *
- * @param serviceTemplateFileName the file name
- * @return the file compute consolidation data
- */
- public FileComputeConsolidationData getFileComputeConsolidationData(String
- serviceTemplateFileName) {
- return fileComputeConsolidationData.get(serviceTemplateFileName);
- }
-
- /**
- * Sets file compute consolidation data.
- *
- * @param serviceTemplateFileName the file name
- * @param fileComputeConsolidationData the file compute consolidation data
- */
- public void setFileComputeConsolidationData(String serviceTemplateFileName,
- FileComputeConsolidationData fileComputeConsolidationData) {
- this.fileComputeConsolidationData.put(serviceTemplateFileName, fileComputeConsolidationData);
- }
+ //Key - Service template file name
+ private final Map<String, FileComputeConsolidationData> fileComputeConsolidationData;
+
+ public ComputeConsolidationData() {
+ fileComputeConsolidationData = new HashMap<>();
+ }
+
+ public Set<String> getAllServiceTemplateFileNames() {
+ return fileComputeConsolidationData.keySet();
+ }
+
+ public FileComputeConsolidationData getFileComputeConsolidationData(String serviceTemplateFileName) {
+ return fileComputeConsolidationData.get(serviceTemplateFileName);
+ }
+
+ public void setFileComputeConsolidationData(String serviceTemplateFileName,
+ FileComputeConsolidationData fileComputeConsolidationData) {
+ this.fileComputeConsolidationData.put(serviceTemplateFileName, fileComputeConsolidationData);
+ }
+
+ /**
+ * add compute template consolidation data entity if it doesn't exist yet
+ * base on given parameters.
+ *
+ * @return compute template consolidation data entity by given keys
+ */
+ ComputeTemplateConsolidationData addComputeTemplateConsolidationData(
+ String serviceTemplateFileName, String computeNodeType, String computeNodeTemplateId) {
+ FileComputeConsolidationData consolidationData = addFileComputeConsolidationData(serviceTemplateFileName);
+ return consolidationData.addComputeTemplateConsolidationData(computeNodeType, computeNodeTemplateId);
+ }
+
+ private FileComputeConsolidationData addFileComputeConsolidationData(String serviceTemplateFileName) {
+ FileComputeConsolidationData consolidationData = getFileComputeConsolidationData(serviceTemplateFileName);
+ if (consolidationData == null) {
+ consolidationData = new FileComputeConsolidationData();
+ setFileComputeConsolidationData(serviceTemplateFileName, consolidationData);
+ }
+ return consolidationData;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
index cc27dd9806..b0c0479e11 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
@@ -76,61 +76,60 @@ public class ComputeConsolidationDataHandler implements ConsolidationDataHandler
NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, sharedTranslatedResourceId);
EntityConsolidationData entityConsolidationData =
- getComputeTemplateConsolidationData(serviceTemplate, nodeTemplate.getType(),
- sharedTranslatedResourceId);
+ getComputeTemplateConsolidationData(ToscaUtil
+ .getServiceTemplateFileName(serviceTemplate), nodeTemplate.getType(), sharedTranslatedResourceId);
if (Objects.nonNull(entityConsolidationData)) {
entityConsolidationData.removeParamNameFromAttrFuncList(paramName);
}
}
- private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
- TranslateTo translateTo, String computeNodeType, String computeNodeTemplateId) {
+ /**
+ * Add compute in consolidation data entity base on given keys.
+ *
+ */
+ public void addConsolidationData(String serviceTemplateFileName,
+ String computeNodeType, String computeNodeTemplateId) {
+ getComputeTemplateConsolidationData(serviceTemplateFileName, computeNodeType, computeNodeTemplateId);
+ }
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- return getComputeTemplateConsolidationData(serviceTemplate, computeNodeType, computeNodeTemplateId);
+ /**
+ * Add port to compute consolidation data entity base on given keys.s
+ *
+ */
+ public void addPortToConsolidationData(TranslateTo translateTo, String computeNodeType,
+ String computeNodeTemplateId, String portType, String portNodeTemplateId) {
+ ComputeTemplateConsolidationData entityConsolidationData =
+ getComputeTemplateConsolidationData(translateTo, computeNodeType, computeNodeTemplateId);
+ entityConsolidationData.addPort(portType, portNodeTemplateId);
}
- private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(ServiceTemplate serviceTemplate,
- String computeNodeType, String computeNodeTemplateId) {
+ private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
+ TranslateTo translateTo, String computeNodeType, String computeNodeTemplateId) {
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ return getComputeTemplateConsolidationData(serviceTemplateFileName, computeNodeType, computeNodeTemplateId);
- FileComputeConsolidationData fileComputeConsolidationData =
- computeConsolidationData.getFileComputeConsolidationData(serviceTemplateFileName);
- if (fileComputeConsolidationData == null) {
- fileComputeConsolidationData = new FileComputeConsolidationData();
- computeConsolidationData.setFileComputeConsolidationData(serviceTemplateFileName,
- fileComputeConsolidationData);
- }
+ }
- TypeComputeConsolidationData typeComputeConsolidationData =
- fileComputeConsolidationData.getTypeComputeConsolidationData(computeNodeType);
- if (typeComputeConsolidationData == null) {
- typeComputeConsolidationData = new TypeComputeConsolidationData();
- fileComputeConsolidationData.setTypeComputeConsolidationData(computeNodeType, typeComputeConsolidationData);
- }
- ComputeTemplateConsolidationData computeTemplateConsolidationData =
- typeComputeConsolidationData.getComputeTemplateConsolidationData(computeNodeTemplateId);
- if (computeTemplateConsolidationData == null) {
- computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
- computeTemplateConsolidationData.setNodeTemplateId(computeNodeTemplateId);
- typeComputeConsolidationData.setComputeTemplateConsolidationData(computeNodeTemplateId,
- computeTemplateConsolidationData);
- }
+ private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
+ String serviceTemplateFileName, String computeNodeType, String computeNodeTemplateId) {
+
+ return computeConsolidationData.addComputeTemplateConsolidationData(
+ serviceTemplateFileName, computeNodeType, computeNodeTemplateId);
- return computeTemplateConsolidationData;
}
- private String getNodeType(NodeTemplate computeNodeTemplate, TranslateTo translateTo, String targetResourceId,
- String nodeTemplateId) {
+ private String getNodeType(NodeTemplate computeNodeTemplate, TranslateTo translateTo,
+ String targetResourceId, String nodeTemplateId) {
if (Objects.isNull(computeNodeTemplate)) {
Resource targetResource = translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId);
NameExtractor nodeTypeNameExtractor = TranslationContext.getNameExtractorImpl(targetResource.getType());
return nodeTypeNameExtractor.extractNodeTypeName(translateTo.getHeatOrchestrationTemplate()
- .getResources().get(nodeTemplateId), nodeTemplateId, nodeTemplateId);
+ .getResources().get(nodeTemplateId), nodeTemplateId, nodeTemplateId);
}
return computeNodeTemplate.getType();
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java
index a40944a13b..e2f3be12fb 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java
@@ -1,88 +1,68 @@
-package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+/*
+ * 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.
+ */
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-/**
- * The type Compute template consolidation data.
- */
-public class ComputeTemplateConsolidationData extends EntityConsolidationData {
- // key - volume node template id
- // List of requirement id and the requirement assignment on the
- // compute node which connect to this volume
- private Map<String,List<RequirementAssignmentData>> volumes;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
- // key - port type (port id excluding index),
- // value - List of connected port node template ids, with this port type
- private Map<String, List<String>> ports;
+public class ComputeTemplateConsolidationData extends EntityConsolidationData {
+ // key - volume node template id
+ // value - List of requirement id and the requirement assignment on the
+ // compute node which connect to this volume
+ private Map<String,List<RequirementAssignmentData>> volumes;
- /**
- * Gets volumes.
- *
- * @return the volumes
- */
- public Map<String,List<RequirementAssignmentData>> getVolumes() {
- return volumes;
- }
+ // key - port type (port id excluding index),
+ // value - List of connected port node template ids, with this port type
+ private Map<String, List<String>> ports;
- /**
- * Sets volumes.
- *
- * @param volumes the volumes
- */
- public void setVolumes(Map<String,List<RequirementAssignmentData>> volumes) {
- this.volumes = volumes;
- }
+ public Map<String,List<RequirementAssignmentData>> getVolumes() {
+ return volumes;
+ }
- /**
- * Gets ports.
- *
- * @return the ports
- */
- public Map<String, List<String>> getPorts() {
- return ports;
- }
+ public void setVolumes(Map<String,List<RequirementAssignmentData>> volumes) {
+ this.volumes = volumes;
+ }
- /**
- * Sets ports.
- *
- * @param ports the ports
- */
- public void setPorts(Map<String, List<String>> ports) {
- this.ports = ports;
- }
+ public Map<String, List<String>> getPorts() {
+ return ports;
+ }
- /**
- * Add port.
- *
- * @param portType the port type
- * @param portNodeTemplateId the port node template id
- */
- public void addPort(String portType, String portNodeTemplateId) {
- if (this.ports == null) {
- this.ports = new HashMap<>();
+ public void setPorts(Map<String, List<String>> ports) {
+ this.ports = ports;
}
- this.ports.putIfAbsent(portType, new ArrayList<>());
- this.ports.get(portType).add(portNodeTemplateId);
- }
+ public void addPort(String portType, String portNodeTemplateId) {
+ if (this.ports == null) {
+ this.ports = new HashMap<>();
+ }
+ this.ports.putIfAbsent(portType, new ArrayList<>());
+ this.ports.get(portType).add(portNodeTemplateId);
+ }
- /**
- * Add volume.
- *
- * @param requirementId the requirement id
- * @param requirementAssignment the requirement assignment
- */
- public void addVolume(String requirementId, RequirementAssignment requirementAssignment) {
- if (this.volumes == null) {
- this.volumes = new HashMap<>();
+ public void addVolume(String requirementId, RequirementAssignment requirementAssignment) {
+ if (this.volumes == null) {
+ this.volumes = new HashMap<>();
+ }
+ this.volumes.computeIfAbsent(requirementAssignment.getNode(), k -> new ArrayList<>())
+ .add(new RequirementAssignmentData(requirementId,
+ requirementAssignment));
}
- this.volumes.computeIfAbsent(requirementAssignment.getNode(), k -> new ArrayList<>())
- .add(new RequirementAssignmentData(requirementId,
- requirementAssignment));
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java
index c46e7450e5..1891408f83 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java
@@ -21,10 +21,10 @@ import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType
public class ConsolidationData {
- private ComputeConsolidationData computeConsolidationData;
+ private final ComputeConsolidationData computeConsolidationData;
private final ComputeConsolidationDataHandler computeConsolidationDataHandler;
- private PortConsolidationData portConsolidationData;
+ private final PortConsolidationData portConsolidationData;
private final PortConsolidationDataHandler portConsolidationDataHandler;
private final SubInterfaceConsolidationDataHandler subInterfaceConsolidationDataHandler;
@@ -54,7 +54,7 @@ public class ConsolidationData {
switch (type) {
case COMPUTE:
- return Optional.of(getComputeConsolidationDataHelper());
+ return Optional.of(getComputeConsolidationDataHandler());
case PORT:
return Optional.of(getPortConsolidationDataHandler());
case SUB_INTERFACE:
@@ -67,7 +67,7 @@ public class ConsolidationData {
}
}
- public ComputeConsolidationDataHandler getComputeConsolidationDataHelper() {
+ public ComputeConsolidationDataHandler getComputeConsolidationDataHandler() {
return computeConsolidationDataHandler;
}
@@ -83,56 +83,18 @@ public class ConsolidationData {
return subInterfaceConsolidationDataHandler;
}
- /**
- * Gets compute consolidation data.
- *
- * @return the compute consolidation data
- */
public ComputeConsolidationData getComputeConsolidationData() {
return computeConsolidationData;
}
- /**
- * Sets compute consolidation data.
- *
- * @param computeConsolidationData the compute consolidation data
- */
- public void setComputeConsolidationData(ComputeConsolidationData computeConsolidationData) {
- this.computeConsolidationData = computeConsolidationData;
- }
-
- /**
- * Gets port consolidation data.
- *
- * @return the port consolidation data
- */
public PortConsolidationData getPortConsolidationData() {
return portConsolidationData;
}
- /**
- * Sets port consolidation data.
- *
- * @param portConsolidationData the port consolidation data
- */
- public void setPortConsolidationData(PortConsolidationData portConsolidationData) {
- this.portConsolidationData = portConsolidationData;
- }
-
- /**
- * Gets nested consolidation data.
- *
- * @return the nested consolidation data
- */
public NestedConsolidationData getNestedConsolidationData() {
return nestedConsolidationData;
}
- /**
- * Sets nested consolidation data.
- *
- * @param nestedConsolidationData the nested consolidation data
- */
public void setNestedConsolidationData(NestedConsolidationData nestedConsolidationData) {
this.nestedConsolidationData = nestedConsolidationData;
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
index 06b1a58718..1360677d78 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
@@ -41,7 +41,6 @@ public class EntityConsolidationData {
private Map<String, List<RequirementAssignmentData>> nodesConnectedOut;
//key - node template id which include get attribute function from this entity
- //key - node template id which include get attribute function from this entity
//value - List of getAttr data
private Map<String, List<GetAttrFuncData>> nodesGetAttrIn;
@@ -52,20 +51,10 @@ public class EntityConsolidationData {
//List of getAttr data
private List<GetAttrFuncData> outputParametersGetAttrIn;
- /**
- * Gets node template id.
- *
- * @return the node template id
- */
public String getNodeTemplateId() {
return nodeTemplateId;
}
- /**
- * Sets node template id.
- *
- * @param nodeTemplateId the node template id
- */
public void setNodeTemplateId(String nodeTemplateId) {
this.nodeTemplateId = nodeTemplateId;
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java
index 04a75d37b2..58f59f965b 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java
@@ -1,3 +1,19 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.Collection;
@@ -5,52 +21,51 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-/**
- * The type File compute consolidation data.
- */
public class FileComputeConsolidationData {
- //key - compute node type name (vm_type)
- private Map<String, TypeComputeConsolidationData> typeComputeConsolidationData;
-
- /**
- * Instantiates a new File compute consolidation data.
- */
- public FileComputeConsolidationData() {
- typeComputeConsolidationData = new HashMap<>();
- }
-
- /**
- * Gets all compute types.
- *
- * @return the all compute types
- */
- public Set<String> getAllComputeTypes() {
- return typeComputeConsolidationData.keySet();
- }
-
- public Collection<TypeComputeConsolidationData> getAllTypeComputeConsolidationData(){
- return typeComputeConsolidationData.values();
- }
-
- /**
- * Gets type compute consolidation data.
- *
- * @param computeType the compute type
- * @return the type compute consolidation data
- */
- public TypeComputeConsolidationData getTypeComputeConsolidationData(String computeType) {
- return typeComputeConsolidationData.get(computeType);
- }
-
- /**
- * Sets type compute consolidation data.
- *
- * @param computeType the compute type
- * @param typeComputeConsolidationData the type compute consolidation data
- */
- public void setTypeComputeConsolidationData(String computeType, TypeComputeConsolidationData
- typeComputeConsolidationData) {
- this.typeComputeConsolidationData.put(computeType, typeComputeConsolidationData);
- }
+ //key - compute node type name (vm_type)
+ private final Map<String, TypeComputeConsolidationData> typeComputeConsolidationData;
+
+ public FileComputeConsolidationData() {
+ typeComputeConsolidationData = new HashMap<>();
+ }
+
+ public Set<String> getAllComputeTypes() {
+ return typeComputeConsolidationData.keySet();
+ }
+
+ public Collection<TypeComputeConsolidationData> getAllTypeComputeConsolidationData() {
+ return typeComputeConsolidationData.values();
+ }
+
+ public TypeComputeConsolidationData getTypeComputeConsolidationData(String computeType) {
+ return typeComputeConsolidationData.get(computeType);
+ }
+
+ public void setTypeComputeConsolidationData(String computeType, TypeComputeConsolidationData
+ typeComputeConsolidationData) {
+ this.typeComputeConsolidationData.put(computeType, typeComputeConsolidationData);
+ }
+
+
+ /**
+ * add compute template consolidation data according to given key if it doesn't exist yet.
+ *
+ * @return compute template consolidation data by given keys
+ */
+ ComputeTemplateConsolidationData addComputeTemplateConsolidationData(
+ String computeType, String computeNodeTemplateId) {
+
+ TypeComputeConsolidationData consolidationData = addTypeComputeConsolidationData(computeType);
+ return consolidationData.addComputeTemplateConsolidationData(computeNodeTemplateId);
+ }
+
+ private TypeComputeConsolidationData addTypeComputeConsolidationData(String computeType) {
+ TypeComputeConsolidationData consolidationData = getTypeComputeConsolidationData(computeType);
+ if (consolidationData == null) {
+ consolidationData = new TypeComputeConsolidationData();
+ setTypeComputeConsolidationData(computeType, consolidationData);
+ }
+ return consolidationData;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileNestedConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileNestedConsolidationData.java
index 1a3948a3a8..61f727ab49 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileNestedConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileNestedConsolidationData.java
@@ -1,3 +1,19 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.Collection;
@@ -5,51 +21,47 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-/**
- * The type File nested node consolidation data.
- */
public class FileNestedConsolidationData {
- //key - nested node template id
- private Map<String, NestedTemplateConsolidationData> nestedTemplateConsolidationData;
-
- public FileNestedConsolidationData() {
- this.nestedTemplateConsolidationData = new HashMap<>();
- }
-
- /**
- * Gets all nested node template ids.
- *
- * @return the all nested node template ids
- */
- public Set<String> getAllNestedNodeTemplateIds() {
- return nestedTemplateConsolidationData.keySet();
- }
-
- public Collection<NestedTemplateConsolidationData> getAllNestedConsolidationData() {
- return nestedTemplateConsolidationData.values();
- }
-
- /**
- * Gets nested template consolidation data.
- *
- * @param nestedNodeTemplateId the nested node template id
- * @return the nested template consolidation data
- */
- public NestedTemplateConsolidationData getNestedTemplateConsolidationData(
- String nestedNodeTemplateId) {
- return nestedTemplateConsolidationData.get(nestedNodeTemplateId);
- }
-
- /**
- * Sets nested template consolidation data.
- *
- * @param nestedNodeTemplateId the nested node template id
- * @param nestedTemplateConsolidationData the nested template consolidation data
- */
- public void setNestedTemplateConsolidationData(
- String nestedNodeTemplateId,
- NestedTemplateConsolidationData nestedTemplateConsolidationData) {
- this.nestedTemplateConsolidationData.put(nestedNodeTemplateId, nestedTemplateConsolidationData);
- }
+ //key - nested node template id
+ private final Map<String, NestedTemplateConsolidationData> nestedTemplateConsolidationData;
+
+ public FileNestedConsolidationData() {
+ this.nestedTemplateConsolidationData = new HashMap<>();
+ }
+
+ public Set<String> getAllNestedNodeTemplateIds() {
+ return nestedTemplateConsolidationData.keySet();
+ }
+
+ public Collection<NestedTemplateConsolidationData> getAllNestedConsolidationData() {
+ return nestedTemplateConsolidationData.values();
+ }
+
+ public NestedTemplateConsolidationData getNestedTemplateConsolidationData(
+ String nestedNodeTemplateId) {
+ return nestedTemplateConsolidationData.get(nestedNodeTemplateId);
+ }
+
+ public void setNestedTemplateConsolidationData(
+ String nestedNodeTemplateId,
+ NestedTemplateConsolidationData nestedTemplateConsolidationData) {
+ this.nestedTemplateConsolidationData.put(nestedNodeTemplateId, nestedTemplateConsolidationData);
+ }
+
+ /**
+ * create nested template consolidation data if it doesn't exist yet.
+ *
+ * @param nestedNodeTemplateId nested node template id
+ * @return nested template consolidation data by given key
+ */
+ NestedTemplateConsolidationData addNestedTemplateConsolidationData(String nestedNodeTemplateId) {
+ NestedTemplateConsolidationData consolidationData = getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ if (consolidationData == null) {
+ consolidationData = new NestedTemplateConsolidationData();
+ consolidationData.setNodeTemplateId(nestedNodeTemplateId);
+ setNestedTemplateConsolidationData(nestedNodeTemplateId, consolidationData);
+ }
+ return consolidationData;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java
index fd02edb818..9335dd4a97 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java
@@ -1,54 +1,108 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
-/**
- * The type File port consolidation data.
- */
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+
+
public class FilePortConsolidationData {
- //key - port node template id
- private Map<String, PortTemplateConsolidationData> portTemplateConsolidationData;
-
- public FilePortConsolidationData() {
- this.portTemplateConsolidationData = new HashMap<>();
- }
-
- /**
- * Gets all port node template ids.
- *
- * @return the all port node template ids
- */
- public Set<String> getAllPortNodeTemplateIds() {
- return portTemplateConsolidationData.keySet();
- }
-
- public Collection<PortTemplateConsolidationData> getAllPortConsolidationData() {
- return portTemplateConsolidationData.values();
- }
-
- /**
- * Gets port template consolidation data.
- *
- * @param portNodeTemplateId the port node template id
- * @return the port template consolidation data
- */
- public PortTemplateConsolidationData getPortTemplateConsolidationData(String portNodeTemplateId) {
- return portTemplateConsolidationData.get(portNodeTemplateId);
- }
-
- /**
- * Sets port template consolidation data.
- *
- * @param portNodeTemplateId the port node template id
- * @param portTemplateConsolidationData the port template consolidation data
- */
- public void setPortTemplateConsolidationData(String portNodeTemplateId,
+ //key - port node template id
+ private final Map<String, PortTemplateConsolidationData> portTemplateConsolidationData;
+
+ public FilePortConsolidationData() {
+ this.portTemplateConsolidationData = new HashMap<>();
+ }
+
+ public Set<String> getAllPortNodeTemplateIds() {
+ return portTemplateConsolidationData.keySet();
+ }
+
+ public Collection<PortTemplateConsolidationData> getAllPortConsolidationData() {
+ return portTemplateConsolidationData.values();
+ }
+
+ public PortTemplateConsolidationData getPortTemplateConsolidationData(String portNodeTemplateId) {
+ return portTemplateConsolidationData.get(portNodeTemplateId);
+ }
+
+ public void setPortTemplateConsolidationData(String portNodeTemplateId,
PortTemplateConsolidationData
portTemplateConsolidationData) {
- this.portTemplateConsolidationData.put(portNodeTemplateId, portTemplateConsolidationData);
- }
+ this.portTemplateConsolidationData.put(portNodeTemplateId, portTemplateConsolidationData);
+ }
+
+ /**
+ * If entity doesn't exist yet - create subInterface template consolidation data entity
+ * base on given parameters.
+ *
+ * @return subInterface template consolidation data entity
+ */
+ SubInterfaceTemplateConsolidationData addSubInterfaceTemplateConsolidationData(
+ Resource resource, String subInterfaceNodeTemplateId, String parentPortNodeTemplateId) {
+ PortTemplateConsolidationData consolidationData =
+ addPortTemplateConsolidationData(parentPortNodeTemplateId);
+ return consolidationData.addSubInterfaceTemplateConsolidationData(resource,
+ subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ }
+
+ /**
+ * If entity doesn't exist yet - create port template consolidation data and
+ * update it's network role according to given resource parameters.
+ *
+ * @return port template consolidation data entity by given keys
+ */
+ PortTemplateConsolidationData addPortTemplateConsolidationData(
+ String portNodeTemplateId, String portResourceId, String portResourceType) {
+ PortTemplateConsolidationData consolidationData = getPortTemplateConsolidationData(portNodeTemplateId);
+ if (consolidationData == null) {
+ consolidationData = createPortTemplateConsolidationData(portNodeTemplateId,
+ portResourceId, portResourceType);
+ setPortTemplateConsolidationData(portNodeTemplateId, consolidationData);
+ }
+ return consolidationData;
+ }
+
+ private PortTemplateConsolidationData addPortTemplateConsolidationData(String portNodeTemplateId) {
+ PortTemplateConsolidationData consolidationData = getPortTemplateConsolidationData(portNodeTemplateId);
+ if (consolidationData == null) {
+ consolidationData = new PortTemplateConsolidationData();
+ setPortTemplateConsolidationData(portNodeTemplateId, consolidationData);
+ }
+ return consolidationData;
+ }
+
+ private PortTemplateConsolidationData createPortTemplateConsolidationData(
+ String portNodeTemplateId, String portResourceId, String portResourceType) {
+ PortTemplateConsolidationData consolidationData = new PortTemplateConsolidationData();
+ consolidationData.setNodeTemplateId(portNodeTemplateId);
+ Optional<String> portNetworkRole = HeatToToscaUtil.evaluateNetworkRoleFromResourceId(portResourceId,
+ portResourceType);
+ portNetworkRole.ifPresent(consolidationData::setNetworkRole);
+ return consolidationData;
+ }
+
+
+
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java
index 8dde9510e2..afad4a9b0f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java
@@ -1,50 +1,65 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-/**
- * The type Nested Node consolidation data.
- */
public class NestedConsolidationData {
- //Key - Service template file name
- private Map<String, FileNestedConsolidationData> fileNestedConsolidationData;
-
- public NestedConsolidationData() {
- this.fileNestedConsolidationData = new HashMap<>();
- }
-
- /**
- * Gets all files.
- *
- * @return the all files
- */
- public Set<String> getAllServiceTemplateFileNames() {
- return fileNestedConsolidationData.keySet();
- }
-
- /**
- * Gets file nested consolidation data.
- *
- * @param serviceTemplateFileName the service template file name
- * @return the file nested consolidation data
- */
- public FileNestedConsolidationData getFileNestedConsolidationData(String
- serviceTemplateFileName) {
- return fileNestedConsolidationData.get(serviceTemplateFileName);
- }
-
- /**
- * Sets file nested consolidation data.
- *
- * @param serviceTemplateFileName the service template file name
- * @param fileNestedConsolidationData the file nested consolidation data
- */
- public void setFileNestedConsolidationData(String serviceTemplateFileName,
- FileNestedConsolidationData
- fileNestedConsolidationData) {
- this.fileNestedConsolidationData.put(serviceTemplateFileName, fileNestedConsolidationData);
- }
+ //Key - Service template file name
+ private final Map<String, FileNestedConsolidationData> fileNestedConsolidationData;
+
+ public NestedConsolidationData() {
+ this.fileNestedConsolidationData = new HashMap<>();
+ }
+
+ public Set<String> getAllServiceTemplateFileNames() {
+ return fileNestedConsolidationData.keySet();
+ }
+
+ public FileNestedConsolidationData getFileNestedConsolidationData(String serviceTemplateFileName) {
+ return fileNestedConsolidationData.get(serviceTemplateFileName);
+ }
+
+ public void setFileNestedConsolidationData(String serviceTemplateFileName,
+ FileNestedConsolidationData fileNestedConsolidationData) {
+ this.fileNestedConsolidationData.put(serviceTemplateFileName, fileNestedConsolidationData);
+ }
+
+ /**
+ * Create nested template consolidation data base on given key - if it doesn't exist yet.
+ *
+ * @return nested template consolidation data by given keys
+ */
+ NestedTemplateConsolidationData addNestedTemplateConsolidationData(
+ String serviceTemplateFileName, String nestedNodeTemplateId) {
+
+ FileNestedConsolidationData consolidationData = addFileNestedConsolidationData(serviceTemplateFileName);
+ return consolidationData.addNestedTemplateConsolidationData(nestedNodeTemplateId);
+ }
+
+ private FileNestedConsolidationData addFileNestedConsolidationData(String serviceTemplateFileName) {
+ FileNestedConsolidationData consolidationData = getFileNestedConsolidationData(serviceTemplateFileName);
+ if (consolidationData == null) {
+ consolidationData = new FileNestedConsolidationData();
+ setFileNestedConsolidationData(serviceTemplateFileName, consolidationData);
+ }
+ return consolidationData;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
index f7c877074d..ef1aefd124 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
@@ -68,61 +68,49 @@ public class NestedConsolidationDataHandler implements ConsolidationDataHandler
String contrailSharedResourceId,
String sharedTranslatedResourceId) {
- throw new UnsupportedOperationException(
- "API removeParamNameFromAttrFuncList not supported for NestedConsolidationDataHandler");
+ throw new UnsupportedOperationException("API removeParamNameFromAttrFuncList "
+ + "not supported for NestedConsolidationDataHandler");
}
+ /**
+ * Add nested consolidation data base on given parameters.
+ */
+ public void addConsolidationData(String serviceTemplateFileName, TranslationContext context,
+ String nestedHeatFileName, String nestedNodeTemplateId) {
+ getNestedTemplateConsolidationData(serviceTemplateFileName, context,
+ nestedHeatFileName, nestedNodeTemplateId);
+ }
+
private NestedTemplateConsolidationData getNestedTemplateConsolidationData(TranslateTo translateTo,
String nestedHeatFileName,
String nestedNodeTemplateId) {
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
TranslationContext context = translateTo.getContext();
- return getNestedTemplateConsolidationData(serviceTemplate, context, nestedHeatFileName, nestedNodeTemplateId);
+ return getNestedTemplateConsolidationData(ToscaUtil
+ .getServiceTemplateFileName(serviceTemplate), context, nestedHeatFileName, nestedNodeTemplateId);
+
}
private NestedTemplateConsolidationData getNestedTemplateConsolidationData(
- ServiceTemplate serviceTemplate, TranslationContext context,
- String nestedHeatFileName, String nestedNodeTemplateId) {
+ String serviceTemplateFileName, TranslationContext context,
+ String nestedHeatFileName, String nestedNodeTemplateId) {
-
- if (isNestedResourceIdOccursInDifferentNestedFiles(context, nestedHeatFileName,
- nestedNodeTemplateId)) {
- throw new CoreException(new
- DuplicateResourceIdsInDifferentFilesErrorBuilder(
- nestedNodeTemplateId).build());
+ if (isNestedResourceIdOccursInDifferentNestedFiles(context, nestedHeatFileName, nestedNodeTemplateId)) {
+ throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(nestedNodeTemplateId).build());
}
if (isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(
nestedNodeTemplateId, nestedHeatFileName, context)) {
return null;
}
+ return nestedConsolidationData
+ .addNestedTemplateConsolidationData(serviceTemplateFileName, nestedNodeTemplateId);
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
- FileNestedConsolidationData fileNestedConsolidationData = nestedConsolidationData
- .getFileNestedConsolidationData(serviceTemplateFileName);
-
- if (fileNestedConsolidationData == null) {
- fileNestedConsolidationData = new FileNestedConsolidationData();
- nestedConsolidationData.setFileNestedConsolidationData(serviceTemplateFileName,
- fileNestedConsolidationData);
- }
-
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- fileNestedConsolidationData.getNestedTemplateConsolidationData(nestedNodeTemplateId);
- if (nestedTemplateConsolidationData == null) {
- nestedTemplateConsolidationData = new NestedTemplateConsolidationData();
- nestedTemplateConsolidationData.setNodeTemplateId(nestedNodeTemplateId);
- fileNestedConsolidationData.setNestedTemplateConsolidationData(nestedNodeTemplateId,
- nestedTemplateConsolidationData);
- }
-
- return nestedTemplateConsolidationData;
}
private boolean isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(String nestedNodeTemplateId,
- String nestedHeatFileName,
- TranslationContext context) {
+ String nestedHeatFileName, TranslationContext context) {
return context.isServiceTemplateWithoutNodeTemplatesSection(
FileUtils.getFileWithoutExtention(nestedHeatFileName))
@@ -130,8 +118,7 @@ public class NestedConsolidationDataHandler implements ConsolidationDataHandler
}
private boolean isNestedResourceIdOccursInDifferentNestedFiles(TranslationContext context,
- String nestedHeatFileName,
- String nestedNodeTemplateId) {
+ String nestedHeatFileName, String nestedNodeTemplateId) {
return Objects.nonNull(nestedHeatFileName) && context.getAllTranslatedResourceIdsFromDiffNestedFiles(
nestedHeatFileName).contains(nestedNodeTemplateId);
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java
index 5c1d38b6e4..ac07daad8f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java
@@ -1,48 +1,80 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-/**
- * The type Port consolidation data.
- */
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+
public class PortConsolidationData {
- //Key - Service template file name
- private Map<String, FilePortConsolidationData> filePortConsolidationData;
-
- public PortConsolidationData() {
- this.filePortConsolidationData = new HashMap<>();
- }
-
- /**
- * Gets all files.
- *
- * @return the all files
- */
- public Set<String> getAllServiceTemplateFileNames() {
- return filePortConsolidationData.keySet();
- }
-
- /**
- * Gets file port consolidation data.
- *
- * @param serviceTemplateFileName the service template file name
- * @return the file port consolidation data
- */
- public FilePortConsolidationData getFilePortConsolidationData(String serviceTemplateFileName) {
- return filePortConsolidationData.get(serviceTemplateFileName);
- }
-
- /**
- * Sets file port consolidation data.
- *
- * @param serviceTemplateFileName the service template file name
- * @param filePortConsolidationData the file port consolidation data
- */
- public void setFilePortConsolidationData(String serviceTemplateFileName, FilePortConsolidationData
- filePortConsolidationData) {
- this.filePortConsolidationData.put(serviceTemplateFileName, filePortConsolidationData);
- }
+ //Key - Service template file name
+ private final Map<String, FilePortConsolidationData> filePortConsolidationData;
+
+ public PortConsolidationData() {
+ this.filePortConsolidationData = new HashMap<>();
+ }
+
+ public Set<String> getAllServiceTemplateFileNames() {
+ return filePortConsolidationData.keySet();
+ }
+
+ public FilePortConsolidationData getFilePortConsolidationData(String serviceTemplateFileName) {
+ return filePortConsolidationData.get(serviceTemplateFileName);
+ }
+
+ public void setFilePortConsolidationData(String serviceTemplateFileName, FilePortConsolidationData
+ filePortConsolidationData) {
+ this.filePortConsolidationData.put(serviceTemplateFileName, filePortConsolidationData);
+ }
+
+ /**
+ * Create port template consolidation data base on given parameters - if it doesn't exist yet.
+ *
+ * @return port template consolidation data
+ */
+ PortTemplateConsolidationData addPortTemplateConsolidationData(String serviceTemplateFileName,
+ String portNodeTemplateId, String portResourceId, String portResourceType) {
+ FilePortConsolidationData consolidationData = addFilePortConsolidationData(serviceTemplateFileName);
+ return consolidationData
+ .addPortTemplateConsolidationData(portNodeTemplateId, portResourceId, portResourceType);
+ }
+
+ /**
+ * Create subInterface template consolidation data base on given parameters - if it doesn't exist yet.
+ *
+ * @return port template consolidation data by given keys
+ */
+ SubInterfaceTemplateConsolidationData addSubInterfaceTemplateConsolidationData(
+ String serviceTemplateFileName, Resource resource, String subInterfaceNodeTemplateId,
+ String parentPortNodeTemplateId) {
+ FilePortConsolidationData consolidationData = addFilePortConsolidationData(serviceTemplateFileName);
+ return consolidationData.addSubInterfaceTemplateConsolidationData(
+ resource, subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ }
+
+ private FilePortConsolidationData addFilePortConsolidationData(String serviceTemplateFileName) {
+ FilePortConsolidationData consolidationData = getFilePortConsolidationData(serviceTemplateFileName);
+ if (consolidationData == null) {
+ consolidationData = new FilePortConsolidationData();
+ setFilePortConsolidationData(serviceTemplateFileName, consolidationData);
+ }
+ return consolidationData;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java
index 2da1f7e0fa..8b9e546280 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java
@@ -1,13 +1,27 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
-import java.util.Optional;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
-import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
public class PortConsolidationDataHandler implements ConsolidationDataHandler {
@@ -19,7 +33,7 @@ public class PortConsolidationDataHandler implements ConsolidationDataHandler {
@Override
public void addNodesConnectedOut(TranslateTo translateTo, String nodeTemplateId, String requirementId,
- RequirementAssignment requirementAssignment) {
+ RequirementAssignment requirementAssignment) {
EntityConsolidationData entityConsolidationData =
getPortTemplateConsolidationData(translateTo, translateTo.getResourceId(),
@@ -31,8 +45,8 @@ public class PortConsolidationDataHandler implements ConsolidationDataHandler {
@Override
public void addNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
- String dependentNodeTemplateId, String targetResourceId, String requirementId,
- RequirementAssignment requirementAssignment) {
+ String dependentNodeTemplateId, String targetResourceId, String requirementId,
+ RequirementAssignment requirementAssignment) {
EntityConsolidationData entityConsolidationData =
getPortTemplateConsolidationData(translateTo, translateTo.getResourceId(),
@@ -44,55 +58,40 @@ public class PortConsolidationDataHandler implements ConsolidationDataHandler {
@Override
public void removeParamNameFromAttrFuncList(ServiceTemplate serviceTemplate,
- HeatOrchestrationTemplate heatOrchestrationTemplate, String paramName, String contrailSharedResourceId,
- String sharedTranslatedResourceId) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate, String paramName,
+ String contrailSharedResourceId, String sharedTranslatedResourceId) {
Resource resource = heatOrchestrationTemplate.getResources().get(contrailSharedResourceId);
- EntityConsolidationData entityConsolidationData = getPortTemplateConsolidationData(serviceTemplate,
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ EntityConsolidationData entityConsolidationData = getPortTemplateConsolidationData(serviceTemplateFileName,
contrailSharedResourceId, resource.getType(), sharedTranslatedResourceId);
entityConsolidationData.removeParamNameFromAttrFuncList(paramName);
}
+ /**
+ * Add port in consolidation data base on given parameters.
+ *
+ */
+ public void addConsolidationData(String serviceTemplateFileName,
+ String portResourceId, String portResourceType, String portNodeTemplateId) {
+ getPortTemplateConsolidationData(
+ serviceTemplateFileName, portResourceId, portResourceType, portNodeTemplateId);
+ }
+
private PortTemplateConsolidationData getPortTemplateConsolidationData(TranslateTo translateTo,
String portResourceId, String portResourceType, String portNodeTemplateId) {
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- return getPortTemplateConsolidationData(serviceTemplate, portResourceId, portResourceType, portNodeTemplateId);
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ return getPortTemplateConsolidationData(serviceTemplateFileName,
+ portResourceId, portResourceType, portNodeTemplateId);
}
- private PortTemplateConsolidationData getPortTemplateConsolidationData(ServiceTemplate serviceTemplate,
+ private PortTemplateConsolidationData getPortTemplateConsolidationData(String serviceTemplateFileName,
String portResourceId, String portResourceType, String portNodeTemplateId) {
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
- FilePortConsolidationData filePortConsolidationData = portConsolidationData
- .getFilePortConsolidationData(serviceTemplateFileName);
-
- if (filePortConsolidationData == null) {
- filePortConsolidationData = new FilePortConsolidationData();
- portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
- filePortConsolidationData);
- }
-
- PortTemplateConsolidationData portTemplateConsolidationData =
- filePortConsolidationData.getPortTemplateConsolidationData(portNodeTemplateId);
- if (portTemplateConsolidationData == null) {
- portTemplateConsolidationData = getInitPortTemplateConsolidationData(portNodeTemplateId,
- portResourceId, portResourceType);
- filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId,
- portTemplateConsolidationData);
- }
-
- return portTemplateConsolidationData;
- }
+ return portConsolidationData.addPortTemplateConsolidationData(serviceTemplateFileName,
+ portNodeTemplateId, portResourceId, portResourceType);
- private static PortTemplateConsolidationData getInitPortTemplateConsolidationData(String portNodeTemplateId,
- String portResourceId,
- String portResourceType) {
- PortTemplateConsolidationData portTemplateConsolidationData = new PortTemplateConsolidationData();
- portTemplateConsolidationData.setNodeTemplateId(portNodeTemplateId);
- Optional<String> portNetworkRole = HeatToToscaUtil.evaluateNetworkRoleFromResourceId(portResourceId,
- portResourceType);
- portNetworkRole.ifPresent(portTemplateConsolidationData::setNetworkRole);
- return portTemplateConsolidationData;
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java
index 2dfa3c90f7..6cdee5a6c5 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java
@@ -19,116 +19,124 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolid
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+public class PortTemplateConsolidationData extends EntityConsolidationData {
+ // key - sub-interface type - for ResourceGroup it is the nested file name
+ // value - List of sub-interfaces of that type in the port
+ private final ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceConsolidationData =
+ Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
-/**
- * The type Port template consolidation data.
- */
-public class PortTemplateConsolidationData extends EntityConsolidationData {
+ private String networkRole;
+
+ public String getNetworkRole() {
+ return networkRole;
+ }
- // key - sub-interface type - for ResourceGroup it is the nested file name
- // value - List of sub-interfaces of that type in the port
- private final ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceConsolidationData =
- Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
-
- private String networkRole;
-
- public String getNetworkRole() {
- return networkRole;
- }
-
- public void setNetworkRole(String networkRole) {
- this.networkRole = networkRole;
- }
-
- public boolean isPortBoundToSubInterface() {
- return !subInterfaceConsolidationData.isEmpty();
- }
-
- public SubInterfaceTemplateConsolidationData getSubInterfaceResourceTemplateConsolidationData(Resource resource,
- String subInterfaceNodeTemplateId,
- String parentPortNodeTemplateId) {
- String subInterfaceType = createSubInterfaceType(resource);
- List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList =
- subInterfaceConsolidationData.get(subInterfaceType);
- SubInterfaceTemplateConsolidationData consolidationData = null;
- if (CollectionUtils.isNotEmpty(subInterfaceTemplateConsolidationDataList)) {
- Optional<SubInterfaceTemplateConsolidationData> optionalConsolidationData =
- subInterfaceTemplateConsolidationDataList.stream()
- .filter(s -> s.getNodeTemplateId().equals(subInterfaceNodeTemplateId))
- .findFirst();
- if (optionalConsolidationData.isPresent()) {
- consolidationData = optionalConsolidationData.get();
- }
+ public void setNetworkRole(String networkRole) {
+ this.networkRole = networkRole;
}
- if (Objects.isNull(consolidationData)) {
- consolidationData = createSubInterfaceConsolidationData(subInterfaceNodeTemplateId, parentPortNodeTemplateId);
- addSubInterfaceConsolidationData(subInterfaceType, consolidationData);
+ public boolean isPortBoundToSubInterface() {
+ return !subInterfaceConsolidationData.isEmpty();
}
- return consolidationData;
- }
- private String createSubInterfaceType(Resource resource) {
+ /**
+ * Create Sub interface template consolidation data base on given parameters - if it doesn't exist yet.
+ *
+ * @param resource resource of sub Interface
+ * @param subInterfaceNodeTemplateId template id of sub interface
+ * @param parentPortNodeTemplateId node template id of port node to which sub interface is related
+ * @return sub interface template consolidation data entity
+ */
+ public SubInterfaceTemplateConsolidationData addSubInterfaceTemplateConsolidationData(
+ Resource resource, String subInterfaceNodeTemplateId, String parentPortNodeTemplateId) {
+ String subInterfaceType = createSubInterfaceType(resource);
+ List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList =
+ subInterfaceConsolidationData.get(subInterfaceType);
+ SubInterfaceTemplateConsolidationData consolidationData = null;
+ if (CollectionUtils.isNotEmpty(subInterfaceTemplateConsolidationDataList)) {
+ Optional<SubInterfaceTemplateConsolidationData> optionalConsolidationData =
+ subInterfaceTemplateConsolidationDataList.stream()
+ .filter(s -> s.getNodeTemplateId().equals(subInterfaceNodeTemplateId))
+ .findFirst();
+ if (optionalConsolidationData.isPresent()) {
+ consolidationData = optionalConsolidationData.get();
+ }
+ }
+
+ if (Objects.isNull(consolidationData)) {
+ consolidationData =
+ createSubInterfaceConsolidationData(subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ addSubInterfaceConsolidationData(subInterfaceType, consolidationData);
+ }
+ return consolidationData;
+ }
- return ToscaNodeType.VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX
- + FileUtils.getFileWithoutExtention(HeatToToscaUtil.getSubInterfaceResourceType(resource));
- }
+ private String createSubInterfaceType(Resource resource) {
+ return ToscaNodeType.VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX
+ + FileUtils.getFileWithoutExtention(
+ HeatToToscaUtil.getSubInterfaceResourceType(resource));
+ }
- private SubInterfaceTemplateConsolidationData createSubInterfaceConsolidationData(String subInterfaceNodeTemplateId, String parentPortNodeTemplateId) {
- SubInterfaceTemplateConsolidationData data = new SubInterfaceTemplateConsolidationData();
- data.setNodeTemplateId(subInterfaceNodeTemplateId);
- data.setParentPortNodeTemplateId(parentPortNodeTemplateId);
- return data;
- }
+ private SubInterfaceTemplateConsolidationData createSubInterfaceConsolidationData(
+ String subInterfaceNodeTemplateId, String parentPortNodeTemplateId) {
+ SubInterfaceTemplateConsolidationData data = new SubInterfaceTemplateConsolidationData();
+ data.setNodeTemplateId(subInterfaceNodeTemplateId);
+ data.setParentPortNodeTemplateId(parentPortNodeTemplateId);
+ return data;
+ }
- public void addSubInterfaceConsolidationData(String subPortType,
+ public void addSubInterfaceConsolidationData(String subPortType,
SubInterfaceTemplateConsolidationData
subInterfaceTemplateConsolidationData) {
- this.subInterfaceConsolidationData.put(subPortType, subInterfaceTemplateConsolidationData);
- }
+ this.subInterfaceConsolidationData.put(subPortType, subInterfaceTemplateConsolidationData);
+ }
- public boolean hasSameSubInterfaceTypes(PortTemplateConsolidationData other) {
- return other != null && this.subInterfaceConsolidationData.keySet().equals(
+ public boolean hasSameSubInterfaceTypes(PortTemplateConsolidationData other) {
+ return other != null && this.subInterfaceConsolidationData.keySet().equals(
other.subInterfaceConsolidationData.keySet());
- }
+ }
- public void copyMappedInto(ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceTypeToEntity) {
- subInterfaceTypeToEntity.putAll(this.subInterfaceConsolidationData);
- }
+ public void copyMappedInto(ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceTypeToEntity) {
+ subInterfaceTypeToEntity.putAll(this.subInterfaceConsolidationData);
+ }
- public void copyFlatInto(List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList) {
- subInterfaceTemplateConsolidationDataList.addAll(subInterfaceConsolidationData.values());
- }
+ public void copyFlatInto(List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList) {
+ subInterfaceTemplateConsolidationDataList.addAll(subInterfaceConsolidationData.values());
+ }
- public boolean isNumberOfSubInterfacesPerTypeSimilar(PortTemplateConsolidationData other) {
- return this.subInterfaceConsolidationData.isEmpty() && other.subInterfaceConsolidationData.isEmpty()
- || !this.subInterfaceConsolidationData.isEmpty() && !other.subInterfaceConsolidationData.isEmpty()
- && this.subInterfaceConsolidationData.keySet().stream().allMatch(
- subInterfaceType -> calculateSize(other.subInterfaceConsolidationData.get(subInterfaceType))
+ public boolean isNumberOfSubInterfacesPerTypeSimilar(PortTemplateConsolidationData other) {
+ return isBothSubInterfaceConsolidationDataEmpty(this, other)
+ || !isBothSubInterfaceConsolidationDataEmpty(this, other)
+ && this.subInterfaceConsolidationData.keySet().stream().allMatch(
+ subInterfaceType -> calculateSize(other.subInterfaceConsolidationData.get(subInterfaceType))
== calculateSize(this.subInterfaceConsolidationData.get(subInterfaceType)));
- }
-
- public boolean isSubInterfaceNodeTemplateIdParameter(String nodeTemplateType) {
- List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList =
- this.subInterfaceConsolidationData.get(nodeTemplateType);
- return (Objects.nonNull(subInterfaceTemplateConsolidationDataList)
- && subInterfaceTemplateConsolidationDataList.size() > 1) ;
- }
+ }
- private int calculateSize(List<SubInterfaceTemplateConsolidationData> subInterfaces) {
- return subInterfaces == null ? 0 : subInterfaces.size();
- }
+ private boolean isBothSubInterfaceConsolidationDataEmpty(
+ PortTemplateConsolidationData object, PortTemplateConsolidationData other) {
+ return object.subInterfaceConsolidationData.isEmpty() && other.subInterfaceConsolidationData.isEmpty();
+ }
+ public boolean isSubInterfaceNodeTemplateIdParameter(String nodeTemplateType) {
+ List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList =
+ this.subInterfaceConsolidationData.get(nodeTemplateType);
+ return (Objects.nonNull(subInterfaceTemplateConsolidationDataList)
+ && subInterfaceTemplateConsolidationDataList.size() > 1);
+ }
+ private int calculateSize(List<SubInterfaceTemplateConsolidationData> subInterfaces) {
+ return subInterfaces == null ? 0 : subInterfaces.size();
+ }
} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java
index ddc770bac7..d5a91f177f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java
@@ -78,45 +78,26 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa
String sharedTranslatedResourceId) {
- throw new UnsupportedOperationException(
- "API removeParamNameFromAttrFuncList not supported for SubInterfaceConsolidationDataHandler");
+ throw new UnsupportedOperationException("API removeParamNameFromAttrFuncList "
+ + "not supported for SubInterfaceConsolidationDataHandler");
+
}
private Optional<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationData(
TranslateTo subInterfaceTo, String subInterfaceNodeTemplateId) {
-
Optional<String> parentPortNodeTemplateId =
HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(subInterfaceTo);
- return parentPortNodeTemplateId.map(s -> getSubInterfaceTemplateConsolidationData(subInterfaceTo, s,
- subInterfaceNodeTemplateId));
-
+ return parentPortNodeTemplateId.map(s -> getSubInterfaceTemplateConsolidationData(subInterfaceTo,
+ s, subInterfaceNodeTemplateId));
}
- private SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(TranslateTo subInterfaceTo,
- String parentPortNodeTemplateId, String subInterfaceNodeTemplateId) {
-
+ private SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(
+ TranslateTo subInterfaceTo, String parentPortNodeTemplateId,String subInterfaceNodeTemplateId) {
String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(subInterfaceTo.getServiceTemplate());
- FilePortConsolidationData filePortConsolidationData =
- portConsolidationData.getFilePortConsolidationData(serviceTemplateFileName);
-
- if (filePortConsolidationData == null) {
- filePortConsolidationData = new FilePortConsolidationData();
- portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
- filePortConsolidationData);
- }
-
- PortTemplateConsolidationData portTemplateConsolidationData =
- filePortConsolidationData.getPortTemplateConsolidationData(parentPortNodeTemplateId);
- if (portTemplateConsolidationData == null) {
- portTemplateConsolidationData = new PortTemplateConsolidationData();
- portTemplateConsolidationData.setNodeTemplateId(parentPortNodeTemplateId);
- filePortConsolidationData.setPortTemplateConsolidationData(parentPortNodeTemplateId,
- portTemplateConsolidationData);
- }
-
- return portTemplateConsolidationData.getSubInterfaceResourceTemplateConsolidationData(
- subInterfaceTo.getResource(), subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ Resource resource = subInterfaceTo.getResource();
+ return portConsolidationData.addSubInterfaceTemplateConsolidationData(
+ serviceTemplateFileName, resource, subInterfaceNodeTemplateId, parentPortNodeTemplateId);
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java
index 2aeb0c95bc..a77cc21077 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java
@@ -1,58 +1,72 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-/**
- * The type Type compute consolidation data.
- */
public class TypeComputeConsolidationData {
- //key - compute node template id
- private Map<String, ComputeTemplateConsolidationData> computeTemplateConsolidationData;
-
- /**
- * Instantiates a new Type compute consolidation data.
- */
- public TypeComputeConsolidationData() {
- computeTemplateConsolidationData = new HashMap<>();
- }
-
- /**
- * Gets all compute node template ids.
- *
- * @return the all compute node template ids
- */
- public Collection<String> getAllComputeNodeTemplateIds() {
- return computeTemplateConsolidationData.keySet();
- }
-
- public Collection<ComputeTemplateConsolidationData> getAllComputeTemplateConsolidationData(){
- return computeTemplateConsolidationData.values();
- }
-
- /**
- * Gets compute template consolidation data.
- *
- * @param computeNodeTemplateId the compute node template id
- * @return the compute template consolidation data
- */
- public ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
- String computeNodeTemplateId) {
- return computeTemplateConsolidationData.get(computeNodeTemplateId);
- }
-
- /**
- * Sets compute template consolidation data.
- *
- * @param computeNodeTemplateId the compute node template id
- * @param computeTemplateConsolidationData the compute template consolidation data
- */
- public void setComputeTemplateConsolidationData(String computeNodeTemplateId,
+ //key - compute node template id
+ private final Map<String, ComputeTemplateConsolidationData> computeTemplateConsolidationData;
+
+ public TypeComputeConsolidationData() {
+ computeTemplateConsolidationData = new HashMap<>();
+ }
+
+ public Collection<String> getAllComputeNodeTemplateIds() {
+ return computeTemplateConsolidationData.keySet();
+ }
+
+ public Collection<ComputeTemplateConsolidationData> getAllComputeTemplateConsolidationData() {
+ return computeTemplateConsolidationData.values();
+ }
+
+ /**
+ * Gets compute template consolidation data.
+ *
+ * @param computeNodeTemplateId the compute node template id
+ * @return the compute template consolidation data
+ */
+ public ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
+ String computeNodeTemplateId) {
+ return computeTemplateConsolidationData.get(computeNodeTemplateId);
+ }
+
+ public void setComputeTemplateConsolidationData(String computeNodeTemplateId,
ComputeTemplateConsolidationData
computeTemplateConsolidationData) {
- this.computeTemplateConsolidationData.put(computeNodeTemplateId,
- computeTemplateConsolidationData);
- }
+ this.computeTemplateConsolidationData.put(computeNodeTemplateId, computeTemplateConsolidationData);
+ }
+
+ /**
+ * create new compute template consolidation data if it doesn't exist yet.
+ *
+ * @return compute template consolidation data entity by given keys
+ */
+ ComputeTemplateConsolidationData addComputeTemplateConsolidationData(String computeNodeTemplateId) {
+ ComputeTemplateConsolidationData consolidationData = getComputeTemplateConsolidationData(computeNodeTemplateId);
+ if (consolidationData == null) {
+ consolidationData = new ComputeTemplateConsolidationData();
+ consolidationData.setNodeTemplateId(computeNodeTemplateId);
+ setComputeTemplateConsolidationData(computeNodeTemplateId, consolidationData);
+ }
+ return consolidationData;
+ }
+
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
index be282082ff..6b2770ceaf 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
@@ -168,11 +168,10 @@ public class ConsolidationDataUtil {
Optional<String> parentPortNodeTemplateId =
HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(subInterfaceTo);
- if (parentPortNodeTemplateId.isPresent()) {
- return Optional.ofNullable(getSubInterfaceTemplateConsolidationData(subInterfaceTo,
- parentPortNodeTemplateId.get(), subInterfaceNodeTemplateId));
- }
- return Optional.empty();
+
+ return parentPortNodeTemplateId.map(s -> getSubInterfaceTemplateConsolidationData(subInterfaceTo,
+ s, subInterfaceNodeTemplateId));
+
}
private static SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(
@@ -201,7 +200,7 @@ public class ConsolidationDataUtil {
portTemplateConsolidationData);
}
- return portTemplateConsolidationData.getSubInterfaceResourceTemplateConsolidationData(
+ return portTemplateConsolidationData.addSubInterfaceTemplateConsolidationData(
subInterfaceTo.getResource(), subInterfaceNodeTemplateId, parentPortNodeTemplateId);
}
@@ -323,14 +322,16 @@ public class ConsolidationDataUtil {
String portResourceType,
String portNodeTemplateId) {
TranslationContext translationContext = translateTo.getContext();
+ String computeNodeTemplateId = translateTo.getTranslatedId();
+ String portType = getPortType(portNodeTemplateId);
+
+ translationContext.getComputeConsolidationDataHandler().addPortToConsolidationData(
+ translateTo, computeNodeType, computeNodeTemplateId, portType, portNodeTemplateId);
+
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- ComputeTemplateConsolidationData computeTemplateConsolidationData =
- getComputeTemplateConsolidationData(translationContext, serviceTemplate, computeNodeType,
- translateTo.getTranslatedId());
- computeTemplateConsolidationData.addPort(getPortType(portNodeTemplateId), portNodeTemplateId);
- // create port in consolidation data
- getPortTemplateConsolidationData(translationContext, serviceTemplate, portResourceId,
- portResourceType, portNodeTemplateId);
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ translationContext.getPortConsolidationDataHandler().addConsolidationData(
+ serviceTemplateFileName, portResourceId, portResourceType, portNodeTemplateId);
}
/**
@@ -390,7 +391,7 @@ public class ConsolidationDataUtil {
requirementId);
Optional<ConsolidationDataHandler> consolidationDataHandler =
- translationContext.getConsolidationData().getConsolidationDataHandler(consolidationEntityType);
+ translationContext.getConsolidationDataHandler(consolidationEntityType);
consolidationDataHandler.ifPresent(handler -> handler.addNodesConnectedOut(
translateTo, nodeTemplateId, requirementId, requirementAssignment));
@@ -402,7 +403,7 @@ public class ConsolidationDataUtil {
* @param translateTo the translate to
* @param sourceNodeTemplateId the node template id of the source node
* @param consolidationEntityType Entity type (compute or port)
- * @param targetResourceId Target Resource Id
+ * @param targetResourceId Target Resource Id
* @param requirementId Requirement Id
* @param requirementAssignment the requirement assignment
*/
@@ -415,7 +416,7 @@ public class ConsolidationDataUtil {
TranslationContext translationContext = translateTo.getContext();
Optional<ConsolidationDataHandler> consolidationDataHandler =
- translationContext.getConsolidationData().getConsolidationDataHandler(consolidationEntityType);
+ translationContext.getConsolidationDataHandler(consolidationEntityType);
String dependentNodeTemplateId = requirementAssignment.getNode();
consolidationDataHandler.ifPresent(
handler -> handler.addNodesConnectedIn(translateTo, sourceNodeTemplateId, dependentNodeTemplateId,
@@ -557,8 +558,12 @@ public class ConsolidationDataUtil {
public static void updateNestedNodeTemplateId(TranslateTo translateTo) {
TranslationContext context = translateTo.getContext();
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- getNestedTemplateConsolidationData(
- context, serviceTemplate, translateTo.getHeatFileName(), translateTo.getTranslatedId());
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ // create nested in consolidation data
+ context.getNestedConsolidationDataHandler()
+ .addConsolidationData(serviceTemplateFileName, context,
+ translateTo.getHeatFileName(), translateTo.getTranslatedId());
+
}
public static void removeSharedResource(ServiceTemplate serviceTemplate,
@@ -577,16 +582,13 @@ public class ConsolidationDataUtil {
}
- public static Optional<ConsolidationDataHandler> getConsolidationDataHandler(
+ private static Optional<ConsolidationDataHandler> getConsolidationDataHandler(
HeatOrchestrationTemplate heatOrchestrationTemplate, TranslationContext context,
String contrailSharedResourceId) {
-
Resource resource = heatOrchestrationTemplate.getResources().get(contrailSharedResourceId);
ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER;
consolidationEntityType.setEntityType(resource, resource, context);
- return context.getConsolidationData().getConsolidationDataHandler(
- consolidationEntityType.getSourceEntityType());
-
+ return context.getConsolidationDataHandler(consolidationEntityType.getSourceEntityType());
}
public static void updateNodeGetAttributeIn(EntityConsolidationData entityConsolidationData,
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
index e865984468..d6f0d7a2b8 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
@@ -49,6 +49,7 @@ import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
@@ -75,9 +76,11 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
String nodeTypeRef = createLocalNodeType(serviceTemplate, translateTo.getResource(),
translateTo.getResourceId(), translateTo.getTranslatedId());
- //create compute in consolidation data
- ConsolidationDataUtil.getComputeTemplateConsolidationData(context, serviceTemplate,
- nodeTypeRef, translateTo.getTranslatedId());
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+
+ context.getComputeConsolidationDataHandler().addConsolidationData(
+ serviceTemplateFileName, nodeTypeRef, translateTo.getTranslatedId());
+
NodeTemplate novaNodeTemplate = new NodeTemplate();
novaNodeTemplate.setType(nodeTypeRef);
HeatOrchestrationTemplate heatOrchestrationTemplate =
@@ -96,13 +99,13 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void manageNovaServerGroupMapping(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate) {
- Map<String, Object> properties = translateTo.getResource().getProperties();
+ NodeTemplate novaNodeTemplate) {
+ Map properties = translateTo.getResource().getProperties();
if (isSchedulerHintsPropExist(properties)) {
Object schedulerHints = properties.get(ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction());
if (schedulerHints instanceof Map) {
addServerGroupHintsToPoliciesGroups(translateTo,
- novaNodeTemplate, (Map<String, Object>) schedulerHints);
+ novaNodeTemplate, (Map) schedulerHints);
} else {
logger.warn("'scheduler_hints' property of resource '{}' is not valid. This property should be a map",
translateTo.getResourceId());
@@ -111,8 +114,8 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void addServerGroupHintsToPoliciesGroups(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate,
- Map<String, Object> schedulerHints) {
+ NodeTemplate novaNodeTemplate,
+ Map schedulerHints) {
for (Object hint : schedulerHints.values()) {
Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
.extractAttachedResourceId(translateTo.getHeatFileName(), translateTo
@@ -130,18 +133,18 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void addServerGroupHintGetParam(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
- Object serverGroupResourceToTranslate) {
+ Object serverGroupResourceToTranslate) {
TranslatedHeatResource translatedServerGroupResource = translateTo.getContext()
.getHeatSharedResourcesByParam().get(serverGroupResourceToTranslate);
if (Objects.nonNull(translatedServerGroupResource)
- && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())
- && isResourceTypeServerGroup(translatedServerGroupResource)) {
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())
+ && isResourceTypeServerGroup(translatedServerGroupResource)) {
Map<String, GroupDefinition> groups =
translateTo.getServiceTemplate().getTopology_template().getGroups();
if (MapUtils.isNotEmpty(groups) && Objects.nonNull(groups.get(translatedServerGroupResource
- .getTranslatedId()))) {
+ .getTranslatedId()))) {
groups.get(translatedServerGroupResource.getTranslatedId()).getMembers()
- .add(translateTo.getTranslatedId());
+ .add(translateTo.getTranslatedId());
//Add group Id to compute consolidation data
updateComputeConsolidationDataGroup(translateTo, novaNodeTemplate,
translatedServerGroupResource.getTranslatedId());
@@ -150,7 +153,7 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void addServerGroupHintGetResource(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
- Object serverGroupResourceToTranslate) {
+ Object serverGroupResourceToTranslate) {
boolean isHintOfTypeNovaServerGroup = isHintOfTypeNovaServerGroup(translateTo
.getHeatOrchestrationTemplate(), serverGroupResourceToTranslate);
if (isHintOfTypeNovaServerGroup) {
@@ -164,25 +167,25 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void updateComputeConsolidationDataGroup(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate,
- String groupId) {
+ NodeTemplate novaNodeTemplate,
+ String groupId) {
TranslationContext translationContext = translateTo.getContext();
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
ComputeTemplateConsolidationData computeTemplateConsolidationData = ConsolidationDataUtil
.getComputeTemplateConsolidationData(translationContext, serviceTemplate,
- novaNodeTemplate.getType(), translateTo.getTranslatedId());
+ novaNodeTemplate.getType(), translateTo.getTranslatedId());
ConsolidationDataUtil.updateGroupIdInConsolidationData(computeTemplateConsolidationData, groupId);
}
private boolean isHintOfTypeNovaServerGroup(HeatOrchestrationTemplate heatOrchestrationTemplate,
- Object resourceToTranslate) {
+ Object resourceToTranslate) {
return heatOrchestrationTemplate.getResources().get(resourceToTranslate).getType()
- .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource());
+ .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource());
}
private void addNovaServerToPolicyGroup(TranslateTo translateTo,
- String resourceToTranslate,
- NodeTemplate novaNodeTemplate) {
+ String resourceToTranslate,
+ NodeTemplate novaNodeTemplate) {
Resource serverGroup =
HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(), resourceToTranslate,
translateTo.getHeatFileName());
@@ -192,18 +195,18 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
translateTo.getContext());
if (serverGroupTranslatedId.isPresent()) {
translateTo.getServiceTemplate().getTopology_template().getGroups().get(serverGroupTranslatedId.get())
- .getMembers().add(translateTo.getTranslatedId());
+ .getMembers().add(translateTo.getTranslatedId());
updateComputeConsolidationDataGroup(translateTo, novaNodeTemplate, serverGroupTranslatedId.get());
}
}
- private boolean isSchedulerHintsPropExist(Map<String, Object> properties) {
+ private boolean isSchedulerHintsPropExist(Map properties) {
return !MapUtils.isEmpty(properties)
- && Objects.nonNull(properties.get(ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction()));
+ && Objects.nonNull(properties.get(ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction()));
}
private void manageNovaServerBlockDeviceMapping(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate) {
+ NodeTemplate novaNodeTemplate) {
Resource resource = translateTo.getResource();
List<Map<String, Object>> blockDeviceMappingList = getBlockDeviceMappingList(resource);
if (CollectionUtils.isEmpty(blockDeviceMappingList)) {
@@ -216,13 +219,13 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private int connectBlockDeviceToNovaServer(TranslateTo translateTo, NodeTemplate novaNodeTemplate, int index,
- Map<String, Object> blockDeviceMapping) {
+ Map<String, Object> blockDeviceMapping) {
Object volumeIdObject = blockDeviceMapping.get(VOL_ID_PROPERTY_NAME);
Object snapshotIdObject = blockDeviceMapping.get(SNAPSHOT_ID_PROPERTY_NAME);
if (volumeIdObject == null && snapshotIdObject == null) {
logger.warn("Resource '{}' has block_device_mapping property with empty/missing volume_id and snapshot_id "
- + "properties. Entry number {}, this entry will be ignored in TOSCA translation.",
+ + "properties. Entry number {}, this entry will be ignored in TOSCA translation.",
translateTo.getResourceId(), (index + 1));
index++;
return index;
@@ -238,7 +241,7 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void connectBlockDeviceUsingVolumeId(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
- Object volumeIdObject) {
+ Object volumeIdObject) {
Optional<AttachedResourceId> attachedVolumeId = HeatToToscaUtil
.extractAttachedResourceId(translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
translateTo.getContext(), volumeIdObject);
@@ -249,8 +252,8 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void connectBlockDeviceUsingSnapshotId(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
- Object snapshotIdObject, int index,
- Map<String, Object> blockDeviceMapping) {
+ Object snapshotIdObject, int index,
+ Map<String, Object> blockDeviceMapping) {
String novaServerTranslatedId = translateTo.getTranslatedId();
String volumeResourceId;
Optional<AttachedResourceId> attachedSnapshotId = HeatToToscaUtil
@@ -269,7 +272,7 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void connectNovaServerToVolume(NodeTemplate novaNodeTemplate, String volumeResourceId,
- String relationshipId, TranslateTo translateTo) {
+ String relationshipId, TranslateTo translateTo) {
RequirementAssignment requirementAssignment = new RequirementAssignment();
requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
requirementAssignment.setNode(volumeResourceId);
@@ -287,8 +290,8 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void createCinderVolumeNodeTemplate(TranslateTo translateTo,
- String volumeResourceId,
- Map<String, Object> blockDeviceMapping) {
+ String volumeResourceId,
+ Map<String, Object> blockDeviceMapping) {
NodeTemplate cinderVolumeNodeTemplate = new NodeTemplate();
cinderVolumeNodeTemplate.setType(ToscaNodeType.CINDER_VOLUME);
cinderVolumeNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
@@ -301,8 +304,8 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void createVolumeAttachesToRelationship(ServiceTemplate serviceTemplate,
- String deviceName, String novaServerTranslatedId,
- String volumeId, String relationshipId) {
+ String deviceName, String novaServerTranslatedId,
+ String volumeId, String relationshipId) {
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
relationshipTemplate.setType(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO);
Map<String, Object> properties = new HashMap<>();
@@ -327,7 +330,7 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
if (blockDeviceMappingList != null && blockDeviceMappingV2List != null) {
blockDeviceMappingList.addAll(blockDeviceMappingV2List);
} else if (CollectionUtils.isEmpty(blockDeviceMappingList)
- && CollectionUtils.isEmpty(blockDeviceMappingV2List)) {
+ && CollectionUtils.isEmpty(blockDeviceMappingV2List)) {
return Collections.emptyList();
} else {
@@ -338,7 +341,7 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void manageNovaServerNetwork(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate) {
+ NodeTemplate novaNodeTemplate) {
Resource resource = translateTo.getResource();
String translatedId = translateTo.getTranslatedId();
@@ -359,9 +362,9 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void getOrTranslatePortTemplate(TranslateTo translateTo,
- Object port,
- String novaServerResourceId,
- NodeTemplate novaNodeTemplate) {
+ Object port,
+ String novaServerResourceId,
+ NodeTemplate novaNodeTemplate) {
String heatFileName = translateTo.getHeatFileName();
HeatOrchestrationTemplate heatOrchestrationTemplate = translateTo.getHeatOrchestrationTemplate();
TranslationContext context = translateTo.getContext();
@@ -373,13 +376,14 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
String resourceId = (String) attachedPortId.get().getEntityId();
Resource portResource = HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceId, heatFileName);
if (!isSupportedPortResource(portResource)) {
- logger.warn("NovaServer connect to port resource with id : {} and type : {}. This resource type is not "
- + "supported, therefore the connection to the port is ignored. Supported types are: {}, {}",
- resourceId, portResource.getType(), HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ logger.warn("NovaServer connect to port resource with id : {} and type : {}. This resource type is "
+ + "not " + "supported, therefore the connection to the port is ignored. "
+ + "Supported types are: {}, {}", resourceId, portResource.getType(),
+ HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource());
return;
} else if (HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE
- .getHeatResource().equals(portResource.getType())) {
+ .getHeatResource().equals(portResource.getType())) {
Map<String, Object> properties = portResource.getProperties();
if (!MapUtils.isEmpty(properties) && Objects.nonNull(properties.get(HeatConstants.PORT_TUPLE_REFS))) {
novaNodeTemplate.getProperties().put(ToscaConstants.CONTRAIL_SERVICE_INSTANCE_IND, true);
@@ -397,21 +401,21 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
ConsolidationDataUtil.updatePortInConsolidationData(translateTo, novaNodeTemplate.getType(), resourceId,
portResource.getType(), translatedPortId.get());
} else {
- logger.warn("NovaServer connect to port resource with id : {} and type : {}. This resource type is not "
- + "supported, therefore the connection to the port is ignored.", resourceId, portResource
- .getType());
+ logger.warn("NovaServer connect to port resource with id : {} and type : {}. This resource type"
+ + " is not supported, therefore the connection to the port is ignored.", resourceId,
+ portResource.getType());
}
}
private boolean isSupportedPortResource(Resource portResource) {
return Arrays.asList(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())
- .contains(portResource.getType());
+ .contains(portResource.getType());
}
private String createLocalNodeType(ServiceTemplate serviceTemplate, Resource resource,
- String resourceId, String translatedId) {
+ String resourceId, String translatedId) {
NameExtractor nodeTypeNameExtractor = TranslationContext.getNameExtractorImpl(resource.getType());
String nodeTypeName =
nodeTypeNameExtractor.extractNodeTypeName(resource, resourceId, translatedId);
@@ -435,16 +439,16 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
Arrays.asList(".+_name$", ".+_names$", ".+_name_[0-9]+"), "_name"));
propertyRegexMatchers
.add(new PropertyRegexMatcher("image", Collections.singletonList(".+_image_name$"),
- "_image_name"));
+ "_image_name"));
propertyRegexMatchers
.add(new PropertyRegexMatcher("flavor", Collections.singletonList(".+_flavor_name$"),
- "_flavor_name"));
+ "_flavor_name"));
return propertyRegexMatchers;
}
private boolean isNodeTypeCreated(ServiceTemplate serviceTemplate, String nodeTypeName) {
return !MapUtils.isEmpty(serviceTemplate.getNode_types())
- && Objects.nonNull(serviceTemplate.getNode_types().get(nodeTypeName));
+ && Objects.nonNull(serviceTemplate.getNode_types().get(nodeTypeName));
}
private NodeType createNodeType() {
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java
new file mode 100644
index 0000000000..a92e298c0a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ComputeConsolidationDataTest {
+
+ private static final String SERVICE_TEMPLATE_FILE_NAME_1 = "serviceTemplateFileName1";
+ private static final String SERVICE_TEMPLATE_FILE_NAME_2 = "serviceTemplateFileName2";
+ private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1";
+ private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2";
+ private static final String COMPUTE_NODE_TYPE_1 = "computeNodeType1";
+ private static final String COMPUTE_NODE_TYPE_2 = "computeNodeType2";
+
+ @Test
+ public void testAddComputeTemplateConsolidationData() {
+ ComputeConsolidationData consolidationData = new ComputeConsolidationData();
+ consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+
+ Set<String> expectedServiceTemplateNames = new HashSet<>();
+ expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1);
+ checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+ }
+
+ @Test
+ public void testAddSameConsolidationDataTwice_noNewCreated() {
+ ComputeConsolidationData consolidationData = new ComputeConsolidationData();
+ consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationData.getFileComputeConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1);
+
+ Set<String> expectedServiceTemplateNames = new HashSet<>();
+ expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1);
+ checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+
+ consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationData.getFileComputeConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1);
+ checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_SameServiceTemplate_DiffNodeTypes() {
+ ComputeConsolidationData consolidationData = new ComputeConsolidationData();
+
+ consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Set<String> expectedServiceTemplateNames = new HashSet<>();
+ expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1);
+ checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+
+ consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ COMPUTE_NODE_TYPE_2, COMPUTE_NODE_TEMPLATE_ID_2);
+ checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_DiffServiceTemplate() {
+ ComputeConsolidationData consolidationData = new ComputeConsolidationData();
+
+ consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Set<String> expectedServiceTemplateNames = new HashSet<>();
+ expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1);
+ checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+
+ consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_2,
+ COMPUTE_NODE_TYPE_2, COMPUTE_NODE_TEMPLATE_ID_2);
+ expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_2);
+ checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_2, expectedServiceTemplateNames);
+
+ }
+
+ private void checkComputeConsolidationData(ComputeConsolidationData consolidationData,
+ String serviceTemplateFileName, Set<String> expectedServiceTemplateNames) {
+
+ FileComputeConsolidationData fileComputeConsolidationData = consolidationData
+ .getFileComputeConsolidationData(serviceTemplateFileName);
+ Assert.assertNotNull(fileComputeConsolidationData);
+ checkGetAllServiceTemplateFileNames(consolidationData, expectedServiceTemplateNames);
+ }
+
+ private void checkGetAllServiceTemplateFileNames(ComputeConsolidationData consolidationData,
+ Set<String> expectedServiceTemplateNames) {
+ Set<String> allServiceTemplateFileNames = consolidationData.getAllServiceTemplateFileNames();
+ Assert.assertNotNull(allServiceTemplateFileNames);
+ Assert.assertEquals(allServiceTemplateFileNames.size(), expectedServiceTemplateNames.size());
+ Assert.assertTrue(allServiceTemplateFileNames.containsAll(expectedServiceTemplateNames));
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataTest.java
new file mode 100644
index 0000000000..726a76c2d2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.Optional;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType;
+
+public class ConsolidationDataTest {
+
+ private final ConsolidationData consolidationData = new ConsolidationData();
+
+ @Test
+ public void testGetConsolidationDataHandler() {
+
+ checkHandlerIsValid(ConsolidationEntityType.COMPUTE, ComputeConsolidationDataHandler.class);
+ checkHandlerIsValid(ConsolidationEntityType.PORT, PortConsolidationDataHandler.class);
+ checkHandlerIsValid(ConsolidationEntityType.SUB_INTERFACE, SubInterfaceConsolidationDataHandler.class);
+ checkHandlerIsValid(ConsolidationEntityType.NESTED, NestedConsolidationDataHandler.class);
+ checkHandlerIsValid(ConsolidationEntityType.VFC_NESTED, NestedConsolidationDataHandler.class);
+ }
+
+ @Test
+ public void testGetConsolidationDataHandler_Negative() {
+ checkHandlerNotExist(ConsolidationEntityType.OTHER);
+ checkHandlerNotExist(ConsolidationEntityType.VOLUME);
+ }
+
+ private void checkHandlerIsValid(ConsolidationEntityType consolidationEntityType, Class cls) {
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ consolidationData.getConsolidationDataHandler(consolidationEntityType);
+ Assert.assertTrue(consolidationDataHandler.isPresent());
+ Assert.assertTrue(cls.isInstance(consolidationDataHandler.get()));
+ }
+
+ private void checkHandlerNotExist(ConsolidationEntityType consolidationEntityType) {
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ consolidationData.getConsolidationDataHandler(consolidationEntityType);
+ Assert.assertFalse(consolidationDataHandler.isPresent());
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java
new file mode 100644
index 0000000000..ec65b43fef
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java
@@ -0,0 +1,170 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+
+@SuppressWarnings("Duplicates")
+public class EntityConsolidationDataTest {
+
+ private static final String NODE_TEMPLATE_ID_1 = "nodeTemplateId1";
+ private static final String NODE_TEMPLATE_ID_2 = "nodeTemplateId2";
+ private static final String REQUIREMENT_ID_1 = "requirementId1";
+ private static final String REQUIREMENT_ID_2 = "requirementId2";
+
+ @Test
+ public void testAddNodesConnectedIn_SameNodeTemplateIds() {
+ EntityConsolidationData consolidationData = new EntityConsolidationData();
+ Map<String, String[]> expectedNodesConnectedData = new HashMap<>();
+
+ addNodesConnectedIn(consolidationData,NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1});
+ checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData);
+
+ addNodesConnectedIn(consolidationData,NODE_TEMPLATE_ID_1, REQUIREMENT_ID_2);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1, REQUIREMENT_ID_2});
+ checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData);
+ }
+
+ @Test
+ public void testAddNodesConnectedIn_DiffNodeTemplateIds() {
+ EntityConsolidationData consolidationData = new EntityConsolidationData();
+ Map<String, String[]> expectedNodesConnectedData = new HashMap<>();
+
+ addNodesConnectedIn(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1});
+ checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData);
+
+ addNodesConnectedIn(consolidationData, NODE_TEMPLATE_ID_2, REQUIREMENT_ID_2);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_2, new String[]{REQUIREMENT_ID_2});
+ checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData);
+ }
+
+ @Test
+ public void testAddNodesConnectedOut_SameNodeTemplateIds() {
+ EntityConsolidationData consolidationData = new EntityConsolidationData();
+ Map<String, String[]> expectedNodesConnectedData = new HashMap<>();
+
+ addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1});
+ checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData);
+
+ addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_2);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1, REQUIREMENT_ID_2});
+ checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData);
+ }
+
+ @Test
+ public void testAddNodesConnectedOut_DiffNodeTemplateIds() {
+ EntityConsolidationData consolidationData = new EntityConsolidationData();
+ Map<String, String[]> expectedNodesConnectedData = new HashMap<>();
+
+ addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1});
+ checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData);
+
+ addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_2, REQUIREMENT_ID_2);
+ expectedNodesConnectedData.put(NODE_TEMPLATE_ID_2, new String[]{REQUIREMENT_ID_2});
+ checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData);
+ }
+
+ @Test
+ public void testAddOutputParamGetAttrIn() {
+ EntityConsolidationData consolidationData = new EntityConsolidationData();
+ GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData("field1");
+
+ consolidationData.addOutputParamGetAttrIn(getAttrFuncData1);
+ List<GetAttrFuncData> outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn();
+ Assert.assertEquals(1, outputParametersGetAttrIn.size());
+ Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData1));
+
+ GetAttrFuncData getAttrFuncData2 = createGetAttrFuncData("field2");
+ consolidationData.addOutputParamGetAttrIn(getAttrFuncData2);
+ Assert.assertEquals(2,outputParametersGetAttrIn.size());
+ Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData1));
+ Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData2));
+ }
+
+ @Test
+ public void testRemoveParamNameFromAttrFuncList() {
+ EntityConsolidationData consolidationData = new EntityConsolidationData();
+ GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData("field1");
+
+ consolidationData.addOutputParamGetAttrIn(getAttrFuncData1);
+ // verify that getAttrFuncData was added
+ List<GetAttrFuncData> outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn();
+ Assert.assertEquals(1, outputParametersGetAttrIn.size());
+
+ consolidationData.removeParamNameFromAttrFuncList("field2");
+ //verify that not existing getAttrFuncData parameter wasn't removed and no Exception
+ outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn();
+ Assert.assertEquals(1, outputParametersGetAttrIn.size());
+
+ consolidationData.removeParamNameFromAttrFuncList("field1");
+ //verify that existing getAttrFuncData parameter was removed
+ outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn();
+ Assert.assertEquals(0, outputParametersGetAttrIn.size());
+ }
+
+ private GetAttrFuncData createGetAttrFuncData(String field) {
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
+ getAttrFuncData.setFieldName(field);
+ getAttrFuncData.setAttributeName("attribute");
+ return getAttrFuncData;
+ }
+
+ private void checkNodesConnected(Map<String, List<RequirementAssignmentData>> actualNodesConnected,
+ Map<String, String[]> expectedNodesConnected) {
+ Assert.assertNotNull(actualNodesConnected);
+
+ expectedNodesConnected.keySet().forEach(expectedNodeTemplateId -> {
+ Assert.assertTrue(actualNodesConnected.containsKey(expectedNodeTemplateId));
+ Assert.assertEquals(expectedNodesConnected.size(), actualNodesConnected.size());
+
+ List<RequirementAssignmentData> actualRequirementAssignmentData =
+ actualNodesConnected.get(expectedNodeTemplateId);
+ List<String> expectedRequirementIdList =
+ Arrays.asList(expectedNodesConnected.get(expectedNodeTemplateId));
+ Assert.assertEquals(expectedRequirementIdList.size(), actualRequirementAssignmentData.size());
+
+ actualRequirementAssignmentData.forEach(actualRequirementAssignment ->
+ Assert.assertTrue(expectedRequirementIdList
+ .contains(actualRequirementAssignment.getRequirementId())));
+ });
+
+ }
+
+ private void addNodesConnectedIn(EntityConsolidationData consolidationData,
+ String nodeTemplateId, String requirementId) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ consolidationData.addNodesConnectedIn(nodeTemplateId, requirementId, requirementAssignment);
+ }
+
+ private void addNodesConnectedOut(EntityConsolidationData consolidationData,
+ String nodeTemplateId, String requirementId) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ consolidationData.addNodesConnectedOut(nodeTemplateId, requirementId, requirementAssignment);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java
new file mode 100644
index 0000000000..eab3bd25b1
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FileComputeConsolidationDataTest {
+
+ private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1";
+ private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2";
+ private static final String COMPUTE_NODE_TYPE_1 = "computeNodeType1";
+ private static final String COMPUTE_NODE_TYPE_2 = "computeNodeType2";
+
+ @Test
+ public void testAddComputeTemplateConsolidationData() {
+ FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_1);
+ checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes);
+ }
+
+ @Test
+ public void testAddSameConsolidationDataTwice_noNewCreated() {
+ FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ TypeComputeConsolidationData firstTypeComputeConsolidationData =
+ consolidationData.getTypeComputeConsolidationData(COMPUTE_NODE_TYPE_1);
+
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ TypeComputeConsolidationData secondTypeComputeConsolidationData =
+ consolidationData.getTypeComputeConsolidationData(COMPUTE_NODE_TYPE_1);
+ Assert.assertEquals(firstTypeComputeConsolidationData, secondTypeComputeConsolidationData);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_DiffNodeType() {
+ FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
+
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_1);
+ checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes);
+
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_2, COMPUTE_NODE_TEMPLATE_ID_2);
+ expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_2);
+ checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_2, expectedComputeNodeTypes);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_SameNodeType_MultiNodeTemplateId() {
+ FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
+
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_1);
+ checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes);
+
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes);
+ }
+
+ private void checkComputeConsolidationData(FileComputeConsolidationData fileComputeConsolidationData,
+ String computeNodeType, Set<String> expectedComputeNodeTypes) {
+ TypeComputeConsolidationData typeComputeConsolidationData =
+ fileComputeConsolidationData.getTypeComputeConsolidationData(computeNodeType);
+ Assert.assertNotNull(typeComputeConsolidationData);
+ checkGetAllComputeTypes(fileComputeConsolidationData, expectedComputeNodeTypes);
+ }
+
+ private void checkGetAllComputeTypes(FileComputeConsolidationData fileComputeConsolidationData,
+ Set<String> expectedComputeNodeTypes) {
+ Collection<String> allComputeTypes = fileComputeConsolidationData.getAllComputeTypes();
+ Assert.assertNotNull(allComputeTypes);
+ Assert.assertEquals(allComputeTypes.size(), expectedComputeNodeTypes.size());
+ Assert.assertTrue(allComputeTypes.containsAll(expectedComputeNodeTypes));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java
new file mode 100644
index 0000000000..7a3c8fa526
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TypeComputeConsolidationDataTest {
+
+ private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1";
+ private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2";
+
+ @Test
+ public void testAddComputeTemplateConsolidationData() {
+ TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData();
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
+
+ Set<String> expectedNodeTemplateIds = new HashSet<>();
+ expectedNodeTemplateIds.add(COMPUTE_NODE_TEMPLATE_ID_1);
+ verifyComputeTemplateConsolidationData(consolidationData, COMPUTE_NODE_TEMPLATE_ID_1, expectedNodeTemplateIds);
+ }
+
+ @Test
+ public void testAddSameConsolidationDataTwice_noNewCreated() {
+ TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData();
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
+ ComputeTemplateConsolidationData firstComputeTemplateConsolidationData =
+ consolidationData.getComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
+
+ consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
+ ComputeTemplateConsolidationData secondComputeTemplateConsolidationData =
+ consolidationData.getComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
+ Assert.assertEquals(firstComputeTemplateConsolidationData, secondComputeTemplateConsolidationData);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_DiffNodeTemplateId() {
+ TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData();
+
+ final ComputeTemplateConsolidationData firstComputeTemplateConsolidationData = consolidationData
+ .addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
+ Set<String> expectedNodeTemplateIds1 = new HashSet<>();
+ expectedNodeTemplateIds1.add(COMPUTE_NODE_TEMPLATE_ID_1);
+ verifyComputeTemplateConsolidationData(consolidationData, COMPUTE_NODE_TEMPLATE_ID_1, expectedNodeTemplateIds1);
+
+ final ComputeTemplateConsolidationData secondComputeTemplateConsolidationData = consolidationData
+ .addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_2);
+ Set<String> expectedNodeTemplateIds2 = new HashSet<>();
+ expectedNodeTemplateIds2.add(COMPUTE_NODE_TEMPLATE_ID_2);
+ verifyComputeTemplateConsolidationData(consolidationData, COMPUTE_NODE_TEMPLATE_ID_2, expectedNodeTemplateIds2);
+
+ Assert.assertNotEquals(firstComputeTemplateConsolidationData, secondComputeTemplateConsolidationData);
+ }
+
+ private void verifyComputeTemplateConsolidationData(TypeComputeConsolidationData typeComputeConsolidationData,
+ String computeNodeTemplateId, Set<String> expectedComputeNodeTemplateIds) {
+ ComputeTemplateConsolidationData computeTemplateConsolidationData =
+ typeComputeConsolidationData.getComputeTemplateConsolidationData(computeNodeTemplateId);
+ Assert.assertNotNull(computeTemplateConsolidationData);
+ Assert.assertEquals(computeTemplateConsolidationData.getNodeTemplateId(), computeNodeTemplateId);
+
+ verifyGetAllComputeNodeTemplateId(typeComputeConsolidationData, expectedComputeNodeTemplateIds);
+ }
+
+ private void verifyGetAllComputeNodeTemplateId(TypeComputeConsolidationData typeComputeConsolidationData,
+ Set<String> expectedComputeNodeTemplateIds) {
+ Collection<String> allComputeNodeTemplateIds = typeComputeConsolidationData.getAllComputeNodeTemplateIds();
+ Assert.assertNotNull(allComputeNodeTemplateIds);
+ Assert.assertTrue(allComputeNodeTemplateIds.containsAll(expectedComputeNodeTemplateIds));
+ }
+}