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 static org.apache.commons.collections.CollectionUtils.isEmpty;
24 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
25 import static org.apache.commons.collections.MapUtils.isNotEmpty;
26 import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput;
27 import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.addInterfaceTypeElement;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import com.fasterxml.jackson.databind.SerializationFeature;
31 import fj.data.Either;
32 import java.beans.IntrospectionException;
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.HashMap;
36 import java.util.LinkedHashSet;
37 import java.util.List;
39 import java.util.Map.Entry;
40 import java.util.Objects;
41 import java.util.Optional;
43 import java.util.function.Supplier;
44 import java.util.stream.Collectors;
45 import org.apache.commons.collections.CollectionUtils;
46 import org.apache.commons.collections.MapUtils;
47 import org.apache.commons.lang.StringUtils;
48 import org.apache.commons.lang3.tuple.ImmutablePair;
49 import org.apache.commons.lang3.tuple.ImmutableTriple;
50 import org.apache.commons.lang3.tuple.Triple;
51 import org.onap.sdc.tosca.services.YamlUtil;
52 import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException;
53 import org.openecomp.sdc.be.config.ConfigurationManager;
54 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
55 import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
58 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
63 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
64 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
65 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
66 import org.openecomp.sdc.be.model.ArtifactDefinition;
67 import org.openecomp.sdc.be.model.CapabilityDefinition;
68 import org.openecomp.sdc.be.model.Component;
69 import org.openecomp.sdc.be.model.ComponentInstance;
70 import org.openecomp.sdc.be.model.ComponentInstanceInput;
71 import org.openecomp.sdc.be.model.ComponentInstanceInterface;
72 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
73 import org.openecomp.sdc.be.model.ComponentParametersView;
74 import org.openecomp.sdc.be.model.DataTypeDefinition;
75 import org.openecomp.sdc.be.model.GroupInstance;
76 import org.openecomp.sdc.be.model.InputDefinition;
77 import org.openecomp.sdc.be.model.InterfaceDefinition;
78 import org.openecomp.sdc.be.model.PropertyDefinition;
79 import org.openecomp.sdc.be.model.RelationshipInfo;
80 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
81 import org.openecomp.sdc.be.model.RequirementDefinition;
82 import org.openecomp.sdc.be.model.Resource;
83 import org.openecomp.sdc.be.model.Service;
84 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
85 import org.openecomp.sdc.be.model.category.CategoryDefinition;
86 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
87 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
88 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
89 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
90 import org.openecomp.sdc.be.model.tosca.converters.ToscaValueBaseConverter;
91 import org.openecomp.sdc.be.tosca.model.CapabilityFilter;
92 import org.openecomp.sdc.be.tosca.model.NodeFilter;
93 import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
94 import org.openecomp.sdc.be.tosca.model.ToscaCapability;
95 import org.openecomp.sdc.be.tosca.model.ToscaDataType;
96 import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate;
97 import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
98 import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
99 import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
100 import org.openecomp.sdc.be.tosca.model.ToscaPolicyTemplate;
101 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
102 import org.openecomp.sdc.be.tosca.model.ToscaRequirement;
103 import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
104 import org.openecomp.sdc.be.tosca.model.ToscaTemplateArtifact;
105 import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
106 import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
107 import org.openecomp.sdc.be.tosca.utils.ForwardingPathToscaUtil;
108 import org.openecomp.sdc.be.tosca.utils.InputConverter;
109 import org.openecomp.sdc.common.log.wrappers.Logger;
110 import org.openecomp.sdc.externalupload.utils.ServiceUtils;
111 import org.springframework.beans.factory.annotation.Autowired;
112 import org.yaml.snakeyaml.DumperOptions;
113 import org.yaml.snakeyaml.DumperOptions.FlowStyle;
114 import org.yaml.snakeyaml.Yaml;
115 import org.yaml.snakeyaml.introspector.BeanAccess;
116 import org.yaml.snakeyaml.introspector.Property;
117 import org.yaml.snakeyaml.introspector.PropertyUtils;
118 import org.yaml.snakeyaml.nodes.MappingNode;
119 import org.yaml.snakeyaml.nodes.Node;
120 import org.yaml.snakeyaml.nodes.NodeTuple;
121 import org.yaml.snakeyaml.nodes.Tag;
122 import org.yaml.snakeyaml.representer.Represent;
123 import org.yaml.snakeyaml.representer.Representer;
125 @org.springframework.stereotype.Component("tosca-export-handler")
126 public class ToscaExportHandler {
128 private ApplicationDataTypeCache dataTypeCache;
129 private ToscaOperationFacade toscaOperationFacade;
130 private CapabilityRequirementConverter capabilityRequirementConverter;
131 private PolicyExportParser policyExportParser;
132 private GroupExportParser groupExportParser;
133 private PropertyConvertor propertyConvertor;
134 private InputConverter inputConverter;
135 private InterfaceLifecycleOperation interfaceLifecycleOperation;
136 private InterfacesOperationsConverter interfacesOperationsConverter;
139 public ToscaExportHandler(ApplicationDataTypeCache dataTypeCache, ToscaOperationFacade toscaOperationFacade,
140 CapabilityRequirementConverter capabilityRequirementConverter, PolicyExportParser policyExportParser,
141 GroupExportParser groupExportParser, PropertyConvertor propertyConvertor, InputConverter inputConverter,
142 InterfaceLifecycleOperation interfaceLifecycleOperation,
143 InterfacesOperationsConverter interfacesOperationsConverter) {
144 this.dataTypeCache = dataTypeCache;
145 this.toscaOperationFacade = toscaOperationFacade;
146 this.capabilityRequirementConverter = capabilityRequirementConverter;
147 this.policyExportParser = policyExportParser;
148 this.groupExportParser = groupExportParser;
149 this.propertyConvertor = propertyConvertor;
150 this.inputConverter = inputConverter;
151 this.interfaceLifecycleOperation = interfaceLifecycleOperation;
152 this.interfacesOperationsConverter = interfacesOperationsConverter;
156 private static final Logger log = Logger.getLogger(ToscaExportHandler.class);
158 private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
159 private static final String SERVICE_NODE_TYPE_PREFIX = "org.openecomp.service.";
160 private static final String IMPORTS_FILE_KEY = "file";
161 private static final String TOSCA_INTERFACE_NAME = "-interface.yml";
162 public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate";
163 private static final String FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION = "convertToToscaTemplate - failed to get Default Imports section from configuration";
164 private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
165 private static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS = ConfigurationManager
166 .getConfigurationManager().getConfiguration().getDefaultImports();
167 private static YamlUtil yamlUtil = new YamlUtil();
169 public ToscaExportHandler(){}
171 public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
173 Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertToToscaTemplate(component);
174 if (toscaTemplateRes.isRight()) {
175 return Either.right(toscaTemplateRes.right().value());
178 ToscaTemplate toscaTemplate = toscaTemplateRes.left().value();
179 ToscaRepresentation toscaRepresentation = this.createToscaRepresentation(toscaTemplate);
180 return Either.left(toscaRepresentation);
183 public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component,
184 boolean isAssociatedComponent) {
185 if (null == DEFAULT_IMPORTS) {
186 log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
187 return Either.right(ToscaError.GENERAL_ERROR);
190 ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
191 toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS));
192 Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
193 Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component,
194 toscaTemplate, nodeTypes, isAssociatedComponent);
195 if (toscaTemplateRes.isRight()) {
196 return Either.right(toscaTemplateRes.right().value());
199 toscaTemplate = toscaTemplateRes.left().value();
200 ToscaRepresentation toscaRepresentation = this.createToscaRepresentation(toscaTemplate);
201 return Either.left(toscaRepresentation);
204 public ToscaRepresentation createToscaRepresentation(ToscaTemplate toscaTemplate) {
205 CustomRepresenter representer = new CustomRepresenter();
206 DumperOptions options = new DumperOptions();
207 options.setAllowReadOnlyProperties(false);
208 options.setPrettyFlow(true);
210 options.setDefaultFlowStyle(FlowStyle.FLOW);
211 options.setCanonical(false);
213 representer.addClassTag(toscaTemplate.getClass(), Tag.MAP);
215 representer.setPropertyUtils(new UnsortedPropertyUtils());
216 Yaml yaml = new Yaml(representer, options);
218 String yamlAsString = yaml.dumpAsMap(toscaTemplate);
220 StringBuilder sb = new StringBuilder();
221 sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader());
222 sb.append(yamlAsString);
223 sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactFooter());
225 ToscaRepresentation toscaRepresentation = new ToscaRepresentation();
226 toscaRepresentation.setMainYaml(sb.toString());
227 toscaRepresentation.setDependencies(toscaTemplate.getDependencies());
229 return toscaRepresentation;
232 public Either<ToscaTemplate, ToscaError> getDependencies(Component component) {
233 ToscaTemplate toscaTemplate = new ToscaTemplate(null);
234 Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports = fillImports(component,
236 if (fillImports.isRight()) {
237 return Either.right(fillImports.right().value());
239 return Either.left(fillImports.left().value().left);
242 private Either<ToscaTemplate, ToscaError> convertToToscaTemplate(Component component) {
243 if (null == DEFAULT_IMPORTS) {
244 log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
245 return Either.right(ToscaError.GENERAL_ERROR);
248 log.trace("start tosca export for {}", component.getUniqueId());
249 ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
251 toscaTemplate.setMetadata(convertMetadata(component));
252 toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS));
253 Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
254 if (ModelConverter.isAtomicComponent(component)) {
255 log.trace("convert component as node type");
256 return convertNodeType(new HashMap<>(), component, toscaTemplate, nodeTypes);
258 log.trace("convert component as topology template");
259 return convertToscaTemplate(component, toscaTemplate);
264 private Either<ToscaTemplate, ToscaError> convertToscaTemplate(Component component, ToscaTemplate toscaNode) {
266 Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> importsRes = fillImports(component,
268 if (importsRes.isRight()) {
269 return Either.right(importsRes.right().value());
271 toscaNode = importsRes.left().value().left;
272 Map<String, Component> componentCache = importsRes.left().value().right;
273 Either<Map<String, ToscaNodeType>, ToscaError> nodeTypesMapEither = createProxyNodeTypes(componentCache,
275 if (nodeTypesMapEither.isRight()) {
276 log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
277 nodeTypesMapEither.right().value());
278 return Either.right(nodeTypesMapEither.right().value());
280 Map<String, ToscaNodeType> nodeTypesMap = nodeTypesMapEither.left().value();
281 if (nodeTypesMap != null && !nodeTypesMap.isEmpty()) {
282 toscaNode.setNode_types(nodeTypesMap);
285 Either<Map<String, Object>, ToscaError> proxyInterfaceTypesEither = createProxyInterfaceTypes(component);
286 if (proxyInterfaceTypesEither.isRight()) {
287 log.debug("Failed to populate service proxy local interface types in tosca, error {}",
288 nodeTypesMapEither.right().value());
289 return Either.right(proxyInterfaceTypesEither.right().value());
291 Map<String, Object> proxyInterfaceTypes = proxyInterfaceTypesEither.left().value();
292 if (MapUtils.isNotEmpty(proxyInterfaceTypes)) {
293 toscaNode.setInterface_types(proxyInterfaceTypes);
296 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll();
297 if (dataTypesEither.isRight()) {
298 log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value());
299 return Either.right(ToscaError.GENERAL_ERROR);
301 Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
302 ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
303 List<InputDefinition> inputDef = component.getInputs();
304 Map<String, ToscaProperty> inputs = inputConverter.convertInputs(inputDef, dataTypes);
306 if (!inputs.isEmpty()) {
307 topologyTemplate.setInputs(inputs);
310 List<ComponentInstance> componentInstances = component.getComponentInstances();
311 Map<String, List<ComponentInstanceProperty>> componentInstancesProperties =
312 component.getComponentInstancesProperties();
313 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces =
314 component.getComponentInstancesInterfaces();
315 if (componentInstances != null && !componentInstances.isEmpty()) {
317 Either<Map<String, ToscaNodeTemplate>, ToscaError> nodeTemplates =
318 convertNodeTemplates(component, componentInstances,
319 componentInstancesProperties, componentInstanceInterfaces,
320 componentCache, dataTypes, topologyTemplate);
321 if (nodeTemplates.isRight()) {
322 return Either.right(nodeTemplates.right().value());
324 log.debug("node templates converted");
326 topologyTemplate.setNode_templates(nodeTemplates.left().value());
330 addGroupsToTopologyTemplate(component, topologyTemplate);
333 addPoliciesToTopologyTemplate(component, topologyTemplate);
334 } catch (SdcResourceNotFoundException e) {
335 log.debug("Fail to add policies to topology template:",e);
336 return Either.right(ToscaError.GENERAL_ERROR);
340 SubstitutionMapping substitutionMapping = new SubstitutionMapping();
341 String toscaResourceName;
342 switch (component.getComponentType()) {
344 toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
345 .getMetadataDataDefinition()).getToscaResourceName();
348 toscaResourceName = SERVICE_NODE_TYPE_PREFIX
349 + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
352 log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
353 return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
355 substitutionMapping.setNode_type(toscaResourceName);
357 Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping, componentCache);
358 if (capabilities.isRight()) {
359 return Either.right(capabilities.right().value());
361 substitutionMapping = capabilities.left().value();
363 Either<SubstitutionMapping, ToscaError> requirements = capabilityRequirementConverter
364 .convertSubstitutionMappingRequirements(componentCache, component, substitutionMapping);
365 if (requirements.isRight()) {
366 return Either.right(requirements.right().value());
368 substitutionMapping = requirements.left().value();
370 topologyTemplate.setSubstitution_mappings(substitutionMapping);
372 toscaNode.setTopology_template(topologyTemplate);
374 return Either.left(toscaNode);
377 private void addGroupsToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate) {
378 Map<String, ToscaGroupTemplate> groups = groupExportParser.getGroups(component);
380 topologyTemplate.addGroups(groups);
384 private void addPoliciesToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate)
385 throws SdcResourceNotFoundException {
386 Map<String, ToscaPolicyTemplate> policies = policyExportParser.getPolicies(component);
387 if(policies!= null) {
388 topologyTemplate.addPolicies(policies);
392 private ToscaMetadata convertMetadata(Component component) {
393 return convertMetadata(component, false, null);
396 private ToscaMetadata convertMetadata(Component component, boolean isInstance,
397 ComponentInstance componentInstance) {
398 ToscaMetadata toscaMetadata = new ToscaMetadata();
399 toscaMetadata.setInvariantUUID(component.getInvariantUUID());
400 toscaMetadata.setUUID(component.getUUID());
401 toscaMetadata.setDescription(component.getDescription());
402 toscaMetadata.setName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
404 List<CategoryDefinition> categories = component.getCategories();
405 CategoryDefinition categoryDefinition = categories.get(0);
406 toscaMetadata.setCategory(categoryDefinition.getName());
409 toscaMetadata.setVersion(component.getVersion());
410 toscaMetadata.setCustomizationUUID(componentInstance.getCustomizationUUID());
411 if (componentInstance.getSourceModelInvariant() != null
412 && !componentInstance.getSourceModelInvariant().isEmpty()) {
413 toscaMetadata.setVersion(componentInstance.getComponentVersion());
414 toscaMetadata.setSourceModelInvariant(componentInstance.getSourceModelInvariant());
415 toscaMetadata.setSourceModelUuid(componentInstance.getSourceModelUuid());
416 toscaMetadata.setSourceModelName(componentInstance.getSourceModelName());
417 toscaMetadata.setName(
418 componentInstance.getSourceModelName() + " " + OriginTypeEnum.ServiceProxy.getDisplayValue());
419 toscaMetadata.setDescription(componentInstance.getDescription());
423 switch (component.getComponentType()) {
425 Resource resource = (Resource) component;
427 if (isInstance && componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
428 toscaMetadata.setType(componentInstance.getOriginType().getDisplayValue());
430 toscaMetadata.setType(resource.getResourceType().name());
432 toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
433 toscaMetadata.setResourceVendor(resource.getVendorName());
434 toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
435 toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber());
438 Service service = (Service) component;
439 toscaMetadata.setType(component.getComponentType().getValue());
440 toscaMetadata.setServiceType(service.getServiceType());
441 toscaMetadata.setServiceRole(service.getServiceRole());
442 toscaMetadata.setServiceFunction(service.getServiceFunction());
443 toscaMetadata.setEnvironmentContext(service.getEnvironmentContext());
444 resolveInstantiationTypeAndSetItToToscaMetaData(toscaMetadata, service);
447 toscaMetadata.setServiceEcompNaming(((Service) component).isEcompGeneratedNaming());
448 toscaMetadata.setEcompGeneratedNaming(((Service) component).isEcompGeneratedNaming());
449 toscaMetadata.setNamingPolicy(((Service) component).getNamingPolicy());
453 log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
455 return toscaMetadata;
458 private void resolveInstantiationTypeAndSetItToToscaMetaData(ToscaMetadata toscaMetadata, Service service) {
459 if (service.getInstantiationType() != null) {
460 toscaMetadata.setInstantiationType(service.getInstantiationType());
463 toscaMetadata.setInstantiationType(StringUtils.EMPTY);
467 private Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports(Component component,
468 ToscaTemplate toscaTemplate) {
470 if (null == DEFAULT_IMPORTS) {
471 log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
472 return Either.right(ToscaError.GENERAL_ERROR);
474 Map<String, Component> componentCache = new HashMap<>();
476 if (!ModelConverter.isAtomicComponent(component)) {
477 List<Map<String, Map<String, String>>> additionalImports = toscaTemplate.getImports() == null
478 ? new ArrayList<>(DEFAULT_IMPORTS) : new ArrayList<>(toscaTemplate.getImports());
480 List<Triple<String, String, Component>> dependecies = new ArrayList<>();
482 Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
483 if (isNotEmpty(toscaArtifacts)) {
484 ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
485 if(artifactDefinition != null) {
486 Map<String, Map<String, String>> importsListMember = new HashMap<>();
487 Map<String, String> interfaceFiles = new HashMap<>();
488 interfaceFiles.put(IMPORTS_FILE_KEY, getInterfaceFilename(artifactDefinition.getArtifactName()));
489 StringBuilder keyNameBuilder = new StringBuilder();
490 keyNameBuilder.append(component.getComponentType().toString().toLowerCase()).append("-")
491 .append(component.getName()).append("-interface");
492 importsListMember.put(keyNameBuilder.toString(), interfaceFiles);
493 additionalImports.add(importsListMember);
496 List<ComponentInstance> componentInstances = component.getComponentInstances();
497 if (componentInstances != null && !componentInstances.isEmpty()) {
498 componentInstances.forEach(ci -> createDependency(componentCache, additionalImports, dependecies, ci));
500 toscaTemplate.setDependencies(dependecies);
501 toscaTemplate.setImports(additionalImports);
503 log.debug("currently imports supported for VF and service only");
505 return Either.left(new ImmutablePair<>(toscaTemplate, componentCache));
508 private void createDependency(Map<String, Component> componentCache, List<Map<String, Map<String, String>>> imports,
509 List<Triple<String, String, Component>> dependecies, ComponentInstance ci) {
510 Map<String, String> files = new HashMap<>();
511 Map<String, Map<String, String>> importsListMember = new HashMap<>();
512 StringBuilder keyNameBuilder;
514 Component componentRI = componentCache.get(ci.getComponentUid());
515 if (componentRI == null) {
516 // all resource must be only once!
517 Either<Component, StorageOperationStatus> resource = toscaOperationFacade
518 .getToscaFullElement(ci.getComponentUid());
519 if ((resource.isRight()) && (log.isDebugEnabled())) {
520 log.debug("Failed to fetch resource with id {} for instance {}",ci.getComponentUid() ,ci.getUniqueId());
524 Component fetchedComponent = resource.left().value();
525 componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent);
527 if (ci.getOriginType() == OriginTypeEnum.ServiceProxy){
528 Either<Component, StorageOperationStatus> sourceService = toscaOperationFacade
529 .getToscaFullElement(ci.getSourceModelUid());
530 if (sourceService.isRight() && (log.isDebugEnabled())) {
531 log.debug("Failed to fetch source service with id {} for proxy {}", ci.getSourceModelUid(), ci.getUniqueId());
533 Component fetchedSource = sourceService.left().value();
534 componentCache.put(fetchedSource.getUniqueId(), fetchedSource);
537 componentRI = fetchedComponent;
539 Map<String, ArtifactDefinition> toscaArtifacts = componentRI.getToscaArtifacts();
540 ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE);
541 if (artifactDefinition != null) {
542 String artifactName = artifactDefinition.getArtifactName();
543 files.put(IMPORTS_FILE_KEY, artifactName);
544 keyNameBuilder = new StringBuilder();
545 keyNameBuilder.append(fetchedComponent.getComponentType().toString().toLowerCase());
546 keyNameBuilder.append("-");
547 keyNameBuilder.append(ci.getComponentName());
548 importsListMember.put(keyNameBuilder.toString(), files);
549 imports.add(importsListMember);
550 dependecies.add(new ImmutableTriple<>(artifactName,
551 artifactDefinition.getEsId(), fetchedComponent));
553 if (!ModelConverter.isAtomicComponent(componentRI)) {
554 importsListMember = new HashMap<>();
555 Map<String, String> interfaceFiles = new HashMap<>();
556 interfaceFiles.put(IMPORTS_FILE_KEY, getInterfaceFilename(artifactName));
557 keyNameBuilder.append("-interface");
558 importsListMember.put(keyNameBuilder.toString(), interfaceFiles);
559 imports.add(importsListMember);
565 public static String getInterfaceFilename(String artifactName) {
566 return artifactName.substring(0, artifactName.lastIndexOf('.')) + ToscaExportHandler.TOSCA_INTERFACE_NAME;
569 private Either<ToscaTemplate, ToscaError> convertNodeType(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode,
570 Map<String, ToscaNodeType> nodeTypes) {
571 return convertInterfaceNodeType(componentsCache, component, toscaNode, nodeTypes, false);
574 private Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache,
575 Component component, ToscaTemplate toscaNode,
576 Map<String, ToscaNodeType> nodeTypes,
577 boolean isAssociatedComponent) {
578 log.debug("start convert node type for {}", component.getUniqueId());
579 ToscaNodeType toscaNodeType = createNodeType(component);
581 Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither =
582 interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
583 if(lifecycleTypeEither.isRight()){
584 log.debug("Failed to fetch all interface types :", lifecycleTypeEither.right().value());
585 return Either.right(ToscaError.GENERAL_ERROR);
587 List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value()
590 .map(InterfaceDataDefinition::getType)
591 .collect(Collectors.toList());
592 toscaNode.setInterface_types(addInterfaceTypeElement(component, allGlobalInterfaceTypes));
594 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll();
595 if (dataTypesEither.isRight()) {
596 log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
597 return Either.right(ToscaError.GENERAL_ERROR);
600 Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
602 List<InputDefinition> inputDef = component.getInputs();
603 Map<String, ToscaProperty> mergedProperties = new HashMap<>();
604 interfacesOperationsConverter.addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedComponent);
605 addInputsToProperties(dataTypes, inputDef, mergedProperties);
607 if(CollectionUtils.isNotEmpty(component.getProperties())) {
608 List<PropertyDefinition> properties = component.getProperties();
609 Map<String, ToscaProperty> convertedProperties = properties.stream()
610 .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs()))
611 .collect(Collectors.toMap(PropertyDataDefinition::getName,
612 property -> propertyConvertor.convertProperty(dataTypes, property,
613 PropertyConvertor.PropertyType.PROPERTY)));
614 // merge component properties and inputs properties
615 mergedProperties.putAll(convertedProperties);
617 if (MapUtils.isNotEmpty(mergedProperties)) {
618 toscaNodeType.setProperties(mergedProperties);
621 /* convert private data_types */
622 List<DataTypeDefinition> privateDataTypes = component.getDataTypes();
623 if (CollectionUtils.isNotEmpty(privateDataTypes) ) {
624 Map<String, ToscaDataType> toscaDataTypeMap = new HashMap<>();
625 for (DataTypeDefinition dataType: privateDataTypes) {
626 log.debug("Emitting private data type: component.name={} dataType.name={}",
627 component.getNormalizedName(), dataType.getName());
628 ToscaDataType toscaDataType = new ToscaDataType();
629 toscaDataType.setDerived_from(dataType.getDerivedFromName());
630 toscaDataType.setDescription(dataType.getDescription());
631 toscaDataType.setVersion(dataType.getVersion());
632 if (CollectionUtils.isNotEmpty(dataType.getProperties())) {
633 toscaDataType.setProperties(dataType.getProperties().stream()
634 .collect(Collectors.toMap(
636 s -> propertyConvertor.convertProperty(dataTypes, s, PropertyConvertor.PropertyType.PROPERTY)
639 toscaDataTypeMap.put(dataType.getName(), toscaDataType);
641 toscaNode.setData_types(toscaDataTypeMap);
644 // Extracted to method for code reuse
645 return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
648 private Either<ToscaTemplate, ToscaError> convertReqCapAndTypeName(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode,
649 Map<String, ToscaNodeType> nodeTypes, ToscaNodeType toscaNodeType,
650 Map<String, DataTypeDefinition> dataTypes) {
651 Either<ToscaNodeType, ToscaError> capabilities = convertCapabilities(componentsCache, component, toscaNodeType, dataTypes);
652 if (capabilities.isRight()) {
653 return Either.right(capabilities.right().value());
655 toscaNodeType = capabilities.left().value();
656 log.debug("Capabilities converted for {}", component.getUniqueId());
658 Either<ToscaNodeType, ToscaError> requirements = capabilityRequirementConverter.convertRequirements(componentsCache, component,
660 if (requirements.isRight()) {
661 return Either.right(requirements.right().value());
663 toscaNodeType = requirements.left().value();
664 log.debug("Requirements converted for {}", component.getUniqueId());
666 String toscaResourceName;
667 switch (component.getComponentType()) {
669 toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
670 .getMetadataDataDefinition()).getToscaResourceName();
673 toscaResourceName = SERVICE_NODE_TYPE_PREFIX
674 + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
677 log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
678 return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
681 nodeTypes.put(toscaResourceName, toscaNodeType);
682 toscaNode.setNode_types(nodeTypes);
683 log.debug("finish convert node type for {}", component.getUniqueId());
684 return Either.left(toscaNode);
687 protected Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplates(
689 List<ComponentInstance> componentInstances,
690 Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
691 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces,
692 Map<String, Component> componentCache, Map<String, DataTypeDefinition> dataTypes,
693 ToscaTopolgyTemplate topologyTemplate) {
695 Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplatesRes = null;
696 log.debug("start convert topology template for {} for type {}", component.getUniqueId(),
697 component.getComponentType());
698 Map<String, ToscaNodeTemplate> nodeTemplates = new HashMap<>();
699 Map<String, List<ComponentInstanceInput>> componentInstancesInputs = component.getComponentInstancesInputs();
701 Map<String, ToscaGroupTemplate> groupsMap = null;
702 for (ComponentInstance componentInstance : componentInstances) {
703 ToscaNodeTemplate nodeTemplate = new ToscaNodeTemplate();
704 if (MapUtils.isNotEmpty(componentInstance.getToscaArtifacts())) {
705 nodeTemplate.setArtifacts(convertToNodeTemplateArtifacts(componentInstance.getToscaArtifacts()));
707 nodeTemplate.setType(componentInstance.getToscaComponentName());
708 nodeTemplate.setDirectives(componentInstance.getDirectives());
709 nodeTemplate.setNode_filter(convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter()));
711 Either<Component, Boolean> originComponentRes = capabilityRequirementConverter
712 .getOriginComponent(componentCache, componentInstance);
713 if (originComponentRes.isRight()) {
714 convertNodeTemplatesRes = Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
717 Either<ToscaNodeTemplate, ToscaError> requirements = convertComponentInstanceRequirements(component,
718 componentInstance, component.getComponentInstancesRelations(), nodeTemplate,
719 originComponentRes.left().value(), componentCache);
720 if (requirements.isRight()) {
721 convertNodeTemplatesRes = Either.right(requirements.right().value());
724 String instanceUniqueId = componentInstance.getUniqueId();
725 log.debug("Component instance Requirements converted for instance {}", instanceUniqueId);
727 nodeTemplate = requirements.left().value();
729 Component originalComponent = componentCache.get(componentInstance.getActualComponentUid());
731 if (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy){
732 Component componentOfProxy = componentCache.get(componentInstance.getComponentUid());
733 nodeTemplate.setMetadata(convertMetadata(componentOfProxy, true, componentInstance));
735 nodeTemplate.setMetadata(convertMetadata(originalComponent, true, componentInstance));
738 Either<ToscaNodeTemplate, ToscaError> capabilities = capabilityRequirementConverter
739 .convertComponentInstanceCapabilities(componentInstance, dataTypes, nodeTemplate);
740 if (capabilities.isRight()) {
741 convertNodeTemplatesRes = Either.right(capabilities.right().value());
744 log.debug("Component instance Capabilities converted for instance {}", instanceUniqueId);
746 nodeTemplate = capabilities.left().value();
747 Map<String, Object> props = new HashMap<>();
749 if (originalComponent.getComponentType() == ComponentTypeEnum.RESOURCE) {
750 // Adds the properties of parent component to map
751 addPropertiesOfParentComponent(dataTypes, originalComponent, props);
754 if (null != componentInstancesProperties && componentInstancesProperties.containsKey(instanceUniqueId)) {
755 addPropertiesOfComponentInstance(componentInstancesProperties, dataTypes, instanceUniqueId,
759 if (componentInstancesInputs != null && componentInstancesInputs.containsKey(instanceUniqueId)
760 && !isComponentOfTypeServiceProxy(componentInstance)) {
761 //For service proxy the inputs are already handled under instance properties above
762 addComponentInstanceInputs(dataTypes, componentInstancesInputs, instanceUniqueId,
765 //M3[00001] - NODE TEMPLATE INTERFACES - START
766 handleInstanceInterfaces(componentInstanceInterfaces, componentInstance, dataTypes, nodeTemplate,
767 instanceUniqueId, component);
768 //M3[00001] - NODE TEMPLATE INTERFACES - END
769 if (props != null && !props.isEmpty()) {
770 nodeTemplate.setProperties(props);
773 List<GroupInstance> groupInstances = componentInstance.getGroupInstances();
774 if (groupInstances != null) {
775 if (groupsMap == null) {
776 groupsMap = new HashMap<>();
778 for (GroupInstance groupInst : groupInstances) {
779 boolean addToTosca = true;
781 List<String> artifacts = groupInst.getArtifacts();
782 if (artifacts == null || artifacts.isEmpty()) {
787 ToscaGroupTemplate toscaGroup = groupExportParser.getToscaGroupTemplate(groupInst, componentInstance.getInvariantName());
788 groupsMap.put(groupInst.getName(), toscaGroup);
793 nodeTemplates.put(componentInstance.getName(), nodeTemplate);
795 if (groupsMap != null) {
796 log.debug("instance groups added");
797 topologyTemplate.addGroups(groupsMap);
799 if (component.getComponentType() == ComponentTypeEnum.SERVICE && isNotEmpty(((Service) component).getForwardingPaths())) {
800 log.debug("Starting converting paths for component {}, name {}", component.getUniqueId(),
801 component.getName());
802 ForwardingPathToscaUtil.addForwardingPaths((Service) component, nodeTemplates, capabilityRequirementConverter, componentCache, toscaOperationFacade);
803 log.debug("Finished converting paths for component {}, name {}", component.getUniqueId(),
804 component.getName());
806 if (convertNodeTemplatesRes == null) {
807 convertNodeTemplatesRes = Either.left(nodeTemplates);
809 log.debug("finish convert topology template for {} for type {}", component.getUniqueId(),
810 component.getComponentType());
811 return convertNodeTemplatesRes;
814 private void handleInstanceInterfaces(
815 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces,
816 ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, ToscaNodeTemplate nodeTemplate,
817 String instanceUniqueId,
818 Component parentComponent) {
820 Map<String, Object> interfaces;
822 // we need to handle service proxy interfaces
823 if(isComponentOfTypeServiceProxy(componentInstance)) {
824 if(MapUtils.isEmpty(componentInstanceInterfaces)
825 || !componentInstanceInterfaces.containsKey(instanceUniqueId)) {
828 List<ComponentInstanceInterface> currServiceInterfaces =
829 componentInstanceInterfaces.get(instanceUniqueId);
831 Map<String, InterfaceDefinition> tmpInterfaces = new HashMap<>();
832 currServiceInterfaces.forEach(instInterface -> tmpInterfaces.put(instInterface
833 .getUniqueId(), instInterface));
835 interfaces = interfacesOperationsConverter
836 .getInterfacesMap(parentComponent, componentInstance, tmpInterfaces, dataTypes, true, true);
840 getComponentInstanceInterfaceInstances(componentInstanceInterfaces,
841 componentInstance, instanceUniqueId);
843 nodeTemplate.setInterfaces(interfaces);
846 private boolean isComponentOfTypeServiceProxy(ComponentInstance componentInstance) {
847 return Objects.nonNull(componentInstance.getOriginType())
848 && componentInstance.getOriginType().getValue().equals("Service Proxy");
851 //M3[00001] - NODE TEMPLATE INTERFACES - START
852 private Map<String, Object> getComponentInstanceInterfaceInstances(Map<String, List<ComponentInstanceInterface>> componentInstancesInterfaces,
853 ComponentInstance componentInstance,
854 String instanceUniqueId) {
855 if(MapUtils.isEmpty(componentInstancesInterfaces)) {
859 List<ComponentInstanceInterface> componentInstanceInterfaces =
860 componentInstancesInterfaces.get(instanceUniqueId);
862 if(CollectionUtils.isEmpty(componentInstanceInterfaces)) {
866 Map<String, Object> interfaces = new HashMap<>();
867 for(ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaces) {
868 interfaces.put(componentInstanceInterface.getInterfaceId(),
869 removeOperationsKeyFromInterface(componentInstanceInterface.getInterfaceInstanceDataDefinition()));
872 componentInstance.setInterfaces(interfaces);
877 private void addComponentInstanceInputs(Map<String, DataTypeDefinition> dataTypes,
878 Map<String, List<ComponentInstanceInput>> componentInstancesInputs,
879 String instanceUniqueId, Map<String, Object> props) {
881 List<ComponentInstanceInput> instanceInputsList = componentInstancesInputs.get(instanceUniqueId);
882 if (instanceInputsList != null) {
883 instanceInputsList.forEach(input -> {
885 Supplier<String> supplier = () -> input.getValue() != null && !Objects.isNull(input.getValue())
886 ? input.getValue() : input.getDefaultValue();
887 propertyConvertor.convertAndAddValue(dataTypes, props, input, supplier);
892 private void addPropertiesOfComponentInstance(
893 Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
894 Map<String, DataTypeDefinition> dataTypes, String instanceUniqueId,
895 Map<String, Object> props) {
897 if (isNotEmpty(componentInstancesProperties)) {
898 componentInstancesProperties.get(instanceUniqueId)
899 // Converts and adds each value to property map
900 .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
905 private void addPropertiesOfParentComponent(Map<String, DataTypeDefinition> dataTypes,
906 Component componentOfInstance, Map<String, Object> props) {
908 List<PropertyDefinition> componentProperties = componentOfInstance.getProperties();
909 if (isNotEmpty(componentProperties)) {
910 componentProperties.stream()
911 // Filters out properties with empty default values
912 .filter(prop -> StringUtils.isNotEmpty(prop.getDefaultValue()))
913 // Converts and adds each value to property map
914 .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
915 prop::getDefaultValue));
921 * @param componentInstance
926 private void convertAndAddValue(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance,
927 Map<String, Object> props, PropertyDefinition prop, Supplier<String> supplier) {
928 Object convertedValue = convertValue(dataTypes, componentInstance, prop, supplier);
929 if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue)) {
930 props.put(prop.getName(), convertedValue);
934 private <T extends PropertyDefinition> Object convertValue(Map<String, DataTypeDefinition> dataTypes,
935 ComponentInstance componentInstance, T input, Supplier<String> supplier) {
936 log.debug("Convert property or input value {} for instance {}", input.getName(),
937 componentInstance.getUniqueId());
938 String propertyType = input.getType();
939 String innerType = null;
940 if (input.getSchema() != null && input.getSchema().getProperty() != null) {
941 innerType = input.getSchema().getProperty().getType();
943 return propertyConvertor.convertToToscaObject(input, supplier.get(), dataTypes, true);
946 private ToscaNodeType createNodeType(Component component) {
947 ToscaNodeType toscaNodeType = new ToscaNodeType();
948 if (ModelConverter.isAtomicComponent(component)) {
949 if (((Resource) component).getDerivedFrom() != null) {
950 toscaNodeType.setDerived_from(((Resource) component).getDerivedFrom().get(0));
952 toscaNodeType.setDescription(component.getDescription());
954 String derivedFrom = null != component.getDerivedFromGenericType() ? component.getDerivedFromGenericType()
955 : "tosca.nodes.Root";
956 toscaNodeType.setDerived_from(derivedFrom);
958 return toscaNodeType;
961 private Either<Map<String, Object>, ToscaError> createProxyInterfaceTypes(Component container) {
963 Map<String, Object> proxyInterfaceTypes = new HashMap<>();
964 Either<Map<String, Object>, ToscaError> res = Either.left(proxyInterfaceTypes);
965 List<ComponentInstance> componentInstances = container.getComponentInstances();
966 if (CollectionUtils.isEmpty(componentInstances)) {
969 Map<String, ComponentInstance> serviceProxyInstanceList = new HashMap<>();
970 componentInstances.stream()
971 .filter(this::isComponentOfTypeServiceProxy)
972 .forEach(inst -> serviceProxyInstanceList.put(inst.getToscaComponentName(), inst));
973 if (MapUtils.isEmpty(serviceProxyInstanceList)) {
976 for (Entry<String, ComponentInstance> entryProxy : serviceProxyInstanceList.entrySet()) {
977 Component serviceComponent;
978 ComponentParametersView componentParametersView = new ComponentParametersView();
979 componentParametersView.disableAll();
980 componentParametersView.setIgnoreInterfaces(false);
981 Either<Component, StorageOperationStatus> service = toscaOperationFacade
982 .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
983 if (service.isRight()) {
984 log.debug("Failed to fetch original service component with id {} for instance {}",
985 entryProxy.getValue().getSourceModelUid(), entryProxy.getValue().getName());
986 return Either.right(ToscaError.GENERAL_ERROR);
988 serviceComponent = service.left().value();
991 Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither =
992 interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
993 if(lifecycleTypeEither.isRight()){
994 log.debug("Failed to retrieve global interface types :", lifecycleTypeEither.right().value());
995 return Either.right(ToscaError.GENERAL_ERROR);
998 List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value().values().stream()
999 .map(InterfaceDataDefinition::getType)
1000 .collect(Collectors.toList());
1001 //Add interface types for local interfaces in the original service component for proxy
1002 Map<String, Object> localInterfaceTypes = addInterfaceTypeElement(serviceComponent,
1003 allGlobalInterfaceTypes);
1004 if (MapUtils.isNotEmpty(localInterfaceTypes)) {
1005 proxyInterfaceTypes.putAll(localInterfaceTypes);
1009 return Either.left(proxyInterfaceTypes);
1012 private Either<Map<String, ToscaNodeType>, ToscaError> createProxyNodeTypes(Map<String, Component> componentCache,
1013 Component container) {
1015 Map<String, ToscaNodeType> nodeTypesMap = new HashMap<>();
1016 Either<Map<String, ToscaNodeType>, ToscaError> res = Either.left(nodeTypesMap);
1018 List<ComponentInstance> componentInstances = container.getComponentInstances();
1020 if (componentInstances == null || componentInstances.isEmpty()) {
1023 Map<String, ComponentInstance> serviceProxyInstanceList = new HashMap<>();
1024 List<ComponentInstance> proxyInst = componentInstances.stream()
1025 .filter(p -> p.getOriginType().name().equals(OriginTypeEnum.ServiceProxy.name()))
1026 .collect(Collectors.toList());
1027 if (proxyInst != null && !proxyInst.isEmpty()) {
1028 for (ComponentInstance inst : proxyInst) {
1029 serviceProxyInstanceList.put(inst.getToscaComponentName(), inst);
1033 if (serviceProxyInstanceList.isEmpty()) {
1036 Either<Resource, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade
1037 .getLatestByName("serviceProxy");
1038 if (serviceProxyOrigin.isRight()) {
1039 log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
1040 serviceProxyOrigin.right().value());
1041 return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
1043 Component origComponent = serviceProxyOrigin.left().value();
1045 for (Entry<String, ComponentInstance> entryProxy : serviceProxyInstanceList.entrySet()) {
1046 Component serviceComponent = null;
1047 ComponentParametersView componentParametersView = new ComponentParametersView();
1048 componentParametersView.disableAll();
1049 componentParametersView.setIgnoreCategories(false);
1050 componentParametersView.setIgnoreProperties(false);
1051 componentParametersView.setIgnoreInputs(false);
1052 componentParametersView.setIgnoreInterfaces(false);
1053 componentParametersView.setIgnoreRequirements(false);
1054 Either<Component, StorageOperationStatus> service = toscaOperationFacade
1055 .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
1056 if (service.isRight()) {
1057 log.debug("Failed to fetch resource with id {} for instance {}", entryProxy.getValue().getSourceModelUid(), entryProxy.getValue().getName());
1059 serviceComponent = service.left().value();
1062 ToscaNodeType toscaNodeType = createProxyNodeType(componentCache, origComponent, serviceComponent,
1063 entryProxy.getValue());
1064 nodeTypesMap.put(entryProxy.getKey(), toscaNodeType);
1067 return Either.left(nodeTypesMap);
1070 private ToscaNodeType createProxyNodeType(Map<String, Component> componentCache , Component origComponent,
1071 Component proxyComponent, ComponentInstance instance) {
1072 ToscaNodeType toscaNodeType = new ToscaNodeType();
1073 String derivedFrom = ((Resource) origComponent).getToscaResourceName();
1075 toscaNodeType.setDerived_from(derivedFrom);
1076 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll();
1077 if (dataTypesEither.isRight()) {
1078 log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value());
1080 Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
1081 Map<String, ToscaCapability> capabilities = this.capabilityRequirementConverter
1082 .convertProxyCapabilities(componentCache, instance, dataTypes);
1084 if (MapUtils.isNotEmpty(capabilities)) {
1085 toscaNodeType.setCapabilities(capabilities);
1087 List<Map<String, ToscaRequirement>> proxyNodeTypeRequirements = this.capabilityRequirementConverter
1088 .convertProxyRequirements(componentCache, instance);
1089 if (CollectionUtils.isNotEmpty(proxyNodeTypeRequirements)) {
1090 toscaNodeType.setRequirements(proxyNodeTypeRequirements);
1092 Optional<Map<String, ToscaProperty>> proxyProperties = getProxyNodeTypeProperties(proxyComponent, dataTypes);
1093 proxyProperties.ifPresent(toscaNodeType::setProperties);
1095 Optional<Map<String, Object>> proxyInterfaces = getProxyNodeTypeInterfaces(proxyComponent, dataTypes);
1096 proxyInterfaces.ifPresent(toscaNodeType::setInterfaces);
1098 return toscaNodeType;
1101 private Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceRequirements(Component component,
1102 ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations,
1103 ToscaNodeTemplate nodeTypeTemplate, Component originComponent, Map<String, Component> componentCache) {
1105 List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
1106 if (!addRequirements(component, componentInstance, relations, originComponent, toscaRequirements, componentCache)) {
1107 log.debug("Failed to convert component instance requirements for the component instance {}. ",
1108 componentInstance.getName());
1109 return Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
1111 if (!toscaRequirements.isEmpty()) {
1112 nodeTypeTemplate.setRequirements(toscaRequirements);
1114 log.debug("Finished to convert requirements for the node type {} ", componentInstance.getName());
1115 return Either.left(nodeTypeTemplate);
1118 private boolean addRequirements(Component component, ComponentInstance componentInstance,
1119 List<RequirementCapabilityRelDef> relations, Component originComponent,
1120 List<Map<String, ToscaTemplateRequirement>> toscaRequirements, Map<String, Component> componentCache) {
1121 List<RequirementCapabilityRelDef> filteredRelations = relations.stream()
1122 .filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).collect(Collectors.toList());
1123 return isEmpty(filteredRelations) ||
1124 filteredRelations.stream()
1125 .allMatch(rel -> addRequirement(componentInstance, originComponent, component.getComponentInstances(), rel, toscaRequirements, componentCache));
1128 private boolean addRequirement(ComponentInstance fromInstance, Component fromOriginComponent,
1129 List<ComponentInstance> instancesList, RequirementCapabilityRelDef rel,
1130 List<Map<String, ToscaTemplateRequirement>> toscaRequirements, Map<String, Component> componentCache) {
1132 boolean result = true;
1133 Map<String, List<RequirementDefinition>> reqMap = fromOriginComponent.getRequirements();
1134 RelationshipInfo reqAndRelationshipPair = rel.getRelationships().get(0).getRelation();
1135 Either<Component, StorageOperationStatus> getOriginRes = null;
1136 Optional<RequirementDefinition> reqOpt = Optional.empty();
1137 Component toOriginComponent = null;
1138 Optional<CapabilityDefinition> capOpt = Optional.empty();
1140 ComponentInstance toInstance = instancesList.stream().filter(i -> rel.getToNode().equals(i.getUniqueId()))
1141 .findFirst().orElse(null);
1142 if (toInstance == null) {
1143 log.debug("Failed to find a relation from the node {} to the node {}", fromInstance.getName(),
1148 reqOpt = findRequirement(fromOriginComponent, reqMap, reqAndRelationshipPair, fromInstance.getUniqueId());
1149 if (!reqOpt.isPresent()) {
1150 log.debug("Failed to find a requirement with uniqueId {} on a component with uniqueId {}",
1151 reqAndRelationshipPair.getRequirementUid(), fromOriginComponent.getUniqueId());
1156 ComponentParametersView filter = new ComponentParametersView(true);
1157 filter.setIgnoreComponentInstances(false);
1158 filter.setIgnoreCapabilities(false);
1159 filter.setIgnoreGroups(false);
1160 getOriginRes = toscaOperationFacade.getToscaElement(toInstance.getActualComponentUid(), filter);
1161 if (getOriginRes.isRight()) {
1162 log.debug("Failed to build substituted name for the requirement {}. Failed to get an origin component with uniqueId {}",
1163 reqOpt.get().getName(), toInstance.getActualComponentUid());
1168 toOriginComponent = getOriginRes.left().value();
1169 capOpt = toOriginComponent.getCapabilities().get(reqOpt.get().getCapability()).stream()
1170 .filter(c -> isCapabilityBelongToRelation(reqAndRelationshipPair, c)).findFirst();
1171 if (!capOpt.isPresent()) {
1172 capOpt = findCapability(reqAndRelationshipPair, toOriginComponent, fromOriginComponent, reqOpt.get());
1173 if(!capOpt.isPresent()){
1175 log.debug("Failed to find a capability with name {} on a component with uniqueId {}",
1176 reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
1181 result = buildAndAddRequirement(toscaRequirements, fromOriginComponent, toOriginComponent, capOpt.get(),
1182 reqOpt.get(), reqAndRelationshipPair, toInstance, componentCache);
1187 private boolean isCapabilityBelongToRelation(RelationshipInfo reqAndRelationshipPair, CapabilityDefinition capability) {
1188 return capability.getName().equals(reqAndRelationshipPair.getCapability()) && (capability.getOwnerId() !=null && capability.getOwnerId().equals(reqAndRelationshipPair.getCapabilityOwnerId()));
1191 private Optional<CapabilityDefinition> findCapability(RelationshipInfo reqAndRelationshipPair, Component toOriginComponent, Component fromOriginComponent, RequirementDefinition requirement) {
1192 Optional<CapabilityDefinition> cap = toOriginComponent.getCapabilities().get(requirement.getCapability()).stream().filter(c -> c.getType().equals(requirement.getCapability())).findFirst();
1193 if (!cap.isPresent()) {
1194 log.debug("Failed to find a capability with name {} on a component with uniqueId {}", reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
1199 private boolean buildAndAddRequirement(List<Map<String, ToscaTemplateRequirement>> toscaRequirements, Component fromOriginComponent, Component toOriginComponent, CapabilityDefinition capability, RequirementDefinition requirement, RelationshipInfo reqAndRelationshipPair, ComponentInstance toInstance, Map<String, Component> componentCache) {
1200 List<String> reducedPath = capability.getPath();
1201 if(capability.getOwnerId() !=null){
1202 reducedPath = capabilityRequirementConverter.getReducedPathByOwner(capability.getPath() , capability.getOwnerId() );
1204 Either<String, Boolean> buildCapNameRes = capabilityRequirementConverter.buildSubstitutedName(componentCache,
1205 toOriginComponent, reducedPath, reqAndRelationshipPair.getCapability(), capability.getPreviousName());
1206 if (buildCapNameRes.isRight()) {
1208 "Failed to build a substituted capability name for the capability with name {} on a component with uniqueId {}",
1209 reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
1212 Either<String, Boolean> buildReqNameRes = capabilityRequirementConverter.buildSubstitutedName(componentCache, fromOriginComponent,
1213 requirement.getPath(), reqAndRelationshipPair.getRequirement(), requirement.getPreviousName());
1214 if (buildReqNameRes.isRight()) {
1216 "Failed to build a substituted requirement name for the requirement with name {} on a component with uniqueId {}",
1217 reqAndRelationshipPair.getRequirement(), fromOriginComponent.getUniqueId());
1220 ToscaTemplateRequirement toscaRequirement = new ToscaTemplateRequirement();
1221 Map<String, ToscaTemplateRequirement> toscaReqMap = new HashMap<>();
1222 toscaRequirement.setNode(toInstance.getName());
1223 toscaRequirement.setCapability(buildCapNameRes.left().value());
1224 toscaReqMap.put(buildReqNameRes.left().value(), toscaRequirement);
1225 toscaRequirements.add(toscaReqMap);
1229 private Optional<RequirementDefinition> findRequirement(Component fromOriginComponent, Map<String, List<RequirementDefinition>> reqMap, RelationshipInfo reqAndRelationshipPair, String fromInstanceId) {
1230 for(List<RequirementDefinition> reqList: reqMap.values()){
1231 Optional<RequirementDefinition> reqOpt = reqList.stream().filter(r -> isRequirementBelongToRelation(fromOriginComponent, reqAndRelationshipPair, r, fromInstanceId)).findFirst();
1232 if(reqOpt.isPresent()){
1236 return Optional.empty();
1240 * Allows detecting the requirement belonging to the received relationship
1241 * The detection logic is: A requirement belongs to a relationship IF 1.The
1242 * name of the requirement equals to the "requirement" field of the
1243 * relation; AND 2. In case of a non-atomic resource, OwnerId of the
1244 * requirement equals to requirementOwnerId of the relation OR uniqueId of
1245 * toInstance equals to capabilityOwnerId of the relation
1247 private boolean isRequirementBelongToRelation(Component originComponent, RelationshipInfo reqAndRelationshipPair, RequirementDefinition requirement, String fromInstanceId) {
1248 if (!StringUtils.equals(requirement.getName(), reqAndRelationshipPair.getRequirement())) {
1249 log.debug("Failed to find a requirement with name {} and reqAndRelationshipPair {}",
1250 requirement.getName(), reqAndRelationshipPair.getRequirement());
1253 return ModelConverter.isAtomicComponent(originComponent) ||
1254 isRequirementBelongToOwner(reqAndRelationshipPair, requirement, fromInstanceId, originComponent);
1257 private boolean isRequirementBelongToOwner(RelationshipInfo reqAndRelationshipPair, RequirementDefinition requirement, String fromInstanceId, Component originComponent) {
1258 return StringUtils.equals(requirement.getOwnerId(), reqAndRelationshipPair.getRequirementOwnerId())
1259 || (isCvfc(originComponent) && StringUtils.equals(fromInstanceId, reqAndRelationshipPair.getRequirementOwnerId())
1260 || StringUtils.equals(requirement.getOwnerId(), originComponent.getUniqueId()));
1263 private boolean isCvfc(Component component) {
1264 return component.getComponentType() == ComponentTypeEnum.RESOURCE &&
1265 ((Resource) component).getResourceType() == ResourceTypeEnum.CVFC;
1268 private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component,
1269 SubstitutionMapping substitutionMappings, Map<String, Component> componentCache) {
1271 Either<SubstitutionMapping, ToscaError> result = Either.left(substitutionMappings);
1272 Either<Map<String, String[]>, ToscaError> toscaCapabilitiesRes = capabilityRequirementConverter
1273 .convertSubstitutionMappingCapabilities(componentCache, component);
1274 if (toscaCapabilitiesRes.isRight()) {
1275 result = Either.right(toscaCapabilitiesRes.right().value());
1276 log.debug("Failed convert capabilities for the component {}. ", component.getName());
1277 } else if (isNotEmpty(toscaCapabilitiesRes.left().value())) {
1278 substitutionMappings.setCapabilities(toscaCapabilitiesRes.left().value());
1279 log.debug("Finish convert capabilities for the component {}. ", component.getName());
1281 log.debug("Finished to convert capabilities for the component {}. ", component.getName());
1285 private Either<ToscaNodeType, ToscaError> convertCapabilities(Map<String, Component> componentsCache, Component component, ToscaNodeType nodeType,
1286 Map<String, DataTypeDefinition> dataTypes) {
1287 Map<String, ToscaCapability> toscaCapabilities = capabilityRequirementConverter.convertCapabilities(componentsCache, component,
1289 if (!toscaCapabilities.isEmpty()) {
1290 nodeType.setCapabilities(toscaCapabilities);
1292 log.debug("Finish convert Capabilities for node type");
1294 return Either.left(nodeType);
1297 private Map<String, ToscaTemplateArtifact> convertToNodeTemplateArtifacts(Map<String, ToscaArtifactDataDefinition> artifacts) {
1298 if (artifacts == null) {
1301 Map<String, ToscaTemplateArtifact> arts = new HashMap<>();
1302 for (Map.Entry<String, ToscaArtifactDataDefinition> entry : artifacts.entrySet()) {
1303 ToscaTemplateArtifact artifact = new ToscaTemplateArtifact();
1304 artifact.setFile(entry.getValue().getFile());
1305 artifact.setType(entry.getValue().getType());
1306 arts.put(entry.getKey(), artifact);
1311 protected NodeFilter convertToNodeTemplateNodeFilterComponent(CINodeFilterDataDefinition inNodeFilter) {
1312 if (inNodeFilter == null){
1315 NodeFilter nodeFilter = new NodeFilter();
1317 ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities =
1318 inNodeFilter.getCapabilities();
1320 ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties = inNodeFilter.getProperties();
1322 List<Map<String, CapabilityFilter>> capabilitiesCopy = new ArrayList<>();
1323 List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
1325 copyNodeFilterCapabilitiesTemplate(origCapabilities, capabilitiesCopy);
1326 copyNodeFilterProperties(origProperties, propertiesCopy);
1328 if(CollectionUtils.isNotEmpty(capabilitiesCopy)) {
1329 nodeFilter.setCapabilities(capabilitiesCopy);
1332 if(CollectionUtils.isNotEmpty(propertiesCopy)) {
1333 nodeFilter.setProperties(propertiesCopy);
1336 nodeFilter.setTosca_id(cloneToscaId(inNodeFilter.getTosca_id()));
1339 nodeFilter = (NodeFilter) cloneObjectFromYml(nodeFilter, NodeFilter.class);
1344 private Object cloneToscaId(Object toscaId) {
1345 return Objects.isNull(toscaId) ? null
1346 : cloneObjectFromYml(toscaId, toscaId.getClass());
1350 private Object cloneObjectFromYml(Object objToClone, Class classOfObj) {
1351 String objectAsYml = yamlUtil.objectToYaml(objToClone);
1352 return yamlUtil.yamlToObject(objectAsYml, classOfObj);
1354 private void copyNodeFilterCapabilitiesTemplate(
1355 ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities,
1356 List<Map<String, CapabilityFilter>> capabilitiesCopy) {
1357 if(origCapabilities == null || origCapabilities.getListToscaDataDefinition() == null ||
1358 origCapabilities.getListToscaDataDefinition().isEmpty() ) {
1361 for(RequirementNodeFilterCapabilityDataDefinition capability : origCapabilities.getListToscaDataDefinition()) {
1362 Map<String, CapabilityFilter> capabilityFilterCopyMap = new HashMap<>();
1363 CapabilityFilter capabilityFilter = new CapabilityFilter();
1364 List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
1365 copyNodeFilterProperties(capability.getProperties(), propertiesCopy);
1366 capabilityFilter.setProperties(propertiesCopy);
1367 capabilityFilterCopyMap.put(capability.getName(), capabilityFilter);
1368 capabilitiesCopy.add(capabilityFilterCopyMap);
1372 private List<Object> copyNodeFilterProperty(List<Object> propertyList) {
1373 String listAsString = yamlUtil.objectToYaml(propertyList);
1374 return yamlUtil.yamlToObject(listAsString, List.class);
1378 private void copyNodeFilterProperties(
1379 ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties,
1380 List<Map<String, List<Object>>> propertiesCopy) {
1381 if(origProperties == null || origProperties.getListToscaDataDefinition() == null ||
1382 origProperties.isEmpty()) {
1385 Map<String, List<Object>> propertyMapCopy = new HashMap<>();
1386 for(RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : origProperties.getListToscaDataDefinition()) {
1387 for(String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
1388 Map propertyValObj = new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
1389 String propertyName = propertyDataDefinition.getName();
1390 if (propertyMapCopy.containsKey(propertyName)){
1391 addPropertyConstraintValueToList(propertyName, propertyValObj, propertyMapCopy.get(propertyName));
1393 if (propertyName != null) {
1394 List propsList = new ArrayList();
1395 addPropertyConstraintValueToList(propertyName, propertyValObj, propsList);
1396 propertyMapCopy.put(propertyName, propsList);
1398 propertyMapCopy.putAll(propertyValObj);
1403 propertyMapCopy.entrySet().stream().forEach(entry ->
1404 addCalculatedConstraintsIntoPropertiesList(propertiesCopy, entry));
1407 private void addPropertyConstraintValueToList(String propertyName, Map propertyValObj, List propsList) {
1408 if(propertyValObj.containsKey(propertyName)) {
1409 propsList.add(propertyValObj.get(propertyName));
1411 propsList.add(propertyValObj);
1417 private void addCalculatedConstraintsIntoPropertiesList(List<Map<String, List<Object>>> propertiesCopy,
1418 Entry<String, List<Object>> entry) {
1419 Map<String, List<Object>> tempMap = new HashMap<>();
1420 tempMap.put(entry.getKey(), entry.getValue());
1421 propertiesCopy.add(tempMap);
1424 private static class CustomRepresenter extends Representer {
1425 CustomRepresenter() {
1427 // null representer is exceptional and it is stored as an instance
1429 this.nullRepresenter = new RepresentNull();
1434 protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
1436 if (propertyValue == null) {
1439 // skip not relevant for Tosca property
1440 if ("dependencies".equals(property.getName())) {
1443 NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
1445 return "_defaultp_".equals(property.getName())
1446 ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
1450 protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
1451 // remove the bean type from the output yaml (!! ...)
1452 if (!classTags.containsKey(javaBean.getClass())) {
1453 addClassTag(javaBean.getClass(), Tag.MAP);
1456 return super.representJavaBean(properties, javaBean);
1459 private class RepresentNull implements Represent {
1461 public Node representData(Object data) {
1462 // possible values are here http://yaml.org/type/null.html
1463 return representScalar(Tag.NULL, "");
1468 private static class UnsortedPropertyUtils extends PropertyUtils {
1470 protected Set<Property> createPropertySet(Class type, BeanAccess bAccess)
1471 throws IntrospectionException {
1472 Collection<Property> fields = getPropertiesMap(type, BeanAccess.FIELD).values();
1473 return new LinkedHashSet<>(fields);
1477 private Object removeOperationsKeyFromInterface(Object interfaceInstanceDataDefinition) {
1478 ObjectMapper objectMapper = new ObjectMapper();
1479 objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
1481 Map<String, Object> interfaceAsMap = ServiceUtils.getObjectAsMap(interfaceInstanceDataDefinition);
1482 Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.remove("operations");
1483 interfaceAsMap.remove("empty");
1485 if(MapUtils.isNotEmpty(operations)) {
1486 interfaceAsMap.putAll(operations);
1489 Object interfaceObject = objectMapper.convertValue(interfaceAsMap, Object.class);
1491 return interfaceObject;
1495 Optional<Map<String, ToscaProperty>> getProxyNodeTypeProperties(Component proxyComponent,
1496 Map<String, DataTypeDefinition>
1498 if (Objects.isNull(proxyComponent)) {
1499 return Optional.empty();
1501 Map<String, ToscaProperty> proxyProperties = new HashMap<>();
1502 addInputsToProperties(dataTypes, proxyComponent.getInputs(), proxyProperties);
1503 if (CollectionUtils.isNotEmpty(proxyComponent.getProperties())) {
1504 proxyProperties.putAll(proxyComponent.getProperties().stream()
1505 .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition,
1506 proxyComponent.getInputs()))
1507 .collect(Collectors.toMap(PropertyDataDefinition::getName,
1508 property -> propertyConvertor.convertProperty(dataTypes, property,
1509 PropertyConvertor.PropertyType.PROPERTY))));
1511 return MapUtils.isNotEmpty(proxyProperties) ? Optional.of(proxyProperties) : Optional.empty();
1514 void addInputsToProperties(Map<String, DataTypeDefinition> dataTypes,
1515 List<InputDefinition> componentInputs,
1516 Map<String, ToscaProperty> mergedProperties) {
1517 if (CollectionUtils.isEmpty(componentInputs)) {
1520 for(InputDefinition input : componentInputs) {
1521 ToscaProperty property = propertyConvertor.convertProperty(dataTypes, input,
1522 PropertyConvertor.PropertyType.INPUT);
1523 mergedProperties.put(input.getName(), property);
1527 Optional<Map<String, Object>> getProxyNodeTypeInterfaces(Component proxyComponent,
1528 Map<String, DataTypeDefinition> dataTypes) {
1529 if (Objects.isNull(proxyComponent) || MapUtils.isEmpty(proxyComponent.getInterfaces())) {
1530 return Optional.empty();
1532 Map<String, InterfaceDefinition> proxyComponentInterfaces = proxyComponent.getInterfaces();
1533 //Unset artifact path for operation implementation for proxy node types as for operations with artifacts it is
1534 // always available in the proxy node template
1535 removeOperationImplementationForProxyNodeType(proxyComponentInterfaces);
1536 return Optional.ofNullable(interfacesOperationsConverter
1537 .getInterfacesMap(proxyComponent, null, proxyComponentInterfaces, dataTypes,
1541 private static void removeOperationImplementationForProxyNodeType(
1542 Map<String, InterfaceDefinition> proxyComponentInterfaces) {
1543 if (MapUtils.isEmpty(proxyComponentInterfaces)) {
1546 proxyComponentInterfaces.values().stream().map(InterfaceDataDefinition::getOperations)
1547 .filter(MapUtils::isNotEmpty)
1548 .forEach(operations -> operations.values().forEach(operation -> operation.setImplementation(null)));