2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.tosca;
23 import java.beans.IntrospectionException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.LinkedHashSet;
28 import java.util.List;
30 import java.util.Map.Entry;
31 import java.util.Optional;
33 import java.util.function.Supplier;
34 import java.util.stream.Collectors;
36 import org.apache.commons.collections.CollectionUtils;
37 import org.apache.commons.collections.MapUtils;
38 import org.apache.commons.lang.StringUtils;
39 import org.apache.commons.lang3.tuple.ImmutablePair;
40 import org.apache.commons.lang3.tuple.ImmutableTriple;
41 import org.apache.commons.lang3.tuple.Triple;
42 import org.openecomp.sdc.be.config.ConfigurationManager;
43 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
44 import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
45 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
46 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
47 import org.openecomp.sdc.be.model.ArtifactDefinition;
48 import org.openecomp.sdc.be.model.CapabilityDefinition;
49 import org.openecomp.sdc.be.model.Component;
50 import org.openecomp.sdc.be.model.ComponentInstance;
51 import org.openecomp.sdc.be.model.ComponentInstanceInput;
52 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
53 import org.openecomp.sdc.be.model.ComponentParametersView;
54 import org.openecomp.sdc.be.model.DataTypeDefinition;
55 import org.openecomp.sdc.be.model.GroupDefinition;
56 import org.openecomp.sdc.be.model.GroupInstance;
57 import org.openecomp.sdc.be.model.GroupProperty;
58 import org.openecomp.sdc.be.model.InputDefinition;
59 import org.openecomp.sdc.be.model.PropertyDefinition;
60 import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
61 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
62 import org.openecomp.sdc.be.model.RequirementDefinition;
63 import org.openecomp.sdc.be.model.Resource;
64 import org.openecomp.sdc.be.model.Service;
65 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
66 import org.openecomp.sdc.be.model.category.CategoryDefinition;
67 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
68 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
69 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
70 import org.openecomp.sdc.be.model.tosca.converters.ToscaValueBaseConverter;
71 import org.openecomp.sdc.be.tosca.model.IToscaMetadata;
72 import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
73 import org.openecomp.sdc.be.tosca.model.ToscaCapability;
74 import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate;
75 import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
76 import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
77 import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
78 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
79 import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
80 import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
81 import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
82 import org.openecomp.sdc.be.tosca.model.VfModuleToscaMetadata;
83 import org.openecomp.sdc.common.api.Constants;
84 import org.slf4j.Logger;
85 import org.slf4j.LoggerFactory;
86 import org.springframework.beans.factory.annotation.Autowired;
87 import org.yaml.snakeyaml.DumperOptions;
88 import org.yaml.snakeyaml.DumperOptions.FlowStyle;
89 import org.yaml.snakeyaml.Yaml;
90 import org.yaml.snakeyaml.introspector.BeanAccess;
91 import org.yaml.snakeyaml.introspector.Property;
92 import org.yaml.snakeyaml.introspector.PropertyUtils;
93 import org.yaml.snakeyaml.nodes.MappingNode;
94 import org.yaml.snakeyaml.nodes.Node;
95 import org.yaml.snakeyaml.nodes.NodeTuple;
96 import org.yaml.snakeyaml.nodes.Tag;
97 import org.yaml.snakeyaml.representer.Represent;
98 import org.yaml.snakeyaml.representer.Representer;
100 import fj.data.Either;
102 @org.springframework.stereotype.Component("tosca-export-handler")
103 public class ToscaExportHandler {
106 private ApplicationDataTypeCache dataTypeCache;
109 private ToscaOperationFacade toscaOperationFacade;
111 private CapabiltyRequirementConvertor capabiltyRequirementConvertor;
112 private PropertyConvertor propertyConvertor = PropertyConvertor.getInstance();
113 Map<String,Component> originComponents = new HashMap<>();
115 private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName());
117 public static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
118 public static final String SERVICE_NODE_TYPE_PREFIX = "org.openecomp.service.";
119 public static final String IMPORTS_FILE_KEY = "file";
120 public static final String TOSCA_TEMPLATE_NAME = "-template.yml";
121 public static final String TOSCA_INTERFACE_NAME = "-interface.yml";
122 public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate";
123 public static final String VF_MODULE_TYPE_KEY = "vf_module_type";
124 public static final String VF_MODULE_DESC_KEY = "vf_module_description";
125 public static final String VOLUME_GROUP_KEY = "volume_group";
126 public static final String VF_MODULE_TYPE_BASE = "Base";
127 public static final String VF_MODULE_TYPE_EXPANSION = "Expansion";
128 private static final String FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION = "convertToToscaTemplate - failed to get Default Imports section from configuration";
129 private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
130 protected static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultImports();
132 public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
134 Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertToToscaTemplate(component);
135 if (toscaTemplateRes.isRight()) {
136 return Either.right(toscaTemplateRes.right().value());
139 ToscaTemplate toscaTemplate = toscaTemplateRes.left().value();
140 ToscaRepresentation toscaRepresentation = this.createToscaRepresentation(toscaTemplate);
141 return Either.left(toscaRepresentation);
144 public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component) {
145 if (null == DEFAULT_IMPORTS) {
146 log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
147 return Either.right(ToscaError.GENERAL_ERROR);
150 ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
151 toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS));
152 Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
153 Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(component, toscaTemplate,
155 if (toscaTemplateRes.isRight()) {
156 return Either.right(toscaTemplateRes.right().value());
159 toscaTemplate = toscaTemplateRes.left().value();
160 ToscaRepresentation toscaRepresentation = this.createToscaRepresentation(toscaTemplate);
161 return Either.left(toscaRepresentation);
164 public ToscaRepresentation createToscaRepresentation(ToscaTemplate toscaTemplate) {
165 CustomRepresenter representer = new CustomRepresenter();
166 DumperOptions options = new DumperOptions();
167 options.setAllowReadOnlyProperties(false);
168 options.setPrettyFlow(true);
170 options.setDefaultFlowStyle(FlowStyle.FLOW);
171 options.setCanonical(false);
173 representer.addClassTag(toscaTemplate.getClass(), Tag.MAP);
175 representer.setPropertyUtils(new UnsortedPropertyUtils());
176 Yaml yaml = new Yaml(representer, options);
178 String yamlAsString = yaml.dumpAsMap(toscaTemplate);
180 StringBuilder sb = new StringBuilder();
181 sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader());
182 sb.append(yamlAsString);
183 sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactFooter());
185 ToscaRepresentation toscaRepresentation = new ToscaRepresentation();
186 toscaRepresentation.setMainYaml(sb.toString());
187 toscaRepresentation.setDependencies(toscaTemplate.getDependencies());
189 return toscaRepresentation;
192 public Either<ToscaTemplate, ToscaError> getDependencies(Component component) {
193 ToscaTemplate toscaTemplate = new ToscaTemplate(null);
194 Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports = fillImports(component,
196 if (fillImports.isRight()) {
197 return Either.right(fillImports.right().value());
199 return Either.left(fillImports.left().value().left);
202 private Either<ToscaTemplate, ToscaError> convertToToscaTemplate(Component component) {
203 if (null == DEFAULT_IMPORTS) {
204 log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
205 return Either.right(ToscaError.GENERAL_ERROR);
208 log.trace("start tosca export for {}", component.getUniqueId());
209 ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
211 toscaTemplate.setMetadata(convertMetadata(component));
212 toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS));
213 Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
214 if (ModelConverter.isAtomicComponent(component)) {
215 log.trace("convert component as node type");
216 return convertNodeType(component, toscaTemplate, nodeTypes);
218 log.trace("convert component as topology template");
219 return convertToscaTemplate(component, toscaTemplate);
224 private Either<ToscaTemplate, ToscaError> convertToscaTemplate(Component component, ToscaTemplate toscaNode) {
226 Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> importsRes = fillImports(component,
228 if (importsRes.isRight()) {
229 return Either.right(importsRes.right().value());
231 toscaNode = importsRes.left().value().left;
232 /*Either<Map<String, ToscaNodeType>, ToscaError> nodeTypesMapEither = createProxyNodeTypes(component);
233 if (nodeTypesMapEither.isRight()) {
234 log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
235 nodeTypesMapEither.right().value());
236 return Either.right(nodeTypesMapEither.right().value());
238 Map<String, ToscaNodeType> nodeTypesMap = nodeTypesMapEither.left().value();
239 if (nodeTypesMap != null && !nodeTypesMap.isEmpty())
240 toscaNode.setNode_types(nodeTypesMap);*/
242 Map<String, Component> componentCache = importsRes.left().value().right;
243 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
244 if (dataTypesEither.isRight()) {
245 log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value());
246 return Either.right(ToscaError.GENERAL_ERROR);
248 Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
250 ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
252 Either<ToscaTopolgyTemplate, ToscaError> inputs = fillInputs(component, topologyTemplate, dataTypes);
253 if (inputs.isRight()) {
254 return Either.right(inputs.right().value());
256 topologyTemplate = inputs.left().value();
258 List<ComponentInstance> componentInstances = component.getComponentInstances();
259 Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = component
260 .getComponentInstancesProperties();
261 List<GroupDefinition> groups = component.getGroups();
262 if (componentInstances != null && !componentInstances.isEmpty()) {
264 Either<Map<String, ToscaNodeTemplate>, ToscaError> nodeTemplates = convertNodeTemplates(component,
265 componentInstances, componentInstancesProperties, componentCache, dataTypes, topologyTemplate);
266 if (nodeTemplates.isRight()) {
267 return Either.right(nodeTemplates.right().value());
269 log.debug("node templates converted");
271 topologyTemplate.setNode_templates(nodeTemplates.left().value());
273 Map<String, ToscaGroupTemplate> groupsMap;
274 if (groups != null && !groups.isEmpty()) {
275 groupsMap = new HashMap<>();
276 for (GroupDefinition group : groups) {
277 ToscaGroupTemplate toscaGroup = convertGroup(group);
278 groupsMap.put(group.getName(), toscaGroup);
281 log.debug("groups converted");
282 topologyTemplate.addGroups(groupsMap);
284 SubstitutionMapping substitutionMapping = new SubstitutionMapping();
285 String toscaResourceName;
286 switch (component.getComponentType()) {
288 toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
289 .getMetadataDataDefinition()).getToscaResourceName();
292 toscaResourceName = SERVICE_NODE_TYPE_PREFIX
293 + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
296 log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
297 return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
299 substitutionMapping.setNode_type(toscaResourceName);
301 Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping);
302 if (capabilities.isRight()) {
303 return Either.right(capabilities.right().value());
305 substitutionMapping = capabilities.left().value();
307 Either<SubstitutionMapping, ToscaError> requirements = capabiltyRequirementConvertor
308 .convertSubstitutionMappingRequirements(originComponents, component, substitutionMapping);
309 if (requirements.isRight()) {
310 return Either.right(requirements.right().value());
312 substitutionMapping = requirements.left().value();
314 topologyTemplate.setSubstitution_mappings(substitutionMapping);
316 toscaNode.setTopology_template(topologyTemplate);
317 return Either.left(toscaNode);
320 private Either<ToscaTopolgyTemplate, ToscaError> fillInputs(Component component,
321 ToscaTopolgyTemplate topologyTemplate, Map<String, DataTypeDefinition> dataTypes) {
322 if (log.isDebugEnabled())
323 log.debug("fillInputs for component {}", component.getUniqueId());
324 List<InputDefinition> inputDef = component.getInputs();
325 Map<String, ToscaProperty> inputs = new HashMap<>();
327 if (inputDef != null) {
328 inputDef.forEach(i -> {
329 ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
330 inputs.put(i.getName(), property);
332 if (!inputs.isEmpty()) {
333 topologyTemplate.setInputs(inputs);
336 return Either.left(topologyTemplate);
339 private ToscaMetadata convertMetadata(Component component) {
340 return convertMetadata(component, false, null);
343 private ToscaMetadata convertMetadata(Component component, boolean isInstance,
344 ComponentInstance componentInstance) {
345 ToscaMetadata toscaMetadata = new ToscaMetadata();
346 toscaMetadata.setName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
347 toscaMetadata.setInvariantUUID(component.getInvariantUUID());
348 toscaMetadata.setUUID(component.getUUID());
349 toscaMetadata.setDescription(component.getDescription());
351 List<CategoryDefinition> categories = component.getCategories();
352 CategoryDefinition categoryDefinition = categories.get(0);
353 toscaMetadata.setCategory(categoryDefinition.getName());
356 toscaMetadata.setVersion(component.getVersion());
357 toscaMetadata.setCustomizationUUID(componentInstance.getCustomizationUUID());
359 switch (component.getComponentType()) {
361 Resource resource = (Resource) component;
362 toscaMetadata.setType(resource.getResourceType().name());
363 toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
364 toscaMetadata.setResourceVendor(resource.getVendorName());
365 toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
366 toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber());
369 Service service = (Service) component;
370 toscaMetadata.setType(component.getComponentType().getValue());
371 toscaMetadata.setServiceType(service.getServiceType());
372 toscaMetadata.setServiceRole(service.getServiceRole());
375 toscaMetadata.setServiceEcompNaming(((Service)component).isEcompGeneratedNaming());
376 toscaMetadata.setEcompGeneratedNaming(((Service)component).isEcompGeneratedNaming());
377 toscaMetadata.setNamingPolicy(((Service)component).getNamingPolicy());
381 log.debug("Not supported component type {}", component.getComponentType());
383 return toscaMetadata;
386 private Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports(Component component,
387 ToscaTemplate toscaTemplate) {
389 if (null == DEFAULT_IMPORTS) {
390 log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
391 return Either.right(ToscaError.GENERAL_ERROR);
394 Map<String, Component> componentCache = new HashMap<>();
396 if (!ModelConverter.isAtomicComponent(component)) {
397 List<ComponentInstance> componentInstances = component.getComponentInstances();
398 if (componentInstances != null && !componentInstances.isEmpty()) {
400 List<Map<String, Map<String, String>>> additionalImports = toscaTemplate.getImports() == null
401 ? new ArrayList<>(DEFAULT_IMPORTS) : new ArrayList<>(toscaTemplate.getImports());
403 List<Triple<String, String, Component>> dependecies = new ArrayList<>();
405 Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
406 ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
408 Map<String, Map<String, String>> importsListMember = new HashMap<>();
409 Map<String, String> interfaceFiles = new HashMap<>();
410 interfaceFiles.put(IMPORTS_FILE_KEY, getInterfaceFilename(artifactDefinition.getArtifactName()));
411 StringBuilder keyNameBuilder = new StringBuilder();
412 keyNameBuilder.append(component.getComponentType().toString().toLowerCase());
413 keyNameBuilder.append("-");
414 keyNameBuilder.append(component.getName());
415 keyNameBuilder.append("-interface");
416 importsListMember.put(keyNameBuilder.toString(), interfaceFiles);
417 additionalImports.add(importsListMember);
419 componentInstances.forEach(ci -> createDependency(componentCache, additionalImports, dependecies, ci));
420 originComponents.putAll(componentCache);
421 toscaTemplate.setDependencies(dependecies);
422 toscaTemplate.setImports(additionalImports);
425 log.debug("currently imports supported for VF and service only");
427 return Either.left(new ImmutablePair<ToscaTemplate, Map<String, Component>>(toscaTemplate, componentCache));
430 private void createDependency(Map<String, Component> componentCache, List<Map<String, Map<String, String>>> imports,
431 List<Triple<String, String, Component>> dependecies, ComponentInstance ci) {
432 Map<String, String> files = new HashMap<>();
433 Map<String, Map<String, String>> importsListMember = new HashMap<>();
434 StringBuilder keyNameBuilder;
436 Component componentRI = componentCache.get(ci.getComponentUid());
437 if (componentRI == null) {
438 // all resource must be only once!
439 Either<Component, StorageOperationStatus> resource = toscaOperationFacade
440 .getToscaFullElement(ci.getComponentUid());
441 if (resource.isRight()) {
442 log.debug("Failed to fetch resource with id {} for instance {}");
444 Component fetchedComponent = resource.left().value();
445 componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent);
446 componentRI = fetchedComponent;
448 Map<String, ArtifactDefinition> toscaArtifacts = componentRI.getToscaArtifacts();
449 ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE);
450 if (artifactDefinition != null) {
451 String artifactName = artifactDefinition.getArtifactName();
452 files.put(IMPORTS_FILE_KEY, artifactName);
453 keyNameBuilder = new StringBuilder();
454 keyNameBuilder.append(fetchedComponent.getComponentType().toString().toLowerCase());
455 keyNameBuilder.append("-");
456 keyNameBuilder.append(ci.getComponentName());
457 importsListMember.put(keyNameBuilder.toString(), files);
458 imports.add(importsListMember);
459 dependecies.add(new ImmutableTriple<String, String, Component>(artifactName,
460 artifactDefinition.getEsId(), fetchedComponent));
462 if (!ModelConverter.isAtomicComponent(componentRI)) {
463 importsListMember = new HashMap<>();
464 Map<String, String> interfaceFiles = new HashMap<>();
465 interfaceFiles.put(IMPORTS_FILE_KEY, getInterfaceFilename(artifactName));
466 keyNameBuilder.append("-interface");
467 importsListMember.put(keyNameBuilder.toString(), interfaceFiles);
468 imports.add(importsListMember);
474 public static String getInterfaceFilename(String artifactName) {
475 return artifactName.substring(0, artifactName.lastIndexOf('.')) + ToscaExportHandler.TOSCA_INTERFACE_NAME;
478 private Either<ToscaTemplate, ToscaError> convertNodeType(Component component, ToscaTemplate toscaNode,
479 Map<String, ToscaNodeType> nodeTypes) {
480 log.debug("start convert node type for {}", component.getUniqueId());
481 ToscaNodeType toscaNodeType = createNodeType(component);
483 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
484 if (dataTypesEither.isRight()) {
485 log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
486 return Either.right(ToscaError.GENERAL_ERROR);
489 Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
490 Either<ToscaNodeType, ToscaError> properties = propertyConvertor.convertProperties(component, toscaNodeType,
492 if (properties.isRight()) {
493 return Either.right(properties.right().value());
495 toscaNodeType = properties.left().value();
496 log.debug("Properties converted for {}", component.getUniqueId());
498 // Extracted to method for code reuse
499 return convertReqCapAndTypeName(component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
502 private Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Component component, ToscaTemplate toscaNode,
503 Map<String, ToscaNodeType> nodeTypes) {
504 log.debug("start convert node type for {}", component.getUniqueId());
505 ToscaNodeType toscaNodeType = createNodeType(component);
507 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
508 if (dataTypesEither.isRight()) {
509 log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
510 return Either.right(ToscaError.GENERAL_ERROR);
513 Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
515 List<InputDefinition> inputDef = component.getInputs();
516 Map<String, ToscaProperty> inputs = new HashMap<>();
518 if (inputDef != null) {
519 inputDef.forEach(i -> {
520 ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
521 inputs.put(i.getName(), property);
523 if (!inputs.isEmpty()) {
524 toscaNodeType.setProperties(inputs);
528 // Extracted to method for code reuse
529 return convertReqCapAndTypeName(component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
532 private Either<ToscaTemplate, ToscaError> convertReqCapAndTypeName(Component component, ToscaTemplate toscaNode,
533 Map<String, ToscaNodeType> nodeTypes, ToscaNodeType toscaNodeType,
534 Map<String, DataTypeDefinition> dataTypes) {
535 Either<ToscaNodeType, ToscaError> capabilities = convertCapabilities(component, toscaNodeType, dataTypes);
536 if (capabilities.isRight()) {
537 return Either.right(capabilities.right().value());
539 toscaNodeType = capabilities.left().value();
540 log.debug("Capabilities converted for {}", component.getUniqueId());
542 Either<ToscaNodeType, ToscaError> requirements = capabiltyRequirementConvertor.convertRequirements(component, toscaNodeType);
543 if (requirements.isRight()) {
544 return Either.right(requirements.right().value());
546 toscaNodeType = requirements.left().value();
547 log.debug("Requirements converted for {}", component.getUniqueId());
549 String toscaResourceName;
550 switch (component.getComponentType()) {
552 toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
553 .getMetadataDataDefinition()).getToscaResourceName();
556 toscaResourceName = SERVICE_NODE_TYPE_PREFIX
557 + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
560 log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
561 return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
564 nodeTypes.put(toscaResourceName, toscaNodeType);
565 toscaNode.setNode_types(nodeTypes);
566 log.debug("finish convert node type for {}", component.getUniqueId());
567 return Either.left(toscaNode);
570 private Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplates(Component component,
571 List<ComponentInstance> componentInstances,
572 Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
573 Map<String, Component> componentCache, Map<String, DataTypeDefinition> dataTypes,
574 ToscaTopolgyTemplate topologyTemplate) {
576 Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplatesRes = null;
577 log.debug("start convert topology template for {} for type {}", component.getUniqueId(),
578 component.getComponentType());
579 Map<String, ToscaNodeTemplate> nodeTemplates = new HashMap<>();
580 Map<String, List<ComponentInstanceInput>> componentInstancesInputs = component.getComponentInstancesInputs();
582 Map<String, ToscaGroupTemplate> groupsMap = null;
583 for (ComponentInstance componentInstance : componentInstances) {
584 ToscaNodeTemplate nodeTemplate = new ToscaNodeTemplate();
585 nodeTemplate.setType(componentInstance.getToscaComponentName());
587 Either<ToscaNodeTemplate, ToscaError> requirements = convertComponentInstanceRequirements(component,
588 componentInstance, component.getComponentInstancesRelations(), nodeTemplate,
589 componentCache.get(componentInstance.getComponentUid()));
590 if (requirements.isRight()) {
591 convertNodeTemplatesRes = Either.right(requirements.right().value());
594 String instanceUniqueId = componentInstance.getUniqueId();
595 log.debug("Component instance Requirements converted for instance {}", instanceUniqueId);
597 nodeTemplate = requirements.left().value();
599 Component componentOfInstance = componentCache.get(componentInstance.getComponentUid());
600 nodeTemplate.setMetadata(convertMetadata(componentOfInstance, true, componentInstance));
602 Either<ToscaNodeTemplate, ToscaError> capabilities = capabiltyRequirementConvertor
603 .convertComponentInstanceCapabilties(componentInstance, dataTypes, nodeTemplate);
604 if (capabilities.isRight()) {
605 convertNodeTemplatesRes = Either.right(requirements.right().value());
608 log.debug("Component instance Capabilities converted for instance {}", instanceUniqueId);
610 nodeTemplate = capabilities.left().value();
611 Map<String, Object> props = new HashMap<>();
613 if (componentOfInstance.getComponentType() == ComponentTypeEnum.RESOURCE) {
614 // Adds the properties of parent component to map
615 addPropertiesOfParentComponent(dataTypes, componentInstance, componentOfInstance, props);
618 if (null != componentInstancesProperties && componentInstancesProperties.containsKey(instanceUniqueId)) {
619 addPropertiesOfComponentInstance(componentInstancesProperties, dataTypes, componentInstance,
620 instanceUniqueId, props);
623 if (componentInstancesInputs != null && componentInstancesInputs.containsKey(instanceUniqueId)) {
624 addComponentInstanceInputs(dataTypes, componentInstancesInputs, componentInstance, instanceUniqueId,
627 if (props != null && !props.isEmpty()) {
628 nodeTemplate.setProperties(props);
631 List<GroupInstance> groupInstances = componentInstance.getGroupInstances();
632 if (groupInstances != null) {
633 if (groupsMap == null) {
634 groupsMap = new HashMap<>();
636 for (GroupInstance groupInst : groupInstances) {
637 ToscaGroupTemplate toscaGroup = convertGroupInstance(groupInst);
639 groupsMap.put(groupInst.getName(), toscaGroup);
643 nodeTemplates.put(componentInstance.getName(), nodeTemplate);
645 if (groupsMap != null) {
646 log.debug("instance groups added");
647 topologyTemplate.addGroups(groupsMap);
650 if (convertNodeTemplatesRes == null) {
651 convertNodeTemplatesRes = Either.left(nodeTemplates);
653 log.debug("finish convert topology template for {} for type {}", component.getUniqueId(),
654 component.getComponentType());
655 return convertNodeTemplatesRes;
658 private void addComponentInstanceInputs(Map<String, DataTypeDefinition> dataTypes,
659 Map<String, List<ComponentInstanceInput>> componentInstancesInputs, ComponentInstance componentInstance,
660 String instanceUniqueId, Map<String, Object> props) {
662 List<ComponentInstanceInput> instanceInputsList = componentInstancesInputs.get(instanceUniqueId);
663 if (instanceInputsList != null) {
664 instanceInputsList.forEach(input -> {
666 Supplier<String> supplier = () -> input.getValue() != null && !input.getValue().isEmpty()
667 ? input.getValue() : input.getDefaultValue();
668 convertAndAddValue(dataTypes, componentInstance, props, input, supplier);
673 private void addPropertiesOfComponentInstance(
674 Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
675 Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance, String instanceUniqueId,
676 Map<String, Object> props) {
678 if (!MapUtils.isEmpty(componentInstancesProperties)) {
679 componentInstancesProperties.get(instanceUniqueId).stream()
680 // Collects filtered properties to List
681 .collect(Collectors.toList()).stream()
682 // Converts and adds each value to property map
683 .forEach(prop -> convertAndAddValue(dataTypes, componentInstance, props, prop,
684 () -> prop.getValue()));
688 private void addPropertiesOfParentComponent(Map<String, DataTypeDefinition> dataTypes,
689 ComponentInstance componentInstance, Component componentOfInstance, Map<String, Object> props) {
691 List<PropertyDefinition> componentProperties = ((Resource) componentOfInstance).getProperties();
692 if (!CollectionUtils.isEmpty(componentProperties)) {
693 componentProperties.stream()
694 // Filters out properties with empty default values
695 .filter(prop -> !StringUtils.isEmpty(prop.getDefaultValue()))
696 // Collects filtered properties to List
697 .collect(Collectors.toList()).stream()
698 // Converts and adds each value to property map
699 .forEach(prop -> convertAndAddValue(dataTypes, componentInstance, props, prop,
700 () -> prop.getDefaultValue()));
706 * @param componentInstance
711 private void convertAndAddValue(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance,
712 Map<String, Object> props, PropertyDefinition prop, Supplier<String> supplier) {
713 Object convertedValue = convertValue(dataTypes, componentInstance, prop, supplier);
714 if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue)) {
715 props.put(prop.getName(), convertedValue);
719 private <T extends PropertyDefinition> Object convertValue(Map<String, DataTypeDefinition> dataTypes,
720 ComponentInstance componentInstance, T input, Supplier<String> supplier) {
721 log.debug("Convert property or input value {} for instance {}", input.getName(),
722 componentInstance.getUniqueId());
723 String propertyType = input.getType();
724 String innerType = null;
725 if (input.getSchema() != null && input.getSchema().getProperty() != null) {
726 innerType = input.getSchema().getProperty().getType();
728 return propertyConvertor.convertToToscaObject(propertyType, supplier.get(), innerType, dataTypes);
731 private ToscaGroupTemplate convertGroup(GroupDefinition group) {
732 ToscaGroupTemplate toscaGroup = new ToscaGroupTemplate();
733 Map<String, String> members = group.getMembers();
735 toscaGroup.setMembers(new ArrayList<String>(members.keySet()));
737 Supplier<String> supplGroupType = () -> group.getType();
738 Supplier<String> supplDescription = () -> group.getDescription();
739 Supplier<List<? extends GroupProperty>> supplProperties = () -> group.convertToGroupProperties();
740 Supplier<String> supplgroupName = () -> group.getName();
741 Supplier<String> supplInvariantUUID = () -> group.getInvariantUUID();
742 Supplier<String> supplGroupUUID = () -> group.getGroupUUID();
743 Supplier<String> supplVersion = () -> group.getVersion();
745 IToscaMetadata toscaMetadata = fillGroup(toscaGroup, supplProperties, supplDescription, supplgroupName,
746 supplInvariantUUID, supplGroupUUID, supplVersion, supplGroupType);
747 toscaGroup.setMetadata(toscaMetadata);
751 private ToscaGroupTemplate convertGroupInstance(GroupInstance groupInstance) {
752 ToscaGroupTemplate toscaGroup = new ToscaGroupTemplate();
754 Supplier<String> supplGroupType = () -> groupInstance.getType();
755 Supplier<String> supplDescription = () -> groupInstance.getDescription();
756 Supplier<List<? extends GroupProperty>> supplProperties = () -> groupInstance
757 .convertToGroupInstancesProperties();
758 Supplier<String> supplgroupName = () -> groupInstance.getGroupName();
759 Supplier<String> supplInvariantUUID = () -> groupInstance.getInvariantUUID();
760 Supplier<String> supplGroupUUID = () -> groupInstance.getGroupUUID();
761 Supplier<String> supplVersion = () -> groupInstance.getVersion();
763 IToscaMetadata toscaMetadata = fillGroup(toscaGroup, supplProperties, supplDescription, supplgroupName,
764 supplInvariantUUID, supplGroupUUID, supplVersion, supplGroupType);
766 toscaMetadata.setCustomizationUUID(groupInstance.getCustomizationUUID());
767 toscaGroup.setMetadata(toscaMetadata);
771 private IToscaMetadata fillGroup(ToscaGroupTemplate toscaGroup, Supplier<List<? extends GroupProperty>> props,
772 Supplier<String> description, Supplier<String> groupName, Supplier<String> invariantUUID,
773 Supplier<String> groupUUID, Supplier<String> version, Supplier<String> groupType) {
774 boolean isVfModule = groupType.get().equals(Constants.DEFAULT_GROUP_VF_MODULE) ? true : false;
775 toscaGroup.setType(groupType.get());
777 IToscaMetadata toscaMetadata;
779 toscaMetadata = new ToscaMetadata();
781 toscaMetadata = new VfModuleToscaMetadata();
783 Map<String, Object> properties = fillGroupProperties(props.get());
784 if (!properties.containsKey(VF_MODULE_DESC_KEY)
785 || StringUtils.isEmpty((String) properties.get(VF_MODULE_DESC_KEY))) {
786 properties.put(VF_MODULE_DESC_KEY, description.get());
788 toscaGroup.setProperties(properties);
790 toscaMetadata.setName(groupName.get());
791 toscaMetadata.setInvariantUUID(invariantUUID.get());
792 toscaMetadata.setUUID(groupUUID.get());
793 toscaMetadata.setVersion(version.get());
794 return toscaMetadata;
797 private Map<String, Object> fillGroupProperties(List<? extends GroupProperty> groupProps) {
798 Map<String, Object> properties = new HashMap<>();
799 if (groupProps != null) {
800 for (GroupProperty gp : groupProps) {
801 if (gp.getName().equals(Constants.IS_BASE)) {
802 Boolean isBase = Boolean.parseBoolean(gp.getValue());
803 String type = isBase ? VF_MODULE_TYPE_BASE : VF_MODULE_TYPE_EXPANSION;
804 properties.put(VF_MODULE_TYPE_KEY, type);
807 String type = gp.getType();
811 if (gp.getValue() != null) {
812 value = Integer.valueOf(gp.getValue());
816 if (gp.getValue() != null) {
817 value = Boolean.valueOf(gp.getValue());
822 value = gp.getValue();
825 properties.put(gp.getName(), value);
832 private ToscaNodeType createNodeType(Component component) {
833 ToscaNodeType toscaNodeType = new ToscaNodeType();
834 if (ModelConverter.isAtomicComponent(component)) {
835 if (((Resource) component).getDerivedFrom() != null) {
836 toscaNodeType.setDerived_from(((Resource) component).getDerivedFrom().get(0));
838 toscaNodeType.setDescription(component.getDescription()); // or
841 String derivedFrom = null != component.getDerivedFromGenericType() ? component.getDerivedFromGenericType()
842 : "tosca.nodes.Root";
843 toscaNodeType.setDerived_from(derivedFrom);
845 return toscaNodeType;
848 /*private Either<Map<String, ToscaNodeType>, ToscaError> createProxyNodeTypes(Component container) {
850 Map<String, ToscaNodeType> nodeTypesMap = null;
851 Either<Map<String, ToscaNodeType>, ToscaError> res = Either.left(nodeTypesMap);
853 List<ComponentInstance> componetInstances = container.getComponentInstances();
855 if (componetInstances == null || componetInstances.isEmpty())
857 Map<String, ComponentInstance> serviceProxyInstanceList = new HashMap<>();
858 List<ComponentInstance> proxyInst = componetInstances.stream().filter(p -> p.getOriginType().name().equals(OriginTypeEnum.ServiceProxy.name())).collect(Collectors.toList());
859 if(proxyInst != null && !proxyInst.isEmpty()){
860 for(ComponentInstance inst: proxyInst){
861 serviceProxyInstanceList.put(inst.getToscaComponentName(), inst);
865 if (serviceProxyInstanceList.isEmpty())
867 ComponentParametersView filter = new ComponentParametersView(true);
868 filter.setIgnoreCapabilities(false);
869 filter.setIgnoreComponentInstances(false);
870 Either<Resource, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade
871 .getLatestByName("serviceProxy");
872 if (serviceProxyOrigin.isRight()) {
873 log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
874 serviceProxyOrigin.right().value());
875 return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
877 Component origComponent = serviceProxyOrigin.left().value();
879 nodeTypesMap = new HashMap<>();
880 for (Entry<String, ComponentInstance> entryProxy : serviceProxyInstanceList.entrySet()) {
881 Component serviceComponent = null;
882 ComponentParametersView componentParametersView = new ComponentParametersView();
883 componentParametersView.disableAll();
884 componentParametersView.setIgnoreCategories(false);
885 Either<Component, StorageOperationStatus> service = toscaOperationFacade
886 .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
887 if (service.isRight()) {
888 log.debug("Failed to fetch resource with id {} for instance {}");
890 serviceComponent = service.left().value();
892 ToscaNodeType toscaNodeType = createProxyNodeType(origComponent, serviceComponent, entryProxy.getValue());
893 nodeTypesMap.put(entryProxy.getKey(), toscaNodeType);
896 return Either.left(nodeTypesMap);
899 private ToscaNodeType createProxyNodeType(Component origComponent, Component proxyComponent,
900 ComponentInstance instance) {
901 ToscaNodeType toscaNodeType = new ToscaNodeType();
902 String derivedFrom = ((Resource) origComponent).getToscaResourceName();
904 toscaNodeType.setDerived_from(derivedFrom);
905 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
906 if (dataTypesEither.isRight()) {
907 log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value());
909 Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
910 Map<String, ToscaCapability> capabilities = this.capabiltyRequirementConvertor
911 .convertProxyCapabilities(origComponent, proxyComponent, instance, dataTypes);
913 toscaNodeType.setCapabilities(capabilities);
915 return toscaNodeType;
918 private Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceRequirements(Component component,
919 ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations,
920 ToscaNodeTemplate nodeTypeTemplate, Component originComponent) {
922 List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
923 if(!addRequirements(component, componentInstance, relations, originComponent, toscaRequirements)){
924 log.debug("Failed to convert component instance requirements for the component instance {}. ", componentInstance.getName());
925 return Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
927 if (!toscaRequirements.isEmpty()) {
928 nodeTypeTemplate.setRequirements(toscaRequirements);
930 log.debug("Finished to convert requirements for the node type {} ", componentInstance.getName());
931 return Either.left(nodeTypeTemplate);
934 private boolean addRequirements(Component component, ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations, Component originComponent,
935 List<Map<String, ToscaTemplateRequirement>> toscaRequirements) {
937 List<RequirementCapabilityRelDef> filteredRelations = relations.stream().filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).collect(Collectors.toList());
938 if(CollectionUtils.isEmpty(filteredRelations)){
941 result = !filteredRelations.stream().filter(rel -> !addRequirement(componentInstance, originComponent, component.getComponentInstances(), rel, toscaRequirements)).findFirst().isPresent();
946 private boolean addRequirement(ComponentInstance fromInstance, Component originComponent, List<ComponentInstance> instancesList, RequirementCapabilityRelDef rel, List<Map<String, ToscaTemplateRequirement>> toscaRequirements){
948 boolean result = true;
949 Map<String,Component> originComponents = new HashMap<>();
950 Map<String, List<RequirementDefinition>> reqMap = originComponent.getRequirements();
951 RequirementAndRelationshipPair reqAndRelationshipPair = rel.getRelationships().get(0);
952 Either<Component, StorageOperationStatus> getOriginRes = null;
953 Optional<RequirementDefinition> reqOpt = null;
954 Component toOriginComponent = null;
955 Optional<CapabilityDefinition> cap = null;
956 Either<String, Boolean> buildCapNameRes = null;
957 Either<String, Boolean> buildReqNameRes = null;
959 ComponentInstance toInstance = instancesList.stream().filter(i -> rel.getToNode().equals(i.getUniqueId())).findFirst().orElse(null);
960 if (toInstance == null) {
961 log.debug("Failed to find a relation from the node {} to the node {}", fromInstance.getName(), rel.getToNode());
965 reqOpt = findRequirement(reqMap, reqAndRelationshipPair.getRequirementUid());
966 if(!reqOpt.isPresent()){
967 log.debug("Failed to find a requirement with uniqueId {} on a component with uniqueId {}", reqAndRelationshipPair.getRequirementUid(), originComponent.getUniqueId());
972 ComponentParametersView filter = new ComponentParametersView(true);
973 filter.setIgnoreComponentInstances(false);
974 filter.setIgnoreCapabilities(false);
975 getOriginRes = toscaOperationFacade.getToscaElement(toInstance.getComponentUid(), filter);
976 if(getOriginRes.isRight()){
977 log.debug("Failed to build substituted name for the requirement {}. Failed to get an origin component with uniqueId {}", reqOpt.get().getName(), toInstance.getComponentUid());
982 toOriginComponent = getOriginRes.left().value();
983 cap = toOriginComponent.getCapabilities().get(reqOpt.get().getCapability()).stream().filter(c -> c.getName().equals(reqAndRelationshipPair.getCapability())).findFirst();
984 if(!cap.isPresent()){
985 log.debug("Failed to find a capability with name {} on a component with uniqueId {}", reqAndRelationshipPair.getCapability(), originComponent.getUniqueId());
990 buildCapNameRes = capabiltyRequirementConvertor.buildSubstitutedName(originComponents, toOriginComponent, cap.get().getPath(), reqAndRelationshipPair.getCapability());
991 if(buildCapNameRes.isRight()){
992 log.debug("Failed to build a substituted capability name for the capability with name {} on a component with uniqueId {}", reqAndRelationshipPair.getCapability(), originComponent.getUniqueId());
997 buildReqNameRes = capabiltyRequirementConvertor.buildSubstitutedName(originComponents, originComponent, reqOpt.get().getPath(), reqAndRelationshipPair.getRequirement());
998 if(buildReqNameRes.isRight()){
999 log.debug("Failed to build a substituted requirement name for the requirement with name {} on a component with uniqueId {}", reqAndRelationshipPair.getRequirement(), originComponent.getUniqueId());
1004 ToscaTemplateRequirement toscaRequirement = new ToscaTemplateRequirement();
1005 Map<String, ToscaTemplateRequirement> toscaReqMap = new HashMap<>();
1006 toscaRequirement.setNode(toInstance.getName());
1007 toscaRequirement.setCapability(buildCapNameRes.left().value());
1008 toscaReqMap.put(buildReqNameRes.left().value(), toscaRequirement);
1009 toscaRequirements.add(toscaReqMap);
1014 private Optional<RequirementDefinition> findRequirement(Map<String, List<RequirementDefinition>> reqMap, String reqId) {
1015 for(List<RequirementDefinition> reqList: reqMap.values()){
1016 Optional<RequirementDefinition> reqOpt = reqList.stream().filter(r -> r.getUniqueId().equals(reqId)).findFirst();
1017 if(reqOpt.isPresent()){
1021 return Optional.empty();
1025 private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component, SubstitutionMapping substitutionMappings) {
1027 Either<SubstitutionMapping, ToscaError> result = Either.left(substitutionMappings);;
1028 Either<Map<String, String[]>, ToscaError> toscaCapabilitiesRes = capabiltyRequirementConvertor
1029 .convertSubstitutionMappingCapabilities(originComponents, component);
1030 if(toscaCapabilitiesRes.isRight()){
1031 result = Either.right(toscaCapabilitiesRes.right().value());
1032 log.error("Failed convert capabilities for the component {}. ", component.getName());
1033 } else if (MapUtils.isNotEmpty(toscaCapabilitiesRes.left().value())) {
1034 substitutionMappings.setCapabilities(toscaCapabilitiesRes.left().value());
1035 log.debug("Finish convert capabilities for the component {}. ", component.getName());
1037 log.debug("Finished to convert capabilities for the component {}. ", component.getName());
1041 private Either<ToscaNodeType, ToscaError> convertCapabilities(Component component, ToscaNodeType nodeType,
1042 Map<String, DataTypeDefinition> dataTypes) {
1043 Map<String, ToscaCapability> toscaCapabilities = capabiltyRequirementConvertor.convertCapabilities(component,
1045 if (!toscaCapabilities.isEmpty()) {
1046 nodeType.setCapabilities(toscaCapabilities);
1048 log.debug("Finish convert Capabilities for node type");
1050 return Either.left(nodeType);
1053 private static class CustomRepresenter extends Representer {
1054 public CustomRepresenter() {
1056 // null representer is exceptional and it is stored as an instance
1058 this.nullRepresenter = new RepresentNull();
1063 protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
1065 if (propertyValue == null) {
1068 // skip not relevant for Tosca property
1069 if ("dependencies".equals(property.getName())) {
1072 NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
1074 return "_defaultp_".equals(property.getName())
1075 ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
1080 protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
1081 // remove the bean type from the output yaml (!! ...)
1082 if (!classTags.containsKey(javaBean.getClass()))
1083 addClassTag(javaBean.getClass(), Tag.MAP);
1085 return super.representJavaBean(properties, javaBean);
1088 private class RepresentNull implements Represent {
1089 public Node representData(Object data) {
1090 // possible values are here http://yaml.org/type/null.html
1091 return representScalar(Tag.NULL, "");
1096 private static class UnsortedPropertyUtils extends PropertyUtils {
1098 protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess)
1099 throws IntrospectionException {
1100 Collection<Property> fields = getPropertiesMap(type, BeanAccess.FIELD).values();
1101 return new LinkedHashSet<>(fields);