2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.translator.datatypes.heattotosca;
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.*;
39 import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
40 import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType;
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;
46 import java.io.InputStream;
47 import java.util.HashMap;
48 import java.util.HashSet;
49 import java.util.List;
51 import java.util.Objects;
52 import java.util.Optional;
56 public class TranslationContext {
58 private ManifestFile manifest;
61 private static final Map<String, Map<String, Map<String, String>>> translationMapping;
62 private static final Map<String, ServiceTemplate> globalServiceTemplates;
63 private static final Map<String, ImplementationConfiguration> nameExtractorImplMap;
64 private static final List<String> vfcGroupSubInterfaceExposedProperties;
65 private static final List<String> enrichPortResourceProperties;
66 private static final ImplementationConfiguration vfcInstanceGroupConfiguration;
68 private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
69 private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
71 private final FileContentHandler files = new FileContentHandler();
72 private final Map<String, FileData.Type> manifestFiles = new HashMap<>();
73 //Key - file name, value - file type
74 private final Set<String> nestedHeatsFiles = new HashSet<>();
75 private final FileContentHandler externalArtifacts = new FileContentHandler();
76 // Key - heat file name,value - set of heat resource ids which were translated
77 private final Map<String, Set<String>> translatedResources = new HashMap<>();
78 // Key - heat file name, value - translated Node template id
79 private final Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
80 // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
81 private final Map<String, Map<String, String>> translatedIds = new HashMap<>();
82 // key - service template type, value - translated service templates
83 private final Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
84 //key - heat param name, value - shared resource data
85 private final Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
86 //key - translated substitute service template file name, value - source nested heat file name
87 private final Map<String, String> nestedHeatFileName = new HashMap<>();
88 //Key - heat file name,value - Map eith key - heat pseudo param name,
89 // value - translated tosca parameter name
90 private final Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
91 //Consolidation data gathered for Unified TOSCA model
92 private ConsolidationData consolidationData = new ConsolidationData();
93 private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
94 private final Set<String> unifiedHandledServiceTemplates = new HashSet<>();
96 private final Map<String, Map<String, Map<String, Integer>>> requirementIdAppearanceInNodeTemplate = new HashMap<>();
98 private final Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
100 private final Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
102 //Key - service template name, value - Map of key: node template id, value: properties with %index%
103 private final Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
106 Configuration config = ConfigurationManager.lookup();
108 config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
110 globalServiceTemplates =
111 GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
112 } catch (Exception exc) {
113 throw new RuntimeException("Failed to load GlobalTypes", exc);
115 nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
116 ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
117 supportedConsolidationComputeResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
118 ConfigConstants.SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
119 supportedConsolidationPortResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
120 ConfigConstants.SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
121 enrichPortResourceProperties = config.getAsStringValues(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
122 ConfigConstants.ENRICH_PORT_RESOURCE_PROP);
123 vfcInstanceGroupConfiguration = getVfcInstanceGroupConfiguration(config);
124 vfcGroupSubInterfaceExposedProperties = config.getAsStringValues(ConfigConstants.UNIFIED_MODEL_NAMESPACE,
125 ConfigConstants.FULL_EXPOSED_PROPERTIES_KEY);
129 private static ImplementationConfiguration getVfcInstanceGroupConfiguration(Configuration config) {
130 Map<String, ImplementationConfiguration> supportedUnifiedModelProperties =
131 config.populateMap(ConfigConstants.UNIFIED_MODEL_NAMESPACE, ConfigConstants.UNIFIED_MODEL_IMPL_KEY,
132 ImplementationConfiguration.class);
133 return MapUtils.isEmpty(supportedUnifiedModelProperties) ? null : supportedUnifiedModelProperties.get(ConfigConstants.VFC_INSTANCE_GROUP_KEY);
136 public static boolean isVfcInstanceGroupingEnabled() {
137 return Objects.nonNull(vfcInstanceGroupConfiguration) && vfcInstanceGroupConfiguration.isEnable();
140 public static List<String> getExposedVfcInstanceGroupingProperties() {
141 return vfcGroupSubInterfaceExposedProperties;
144 public static List<String> getEnrichPortResourceProperties() {
145 return enrichPortResourceProperties;
148 public static Map<String, ImplementationConfiguration> getSupportedConsolidationComputeResources() {
149 return supportedConsolidationComputeResources;
152 public static void setSupportedConsolidationComputeResources(Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
153 TranslationContext.supportedConsolidationComputeResources = supportedConsolidationComputeResources;
156 public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
157 return supportedConsolidationPortResources;
160 public static void setSupportedConsolidationPortResources(Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
161 TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
165 * Get nameExtractor implemetation class instance.
167 * @param extractorImplKey configuration key for the implementation class
168 * @return implemetation class instance
170 public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
171 String nameExtractorImplClassName = nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
173 return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
176 public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
177 return unifiedSubstitutionData;
180 public void setUnifiedSubstitutionData(Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
181 this.unifiedSubstitutionData = unifiedSubstitutionData;
184 public void addCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId, UnifiedCompositionEntity unifiedCompositionEntity,
185 NodeTemplate nodeTemplate) {
186 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
187 this.unifiedSubstitutionData.get(serviceTemplateName)
188 .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
191 public Optional<List<String>> getIndexVarProperties(String serviceTemplateName, String nodeTemplateId) {
192 ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties.get(serviceTemplateName);
193 if (Objects.nonNull(serviceTemplateIndexVarProperties)) {
194 return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId));
196 return Optional.empty();
199 public void addIndexVarProperties(String serviceTemplateName, String nodeTemplateId, List<String> indexVarProperties) {
200 this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create());
201 this.indexVarProperties.get(serviceTemplateName).putAll(nodeTemplateId, indexVarProperties);
204 public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId) {
205 return this.unifiedSubstitutionData.get(serviceTemplateName).getCleanedNodeTemplate(nodeTemplateId);
208 public void addUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId, String unifiedNestedNodeTemplateId) {
209 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
210 this.unifiedSubstitutionData.get(serviceTemplateName)
211 .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
214 public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId) {
215 return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() :
216 this.unifiedSubstitutionData.get(serviceTemplateName).getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
219 public void addUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTypeId, String unifiedNestedNodeTypeId) {
220 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
221 this.unifiedSubstitutionData.get(serviceTemplateName)
222 .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
225 public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTemplateId) {
226 return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() :
227 this.unifiedSubstitutionData.get(serviceTemplateName).getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
230 public ConsolidationData getConsolidationData() {
231 return consolidationData;
234 public void setConsolidationData(ConsolidationData consolidationData) {
235 this.consolidationData = consolidationData;
238 public Optional<ConsolidationDataHandler> getConsolidationDataHandler(ConsolidationEntityType type) {
239 return consolidationData.getConsolidationDataHandler(type);
242 public ComputeConsolidationDataHandler getComputeConsolidationDataHandler() {
243 return consolidationData.getComputeConsolidationDataHandler();
246 public PortConsolidationDataHandler getPortConsolidationDataHandler() {
247 return consolidationData.getPortConsolidationDataHandler();
250 public NestedConsolidationDataHandler getNestedConsolidationDataHandler() {
251 return consolidationData.getNestedConsolidationDataHandler();
254 public SubInterfaceConsolidationDataHandler getSubInterfaceComputeConsolidationDataHandler() {
255 return consolidationData.getSubInterfaceConsolidationDataHandler();
258 public void addManifestFile(String fileName, FileData.Type fileType) {
259 this.manifestFiles.put(fileName, fileType);
262 public Set<String> getNestedHeatsFiles() {
263 return nestedHeatsFiles;
266 public Map<String, Set<String>> getHeatStackGroupMembers() {
267 return heatStackGroupMembers;
270 public FileContentHandler getFiles() {
274 public void setFiles(Map<String, byte[]> files) {
275 this.files.putAll(files);
278 public InputStream getFileContent(String fileName) {
279 return files.getFileContent(fileName);
282 public void addFile(String name, byte[] content) {
283 files.addFile(name, content);
286 public ManifestFile getManifest() {
290 public void setManifest(ManifestFile manifest) {
291 this.manifest = manifest;
294 public Map<String, Set<String>> getTranslatedResources() {
295 return translatedResources;
298 public Map<String, Map<String, String>> getTranslatedIds() {
299 return translatedIds;
302 public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
303 nestedHeatFileNameToSkip) {
304 Set<String> allTranslatedResourceIds = new HashSet<>();
306 this.translatedIds.entrySet().stream().filter(
307 heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
308 .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry ->
309 allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet())
312 return allTranslatedResourceIds;
315 // get tosca name from mapping configuration file
316 //element type - parameter/attribute
317 // element name - heat parameter/attribute name
318 //return value - tosca parameter/attribute name
319 public String getElementMapping(String resourceType, String elementType, String elementName) {
320 if (Objects.isNull(translationMapping.get(resourceType))) {
323 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
326 return translationMapping.get(resourceType).get(elementType).get(elementName);
329 public Map<String, String> getElementMapping(String resourceType, String elementType) {
330 if (Objects.isNull(translationMapping.get(resourceType))) {
333 return translationMapping.get(resourceType).get(elementType);
336 public Set<String> getElementSet(String resourceType, String elementType) {
337 if (Objects.isNull(translationMapping.get(resourceType))) {
338 return new HashSet<>();
340 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
341 return new HashSet<>();
343 return translationMapping.get(resourceType).get(elementType).keySet();
346 public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
347 return translatedServiceTemplates;
350 public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
351 return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
354 public FileContentHandler getExternalArtifacts() {
355 return externalArtifacts;
358 public void addExternalArtifacts(String name, byte[] content) {
359 this.externalArtifacts.addFile(name, content);
362 public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
363 return heatSharedResourcesByParam;
366 public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
368 this.addHeatSharedResourcesByParam(parameterName,
369 new TranslatedHeatResource(resourceId, resource));
372 private void addHeatSharedResourcesByParam(String parameterName,
373 TranslatedHeatResource translatedHeatResource) {
374 this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
377 public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
378 return globalServiceTemplates;
381 public Map<String, String> getNestedHeatFileName() {
382 return nestedHeatFileName;
385 public void addNestedHeatFileName(String substituteServiceTempalteName,
386 String nestedHeatFileName) {
387 this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
390 public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
391 return usedHeatPseudoParams;
394 public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
395 translatedToscaParam) {
396 if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
397 this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
399 this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
402 public Set<String> getTranslatedResourceIdsFromOtherFiles(String fileNameToIgnore){
403 if(MapUtils.isEmpty(this.translatedResources)){
404 return new HashSet<>();
407 Set<String> translatedResourceIds = new HashSet<>();
409 this.translatedResources.entrySet().stream().filter(entry -> !entry.getKey().equals(fileNameToIgnore))
410 .forEach(entry -> translatedResourceIds.addAll(entry.getValue()));
412 return translatedResourceIds;
416 * Add the unified substitution data info in context. Contains a mapping of original node
417 * template id and the new node template id in the abstract substitute
419 * @param serviceTemplateFileName the service template file name
420 * @param originalNodeTemplateId the original node template id
421 * @param abstractNodeTemplateId the node template id in the abstract substitute
423 public void addUnifiedSubstitutionData(String serviceTemplateFileName,
424 String originalNodeTemplateId,
425 String abstractNodeTemplateId) {
427 Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
428 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
429 .getNodesRelatedAbstractNode();
431 if (nodeAbstractNodeTemplateIdMap == null) {
432 nodeAbstractNodeTemplateIdMap = new HashMap<>();
435 if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
436 throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
438 nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
439 this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
440 nodeAbstractNodeTemplateIdMap);
444 * Add the unified substitution data info in context. Contains a mapping of original node
445 * template id and the new node template id in the abstract substitute
447 * @param serviceTemplateFileName the service template file name
448 * @param originalNodeTemplateId the original node template id
449 * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
452 public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
453 String serviceTemplateFileName,
454 String originalNodeTemplateId,
455 String substitutionServiceTemplateNodeTemplateId) {
457 Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
458 .getUnifiedSubstitutionData()
459 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
460 .getNodesRelatedSubstitutionServiceTemplateNode();
462 if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
463 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
465 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
466 substitutionServiceTemplateNodeTemplateId);
467 this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
468 .setNodesRelatedSubstitutionServiceTemplateNode(
469 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
473 * Get unified abstract node template which is mapped to the input node template id.
475 * @param serviceTemplate the service template
476 * @param nodeTemplateId the node template id
478 public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
479 String nodeTemplateId) {
480 UnifiedSubstitutionData unifiedSubsData =
481 this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
482 return unifiedSubsData.getNodesRelatedAbstractNode().get(nodeTemplateId);
486 * Get unified node template in the substitution service template which is mapped to the
487 * original input node template id.
489 * @param serviceTemplate the service template
490 * @param nodeTemplateId the node template id
492 public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
493 String nodeTemplateId) {
494 UnifiedSubstitutionData unifiedSubsData =
495 this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
496 return unifiedSubsData.getNodesRelatedSubstitutionServiceTemplateNode()
497 .get(nodeTemplateId);
500 public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
501 String computeType) {
502 return this.unifiedSubstitutionData.get(serviceTemplateName)
503 .getHandledNestedComputeNodeTemplateIndex(computeType);
506 public void updateHandledComputeType(String serviceTemplateName,
507 String handledComputeType,
508 String nestedServiceTemplateFileName) {
509 String globalSTName =
510 ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
511 this.unifiedSubstitutionData.putIfAbsent(
512 globalSTName, new UnifiedSubstitutionData());
513 this.unifiedSubstitutionData.get(globalSTName)
514 .addHandledComputeType(handledComputeType);
515 this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
517 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
518 this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
521 public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
522 String handledComputeType){
523 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
524 this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
527 public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
528 String computeType) {
529 return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
530 && this.unifiedSubstitutionData.get(serviceTemplateName)
531 .isComputeTypeHandledInServiceTemplate(computeType);
534 public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
535 String nestedServiceTemplateFileName) {
536 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
539 return this.unifiedSubstitutionData.get(serviceTemplateName)
540 .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
543 public Set<String> getAllRelatedNestedNodeTypeIds() {
544 String globalName = "GlobalSubstitutionTypes";
545 if (Objects.isNull(this.unifiedSubstitutionData)
546 || Objects.isNull(this.unifiedSubstitutionData.get(globalName))) {
547 return new HashSet<>();
550 return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
553 public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
554 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
555 return unifiedHandledServiceTemplates.contains(serviceTemplateFileName)? true:false;
560 public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
561 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
562 this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
565 public boolean isNestedNodeWasHandled(String serviceTemplateName,
566 String nestedNodeTemplateId) {
567 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
570 return this.unifiedSubstitutionData.get(serviceTemplateName)
571 .isNestedNodeWasHandled(nestedNodeTemplateId);
574 public void addNestedNodeAsHandled(String serviceTemplateName,
575 String nestedNodeTemplateId) {
576 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
577 this.unifiedSubstitutionData.get(serviceTemplateName)
578 .addHandledNestedNodes(nestedNodeTemplateId);
581 public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
582 String computeType) {
583 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
585 this.unifiedSubstitutionData.get(serviceTemplateName)
586 .updateUsedTimesForNestedComputeNodeType(computeType);
589 public int getGlobalNodeTypeIndex(String serviceTemplateName,
590 String computeType) {
591 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
594 return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
598 public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
599 String newPropertyId,
600 Object origPropertyValue){
601 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
602 this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
603 newPropertyId, origPropertyValue);
606 public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
607 String newPropertyId){
608 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
609 return Optional.empty();
612 return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
616 public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
617 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
618 return new HashMap<>();
621 return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
625 public boolean isServiceTemplateWithoutNodeTemplatesSection(String serviceTemplateName){
626 return Objects.nonNull(serviceTemplateName)
627 && serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
630 public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
631 this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
634 public void addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
635 this.nodeTemplateIdsPointingToStWithoutNodeTemplates.add(nodeTemplateId);
638 public boolean isNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
639 return Objects.nonNull(nodeTemplateId)
640 && nodeTemplateIdsPointingToStWithoutNodeTemplates.contains(nodeTemplateId);
643 public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
644 String nodeTemplateId,
645 String requirementId){
646 requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
647 requirementIdAppearanceInNodeTemplate
648 .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
650 Map<String, Integer> requirementIdToAppearance =
651 requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
653 if(requirementIdToAppearance.containsKey(requirementId)){
654 requirementIdToAppearance
655 .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
657 requirementIdToAppearance.put(requirementId, 0);