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