6f77f226257d201e0a78a5c2d604948fc316e0ca
[sdc.git] /
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.translator.datatypes.heattotosca;
18
19 import org.apache.commons.collections.MapUtils;
20 import org.openecomp.config.api.Configuration;
21 import org.openecomp.config.api.ConfigurationManager;
22 import org.openecomp.core.utilities.CommonMethods;
23 import org.openecomp.core.utilities.file.FileContentHandler;
24 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
25 import org.openecomp.sdc.common.errors.CoreException;
26 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
27 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
28 import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile;
29 import org.openecomp.sdc.heat.datatypes.model.Resource;
30 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
31 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
32 import org.openecomp.sdc.tosca.services.ToscaUtil;
33 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
34 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity;
35 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedSubstitutionData;
36 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
37 import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
38 import org.openecomp.sdc.translator.services.heattotosca.Constants;
39 import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
40 import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
41 import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
42
43 import java.io.InputStream;
44 import java.util.HashMap;
45 import java.util.HashSet;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.Objects;
49 import java.util.Optional;
50 import java.util.Set;
51
52
53 public class TranslationContext {
54
55
56   private static Map<String, Map<String, Map<String, String>>> translationMapping;
57   private static Map<String, ServiceTemplate> globalServiceTemplates;
58   private static Map<String, ImplementationConfiguration> nameExtractorImplMap;
59   private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
60   private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
61   private static List<String> enrichPortResourceProperties;
62   private ManifestFile manifest;
63   private FileContentHandler files = new FileContentHandler();
64   private Map<String, FileData.Type> manifestFiles = new HashMap<>();
65   //Key - file name, value - file type
66   private Set<String> nestedHeatsFiles = new HashSet<>();
67   private FileContentHandler externalArtifacts = new FileContentHandler();
68   // Key - heat file name,value - set of heat resource ids which were translated
69   private Map<String, Set<String>> translatedResources = new HashMap<>();
70   // Key - heat file name, value - translated Node template id
71   private Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
72   // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
73   private Map<String, Map<String, String>> translatedIds = new HashMap<>();
74   // key - service template type, value - translated service templates
75   private Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
76   //key - heat param name, value - shared resource data
77   private Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
78   //key - translated substitute service template file name, value - source nested heat file name
79   private Map<String, String> nestedHeatFileName = new HashMap<>();
80   //Key - heat file name,value - Map eith key - heat pseudo param name,
81   // value - translated tosca parameter name
82   private Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
83   //Consolidation data gathered for Unified TOSCA model
84   private ConsolidationData consolidationData = new ConsolidationData();
85   private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
86   private Set<String> unifiedHandledServiceTemplates = new HashSet<>();
87
88   private Map<String, Map<String, Map<String, Integer>>>
89       requirementIdAppearanceInNodeTemplate = new HashMap<>();
90
91   private Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
92
93   private Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
94
95   static {
96     Configuration config = ConfigurationManager.lookup();
97     translationMapping =
98             config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
99     try {
100       globalServiceTemplates =
101               GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
102     } catch (Exception exc) {
103       throw new RuntimeException("Failed to load GlobalTypes", exc);
104     }
105     nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
106             ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
107     supportedConsolidationComputeResources = config.populateMap(ConfigConstants
108             .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
109             .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
110     supportedConsolidationPortResources = config.populateMap(ConfigConstants
111             .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
112             .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
113     enrichPortResourceProperties = config.getAsStringValues(ConfigConstants
114             .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
115             .ENRICH_PORT_RESOURCE_PROP);
116   }
117
118   public static List<String> getEnrichPortResourceProperties() {
119     return enrichPortResourceProperties;
120   }
121
122   public static Map<String, ImplementationConfiguration>
123   getSupportedConsolidationComputeResources() {
124     return supportedConsolidationComputeResources;
125   }
126
127   public static void setSupportedConsolidationComputeResources(
128       Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
129     TranslationContext.supportedConsolidationComputeResources =
130         supportedConsolidationComputeResources;
131   }
132
133   public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
134     return supportedConsolidationPortResources;
135   }
136
137   public static void setSupportedConsolidationPortResources(
138       Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
139     TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
140   }
141
142   /**
143    * Get nameExtractor implemetation class instance.
144    *
145    * @param extractorImplKey configuration key for the implementation class
146    * @return implemetation class instance
147    */
148   public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
149     String nameExtractorImplClassName =
150         nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
151
152     return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
153   }
154
155   public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
156     return unifiedSubstitutionData;
157   }
158
159   public void setUnifiedSubstitutionData(
160       Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
161     this.unifiedSubstitutionData = unifiedSubstitutionData;
162   }
163
164   public void addCleanedNodeTemplate(String serviceTemplateName,
165                                      String nodeTemplateId,
166                                      UnifiedCompositionEntity unifiedCompositionEntity,
167                                      NodeTemplate nodeTemplate) {
168     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
169     this.unifiedSubstitutionData
170         .get(serviceTemplateName)
171         .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
172   }
173
174   public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName,
175                                              String nodeTemplateId) {
176     return this.unifiedSubstitutionData.get(serviceTemplateName)
177         .getCleanedNodeTemplate(nodeTemplateId);
178   }
179
180   public void addUnifiedNestedNodeTemplateId(String serviceTemplateName,
181                                              String nestedNodeTemplateId,
182                                              String unifiedNestedNodeTemplateId) {
183     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
184     this.unifiedSubstitutionData.get(serviceTemplateName)
185         .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
186   }
187
188   public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName,
189                                                          String nestedNodeTemplateId) {
190     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
191         : this.unifiedSubstitutionData.get(serviceTemplateName)
192             .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
193   }
194
195   public void addUnifiedNestedNodeTypeId(String serviceTemplateName,
196                                          String nestedNodeTypeId,
197                                          String unifiedNestedNodeTypeId) {
198     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
199     this.unifiedSubstitutionData.get(serviceTemplateName)
200         .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
201   }
202
203   public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName,
204                                                      String nestedNodeTemplateId) {
205     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
206         : this.unifiedSubstitutionData.get(serviceTemplateName)
207             .getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
208   }
209
210   public ConsolidationData getConsolidationData() {
211     return consolidationData;
212   }
213
214   public void setConsolidationData(ConsolidationData consolidationData) {
215     this.consolidationData = consolidationData;
216   }
217
218   public void addManifestFile(String fileName, FileData.Type fileType) {
219     this.manifestFiles.put(fileName, fileType);
220   }
221
222   public Set<String> getNestedHeatsFiles() {
223     return nestedHeatsFiles;
224   }
225
226   public Map<String, Set<String>> getHeatStackGroupMembers() {
227     return heatStackGroupMembers;
228   }
229
230   public FileContentHandler getFiles() {
231     return files;
232   }
233
234   public void setFiles(Map<String, byte[]> files) {
235     this.files.putAll(files);
236   }
237
238   public InputStream getFileContent(String fileName) {
239     return files.getFileContent(fileName);
240   }
241
242   public void addFile(String name, byte[] content) {
243     files.addFile(name, content);
244   }
245
246   public ManifestFile getManifest() {
247     return manifest;
248   }
249
250   public void setManifest(ManifestFile manifest) {
251     this.manifest = manifest;
252   }
253
254   public Map<String, Set<String>> getTranslatedResources() {
255     return translatedResources;
256   }
257
258   public Map<String, Map<String, String>> getTranslatedIds() {
259     return translatedIds;
260   }
261
262   public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
263                                                                         nestedHeatFileNameToSkip) {
264     Set<String> allTranslatedResourceIds = new HashSet<>();
265
266     this.translatedIds.entrySet().stream().filter(
267         heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
268             .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry ->
269       allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet())
270     );
271
272     return allTranslatedResourceIds;
273   }
274
275   // get tosca name from mapping configuration file
276   //element type - parameter/attribute
277   // element name - heat parameter/attribute name
278   //return value - tosca parameter/attribute name
279   public String getElementMapping(String resourceType, String elementType, String elementName) {
280     if (Objects.isNull(translationMapping.get(resourceType))) {
281       return null;
282     }
283     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
284       return null;
285     }
286     return translationMapping.get(resourceType).get(elementType).get(elementName);
287   }
288
289   public Map<String, String> getElementMapping(String resourceType, String elementType) {
290     if (Objects.isNull(translationMapping.get(resourceType))) {
291       return null;
292     }
293     return translationMapping.get(resourceType).get(elementType);
294   }
295
296   public Set<String> getElementSet(String resourceType, String elementType) {
297     if (Objects.isNull(translationMapping.get(resourceType))) {
298       return new HashSet<>();
299     }
300     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
301       return new HashSet<>();
302     }
303     return translationMapping.get(resourceType).get(elementType).keySet();
304   }
305
306   public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
307     return translatedServiceTemplates;
308   }
309
310   public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
311     return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
312   }
313
314   public FileContentHandler getExternalArtifacts() {
315     return externalArtifacts;
316   }
317
318   public void addExternalArtifacts(String name, byte[] content) {
319     this.externalArtifacts.addFile(name, content);
320   }
321
322   public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
323     return heatSharedResourcesByParam;
324   }
325
326   public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
327                                             Resource resource) {
328     this.addHeatSharedResourcesByParam(parameterName,
329         new TranslatedHeatResource(resourceId, resource));
330   }
331
332   private void addHeatSharedResourcesByParam(String parameterName,
333                                              TranslatedHeatResource translatedHeatResource) {
334     this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
335   }
336
337   public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
338     return globalServiceTemplates;
339   }
340
341   public Map<String, String> getNestedHeatFileName() {
342     return nestedHeatFileName;
343   }
344
345   public void addNestedHeatFileName(String substituteServiceTempalteName,
346                                     String nestedHeatFileName) {
347     this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
348   }
349
350   public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
351     return usedHeatPseudoParams;
352   }
353
354   public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
355       translatedToscaParam) {
356     if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
357       this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
358     }
359     this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
360   }
361
362   public Set<String> getTranslatedResourceIdsFromOtherFiles(String fileNameToIgnore){
363     if(MapUtils.isEmpty(this.translatedResources)){
364       return new HashSet<>();
365     }
366
367     Set<String> translatedResourceIds = new HashSet<>();
368
369     this.translatedResources.entrySet().stream().filter(entry -> !entry.getKey().equals(fileNameToIgnore))
370         .forEach(entry -> translatedResourceIds.addAll(entry.getValue()));
371
372     return translatedResourceIds;
373   }
374
375   /**
376    * Add the unified substitution data info in context. Contains a mapping of original node
377    * template id and the new node template id in the abstract substitute
378    *
379    * @param serviceTemplateFileName the service template file name
380    * @param originalNodeTemplateId  the original node template id
381    * @param abstractNodeTemplateId  the node template id in the abstract substitute
382    */
383   public void addUnifiedSubstitutionData(String serviceTemplateFileName,
384                                          String originalNodeTemplateId,
385                                          String abstractNodeTemplateId) {
386
387     Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
388         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
389         .getNodesRelatedAbstractNode();
390
391     if (nodeAbstractNodeTemplateIdMap == null) {
392       nodeAbstractNodeTemplateIdMap = new HashMap<>();
393     }
394
395     if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
396       throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
397     }
398     nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
399     this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
400         nodeAbstractNodeTemplateIdMap);
401   }
402
403   /**
404    * Add the unified substitution data info in context. Contains a mapping of original node
405    * template id and the new node template id in the abstract substitute
406    *
407    * @param serviceTemplateFileName                   the service template file name
408    * @param originalNodeTemplateId                    the original node template id
409    * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
410    *                                                  service template
411    */
412   public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
413       String serviceTemplateFileName,
414       String originalNodeTemplateId,
415       String substitutionServiceTemplateNodeTemplateId) {
416
417     Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
418         .getUnifiedSubstitutionData()
419         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
420         .getNodesRelatedSubstitutionServiceTemplateNode();
421
422     if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
423       nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
424     }
425     nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
426         substitutionServiceTemplateNodeTemplateId);
427     this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
428         .setNodesRelatedSubstitutionServiceTemplateNode(
429             nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
430   }
431
432   /**
433    * Get unified abstract node template which is mapped to the input node template id.
434    *
435    * @param serviceTemplate the service template
436    * @param nodeTemplateId  the node template id
437    */
438   public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
439                                                  String nodeTemplateId) {
440     UnifiedSubstitutionData unifiedSubsData =
441         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
442     return unifiedSubsData.getNodesRelatedAbstractNode().get(nodeTemplateId);
443   }
444
445   /**
446    * Get unified node template in the substitution service template which is mapped to the
447    * original input node template id.
448    *
449    * @param serviceTemplate the service template
450    * @param nodeTemplateId  the node template id
451    */
452   public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
453                                                      String nodeTemplateId) {
454     UnifiedSubstitutionData unifiedSubsData =
455         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
456     return unifiedSubsData.getNodesRelatedSubstitutionServiceTemplateNode()
457         .get(nodeTemplateId);
458   }
459
460   public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
461                                                       String computeType) {
462     return this.unifiedSubstitutionData.get(serviceTemplateName)
463         .getHandledNestedComputeNodeTemplateIndex(computeType);
464   }
465
466   public void updateHandledComputeType(String serviceTemplateName,
467                                        String handledComputeType,
468                                        String nestedServiceTemplateFileName) {
469     String globalSTName =
470         ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
471     this.unifiedSubstitutionData.putIfAbsent(
472         globalSTName, new UnifiedSubstitutionData());
473     this.unifiedSubstitutionData.get(globalSTName)
474         .addHandledComputeType(handledComputeType);
475     this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
476
477     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
478     this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
479   }
480
481   public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
482                                                      String handledComputeType){
483     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
484     this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
485   }
486
487   public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
488                                                        String computeType) {
489     return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
490         && this.unifiedSubstitutionData.get(serviceTemplateName)
491         .isComputeTypeHandledInServiceTemplate(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 }