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