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.openecomp.config.api.Configuration;
23 import org.openecomp.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.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
33 import org.openecomp.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> enrichPortResourceProperties;
64 private ManifestFile manifest;
65 private FileContentHandler files = new FileContentHandler();
66 private Map<String, FileData.Type> manifestFiles = new HashMap<>();
67 //Key - file name, value - file type
68 private Set<String> nestedHeatsFiles = new HashSet<>();
69 private FileContentHandler externalArtifacts = new FileContentHandler();
70 // Key - heat file name,value - set of heat resource ids which were translated
71 private Map<String, Set<String>> translatedResources = new HashMap<>();
72 // Key - heat file name, value - translated Node template id
73 private Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
74 // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
75 private Map<String, Map<String, String>> translatedIds = new HashMap<>();
76 // key - service template type, value - translated service templates
77 private Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
78 //key - heat param name, value - shared resource data
79 private Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
80 //key - translated substitute service template file name, value - source nested heat file name
81 private Map<String, String> nestedHeatFileName = new HashMap<>();
82 //Key - heat file name,value - Map eith key - heat pseudo param name,
83 // value - translated tosca parameter name
84 private Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
85 //Consolidation data gathered for Unified TOSCA model
86 private ConsolidationData consolidationData = new ConsolidationData();
87 private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
88 private Set<String> unifiedHandledServiceTemplates = new HashSet<>();
90 private Map<String, Map<String, Map<String, Integer>>>
91 requirementIdAppearanceInNodeTemplate = new HashMap<>();
93 private Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
95 private Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
97 //Key - service template name, value - Map of key: node template id, value: proerties with %index%
98 private Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
101 Configuration config = ConfigurationManager.lookup();
103 config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
105 globalServiceTemplates =
106 GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
107 } catch (Exception exc) {
108 throw new RuntimeException("Failed to load GlobalTypes", exc);
110 nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
111 ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
112 supportedConsolidationComputeResources = config.populateMap(ConfigConstants
113 .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
114 .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
115 supportedConsolidationPortResources = config.populateMap(ConfigConstants
116 .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
117 .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
118 enrichPortResourceProperties = config.getAsStringValues(ConfigConstants
119 .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
120 .ENRICH_PORT_RESOURCE_PROP);
123 public static List<String> getEnrichPortResourceProperties() {
124 return enrichPortResourceProperties;
127 public static Map<String, ImplementationConfiguration>
128 getSupportedConsolidationComputeResources() {
129 return supportedConsolidationComputeResources;
132 public static void setSupportedConsolidationComputeResources(
133 Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
134 TranslationContext.supportedConsolidationComputeResources =
135 supportedConsolidationComputeResources;
138 public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
139 return supportedConsolidationPortResources;
142 public static void setSupportedConsolidationPortResources(
143 Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
144 TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
148 * Get nameExtractor implemetation class instance.
150 * @param extractorImplKey configuration key for the implementation class
151 * @return implemetation class instance
153 public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
154 String nameExtractorImplClassName =
155 nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
157 return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
160 public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
161 return unifiedSubstitutionData;
164 public void setUnifiedSubstitutionData(
165 Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
166 this.unifiedSubstitutionData = unifiedSubstitutionData;
169 public void addCleanedNodeTemplate(String serviceTemplateName,
170 String nodeTemplateId,
171 UnifiedCompositionEntity unifiedCompositionEntity,
172 NodeTemplate nodeTemplate) {
173 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
174 this.unifiedSubstitutionData
175 .get(serviceTemplateName)
176 .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
179 public Optional<List<String>> getIndexVarProperties(String serviceTemplateName,
180 String nodeTemplateId) {
181 ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties
182 .get(serviceTemplateName);
183 if (Objects.nonNull(serviceTemplateIndexVarProperties)) {
184 return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId));
186 return Optional.empty();
189 public void addIndexVarProperties(String serviceTemplateName,
190 String nodeTemplateId,
191 List<String> indexVarProperties) {
192 this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create());
193 this.indexVarProperties
194 .get(serviceTemplateName)
195 .putAll(nodeTemplateId, indexVarProperties);
198 public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName,
199 String nodeTemplateId) {
200 return this.unifiedSubstitutionData.get(serviceTemplateName)
201 .getCleanedNodeTemplate(nodeTemplateId);
204 public void addUnifiedNestedNodeTemplateId(String serviceTemplateName,
205 String nestedNodeTemplateId,
206 String unifiedNestedNodeTemplateId) {
207 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
208 this.unifiedSubstitutionData.get(serviceTemplateName)
209 .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
212 public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName,
213 String nestedNodeTemplateId) {
214 return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
215 : this.unifiedSubstitutionData.get(serviceTemplateName)
216 .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
219 public void addUnifiedNestedNodeTypeId(String serviceTemplateName,
220 String nestedNodeTypeId,
221 String unifiedNestedNodeTypeId) {
222 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
223 this.unifiedSubstitutionData.get(serviceTemplateName)
224 .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
227 public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName,
228 String nestedNodeTemplateId) {
229 return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
230 : this.unifiedSubstitutionData.get(serviceTemplateName)
231 .getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
234 public ConsolidationData getConsolidationData() {
235 return consolidationData;
238 public void setConsolidationData(ConsolidationData consolidationData) {
239 this.consolidationData = consolidationData;
242 public void addManifestFile(String fileName, FileData.Type fileType) {
243 this.manifestFiles.put(fileName, fileType);
246 public Set<String> getNestedHeatsFiles() {
247 return nestedHeatsFiles;
250 public Map<String, Set<String>> getHeatStackGroupMembers() {
251 return heatStackGroupMembers;
254 public FileContentHandler getFiles() {
258 public void setFiles(Map<String, byte[]> files) {
259 this.files.putAll(files);
262 public InputStream getFileContent(String fileName) {
263 return files.getFileContent(fileName);
266 public void addFile(String name, byte[] content) {
267 files.addFile(name, content);
270 public ManifestFile getManifest() {
274 public void setManifest(ManifestFile manifest) {
275 this.manifest = manifest;
278 public Map<String, Set<String>> getTranslatedResources() {
279 return translatedResources;
282 public Map<String, Map<String, String>> getTranslatedIds() {
283 return translatedIds;
286 public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
287 nestedHeatFileNameToSkip) {
288 Set<String> allTranslatedResourceIds = new HashSet<>();
290 this.translatedIds.entrySet().stream().filter(
291 heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
292 .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry ->
293 allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet())
296 return allTranslatedResourceIds;
299 // get tosca name from mapping configuration file
300 //element type - parameter/attribute
301 // element name - heat parameter/attribute name
302 //return value - tosca parameter/attribute name
303 public String getElementMapping(String resourceType, String elementType, String elementName) {
304 if (Objects.isNull(translationMapping.get(resourceType))) {
307 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
310 return translationMapping.get(resourceType).get(elementType).get(elementName);
313 public Map<String, String> getElementMapping(String resourceType, String elementType) {
314 if (Objects.isNull(translationMapping.get(resourceType))) {
317 return translationMapping.get(resourceType).get(elementType);
320 public Set<String> getElementSet(String resourceType, String elementType) {
321 if (Objects.isNull(translationMapping.get(resourceType))) {
322 return new HashSet<>();
324 if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
325 return new HashSet<>();
327 return translationMapping.get(resourceType).get(elementType).keySet();
330 public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
331 return translatedServiceTemplates;
334 public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
335 return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
338 public FileContentHandler getExternalArtifacts() {
339 return externalArtifacts;
342 public void addExternalArtifacts(String name, byte[] content) {
343 this.externalArtifacts.addFile(name, content);
346 public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
347 return heatSharedResourcesByParam;
350 public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
352 this.addHeatSharedResourcesByParam(parameterName,
353 new TranslatedHeatResource(resourceId, resource));
356 private void addHeatSharedResourcesByParam(String parameterName,
357 TranslatedHeatResource translatedHeatResource) {
358 this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
361 public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
362 return globalServiceTemplates;
365 public Map<String, String> getNestedHeatFileName() {
366 return nestedHeatFileName;
369 public void addNestedHeatFileName(String substituteServiceTempalteName,
370 String nestedHeatFileName) {
371 this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
374 public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
375 return usedHeatPseudoParams;
378 public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
379 translatedToscaParam) {
380 if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
381 this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
383 this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
386 public Set<String> getTranslatedResourceIdsFromOtherFiles(String fileNameToIgnore){
387 if(MapUtils.isEmpty(this.translatedResources)){
388 return new HashSet<>();
391 Set<String> translatedResourceIds = new HashSet<>();
393 this.translatedResources.entrySet().stream().filter(entry -> !entry.getKey().equals(fileNameToIgnore))
394 .forEach(entry -> translatedResourceIds.addAll(entry.getValue()));
396 return translatedResourceIds;
400 * Add the unified substitution data info in context. Contains a mapping of original node
401 * template id and the new node template id in the abstract substitute
403 * @param serviceTemplateFileName the service template file name
404 * @param originalNodeTemplateId the original node template id
405 * @param abstractNodeTemplateId the node template id in the abstract substitute
407 public void addUnifiedSubstitutionData(String serviceTemplateFileName,
408 String originalNodeTemplateId,
409 String abstractNodeTemplateId) {
411 Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
412 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
413 .getNodesRelatedAbstractNode();
415 if (nodeAbstractNodeTemplateIdMap == null) {
416 nodeAbstractNodeTemplateIdMap = new HashMap<>();
419 if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
420 throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
422 nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
423 this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
424 nodeAbstractNodeTemplateIdMap);
428 * Add the unified substitution data info in context. Contains a mapping of original node
429 * template id and the new node template id in the abstract substitute
431 * @param serviceTemplateFileName the service template file name
432 * @param originalNodeTemplateId the original node template id
433 * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
436 public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
437 String serviceTemplateFileName,
438 String originalNodeTemplateId,
439 String substitutionServiceTemplateNodeTemplateId) {
441 Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
442 .getUnifiedSubstitutionData()
443 .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
444 .getNodesRelatedSubstitutionServiceTemplateNode();
446 if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
447 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
449 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
450 substitutionServiceTemplateNodeTemplateId);
451 this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
452 .setNodesRelatedSubstitutionServiceTemplateNode(
453 nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
457 * Get unified abstract node template which is mapped to the input node template id.
459 * @param serviceTemplate the service template
460 * @param nodeTemplateId the node template id
462 public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
463 String nodeTemplateId) {
464 UnifiedSubstitutionData unifiedSubsData =
465 this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
466 return unifiedSubsData.getNodesRelatedAbstractNode().get(nodeTemplateId);
470 * Get unified node template in the substitution service template which is mapped to the
471 * original input node template id.
473 * @param serviceTemplate the service template
474 * @param nodeTemplateId the node template id
476 public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
477 String nodeTemplateId) {
478 UnifiedSubstitutionData unifiedSubsData =
479 this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
480 return unifiedSubsData.getNodesRelatedSubstitutionServiceTemplateNode()
481 .get(nodeTemplateId);
484 public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
485 String computeType) {
486 return this.unifiedSubstitutionData.get(serviceTemplateName)
487 .getHandledNestedComputeNodeTemplateIndex(computeType);
490 public void updateHandledComputeType(String serviceTemplateName,
491 String handledComputeType,
492 String nestedServiceTemplateFileName) {
493 String globalSTName =
494 ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
495 this.unifiedSubstitutionData.putIfAbsent(
496 globalSTName, new UnifiedSubstitutionData());
497 this.unifiedSubstitutionData.get(globalSTName)
498 .addHandledComputeType(handledComputeType);
499 this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
501 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
502 this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
505 public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
506 String handledComputeType){
507 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
508 this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
511 public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
512 String computeType) {
513 return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
514 && this.unifiedSubstitutionData.get(serviceTemplateName)
515 .isComputeTypeHandledInServiceTemplate(computeType);
518 public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
519 String nestedServiceTemplateFileName) {
520 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
523 return this.unifiedSubstitutionData.get(serviceTemplateName)
524 .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
527 public Set<String> getAllRelatedNestedNodeTypeIds() {
528 String globalName = "GlobalSubstitutionTypes";
529 if (Objects.isNull(this.unifiedSubstitutionData)
530 || Objects.isNull(this.unifiedSubstitutionData.get(globalName))) {
531 return new HashSet<>();
534 return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
537 public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
538 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
539 if (unifiedHandledServiceTemplates.contains(serviceTemplateFileName)) {
547 public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
548 String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
549 this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
552 public boolean isNestedNodeWasHandled(String serviceTemplateName,
553 String nestedNodeTemplateId) {
554 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
557 return this.unifiedSubstitutionData.get(serviceTemplateName)
558 .isNestedNodeWasHandled(nestedNodeTemplateId);
561 public void addNestedNodeAsHandled(String serviceTemplateName,
562 String nestedNodeTemplateId) {
563 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
564 this.unifiedSubstitutionData.get(serviceTemplateName)
565 .addHandledNestedNodes(nestedNodeTemplateId);
568 public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
569 String computeType) {
570 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
572 this.unifiedSubstitutionData.get(serviceTemplateName)
573 .updateUsedTimesForNestedComputeNodeType(computeType);
576 public int getGlobalNodeTypeIndex(String serviceTemplateName,
577 String computeType) {
578 if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
581 return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
585 public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
586 String newPropertyId,
587 Object origPropertyValue){
588 this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
589 this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
590 newPropertyId, origPropertyValue);
593 public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
594 String newPropertyId){
595 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
596 return Optional.empty();
599 return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
603 public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
604 if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
605 return new HashMap<>();
608 return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
612 public boolean isServiceTemplateWithoutNodeTemplatesSection(String serviceTemplateName){
613 return Objects.nonNull(serviceTemplateName)
614 && serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
617 public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
618 this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
621 public void addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
622 this.nodeTemplateIdsPointingToStWithoutNodeTemplates.add(nodeTemplateId);
625 public boolean isNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
626 return Objects.nonNull(nodeTemplateId)
627 && nodeTemplateIdsPointingToStWithoutNodeTemplates.contains(nodeTemplateId);
630 public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
631 String nodeTemplateId,
632 String requirementId){
633 requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
634 requirementIdAppearanceInNodeTemplate
635 .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
637 Map<String, Integer> requirementIdToAppearance =
638 requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
640 if(requirementIdToAppearance.containsKey(requirementId)){
641 requirementIdToAppearance
642 .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
644 requirementIdToAppearance.put(requirementId, 0);