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;
21 import com.google.common.collect.ArrayListMultimap;
22 import com.google.common.collect.ListMultimap;
23 import org.apache.commons.collections.MapUtils;
25 import org.onap.config.api.Configuration;
26 import org.onap.config.api.ConfigurationManager;
27 import org.openecomp.core.utilities.CommonMethods;
28 import org.openecomp.core.utilities.file.FileContentHandler;
29 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
30 import org.openecomp.sdc.common.errors.CoreException;
31 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
32 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
33 import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile;
34 import org.openecomp.sdc.heat.datatypes.model.Resource;
35 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
36 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
37 import org.openecomp.sdc.tosca.services.ToscaUtil;
38 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
39 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity;
40 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedSubstitutionData;
41 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeConsolidationDataHandler;
42 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
43 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationDataHandler;
44 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortConsolidationDataHandler;
45 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedConsolidationDataHandler;
46 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceConsolidationDataHandler;
47 import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
48 import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType;
49 import org.openecomp.sdc.translator.services.heattotosca.Constants;
50 import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
51 import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
52 import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
54 import java.io.InputStream;
55 import java.util.HashMap;
56 import java.util.HashSet;
57 import java.util.List;
59 import java.util.Objects;
60 import java.util.Optional;
63 public class TranslationContext {
65 private ManifestFile manifest;
68 private static final Map<String, Map<String, Map<String, String>>> translationMapping;
69 private static final Map<String, ServiceTemplate> globalServiceTemplates;
70 private static final Map<String, ImplementationConfiguration> nameExtractorImplMap;
71 private static final List<String> vfcGroupSubInterfaceExposedProperties;
72 private static final List<String> enrichPortResourceProperties;
73 private static final ImplementationConfiguration vfcInstanceGroupConfiguration;
75 private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
76 private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
78 private final FileContentHandler files = new FileContentHandler();
79 private final Map<String, FileData.Type> manifestFiles = new HashMap<>();
80 //Key - file name, value - file type
81 private final Set<String> nestedHeatsFiles = new HashSet<>();
82 private final FileContentHandler externalArtifacts = new FileContentHandler();
83 // Key - heat file name,value - set of heat resource ids which were translated
84 private final Map<String, Set<String>> translatedResources = new HashMap<>();
85 // Key - heat file name, value - translated Node template id
86 private final Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
87 // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
88 private final Map<String, Map<String, String>> translatedIds = new HashMap<>();
89 // key - service template type, value - translated service templates
90 private final Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
91 //key - heat param name, value - shared resource data
92 private final Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
93 //key - translated substitute service template file name, value - source nested heat file name
94 private final Map<String, String> nestedHeatFileName = new HashMap<>();
95 //Key - heat file name,value - Map eith key - heat pseudo param name,
96 // value - translated tosca parameter name
97 private final Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
98 //Consolidation data gathered for Unified TOSCA model
99 private ConsolidationData consolidationData = new ConsolidationData();
100 private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
101 private final Set<String> unifiedHandledServiceTemplates = new HashSet<>();
103 private final Map<String, Map<String, Map<String, Integer>>> requirementIdAppearanceInNodeTemplate = new HashMap<>();
105 private final Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
107 private final Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
109 //Key - service template name, value - Map of key: node template id, value: properties with %index%
110 private final Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
113 Configuration config = ConfigurationManager.lookup();
115 config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
117 globalServiceTemplates =
118 GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
119 } catch (Exception exc) {
120 throw new RuntimeException("Failed to load GlobalTypes", exc);
122 nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
123 ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
124 supportedConsolidationComputeResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
125 ConfigConstants.SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
126 supportedConsolidationPortResources = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
127 ConfigConstants.SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
128 enrichPortResourceProperties = config.getAsStringValues(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE,
129 ConfigConstants.ENRICH_PORT_RESOURCE_PROP);
130 vfcInstanceGroupConfiguration = getVfcInstanceGroupConfiguration(config);
131 vfcGroupSubInterfaceExposedProperties = config.getAsStringValues(ConfigConstants.UNIFIED_MODEL_NAMESPACE,
132 ConfigConstants.FULL_EXPOSED_PROPERTIES_KEY);
136 private static ImplementationConfiguration getVfcInstanceGroupConfiguration(Configuration config) {
137 Map<String, ImplementationConfiguration> supportedUnifiedModelProperties =
138 config.populateMap(ConfigConstants.UNIFIED_MODEL_NAMESPACE, ConfigConstants.UNIFIED_MODEL_IMPL_KEY,
139 ImplementationConfiguration.class);
140 return MapUtils.isEmpty(supportedUnifiedModelProperties) ? null : supportedUnifiedModelProperties.get(ConfigConstants.VFC_INSTANCE_GROUP_KEY);
143 public static boolean isVfcInstanceGroupingEnabled() {
144 return Objects.nonNull(vfcInstanceGroupConfiguration) && vfcInstanceGroupConfiguration.isEnable();
147 public static List<String> getExposedVfcInstanceGroupingProperties() {
148 return vfcGroupSubInterfaceExposedProperties;
151 public static List<String> getEnrichPortResourceProperties() {
152 return enrichPortResourceProperties;
155 public static Map<String, ImplementationConfiguration> getSupportedConsolidationComputeResources() {
156 return supportedConsolidationComputeResources;
159 public static void setSupportedConsolidationComputeResources(Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
160 TranslationContext.supportedConsolidationComputeResources = supportedConsolidationComputeResources;
163 public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
164 return supportedConsolidationPortResources;
167 public static void setSupportedConsolidationPortResources(Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
168 TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
172 * Get nameExtractor implemetation class instance.
174 * @param extractorImplKey configuration key for the implementation class
175 * @return implemetation class instance
177 public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
178 String nameExtractorImplClassName = nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
180 return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
183 public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
184 return unifiedSubstitutionData;
187 public void setUnifiedSubstitutionData(Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
188 this.unifiedSubstitutionData = unifiedSubstitutionData;
191 public void addCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId, UnifiedCompositionEntity unifiedCompositionEntity,
192 NodeTemplate nodeTemplate) {
193 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
194 this.unifiedSubstitutionData.get(serviceTemplateName)
195 .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
198 public Optional<List<String>> getIndexVarProperties(String serviceTemplateName, String nodeTemplateId) {
199 ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties.get(serviceTemplateName);
200 if (Objects.nonNull(serviceTemplateIndexVarProperties)) {
201 return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId));
203 return Optional.empty();
206 public void addIndexVarProperties(String serviceTemplateName, String nodeTemplateId, List<String> indexVarProperties) {
207 this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create());
208 this.indexVarProperties.get(serviceTemplateName).putAll(nodeTemplateId, indexVarProperties);
211 public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId) {
212 return this.unifiedSubstitutionData.get(serviceTemplateName).getCleanedNodeTemplate(nodeTemplateId);
215 public void addUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId, String unifiedNestedNodeTemplateId) {
216 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
217 this.unifiedSubstitutionData.get(serviceTemplateName)
218 .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
221 public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId) {
222 return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() :
223 this.unifiedSubstitutionData.get(serviceTemplateName).getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
226 public void addUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTypeId, String unifiedNestedNodeTypeId) {
227 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
228 this.unifiedSubstitutionData.get(serviceTemplateName)
229 .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
232 public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTemplateId) {
233 UnifiedSubstitutionData substitutionData = this.unifiedSubstitutionData.get(serviceTemplateName);
234 return substitutionData == null ? Optional.empty() :
235 substitutionData.getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
238 public ConsolidationData getConsolidationData() {
239 return consolidationData;
242 public void setConsolidationData(ConsolidationData consolidationData) {
243 this.consolidationData = consolidationData;
246 public Optional<ConsolidationDataHandler> getConsolidationDataHandler(ConsolidationEntityType type) {
247 return consolidationData.getConsolidationDataHandler(type);
250 public ComputeConsolidationDataHandler getComputeConsolidationDataHandler() {
251 return consolidationData.getComputeConsolidationDataHandler();
254 public PortConsolidationDataHandler getPortConsolidationDataHandler() {
255 return consolidationData.getPortConsolidationDataHandler();
258 public NestedConsolidationDataHandler getNestedConsolidationDataHandler() {
259 return consolidationData.getNestedConsolidationDataHandler();
262 public SubInterfaceConsolidationDataHandler getSubInterfaceConsolidationDataHandler() {
263 return consolidationData.getSubInterfaceConsolidationDataHandler();
266 public void addManifestFile(String fileName, FileData.Type fileType) {
267 this.manifestFiles.put(fileName, fileType);
270 public Set<String> getNestedHeatsFiles() {
271 return nestedHeatsFiles;
274 public Map<String, Set<String>> getHeatStackGroupMembers() {
275 return heatStackGroupMembers;
278 public FileContentHandler getFiles() {
282 public void setFiles(Map<String, byte[]> files) {
283 this.files.putAll(files);
286 public InputStream getFileContent(String fileName) {
287 return files.getFileContent(fileName);
290 public void addFile(String name, byte[] content) {
291 files.addFile(name, content);
294 public ManifestFile getManifest() {
298 public void setManifest(ManifestFile manifest) {
299 this.manifest = manifest;
302 public Map<String, Set<String>> getTranslatedResources() {
303 return translatedResources;
306 public Map<String, Map<String, String>> getTranslatedIds() {
307 return translatedIds;
310 public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
311 nestedHeatFileNameToSkip) {
312 Set<String> allTranslatedResourceIds = new HashSet<>();
314 this.translatedIds.entrySet().stream().filter(
315 heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
316 .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry ->
317 allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet())
320 return allTranslatedResourceIds;
323 // get tosca name from mapping configuration file
324 //element type - parameter/attribute
325 // element name - heat parameter/attribute name
326 //return value - tosca parameter/attribute name
327 public String getElementMapping(String resourceType, String elementType, String elementName) {
328 if (Objects.isNull(translationMapping.get(resourceType))) {
331 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
334 return translationMapping.get(resourceType).get(elementType).get(elementName);
337 public Map<String, String> getElementMapping(String resourceType, String elementType) {
338 if (Objects.isNull(translationMapping.get(resourceType))) {
341 return translationMapping.get(resourceType).get(elementType);
344 public Set<String> getElementSet(String resourceType, String elementType) {
345 if (Objects.isNull(translationMapping.get(resourceType))) {
346 return new HashSet<>();
348 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
349 return new HashSet<>();
351 return translationMapping.get(resourceType).get(elementType).keySet();
354 public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
355 return translatedServiceTemplates;
358 public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
359 return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
362 public FileContentHandler getExternalArtifacts() {
363 return externalArtifacts;
366 public void addExternalArtifacts(String name, byte[] content) {
367 this.externalArtifacts.addFile(name, content);
370 public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
371 return heatSharedResourcesByParam;
374 public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
376 this.addHeatSharedResourcesByParam(parameterName,
377 new TranslatedHeatResource(resourceId, resource));
380 private void addHeatSharedResourcesByParam(String parameterName,
381 TranslatedHeatResource translatedHeatResource) {
382 this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
385 public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
386 return globalServiceTemplates;
389 public Map<String, String> getNestedHeatFileName() {
390 return nestedHeatFileName;
393 public void addNestedHeatFileName(String substituteServiceTempalteName,
394 String nestedHeatFileName) {
395 this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
398 public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
399 return usedHeatPseudoParams;
402 public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
403 translatedToscaParam) {
404 if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
405 this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
407 this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
410 public Set<String> getTranslatedResourceIdsFromOtherFiles(String fileNameToIgnore){
411 if(MapUtils.isEmpty(this.translatedResources)){
412 return new HashSet<>();
415 Set<String> translatedResourceIds = new HashSet<>();
417 this.translatedResources.entrySet().stream().filter(entry -> !entry.getKey().equals(fileNameToIgnore))
418 .forEach(entry -> translatedResourceIds.addAll(entry.getValue()));
420 return translatedResourceIds;
424 * Add the unified substitution data info in context. Contains a mapping of original node
425 * template id and the new node template id in the abstract substitute
427 * @param serviceTemplateFileName the service template file name
428 * @param originalNodeTemplateId the original node template id
429 * @param abstractNodeTemplateId the node template id in the abstract substitute
431 public void addUnifiedSubstitutionData(String serviceTemplateFileName,
432 String originalNodeTemplateId,
433 String abstractNodeTemplateId) {
435 Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
436 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
437 .getNodesRelatedAbstractNode();
439 if (nodeAbstractNodeTemplateIdMap == null) {
440 nodeAbstractNodeTemplateIdMap = new HashMap<>();
443 if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
444 throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
446 nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
447 this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
448 nodeAbstractNodeTemplateIdMap);
452 * Add the unified substitution data info in context. Contains a mapping of original node
453 * template id and the new node template id in the abstract substitute
455 * @param serviceTemplateFileName the service template file name
456 * @param originalNodeTemplateId the original node template id
457 * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
460 public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
461 String serviceTemplateFileName,
462 String originalNodeTemplateId,
463 String substitutionServiceTemplateNodeTemplateId) {
465 Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
466 .getUnifiedSubstitutionData()
467 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
468 .getNodesRelatedSubstitutionServiceTemplateNode();
470 if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
471 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
473 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
474 substitutionServiceTemplateNodeTemplateId);
475 this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
476 .setNodesRelatedSubstitutionServiceTemplateNode(
477 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
481 * Get unified abstract node template which is mapped to the input node template id.
483 * @param serviceTemplate the service template
484 * @param nodeTemplateId the node template id
486 public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
487 String nodeTemplateId) {
488 UnifiedSubstitutionData unifiedSubsData =
489 this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
490 return unifiedSubsData.getNodesRelatedAbstractNode().get(nodeTemplateId);
494 * Get unified node template in the substitution service template which is mapped to the
495 * original input node template id.
497 * @param serviceTemplate the service template
498 * @param nodeTemplateId the node template id
500 public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
501 String nodeTemplateId) {
502 UnifiedSubstitutionData unifiedSubsData =
503 this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
504 return unifiedSubsData.getNodesRelatedSubstitutionServiceTemplateNode()
505 .get(nodeTemplateId);
508 public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
509 String computeType) {
510 return this.unifiedSubstitutionData.get(serviceTemplateName)
511 .getHandledNestedComputeNodeTemplateIndex(computeType);
514 public void updateHandledComputeType(String serviceTemplateName,
515 String handledComputeType,
516 String nestedServiceTemplateFileName) {
517 String globalSTName =
518 ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
519 this.unifiedSubstitutionData.putIfAbsent(
520 globalSTName, new UnifiedSubstitutionData());
521 this.unifiedSubstitutionData.get(globalSTName)
522 .addHandledComputeType(handledComputeType);
523 this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
525 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
526 this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
529 public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
530 String handledComputeType){
531 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
532 this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
535 public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
536 String computeType) {
537 return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
538 && this.unifiedSubstitutionData.get(serviceTemplateName)
539 .isComputeTypeHandledInServiceTemplate(computeType);
542 public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
543 String nestedServiceTemplateFileName) {
544 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
547 return this.unifiedSubstitutionData.get(serviceTemplateName)
548 .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
551 public Set<String> getAllRelatedNestedNodeTypeIds() {
552 String globalName = "GlobalSubstitutionTypes";
553 if (Objects.isNull(this.unifiedSubstitutionData)
554 || Objects.isNull(this.unifiedSubstitutionData.get(globalName))) {
555 return new HashSet<>();
558 return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
561 public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
562 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
563 return unifiedHandledServiceTemplates.contains(serviceTemplateFileName);
568 public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
569 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
570 this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
573 public boolean isNestedNodeWasHandled(String serviceTemplateName,
574 String nestedNodeTemplateId) {
575 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
578 return this.unifiedSubstitutionData.get(serviceTemplateName)
579 .isNestedNodeWasHandled(nestedNodeTemplateId);
582 public void addNestedNodeAsHandled(String serviceTemplateName,
583 String nestedNodeTemplateId) {
584 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
585 this.unifiedSubstitutionData.get(serviceTemplateName)
586 .addHandledNestedNodes(nestedNodeTemplateId);
589 public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
590 String computeType) {
591 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
593 this.unifiedSubstitutionData.get(serviceTemplateName)
594 .updateUsedTimesForNestedComputeNodeType(computeType);
597 public int getGlobalNodeTypeIndex(String serviceTemplateName,
598 String computeType) {
599 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
602 return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
606 public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
607 String newPropertyId,
608 Object origPropertyValue){
609 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
610 this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
611 newPropertyId, origPropertyValue);
614 public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
615 String newPropertyId){
616 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
617 return Optional.empty();
620 return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
624 public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
625 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
626 return new HashMap<>();
629 return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
633 public boolean isServiceTemplateWithoutNodeTemplatesSection(String serviceTemplateName){
634 return Objects.nonNull(serviceTemplateName)
635 && serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
638 public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
639 this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
642 public void addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
643 this.nodeTemplateIdsPointingToStWithoutNodeTemplates.add(nodeTemplateId);
646 public boolean isNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
647 return Objects.nonNull(nodeTemplateId)
648 && nodeTemplateIdsPointingToStWithoutNodeTemplates.contains(nodeTemplateId);
651 public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
652 String nodeTemplateId,
653 String requirementId){
654 requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
655 requirementIdAppearanceInNodeTemplate
656 .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
658 Map<String, Integer> requirementIdToAppearance =
659 requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
661 if(requirementIdToAppearance.containsKey(requirementId)){
662 requirementIdToAppearance
663 .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
665 requirementIdToAppearance.put(requirementId, 0);