ddbcaf72b9ebbbb2b4725c1ec34d523764a67578
[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   public static Map<String, ImplementationConfiguration>
127   getSupportedConsolidationComputeResources() {
128     return supportedConsolidationComputeResources;
129   }
130
131   public static void setSupportedConsolidationComputeResources(
132       Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
133     TranslationContext.supportedConsolidationComputeResources =
134         supportedConsolidationComputeResources;
135   }
136
137   public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
138     return supportedConsolidationPortResources;
139   }
140
141   public static void setSupportedConsolidationPortResources(
142       Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
143     TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
144   }
145
146   /**
147    * Get nameExtractor implemetation class instance.
148    *
149    * @param extractorImplKey configuration key for the implementation class
150    * @return implemetation class instance
151    */
152   public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
153     String nameExtractorImplClassName =
154         nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
155
156     return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
157   }
158
159   public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
160     return unifiedSubstitutionData;
161   }
162
163   public void setUnifiedSubstitutionData(
164       Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
165     this.unifiedSubstitutionData = unifiedSubstitutionData;
166   }
167
168   public void addCleanedNodeTemplate(String serviceTemplateName,
169                                      String nodeTemplateId,
170                                      UnifiedCompositionEntity unifiedCompositionEntity,
171                                      NodeTemplate nodeTemplate) {
172     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
173     this.unifiedSubstitutionData
174         .get(serviceTemplateName)
175         .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
176   }
177
178   public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName,
179                                              String nodeTemplateId) {
180     return this.unifiedSubstitutionData.get(serviceTemplateName)
181         .getCleanedNodeTemplate(nodeTemplateId);
182   }
183
184   public void addUnifiedNestedNodeTemplateId(String serviceTemplateName,
185                                              String nestedNodeTemplateId,
186                                              String unifiedNestedNodeTemplateId) {
187     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
188     this.unifiedSubstitutionData.get(serviceTemplateName)
189         .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
190   }
191
192   public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName,
193                                                          String nestedNodeTemplateId) {
194     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
195         : this.unifiedSubstitutionData.get(serviceTemplateName)
196             .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
197   }
198
199   public void addUnifiedNestedNodeTypeId(String serviceTemplateName,
200                                          String nestedNodeTypeId,
201                                          String unifiedNestedNodeTypeId) {
202     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
203     this.unifiedSubstitutionData.get(serviceTemplateName)
204         .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
205   }
206
207   public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName,
208                                                      String nestedNodeTemplateId) {
209     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
210         : this.unifiedSubstitutionData.get(serviceTemplateName)
211             .getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
212   }
213
214   public ConsolidationData getConsolidationData() {
215     return consolidationData;
216   }
217
218   public void setConsolidationData(ConsolidationData consolidationData) {
219     this.consolidationData = consolidationData;
220   }
221
222   public void addManifestFile(String fileName, FileData.Type fileType) {
223     this.manifestFiles.put(fileName, fileType);
224   }
225
226   public Set<String> getNestedHeatsFiles() {
227     return nestedHeatsFiles;
228   }
229
230   public Map<String, Set<String>> getHeatStackGroupMembers() {
231     return heatStackGroupMembers;
232   }
233
234   public FileContentHandler getFiles() {
235     return files;
236   }
237
238   public void setFiles(Map<String, byte[]> files) {
239     this.files.putAll(files);
240   }
241
242   public InputStream getFileContent(String fileName) {
243     return files.getFileContent(fileName);
244   }
245
246   public void addFile(String name, byte[] content) {
247     files.addFile(name, content);
248   }
249
250   public ManifestFile getManifest() {
251     return manifest;
252   }
253
254   public void setManifest(ManifestFile manifest) {
255     this.manifest = manifest;
256   }
257
258   public Map<String, Set<String>> getTranslatedResources() {
259     return translatedResources;
260   }
261
262   public Map<String, Map<String, String>> getTranslatedIds() {
263     return translatedIds;
264   }
265
266   public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
267                                                                         nestedHeatFileNameToSkip){
268     Set<String> allTranslatedResourceIds = new HashSet<>();
269
270     this.translatedIds.entrySet().stream().filter(
271         heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
272             .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry -> {
273       allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet());
274     });
275
276     return allTranslatedResourceIds;
277   }
278
279   // get tosca name from mapping configuration file
280   //element type - parameter/attribute
281   // element name - heat parameter/attribute name
282   //return value - tosca parameter/attribute name
283   public String getElementMapping(String resourceType, String elementType, String elementName) {
284     if (Objects.isNull(translationMapping.get(resourceType))) {
285       return null;
286     }
287     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
288       return null;
289     }
290     return translationMapping.get(resourceType).get(elementType).get(elementName);
291   }
292
293   public Map<String, String> getElementMapping(String resourceType, String elementType) {
294     if (Objects.isNull(translationMapping.get(resourceType))) {
295       return null;
296     }
297     return translationMapping.get(resourceType).get(elementType);
298   }
299
300   public Set<String> getElementSet(String resourceType, String elementType) {
301     if (Objects.isNull(translationMapping.get(resourceType))) {
302       return new HashSet<>();
303     }
304     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
305       return new HashSet<>();
306     }
307     return translationMapping.get(resourceType).get(elementType).keySet();
308   }
309
310   public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
311     return translatedServiceTemplates;
312   }
313
314   public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
315     return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
316   }
317
318   public FileContentHandler getExternalArtifacts() {
319     return externalArtifacts;
320   }
321
322   public void addExternalArtifacts(String name, byte[] content) {
323     this.externalArtifacts.addFile(name, content);
324   }
325
326   public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
327     return heatSharedResourcesByParam;
328   }
329
330   public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
331                                             Resource resource) {
332     this.addHeatSharedResourcesByParam(parameterName,
333         new TranslatedHeatResource(resourceId, resource));
334   }
335
336   private void addHeatSharedResourcesByParam(String parameterName,
337                                              TranslatedHeatResource translatedHeatResource) {
338     this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
339   }
340
341   public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
342     return globalServiceTemplates;
343   }
344
345   public Map<String, String> getNestedHeatFileName() {
346     return nestedHeatFileName;
347   }
348
349   public void addNestedHeatFileName(String substituteServiceTempalteName,
350                                     String nestedHeatFileName) {
351     this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
352   }
353
354   public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
355     return usedHeatPseudoParams;
356   }
357
358   public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
359       translatedToscaParam) {
360     if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
361       this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
362     }
363     this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
364   }
365
366   /**
367    * Add the unified substitution data info in context. Contains a mapping of original node
368    * template id and the new node template id in the abstract substitute
369    *
370    * @param serviceTemplateFileName the service template file name
371    * @param originalNodeTemplateId  the original node template id
372    * @param abstractNodeTemplateId  the node template id in the abstract substitute
373    */
374   public void addUnifiedSubstitutionData(String serviceTemplateFileName,
375                                          String originalNodeTemplateId,
376                                          String abstractNodeTemplateId) {
377
378     Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
379         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
380         .getNodesRelatedAbstractNode();
381
382     if (nodeAbstractNodeTemplateIdMap == null) {
383       nodeAbstractNodeTemplateIdMap = new HashMap<>();
384     }
385
386     if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
387       throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
388     }
389     nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
390     this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
391         nodeAbstractNodeTemplateIdMap);
392   }
393
394   /**
395    * Add the unified substitution data info in context. Contains a mapping of original node
396    * template id and the new node template id in the abstract substitute
397    *
398    * @param serviceTemplateFileName                   the service template file name
399    * @param originalNodeTemplateId                    the original node template id
400    * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
401    *                                                  service template
402    */
403   public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
404       String serviceTemplateFileName,
405       String originalNodeTemplateId,
406       String substitutionServiceTemplateNodeTemplateId) {
407
408     Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
409         .getUnifiedSubstitutionData()
410         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
411         .getNodesRelatedSubstitutionServiceTemplateNode();
412
413     if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
414       nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
415     }
416     nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
417         substitutionServiceTemplateNodeTemplateId);
418     this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
419         .setNodesRelatedSubstitutionServiceTemplateNode(
420             nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
421   }
422
423   /**
424    * Get unified abstract node template which is mapped to the input node template id.
425    *
426    * @param serviceTemplate the service template
427    * @param nodeTemplateId  the node template id
428    */
429   public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
430                                                  String nodeTemplateId) {
431     UnifiedSubstitutionData unifiedSubstitutionData =
432         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
433     return unifiedSubstitutionData.getNodesRelatedAbstractNode().get(nodeTemplateId);
434   }
435
436   /**
437    * Get unified node template in the substitution service template which is mapped to the
438    * original input node template id.
439    *
440    * @param serviceTemplate the service template
441    * @param nodeTemplateId  the node template id
442    */
443   public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
444                                                      String nodeTemplateId) {
445     UnifiedSubstitutionData unifiedSubstitutionData =
446         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
447     return unifiedSubstitutionData.getNodesRelatedSubstitutionServiceTemplateNode()
448         .get(nodeTemplateId);
449   }
450
451   public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
452                                                       String computeType) {
453     return this.unifiedSubstitutionData.get(serviceTemplateName)
454         .getHandledNestedComputeNodeTemplateIndex(computeType);
455   }
456
457   public void updateHandledComputeType(String serviceTemplateName,
458                                        String handledComputeType,
459                                        String nestedServiceTemplateFileName) {
460     String globalSTName =
461         ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
462     this.unifiedSubstitutionData.putIfAbsent(
463         globalSTName, new UnifiedSubstitutionData());
464     this.unifiedSubstitutionData.get(globalSTName)
465         .addHandledComputeType(handledComputeType);
466     this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
467
468     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
469     this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
470   }
471
472   public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
473                                                      String handledComputeType){
474     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
475     this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
476   }
477
478   public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
479                                                        String computeType) {
480     return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
481         && this.unifiedSubstitutionData.get(serviceTemplateName)
482         .isComputeTypeHandledInServiceTemplate(computeType);
483   }
484
485   public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
486                                                       String nestedServiceTemplateName,
487                                                       String computeType){
488     return this.unifiedSubstitutionData.get(serviceTemplateName)
489         .getHandledNestedComputeNodeTemplateIndex(computeType);
490   }
491
492   public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
493                                                    String nestedServiceTemplateFileName) {
494     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
495       return false;
496     }
497     return this.unifiedSubstitutionData.get(serviceTemplateName)
498         .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
499   }
500
501   public Set<String> getAllRelatedNestedNodeTypeIds(){
502     String globalName = "GlobalSubstitutionTypes";
503     if(Objects.isNull(this.unifiedSubstitutionData) ||
504         Objects.isNull(this.unifiedSubstitutionData.get(globalName))){
505       return new HashSet<>();
506     }
507
508     return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
509   }
510
511   public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
512     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
513     if (unifiedHandledServiceTemplates.contains(serviceTemplateFileName)) {
514       return true;
515     }
516     return false;
517   }
518
519
520
521   public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
522     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
523     this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
524   }
525
526   public boolean isNestedNodeWasHandled(String serviceTemplateName,
527                                         String nestedNodeTemplateId) {
528     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
529       return false;
530     }
531     return this.unifiedSubstitutionData.get(serviceTemplateName)
532         .isNestedNodeWasHandled(nestedNodeTemplateId);
533   }
534
535   public void addNestedNodeAsHandled(String serviceTemplateName,
536                                      String nestedNodeTemplateId) {
537     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
538     this.unifiedSubstitutionData.get(serviceTemplateName)
539         .addHandledNestedNodes(nestedNodeTemplateId);
540   }
541
542   public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
543                                                       String computeType) {
544     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
545
546     this.unifiedSubstitutionData.get(serviceTemplateName)
547         .updateUsedTimesForNestedComputeNodeType(computeType);
548   }
549
550   public int getGlobalNodeTypeIndex(String serviceTemplateName,
551                                     String computeType) {
552     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
553       return 0;
554     }
555     return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
556         (computeType);
557   }
558
559   public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
560                                              String newPropertyId,
561                                              Object origPropertyValue){
562     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
563     this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
564         newPropertyId, origPropertyValue);
565   }
566
567   public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
568                                                      String newPropertyId){
569     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
570       return Optional.empty();
571     }
572
573     return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
574         (newPropertyId);
575   }
576
577   public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
578     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
579       return new HashMap<>();
580     }
581
582     return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
583
584   }
585
586   public Set<String> getServiceTemplatesWithoutNodeTemplateSection() {
587     return serviceTemplatesWithoutNodeTemplateSection;
588   }
589
590   public void setServiceTemplatesWithoutNodeTemplateSection(
591       Set<String> serviceTemplatesWithoutNodeTemplateSection) {
592     this.serviceTemplatesWithoutNodeTemplateSection = serviceTemplatesWithoutNodeTemplateSection;
593   }
594
595   public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
596     this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
597   }
598
599   public boolean isServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
600     return !Objects.isNull(serviceTemplateName) &&
601         this.serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
602   }
603
604   public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
605                                                  String nodeTemplateId,
606                                                  String requirementId){
607     requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
608     requirementIdAppearanceInNodeTemplate
609         .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
610
611     Map<String, Integer> requirementIdToAppearance =
612         requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
613
614     if(requirementIdToAppearance.containsKey(requirementId)){
615       requirementIdToAppearance
616           .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
617     } else {
618       requirementIdToAppearance.put(requirementId, 0);
619     }
620   }
621
622 }