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.ConsolidationData;
39 import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
40 import org.openecomp.sdc.translator.services.heattotosca.Constants;
41 import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
42 import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
43 import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
45 import java.io.InputStream;
46 import java.util.HashMap;
47 import java.util.HashSet;
48 import java.util.List;
50 import java.util.Objects;
51 import java.util.Optional;
55 public class TranslationContext {
58 private static Map<String, Map<String, Map<String, String>>> translationMapping;
59 private static Map<String, ServiceTemplate> globalServiceTemplates;
60 private static Map<String, ImplementationConfiguration> nameExtractorImplMap;
61 private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
62 private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
63 private static List<String> vfcGroupSubInterfaceExposedProperties;
64 private static List<String> enrichPortResourceProperties;
65 private static ImplementationConfiguration vfcInstanceGroupConfiguration;
66 private ManifestFile manifest;
67 private FileContentHandler files = new FileContentHandler();
68 private Map<String, FileData.Type> manifestFiles = new HashMap<>();
69 //Key - file name, value - file type
70 private Set<String> nestedHeatsFiles = new HashSet<>();
71 private FileContentHandler externalArtifacts = new FileContentHandler();
72 // Key - heat file name,value - set of heat resource ids which were translated
73 private Map<String, Set<String>> translatedResources = new HashMap<>();
74 // Key - heat file name, value - translated Node template id
75 private Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
76 // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
77 private Map<String, Map<String, String>> translatedIds = new HashMap<>();
78 // key - service template type, value - translated service templates
79 private Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
80 //key - heat param name, value - shared resource data
81 private Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
82 //key - translated substitute service template file name, value - source nested heat file name
83 private Map<String, String> nestedHeatFileName = new HashMap<>();
84 //Key - heat file name,value - Map eith key - heat pseudo param name,
85 // value - translated tosca parameter name
86 private Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
87 //Consolidation data gathered for Unified TOSCA model
88 private ConsolidationData consolidationData = new ConsolidationData();
89 private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
90 private Set<String> unifiedHandledServiceTemplates = new HashSet<>();
92 private Map<String, Map<String, Map<String, Integer>>>
93 requirementIdAppearanceInNodeTemplate = new HashMap<>();
95 private Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
97 private Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
99 //Key - service template name, value - Map of key: node template id, value: properties with %index%
100 private Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
103 Configuration config = ConfigurationManager.lookup();
105 config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
107 globalServiceTemplates =
108 GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
109 } catch (Exception exc) {
110 throw new RuntimeException("Failed to load GlobalTypes", exc);
112 nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
113 ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
114 supportedConsolidationComputeResources = config.populateMap(ConfigConstants
115 .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
116 .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
117 supportedConsolidationPortResources = config.populateMap(ConfigConstants
118 .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
119 .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
120 enrichPortResourceProperties = config.getAsStringValues(ConfigConstants
121 .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
122 .ENRICH_PORT_RESOURCE_PROP);
123 vfcInstanceGroupConfiguration = getVfcInstanceGroupConfiguration(config);
124 vfcGroupSubInterfaceExposedProperties = config.getAsStringValues(ConfigConstants
125 .UNIFIED_MODEL_NAMESPACE, 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 :
134 supportedUnifiedModelProperties.get(ConfigConstants.VFC_INSTANCE_GROUP_KEY);
137 public static boolean isVfcInstanceGroupingEnabled() {
138 return Objects.nonNull(vfcInstanceGroupConfiguration) && vfcInstanceGroupConfiguration.isEnable();
141 public static List<String> getExposedVfcInstanceGroupingProperties() {
142 return vfcGroupSubInterfaceExposedProperties;
145 public static List<String> getEnrichPortResourceProperties() {
146 return enrichPortResourceProperties;
149 public static Map<String, ImplementationConfiguration>
150 getSupportedConsolidationComputeResources() {
151 return supportedConsolidationComputeResources;
154 public static void setSupportedConsolidationComputeResources(
155 Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
156 TranslationContext.supportedConsolidationComputeResources =
157 supportedConsolidationComputeResources;
160 public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
161 return supportedConsolidationPortResources;
164 public static void setSupportedConsolidationPortResources(
165 Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
166 TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
170 * Get nameExtractor implemetation class instance.
172 * @param extractorImplKey configuration key for the implementation class
173 * @return implemetation class instance
175 public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
176 String nameExtractorImplClassName =
177 nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
179 return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
182 public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
183 return unifiedSubstitutionData;
186 public void setUnifiedSubstitutionData(
187 Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
188 this.unifiedSubstitutionData = unifiedSubstitutionData;
191 public void addCleanedNodeTemplate(String serviceTemplateName,
192 String nodeTemplateId,
193 UnifiedCompositionEntity unifiedCompositionEntity,
194 NodeTemplate nodeTemplate) {
195 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
196 this.unifiedSubstitutionData
197 .get(serviceTemplateName)
198 .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
201 public Optional<List<String>> getIndexVarProperties(String serviceTemplateName,
202 String nodeTemplateId) {
203 ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties
204 .get(serviceTemplateName);
205 if (Objects.nonNull(serviceTemplateIndexVarProperties)) {
206 return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId));
208 return Optional.empty();
211 public void addIndexVarProperties(String serviceTemplateName,
212 String nodeTemplateId,
213 List<String> indexVarProperties) {
214 this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create());
215 this.indexVarProperties
216 .get(serviceTemplateName)
217 .putAll(nodeTemplateId, indexVarProperties);
220 public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName,
221 String nodeTemplateId) {
222 return this.unifiedSubstitutionData.get(serviceTemplateName)
223 .getCleanedNodeTemplate(nodeTemplateId);
226 public void addUnifiedNestedNodeTemplateId(String serviceTemplateName,
227 String nestedNodeTemplateId,
228 String unifiedNestedNodeTemplateId) {
229 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
230 this.unifiedSubstitutionData.get(serviceTemplateName)
231 .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
234 public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName,
235 String nestedNodeTemplateId) {
236 return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
237 : this.unifiedSubstitutionData.get(serviceTemplateName)
238 .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
241 public void addUnifiedNestedNodeTypeId(String serviceTemplateName,
242 String nestedNodeTypeId,
243 String unifiedNestedNodeTypeId) {
244 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
245 this.unifiedSubstitutionData.get(serviceTemplateName)
246 .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
249 public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName,
250 String nestedNodeTemplateId) {
251 return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
252 : this.unifiedSubstitutionData.get(serviceTemplateName)
253 .getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
256 public ConsolidationData getConsolidationData() {
257 return consolidationData;
260 public void setConsolidationData(ConsolidationData consolidationData) {
261 this.consolidationData = consolidationData;
264 public void addManifestFile(String fileName, FileData.Type fileType) {
265 this.manifestFiles.put(fileName, fileType);
268 public Set<String> getNestedHeatsFiles() {
269 return nestedHeatsFiles;
272 public Map<String, Set<String>> getHeatStackGroupMembers() {
273 return heatStackGroupMembers;
276 public FileContentHandler getFiles() {
280 public void setFiles(Map<String, byte[]> files) {
281 this.files.putAll(files);
284 public InputStream getFileContent(String fileName) {
285 return files.getFileContent(fileName);
288 public void addFile(String name, byte[] content) {
289 files.addFile(name, content);
292 public ManifestFile getManifest() {
296 public void setManifest(ManifestFile manifest) {
297 this.manifest = manifest;
300 public Map<String, Set<String>> getTranslatedResources() {
301 return translatedResources;
304 public Map<String, Map<String, String>> getTranslatedIds() {
305 return translatedIds;
308 public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
309 nestedHeatFileNameToSkip) {
310 Set<String> allTranslatedResourceIds = new HashSet<>();
312 this.translatedIds.entrySet().stream().filter(
313 heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
314 .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry ->
315 allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet())
318 return allTranslatedResourceIds;
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))) {
329 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
332 return translationMapping.get(resourceType).get(elementType).get(elementName);
335 public Map<String, String> getElementMapping(String resourceType, String elementType) {
336 if (Objects.isNull(translationMapping.get(resourceType))) {
339 return translationMapping.get(resourceType).get(elementType);
342 public Set<String> getElementSet(String resourceType, String elementType) {
343 if (Objects.isNull(translationMapping.get(resourceType))) {
344 return new HashSet<>();
346 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
347 return new HashSet<>();
349 return translationMapping.get(resourceType).get(elementType).keySet();
352 public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
353 return translatedServiceTemplates;
356 public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
357 return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
360 public FileContentHandler getExternalArtifacts() {
361 return externalArtifacts;
364 public void addExternalArtifacts(String name, byte[] content) {
365 this.externalArtifacts.addFile(name, content);
368 public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
369 return heatSharedResourcesByParam;
372 public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
374 this.addHeatSharedResourcesByParam(parameterName,
375 new TranslatedHeatResource(resourceId, resource));
378 private void addHeatSharedResourcesByParam(String parameterName,
379 TranslatedHeatResource translatedHeatResource) {
380 this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
383 public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
384 return globalServiceTemplates;
387 public Map<String, String> getNestedHeatFileName() {
388 return nestedHeatFileName;
391 public void addNestedHeatFileName(String substituteServiceTempalteName,
392 String nestedHeatFileName) {
393 this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
396 public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
397 return usedHeatPseudoParams;
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<>());
405 this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
408 public Set<String> getTranslatedResourceIdsFromOtherFiles(String fileNameToIgnore){
409 if(MapUtils.isEmpty(this.translatedResources)){
410 return new HashSet<>();
413 Set<String> translatedResourceIds = new HashSet<>();
415 this.translatedResources.entrySet().stream().filter(entry -> !entry.getKey().equals(fileNameToIgnore))
416 .forEach(entry -> translatedResourceIds.addAll(entry.getValue()));
418 return translatedResourceIds;
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
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
429 public void addUnifiedSubstitutionData(String serviceTemplateFileName,
430 String originalNodeTemplateId,
431 String abstractNodeTemplateId) {
433 Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
434 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
435 .getNodesRelatedAbstractNode();
437 if (nodeAbstractNodeTemplateIdMap == null) {
438 nodeAbstractNodeTemplateIdMap = new HashMap<>();
441 if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
442 throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
444 nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
445 this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
446 nodeAbstractNodeTemplateIdMap);
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
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
458 public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
459 String serviceTemplateFileName,
460 String originalNodeTemplateId,
461 String substitutionServiceTemplateNodeTemplateId) {
463 Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
464 .getUnifiedSubstitutionData()
465 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
466 .getNodesRelatedSubstitutionServiceTemplateNode();
468 if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
469 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
471 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
472 substitutionServiceTemplateNodeTemplateId);
473 this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
474 .setNodesRelatedSubstitutionServiceTemplateNode(
475 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
479 * Get unified abstract node template which is mapped to the input node template id.
481 * @param serviceTemplate the service template
482 * @param nodeTemplateId the node template id
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);
492 * Get unified node template in the substitution service template which is mapped to the
493 * original input node template id.
495 * @param serviceTemplate the service template
496 * @param nodeTemplateId the node template id
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);
506 public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
507 String computeType) {
508 return this.unifiedSubstitutionData.get(serviceTemplateName)
509 .getHandledNestedComputeNodeTemplateIndex(computeType);
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);
523 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
524 this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
527 public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
528 String handledComputeType){
529 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
530 this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
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);
540 public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
541 String nestedServiceTemplateFileName) {
542 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
545 return this.unifiedSubstitutionData.get(serviceTemplateName)
546 .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
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<>();
556 return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
559 public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
560 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
561 if (unifiedHandledServiceTemplates.contains(serviceTemplateFileName)) {
569 public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
570 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
571 this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
574 public boolean isNestedNodeWasHandled(String serviceTemplateName,
575 String nestedNodeTemplateId) {
576 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
579 return this.unifiedSubstitutionData.get(serviceTemplateName)
580 .isNestedNodeWasHandled(nestedNodeTemplateId);
583 public void addNestedNodeAsHandled(String serviceTemplateName,
584 String nestedNodeTemplateId) {
585 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
586 this.unifiedSubstitutionData.get(serviceTemplateName)
587 .addHandledNestedNodes(nestedNodeTemplateId);
590 public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
591 String computeType) {
592 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
594 this.unifiedSubstitutionData.get(serviceTemplateName)
595 .updateUsedTimesForNestedComputeNodeType(computeType);
598 public int getGlobalNodeTypeIndex(String serviceTemplateName,
599 String computeType) {
600 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
603 return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
607 public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
608 String newPropertyId,
609 Object origPropertyValue){
610 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
611 this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
612 newPropertyId, origPropertyValue);
615 public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
616 String newPropertyId){
617 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
618 return Optional.empty();
621 return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
625 public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
626 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
627 return new HashMap<>();
630 return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
634 public boolean isServiceTemplateWithoutNodeTemplatesSection(String serviceTemplateName){
635 return Objects.nonNull(serviceTemplateName)
636 && serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
639 public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
640 this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
643 public void addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
644 this.nodeTemplateIdsPointingToStWithoutNodeTemplates.add(nodeTemplateId);
647 public boolean isNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
648 return Objects.nonNull(nodeTemplateId)
649 && nodeTemplateIdsPointingToStWithoutNodeTemplates.contains(nodeTemplateId);
652 public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
653 String nodeTemplateId,
654 String requirementId){
655 requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
656 requirementIdAppearanceInNodeTemplate
657 .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
659 Map<String, Integer> requirementIdToAppearance =
660 requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
662 if(requirementIdToAppearance.containsKey(requirementId)){
663 requirementIdToAppearance
664 .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
666 requirementIdToAppearance.put(requirementId, 0);