7d3ebb9c7c3d47978eca0b037068c688225f374e
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.translator.datatypes.heattotosca;
22
23 import org.openecomp.config.api.Configuration;
24 import org.openecomp.config.api.ConfigurationManager;
25 import org.openecomp.core.utilities.CommonMethods;
26 import org.openecomp.core.utilities.file.FileContentHandler;
27 import org.openecomp.sdc.common.errors.CoreException;
28 import org.openecomp.sdc.common.utils.SdcCommon;
29 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
30 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
31 import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile;
32 import org.openecomp.sdc.heat.datatypes.model.Resource;
33 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
34 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
35 import org.openecomp.sdc.tosca.services.ToscaUtil;
36 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
37 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity;
38 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedSubstitutionData;
39 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
40 import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
41 import org.openecomp.sdc.translator.services.heattotosca.Constants;
42 import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
43 import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
44 import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
45
46 import java.io.InputStream;
47 import java.util.HashMap;
48 import java.util.HashSet;
49 import java.util.List;
50 import java.util.Map;
51 import java.util.Objects;
52 import java.util.Optional;
53 import java.util.Set;
54
55
56 public class TranslationContext {
57
58
59   private static Map<String, Map<String, Map<String, String>>> translationMapping;
60   private static Map<String, ServiceTemplate> globalServiceTemplates;
61   private static Map<String, ImplementationConfiguration> nameExtractorImplMap;
62   private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
63   private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
64   private static List enrichPortResourceProperties;
65
66   static {
67     Configuration config = ConfigurationManager.lookup();
68     String propertyFileName = SdcCommon.HEAT_TO_TOSCA_MAPPING_CONF;
69     translationMapping =
70         config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
71     try {
72       globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate();
73     } catch (Exception exc) {
74       throw new RuntimeException("Failed to load GlobalTypes", exc);
75     }
76     nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
77         ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
78     supportedConsolidationComputeResources = config.populateMap(ConfigConstants
79         .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
80         .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
81     supportedConsolidationPortResources = config.populateMap(ConfigConstants
82         .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
83         .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
84     enrichPortResourceProperties = config.getAsStringValues(ConfigConstants
85         .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
86         .ENRICH_PORT_RESOURCE_PROP);
87
88   }
89
90   private ManifestFile manifest;
91
92   public static List getEnrichPortResourceProperties() {
93     return enrichPortResourceProperties;
94   }
95
96   private FileContentHandler files = new FileContentHandler();
97   private Map<String, FileData.Type> manifestFiles = new HashMap<>();
98   //Key - file name, value - file type
99   private Set<String> nestedHeatsFiles = new HashSet<>();
100   private FileContentHandler externalArtifacts = new FileContentHandler();
101   // Key - heat file name,value - set of heat resource ids which were translated
102   private Map<String, Set<String>> translatedResources = new HashMap<>();
103   // Key - heat file name, value - translated Node template id
104   private Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
105   // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
106   private Map<String, Map<String, String>> translatedIds = new HashMap<>();
107   // key - service template type, value - translated service templates
108   private Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
109   //key - heat param name, value - shared resource data
110   private Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
111   //key - translated substitute service template file name, value - source nested heat file name
112   private Map<String, String> nestedHeatFileName = new HashMap<>();
113   //Key - heat file name,value - Map eith key - heat pseudo param name,
114   // value - translated tosca parameter name
115   private Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
116   //Consolidation data gathered for Unified TOSCA model
117   private ConsolidationData consolidationData = new ConsolidationData();
118   private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
119   private Set<String> unifiedHandledServiceTemplates = new HashSet<>();
120
121   private Map<String, Map<String, Map<String, Integer>>>
122       requirementIdAppearanceInNodeTemplate = new HashMap<>();
123
124   private Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
125
126   private Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
127
128   public static Map<String, ImplementationConfiguration>
129   getSupportedConsolidationComputeResources() {
130     return supportedConsolidationComputeResources;
131   }
132
133   public static void setSupportedConsolidationComputeResources(
134       Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
135     TranslationContext.supportedConsolidationComputeResources =
136         supportedConsolidationComputeResources;
137   }
138
139   public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
140     return supportedConsolidationPortResources;
141   }
142
143   public static void setSupportedConsolidationPortResources(
144       Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
145     TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
146   }
147
148   /**
149    * Get nameExtractor implemetation class instance.
150    *
151    * @param extractorImplKey configuration key for the implementation class
152    * @return implemetation class instance
153    */
154   public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
155     String nameExtractorImplClassName =
156         nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
157
158     return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
159   }
160
161   public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
162     return unifiedSubstitutionData;
163   }
164
165   public void setUnifiedSubstitutionData(
166       Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
167     this.unifiedSubstitutionData = unifiedSubstitutionData;
168   }
169
170   public void addCleanedNodeTemplate(String serviceTemplateName,
171                                      String nodeTemplateId,
172                                      UnifiedCompositionEntity unifiedCompositionEntity,
173                                      NodeTemplate nodeTemplate) {
174     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
175     this.unifiedSubstitutionData
176         .get(serviceTemplateName)
177         .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
178   }
179
180   public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName,
181                                              String nodeTemplateId) {
182     return this.unifiedSubstitutionData.get(serviceTemplateName)
183         .getCleanedNodeTemplate(nodeTemplateId);
184   }
185
186   public void addUnifiedNestedNodeTemplateId(String serviceTemplateName,
187                                              String nestedNodeTemplateId,
188                                              String unifiedNestedNodeTemplateId) {
189     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
190     this.unifiedSubstitutionData.get(serviceTemplateName)
191         .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
192   }
193
194   public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName,
195                                                          String nestedNodeTemplateId) {
196     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
197         : this.unifiedSubstitutionData.get(serviceTemplateName)
198             .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
199   }
200
201   public void addUnifiedNestedNodeTypeId(String serviceTemplateName,
202                                          String nestedNodeTypeId,
203                                          String unifiedNestedNodeTypeId) {
204     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
205     this.unifiedSubstitutionData.get(serviceTemplateName)
206         .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
207   }
208
209   public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName,
210                                                      String nestedNodeTemplateId) {
211     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
212         : this.unifiedSubstitutionData.get(serviceTemplateName)
213             .getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
214   }
215
216   public ConsolidationData getConsolidationData() {
217     return consolidationData;
218   }
219
220   public void setConsolidationData(ConsolidationData consolidationData) {
221     this.consolidationData = consolidationData;
222   }
223
224   public void addManifestFile(String fileName, FileData.Type fileType) {
225     this.manifestFiles.put(fileName, fileType);
226   }
227
228   public Set<String> getNestedHeatsFiles() {
229     return nestedHeatsFiles;
230   }
231
232   public Map<String, Set<String>> getHeatStackGroupMembers() {
233     return heatStackGroupMembers;
234   }
235
236   public FileContentHandler getFiles() {
237     return files;
238   }
239
240   public void setFiles(Map<String, byte[]> files) {
241     this.files.putAll(files);
242   }
243
244   public InputStream getFileContent(String fileName) {
245     return files.getFileContent(fileName);
246   }
247
248   public void addFile(String name, byte[] content) {
249     files.addFile(name, content);
250   }
251
252   public ManifestFile getManifest() {
253     return manifest;
254   }
255
256   public void setManifest(ManifestFile manifest) {
257     this.manifest = manifest;
258   }
259
260   public Map<String, Set<String>> getTranslatedResources() {
261     return translatedResources;
262   }
263
264   public Map<String, Map<String, String>> getTranslatedIds() {
265     return translatedIds;
266   }
267
268   public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
269                                                                         nestedHeatFileNameToSkip){
270     Set<String> allTranslatedResourceIds = new HashSet<>();
271
272     this.translatedIds.entrySet().stream().filter(
273         heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
274             .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry -> {
275       allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet());
276     });
277
278     return allTranslatedResourceIds;
279   }
280
281   // get tosca name from mapping configuration file
282   //element type - parameter/attribute
283   // element name - heat parameter/attribute name
284   //return value - tosca parameter/attribute name
285   public String getElementMapping(String resourceType, String elementType, String elementName) {
286     if (Objects.isNull(translationMapping.get(resourceType))) {
287       return null;
288     }
289     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
290       return null;
291     }
292     return translationMapping.get(resourceType).get(elementType).get(elementName);
293   }
294
295   public Map<String, String> getElementMapping(String resourceType, String elementType) {
296     if (Objects.isNull(translationMapping.get(resourceType))) {
297       return null;
298     }
299     return translationMapping.get(resourceType).get(elementType);
300   }
301
302   public Set<String> getElementSet(String resourceType, String elementType) {
303     if (Objects.isNull(translationMapping.get(resourceType))) {
304       return new HashSet<>();
305     }
306     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
307       return new HashSet<>();
308     }
309     return translationMapping.get(resourceType).get(elementType).keySet();
310   }
311
312   public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
313     return translatedServiceTemplates;
314   }
315
316   public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
317     return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
318   }
319
320   public FileContentHandler getExternalArtifacts() {
321     return externalArtifacts;
322   }
323
324   public void addExternalArtifacts(String name, byte[] content) {
325     this.externalArtifacts.addFile(name, content);
326   }
327
328   public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
329     return heatSharedResourcesByParam;
330   }
331
332   public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
333                                             Resource resource) {
334     this.addHeatSharedResourcesByParam(parameterName,
335         new TranslatedHeatResource(resourceId, resource));
336   }
337
338   private void addHeatSharedResourcesByParam(String parameterName,
339                                              TranslatedHeatResource translatedHeatResource) {
340     this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
341   }
342
343   public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
344     return globalServiceTemplates;
345   }
346
347   public Map<String, String> getNestedHeatFileName() {
348     return nestedHeatFileName;
349   }
350
351   public void addNestedHeatFileName(String substituteServiceTempalteName,
352                                     String nestedHeatFileName) {
353     this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
354   }
355
356   public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
357     return usedHeatPseudoParams;
358   }
359
360   public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
361       translatedToscaParam) {
362     if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
363       this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
364     }
365     this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
366   }
367
368   /**
369    * Add the unified substitution data info in context. Contains a mapping of original node
370    * template id and the new node template id in the abstract substitute
371    *
372    * @param serviceTemplateFileName the service template file name
373    * @param originalNodeTemplateId  the original node template id
374    * @param abstractNodeTemplateId  the node template id in the abstract substitute
375    */
376   public void addUnifiedSubstitutionData(String serviceTemplateFileName,
377                                          String originalNodeTemplateId,
378                                          String abstractNodeTemplateId) {
379
380     Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
381         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
382         .getNodesRelatedAbstractNode();
383
384     if (nodeAbstractNodeTemplateIdMap == null) {
385       nodeAbstractNodeTemplateIdMap = new HashMap<>();
386     }
387
388     if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
389       throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
390     }
391     nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
392     this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
393         nodeAbstractNodeTemplateIdMap);
394   }
395
396   /**
397    * Add the unified substitution data info in context. Contains a mapping of original node
398    * template id and the new node template id in the abstract substitute
399    *
400    * @param serviceTemplateFileName                   the service template file name
401    * @param originalNodeTemplateId                    the original node template id
402    * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
403    *                                                  service template
404    */
405   public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
406       String serviceTemplateFileName,
407       String originalNodeTemplateId,
408       String substitutionServiceTemplateNodeTemplateId) {
409
410     Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
411         .getUnifiedSubstitutionData()
412         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
413         .getNodesRelatedSubstitutionServiceTemplateNode();
414
415     if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
416       nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
417     }
418     nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
419         substitutionServiceTemplateNodeTemplateId);
420     this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
421         .setNodesRelatedSubstitutionServiceTemplateNode(
422             nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
423   }
424
425   /**
426    * Get unified abstract node template which is mapped to the input node template id.
427    *
428    * @param serviceTemplate the service template
429    * @param nodeTemplateId  the node template id
430    */
431   public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
432                                                  String nodeTemplateId) {
433     UnifiedSubstitutionData unifiedSubstitutionData =
434         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
435     return unifiedSubstitutionData.getNodesRelatedAbstractNode().get(nodeTemplateId);
436   }
437
438   /**
439    * Get unified node template in the substitution service template which is mapped to the
440    * original input node template id.
441    *
442    * @param serviceTemplate the service template
443    * @param nodeTemplateId  the node template id
444    */
445   public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
446                                                      String nodeTemplateId) {
447     UnifiedSubstitutionData unifiedSubstitutionData =
448         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
449     return unifiedSubstitutionData.getNodesRelatedSubstitutionServiceTemplateNode()
450         .get(nodeTemplateId);
451   }
452
453   public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
454                                                       String computeType) {
455     return this.unifiedSubstitutionData.get(serviceTemplateName)
456         .getHandledNestedComputeNodeTemplateIndex(computeType);
457   }
458
459   public void updateHandledComputeType(String serviceTemplateName,
460                                        String handledComputeType,
461                                        String nestedServiceTemplateFileName) {
462     String globalSTName =
463         ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
464     this.unifiedSubstitutionData.putIfAbsent(
465         globalSTName, new UnifiedSubstitutionData());
466     this.unifiedSubstitutionData.get(globalSTName)
467         .addHandledComputeType(handledComputeType);
468     this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
469
470     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
471     this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
472   }
473
474   public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
475                                                      String handledComputeType){
476     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
477     this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
478   }
479
480   public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
481                                                        String computeType) {
482     return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
483         && this.unifiedSubstitutionData.get(serviceTemplateName)
484         .isComputeTypeHandledInServiceTemplate(computeType);
485   }
486
487   public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
488                                                       String nestedServiceTemplateName,
489                                                       String computeType){
490     return this.unifiedSubstitutionData.get(serviceTemplateName)
491         .getHandledNestedComputeNodeTemplateIndex(computeType);
492   }
493
494   public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
495                                                    String nestedServiceTemplateFileName) {
496     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
497       return false;
498     }
499     return this.unifiedSubstitutionData.get(serviceTemplateName)
500         .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
501   }
502
503   public Set<String> getAllRelatedNestedNodeTypeIds(){
504     String globalName = "GlobalSubstitutionTypes";
505     if(Objects.isNull(this.unifiedSubstitutionData) ||
506         Objects.isNull(this.unifiedSubstitutionData.get(globalName))){
507       return new HashSet<>();
508     }
509
510     return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
511   }
512
513   public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
514     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
515     if (unifiedHandledServiceTemplates.contains(serviceTemplateFileName)) {
516       return true;
517     }
518     return false;
519   }
520
521
522
523   public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
524     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
525     this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
526   }
527
528   public boolean isNestedNodeWasHandled(String serviceTemplateName,
529                                         String nestedNodeTemplateId) {
530     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
531       return false;
532     }
533     return this.unifiedSubstitutionData.get(serviceTemplateName)
534         .isNestedNodeWasHandled(nestedNodeTemplateId);
535   }
536
537   public void addNestedNodeAsHandled(String serviceTemplateName,
538                                      String nestedNodeTemplateId) {
539     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
540     this.unifiedSubstitutionData.get(serviceTemplateName)
541         .addHandledNestedNodes(nestedNodeTemplateId);
542   }
543
544   public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
545                                                       String computeType) {
546     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
547
548     this.unifiedSubstitutionData.get(serviceTemplateName)
549         .updateUsedTimesForNestedComputeNodeType(computeType);
550   }
551
552   public int getGlobalNodeTypeIndex(String serviceTemplateName,
553                                     String computeType) {
554     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
555       return 0;
556     }
557     return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
558         (computeType);
559   }
560
561   public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
562                                              String newPropertyId,
563                                              Object origPropertyValue){
564     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
565     this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
566         newPropertyId, origPropertyValue);
567   }
568
569   public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
570                                                      String newPropertyId){
571     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
572       return Optional.empty();
573     }
574
575     return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
576         (newPropertyId);
577   }
578
579   public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
580     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
581       return new HashMap<>();
582     }
583
584     return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
585
586   }
587
588   public boolean isServiceTemplateWithoutNodeTemplatesSection(String serviceTemplateName){
589     return Objects.nonNull(serviceTemplateName)
590           && serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
591   }
592
593   public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
594     this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
595   }
596
597   public void addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
598     this.nodeTemplateIdsPointingToStWithoutNodeTemplates.add(nodeTemplateId);
599   }
600
601   public boolean isNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
602     return Objects.nonNull(nodeTemplateId)
603         && nodeTemplateIdsPointingToStWithoutNodeTemplates.contains(nodeTemplateId);
604   }
605
606   public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
607                                                  String nodeTemplateId,
608                                                  String requirementId){
609     requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
610     requirementIdAppearanceInNodeTemplate
611         .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
612
613     Map<String, Integer> requirementIdToAppearance =
614         requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
615
616     if(requirementIdToAppearance.containsKey(requirementId)){
617       requirementIdToAppearance
618           .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
619     } else {
620       requirementIdToAppearance.put(requirementId, 0);
621     }
622   }
623
624 }