2  * Copyright © 2016-2018 European Support Limited
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *      http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  17 package org.openecomp.sdc.translator.datatypes.heattotosca;
 
  19 import com.google.common.collect.ArrayListMultimap;
 
  20 import com.google.common.collect.ListMultimap;
 
  21 import org.apache.commons.collections.MapUtils;
 
  22 import org.onap.config.api.Configuration;
 
  23 import org.onap.config.api.ConfigurationManager;
 
  24 import org.openecomp.core.utilities.CommonMethods;
 
  25 import org.openecomp.core.utilities.file.FileContentHandler;
 
  26 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 
  27 import org.openecomp.sdc.common.errors.CoreException;
 
  28 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
 
  29 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
 
  30 import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile;
 
  31 import org.openecomp.sdc.heat.datatypes.model.Resource;
 
  32 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
 
  33 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
 
  34 import org.openecomp.sdc.tosca.services.ToscaUtil;
 
  35 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
 
  36 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity;
 
  37 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedSubstitutionData;
 
  38 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeConsolidationDataHandler;
 
  39 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
 
  40 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationDataHandler;
 
  41 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortConsolidationDataHandler;
 
  42 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedConsolidationDataHandler;
 
  43 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceConsolidationDataHandler;
 
  44 import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
 
  45 import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType;
 
  46 import org.openecomp.sdc.translator.services.heattotosca.Constants;
 
  47 import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
 
  48 import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
 
  49 import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
 
  51 import java.io.InputStream;
 
  52 import java.util.HashMap;
 
  53 import java.util.HashSet;
 
  54 import java.util.List;
 
  56 import java.util.Objects;
 
  57 import java.util.Optional;
 
  61 public class TranslationContext {
 
  63   private ManifestFile manifest;
 
  66   private static final Map<String, Map<String, Map<String, String>>> translationMapping;
 
  67   private static final Map<String, ServiceTemplate> globalServiceTemplates;
 
  68   private static final Map<String, ImplementationConfiguration> nameExtractorImplMap;
 
  69   private static final List<String> vfcGroupSubInterfaceExposedProperties;
 
  70   private static final List<String> enrichPortResourceProperties;
 
  71   private static final ImplementationConfiguration vfcInstanceGroupConfiguration;
 
  73   private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
 
  74   private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
 
  76   private final FileContentHandler files = new FileContentHandler();
 
  77   private final Map<String, FileData.Type> manifestFiles = new HashMap<>();
 
  78   //Key - file name, value - file type
 
  79   private final Set<String> nestedHeatsFiles = new HashSet<>();
 
  80   private final FileContentHandler externalArtifacts = new FileContentHandler();
 
  81   // Key - heat file name,value - set of heat resource ids which were translated
 
  82   private final Map<String, Set<String>> translatedResources = new HashMap<>();
 
  83   // Key - heat file name, value - translated Node template id
 
  84   private final Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
 
  85   // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
 
  86   private final Map<String, Map<String, String>> translatedIds = new HashMap<>();
 
  87   // key - service template type, value - translated service templates
 
  88   private final Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
 
  89   //key - heat param name, value - shared resource data
 
  90   private final Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
 
  91   //key - translated substitute service template file name, value - source nested heat file name
 
  92   private final Map<String, String> nestedHeatFileName = new HashMap<>();
 
  93   //Key - heat file name,value - Map eith key - heat pseudo param name,
 
  94   // value - translated tosca parameter name
 
  95   private final Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
 
  96   //Consolidation data gathered for Unified TOSCA model
 
  97   private ConsolidationData consolidationData = new ConsolidationData();
 
  98   private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
 
  99   private final Set<String> unifiedHandledServiceTemplates = new HashSet<>();
 
 101   private final Map<String, Map<String, Map<String, Integer>>> requirementIdAppearanceInNodeTemplate = new HashMap<>();
 
 103   private final Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
 
 105   private final Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
 
 107   //Key - service template name, value - Map of key: node template id, value: properties with %index%
 
 108   private final Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
 
 111     Configuration config = ConfigurationManager.lookup();
 
 113             config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
 
 115       globalServiceTemplates =
 
 116               GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
 
 117     } catch (Exception exc) {
 
 118       throw new RuntimeException("Failed to load GlobalTypes", exc);
 
 120     nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
 
 121             ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
 
 122     supportedConsolidationComputeResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
 
 123             ConfigConstants.SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
 
 124     supportedConsolidationPortResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
 
 125             ConfigConstants.SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
 
 126     enrichPortResourceProperties = config.getAsStringValues(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
 
 127             ConfigConstants.ENRICH_PORT_RESOURCE_PROP);
 
 128     vfcInstanceGroupConfiguration = getVfcInstanceGroupConfiguration(config);
 
 129     vfcGroupSubInterfaceExposedProperties = config.getAsStringValues(ConfigConstants.UNIFIED_MODEL_NAMESPACE,
 
 130             ConfigConstants.FULL_EXPOSED_PROPERTIES_KEY);
 
 134   private static ImplementationConfiguration getVfcInstanceGroupConfiguration(Configuration config) {
 
 135     Map<String, ImplementationConfiguration> supportedUnifiedModelProperties =
 
 136             config.populateMap(ConfigConstants.UNIFIED_MODEL_NAMESPACE, ConfigConstants.UNIFIED_MODEL_IMPL_KEY,
 
 137                     ImplementationConfiguration.class);
 
 138     return MapUtils.isEmpty(supportedUnifiedModelProperties) ? null : supportedUnifiedModelProperties.get(ConfigConstants.VFC_INSTANCE_GROUP_KEY);
 
 141   public static boolean isVfcInstanceGroupingEnabled() {
 
 142     return Objects.nonNull(vfcInstanceGroupConfiguration) && vfcInstanceGroupConfiguration.isEnable();
 
 145   public static List<String> getExposedVfcInstanceGroupingProperties() {
 
 146     return vfcGroupSubInterfaceExposedProperties;
 
 149   public static List<String> getEnrichPortResourceProperties() {
 
 150     return enrichPortResourceProperties;
 
 153   public static Map<String, ImplementationConfiguration> getSupportedConsolidationComputeResources() {
 
 154     return supportedConsolidationComputeResources;
 
 157   public static void setSupportedConsolidationComputeResources(Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
 
 158     TranslationContext.supportedConsolidationComputeResources = supportedConsolidationComputeResources;
 
 161   public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
 
 162     return supportedConsolidationPortResources;
 
 165   public static void setSupportedConsolidationPortResources(Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
 
 166     TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
 
 170    * Get nameExtractor implemetation class instance.
 
 172    * @param extractorImplKey configuration key for the implementation class
 
 173    * @return implemetation class instance
 
 175   public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
 
 176     String nameExtractorImplClassName = nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
 
 178     return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
 
 181   public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
 
 182     return unifiedSubstitutionData;
 
 185   public void setUnifiedSubstitutionData(Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
 
 186     this.unifiedSubstitutionData = unifiedSubstitutionData;
 
 189   public void addCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId, UnifiedCompositionEntity unifiedCompositionEntity,
 
 190                                             NodeTemplate nodeTemplate) {
 
 191     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 192     this.unifiedSubstitutionData.get(serviceTemplateName)
 
 193                                 .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
 
 196   public Optional<List<String>> getIndexVarProperties(String serviceTemplateName, String nodeTemplateId) {
 
 197     ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties.get(serviceTemplateName);
 
 198     if (Objects.nonNull(serviceTemplateIndexVarProperties)) {
 
 199       return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId));
 
 201     return Optional.empty();
 
 204   public void addIndexVarProperties(String serviceTemplateName, String nodeTemplateId, List<String> indexVarProperties) {
 
 205     this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create());
 
 206     this.indexVarProperties.get(serviceTemplateName).putAll(nodeTemplateId, indexVarProperties);
 
 209   public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId) {
 
 210     return this.unifiedSubstitutionData.get(serviceTemplateName).getCleanedNodeTemplate(nodeTemplateId);
 
 213   public void addUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId, String unifiedNestedNodeTemplateId) {
 
 214     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 215     this.unifiedSubstitutionData.get(serviceTemplateName)
 
 216                                 .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
 
 219   public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId) {
 
 220     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() :
 
 221                    this.unifiedSubstitutionData.get(serviceTemplateName).getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
 
 224   public void addUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTypeId, String unifiedNestedNodeTypeId) {
 
 225     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 226     this.unifiedSubstitutionData.get(serviceTemplateName)
 
 227                                 .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
 
 230   public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTemplateId) {
 
 231     UnifiedSubstitutionData substitutionData = this.unifiedSubstitutionData.get(serviceTemplateName);
 
 232     return substitutionData == null ? Optional.empty() :
 
 233                    substitutionData.getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
 
 236   public ConsolidationData getConsolidationData() {
 
 237     return consolidationData;
 
 240   public void setConsolidationData(ConsolidationData consolidationData) {
 
 241     this.consolidationData = consolidationData;
 
 244   public Optional<ConsolidationDataHandler> getConsolidationDataHandler(ConsolidationEntityType type) {
 
 245     return consolidationData.getConsolidationDataHandler(type);
 
 248   public ComputeConsolidationDataHandler getComputeConsolidationDataHandler() {
 
 249     return consolidationData.getComputeConsolidationDataHandler();
 
 252   public PortConsolidationDataHandler getPortConsolidationDataHandler() {
 
 253     return consolidationData.getPortConsolidationDataHandler();
 
 256   public NestedConsolidationDataHandler getNestedConsolidationDataHandler() {
 
 257     return consolidationData.getNestedConsolidationDataHandler();
 
 260   public SubInterfaceConsolidationDataHandler getSubInterfaceComputeConsolidationDataHandler() {
 
 261     return consolidationData.getSubInterfaceConsolidationDataHandler();
 
 264   public void addManifestFile(String fileName, FileData.Type fileType) {
 
 265     this.manifestFiles.put(fileName, fileType);
 
 268   public Set<String> getNestedHeatsFiles() {
 
 269     return nestedHeatsFiles;
 
 272   public Map<String, Set<String>> getHeatStackGroupMembers() {
 
 273     return heatStackGroupMembers;
 
 276   public FileContentHandler getFiles() {
 
 280   public void setFiles(Map<String, byte[]> files) {
 
 281     this.files.putAll(files);
 
 284   public InputStream getFileContent(String fileName) {
 
 285     return files.getFileContent(fileName);
 
 288   public void addFile(String name, byte[] content) {
 
 289     files.addFile(name, content);
 
 292   public ManifestFile getManifest() {
 
 296   public void setManifest(ManifestFile manifest) {
 
 297     this.manifest = manifest;
 
 300   public Map<String, Set<String>> getTranslatedResources() {
 
 301     return translatedResources;
 
 304   public Map<String, Map<String, String>> getTranslatedIds() {
 
 305     return translatedIds;
 
 308   public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
 
 309                                                                         nestedHeatFileNameToSkip) {
 
 310     Set<String> allTranslatedResourceIds = new HashSet<>();
 
 312     this.translatedIds.entrySet().stream().filter(
 
 313         heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
 
 314             .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry ->
 
 315       allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet())
 
 318     return allTranslatedResourceIds;
 
 321   // get tosca name from mapping configuration file
 
 322   //element type - parameter/attribute
 
 323   // element name - heat parameter/attribute name
 
 324   //return value - tosca parameter/attribute name
 
 325   public String getElementMapping(String resourceType, String elementType, String elementName) {
 
 326     if (Objects.isNull(translationMapping.get(resourceType))) {
 
 329     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
 
 332     return translationMapping.get(resourceType).get(elementType).get(elementName);
 
 335   public Map<String, String> getElementMapping(String resourceType, String elementType) {
 
 336     if (Objects.isNull(translationMapping.get(resourceType))) {
 
 339     return translationMapping.get(resourceType).get(elementType);
 
 342   public Set<String> getElementSet(String resourceType, String elementType) {
 
 343     if (Objects.isNull(translationMapping.get(resourceType))) {
 
 344       return new HashSet<>();
 
 346     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
 
 347       return new HashSet<>();
 
 349     return translationMapping.get(resourceType).get(elementType).keySet();
 
 352   public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
 
 353     return translatedServiceTemplates;
 
 356   public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
 
 357     return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
 
 360   public FileContentHandler getExternalArtifacts() {
 
 361     return externalArtifacts;
 
 364   public void addExternalArtifacts(String name, byte[] content) {
 
 365     this.externalArtifacts.addFile(name, content);
 
 368   public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
 
 369     return heatSharedResourcesByParam;
 
 372   public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
 
 374     this.addHeatSharedResourcesByParam(parameterName,
 
 375         new TranslatedHeatResource(resourceId, resource));
 
 378   private void addHeatSharedResourcesByParam(String parameterName,
 
 379                                              TranslatedHeatResource translatedHeatResource) {
 
 380     this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
 
 383   public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
 
 384     return globalServiceTemplates;
 
 387   public Map<String, String> getNestedHeatFileName() {
 
 388     return nestedHeatFileName;
 
 391   public void addNestedHeatFileName(String substituteServiceTempalteName,
 
 392                                     String nestedHeatFileName) {
 
 393     this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
 
 396   public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
 
 397     return usedHeatPseudoParams;
 
 400   public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
 
 401       translatedToscaParam) {
 
 402     if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
 
 403       this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
 
 405     this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
 
 408   public Set<String> getTranslatedResourceIdsFromOtherFiles(String fileNameToIgnore){
 
 409     if(MapUtils.isEmpty(this.translatedResources)){
 
 410       return new HashSet<>();
 
 413     Set<String> translatedResourceIds = new HashSet<>();
 
 415     this.translatedResources.entrySet().stream().filter(entry -> !entry.getKey().equals(fileNameToIgnore))
 
 416         .forEach(entry -> translatedResourceIds.addAll(entry.getValue()));
 
 418     return translatedResourceIds;
 
 422    * Add the unified substitution data info in context. Contains a mapping of original node
 
 423    * template id and the new node template id in the abstract substitute
 
 425    * @param serviceTemplateFileName the service template file name
 
 426    * @param originalNodeTemplateId  the original node template id
 
 427    * @param abstractNodeTemplateId  the node template id in the abstract substitute
 
 429   public void addUnifiedSubstitutionData(String serviceTemplateFileName,
 
 430                                          String originalNodeTemplateId,
 
 431                                          String abstractNodeTemplateId) {
 
 433     Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
 
 434         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
 
 435         .getNodesRelatedAbstractNode();
 
 437     if (nodeAbstractNodeTemplateIdMap == null) {
 
 438       nodeAbstractNodeTemplateIdMap = new HashMap<>();
 
 441     if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
 
 442       throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
 
 444     nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
 
 445     this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
 
 446         nodeAbstractNodeTemplateIdMap);
 
 450    * Add the unified substitution data info in context. Contains a mapping of original node
 
 451    * template id and the new node template id in the abstract substitute
 
 453    * @param serviceTemplateFileName                   the service template file name
 
 454    * @param originalNodeTemplateId                    the original node template id
 
 455    * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
 
 458   public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
 
 459       String serviceTemplateFileName,
 
 460       String originalNodeTemplateId,
 
 461       String substitutionServiceTemplateNodeTemplateId) {
 
 463     Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
 
 464         .getUnifiedSubstitutionData()
 
 465         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
 
 466         .getNodesRelatedSubstitutionServiceTemplateNode();
 
 468     if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
 
 469       nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
 
 471     nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
 
 472         substitutionServiceTemplateNodeTemplateId);
 
 473     this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
 
 474         .setNodesRelatedSubstitutionServiceTemplateNode(
 
 475             nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
 
 479    * Get unified abstract node template which is mapped to the input node template id.
 
 481    * @param serviceTemplate the service template
 
 482    * @param nodeTemplateId  the node template id
 
 484   public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
 
 485                                                  String nodeTemplateId) {
 
 486     UnifiedSubstitutionData unifiedSubsData =
 
 487         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
 
 488     return unifiedSubsData.getNodesRelatedAbstractNode().get(nodeTemplateId);
 
 492    * Get unified node template in the substitution service template which is mapped to the
 
 493    * original input node template id.
 
 495    * @param serviceTemplate the service template
 
 496    * @param nodeTemplateId  the node template id
 
 498   public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
 
 499                                                      String nodeTemplateId) {
 
 500     UnifiedSubstitutionData unifiedSubsData =
 
 501         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
 
 502     return unifiedSubsData.getNodesRelatedSubstitutionServiceTemplateNode()
 
 503         .get(nodeTemplateId);
 
 506   public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
 
 507                                                       String computeType) {
 
 508     return this.unifiedSubstitutionData.get(serviceTemplateName)
 
 509         .getHandledNestedComputeNodeTemplateIndex(computeType);
 
 512   public void updateHandledComputeType(String serviceTemplateName,
 
 513                                        String handledComputeType,
 
 514                                        String nestedServiceTemplateFileName) {
 
 515     String globalSTName =
 
 516         ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
 
 517     this.unifiedSubstitutionData.putIfAbsent(
 
 518         globalSTName, new UnifiedSubstitutionData());
 
 519     this.unifiedSubstitutionData.get(globalSTName)
 
 520         .addHandledComputeType(handledComputeType);
 
 521     this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
 
 523     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 524     this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
 
 527   public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
 
 528                                                      String handledComputeType){
 
 529     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 530     this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
 
 533   public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
 
 534                                                        String computeType) {
 
 535     return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
 
 536         && this.unifiedSubstitutionData.get(serviceTemplateName)
 
 537         .isComputeTypeHandledInServiceTemplate(computeType);
 
 540   public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
 
 541                                                    String nestedServiceTemplateFileName) {
 
 542     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
 
 545     return this.unifiedSubstitutionData.get(serviceTemplateName)
 
 546         .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
 
 549   public Set<String> getAllRelatedNestedNodeTypeIds() {
 
 550     String globalName = "GlobalSubstitutionTypes";
 
 551     if (Objects.isNull(this.unifiedSubstitutionData)
 
 552         || Objects.isNull(this.unifiedSubstitutionData.get(globalName))) {
 
 553       return new HashSet<>();
 
 556     return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
 
 559   public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
 
 560     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
 
 561     return unifiedHandledServiceTemplates.contains(serviceTemplateFileName);
 
 566   public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
 
 567     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
 
 568     this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
 
 571   public boolean isNestedNodeWasHandled(String serviceTemplateName,
 
 572                                         String nestedNodeTemplateId) {
 
 573     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
 
 576     return this.unifiedSubstitutionData.get(serviceTemplateName)
 
 577         .isNestedNodeWasHandled(nestedNodeTemplateId);
 
 580   public void addNestedNodeAsHandled(String serviceTemplateName,
 
 581                                      String nestedNodeTemplateId) {
 
 582     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 583     this.unifiedSubstitutionData.get(serviceTemplateName)
 
 584         .addHandledNestedNodes(nestedNodeTemplateId);
 
 587   public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
 
 588                                                       String computeType) {
 
 589     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 591     this.unifiedSubstitutionData.get(serviceTemplateName)
 
 592         .updateUsedTimesForNestedComputeNodeType(computeType);
 
 595   public int getGlobalNodeTypeIndex(String serviceTemplateName,
 
 596                                     String computeType) {
 
 597     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
 
 600     return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
 
 604   public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
 
 605                                              String newPropertyId,
 
 606                                              Object origPropertyValue){
 
 607     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
 
 608     this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
 
 609         newPropertyId, origPropertyValue);
 
 612   public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
 
 613                                                      String newPropertyId){
 
 614     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
 
 615       return Optional.empty();
 
 618     return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
 
 622   public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
 
 623     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
 
 624       return new HashMap<>();
 
 627     return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
 
 631   public boolean isServiceTemplateWithoutNodeTemplatesSection(String serviceTemplateName){
 
 632     return Objects.nonNull(serviceTemplateName)
 
 633           && serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
 
 636   public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
 
 637     this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
 
 640   public void addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
 
 641     this.nodeTemplateIdsPointingToStWithoutNodeTemplates.add(nodeTemplateId);
 
 644   public boolean isNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
 
 645     return Objects.nonNull(nodeTemplateId)
 
 646         && nodeTemplateIdsPointingToStWithoutNodeTemplates.contains(nodeTemplateId);
 
 649   public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
 
 650                                                  String nodeTemplateId,
 
 651                                                  String requirementId){
 
 652     requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
 
 653     requirementIdAppearanceInNodeTemplate
 
 654         .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
 
 656     Map<String, Integer> requirementIdToAppearance =
 
 657         requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
 
 659     if(requirementIdToAppearance.containsKey(requirementId)){
 
 660       requirementIdToAppearance
 
 661           .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
 
 663       requirementIdToAppearance.put(requirementId, 0);