2 * ============LICENSE_START=======================================================
3 * sdc-distribution-client
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.tosca.parser.impl;
24 import java.util.Map.Entry;
25 import java.util.stream.Collectors;
27 import org.apache.commons.lang3.tuple.ImmutablePair;
28 import org.apache.commons.lang3.tuple.Pair;
29 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
30 import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
31 import org.openecomp.sdc.tosca.parser.utils.SdcToscaUtility;
32 import org.openecomp.sdc.toscaparser.api.Group;
33 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
34 import org.openecomp.sdc.toscaparser.api.Property;
35 import org.openecomp.sdc.toscaparser.api.SubstitutionMappings;
36 import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
37 import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
38 import org.openecomp.sdc.toscaparser.api.elements.Metadata;
39 import org.openecomp.sdc.toscaparser.api.elements.NodeType;
40 import org.openecomp.sdc.toscaparser.api.functions.Function;
41 import org.openecomp.sdc.toscaparser.api.parameters.Input;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 import static org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID;
47 public class SdcCsarHelperImpl implements ISdcCsarHelper {
49 private static final String PATH_DELIMITER = "#";
50 private static final String CUSTOMIZATION_UUID = "customizationUUID";
51 private ToscaTemplate toscaTemplate;
52 private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
54 public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) {
55 this.toscaTemplate = toscaTemplate;
59 //Sunny flow - covered with UT, flat and nested
60 public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
61 if (nodeTemplate == null) {
62 log.error("getNodeTemplatePropertyLeafValue - nodeTemplate is null");
65 if (GeneralUtility.isEmptyString(leafValuePath)) {
66 log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty");
69 String[] split = getSplittedPath(leafValuePath);
70 LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
71 Object property = processProperties(split, properties);
72 return property == null || property instanceof Function ? null : String.valueOf(property);
76 public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String leafValuePath) {
77 if (nodeTemplate == null) {
78 log.error("getNodeTemplatePropertyAsObject - nodeTemplate is null");
81 if (GeneralUtility.isEmptyString(leafValuePath)) {
82 log.error("getNodeTemplatePropertyAsObject - leafValuePath is null or empty");
85 String[] split = getSplittedPath(leafValuePath);
86 LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
87 return processProperties(split, properties);
90 public Map<String, Map<String, Object>> getCpPropertiesFromVfcAsObject(NodeTemplate vfc) {
92 log.error("getCpPropertiesFromVfc - vfc is null");
93 return new HashMap<>();
96 String presetProperty = "_ip_requirements";
97 Map<String, Map<String, Object>> cps = new HashMap<>();
99 Map<String, Property> props = vfc.getProperties();
101 // find all port names by pre-set property (ip_requirements)
102 for (Map.Entry<String, Property> entry : props.entrySet()) {
103 if (entry.getKey().endsWith(presetProperty)) {
104 String portName = entry.getKey().replaceAll(presetProperty, "");
105 cps.put(portName, new HashMap<>());
109 if (cps.size() > 0) {
110 // ports found - find all their properties
111 for (String portName : cps.keySet()) {
112 for (Map.Entry<String, Property> property: props.entrySet()) {
113 if (property.getKey().startsWith(portName)) {
114 String portProperty = property.getKey().replaceFirst(portName + "_", "");
115 if (property.getValue() != null) {
116 cps.get(portName).put(portProperty, property.getValue().getValue());
127 public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc) {
130 log.error("getCpPropertiesFromVfc - vfc is null");
131 return new HashMap<>();
134 String presetProperty = "_ip_requirements";
135 Map<String, Map<String, Object>> cps = new HashMap<>();
137 Map<String, Property> props = vfc.getProperties();
139 // find all port names by pre-set property (ip_requirements)
140 for (Map.Entry<String, Property> entry : props.entrySet()) {
141 if (entry.getKey().endsWith(presetProperty)) {
142 String portName = entry.getKey().replaceAll(presetProperty, "");
143 cps.put(portName, new HashMap<>());
147 if (cps.size() > 0) {
148 // ports found - find all their properties
149 for (String portName : cps.keySet()) {
150 for (Map.Entry<String, Property> property: props.entrySet()) {
151 if (property.getKey().startsWith(portName)) {
152 Map<String, Object> portPaths = new HashMap<>();
153 String portProperty = property.getKey().replaceFirst(portName + "_", "");
154 buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths);
156 cps.get(portName).putAll(portPaths);
166 @SuppressWarnings("unchecked")
167 private void buildPathMappedToValue(String path, Object property, Map<String, Object> pathsMap) {
168 if (property instanceof Map) {
169 for (Map.Entry<String, Object> item : ((Map<String, Object>) property).entrySet()) {
170 if (item.getValue() instanceof Map || item.getValue() instanceof List) {
171 buildPathMappedToValue(path + PATH_DELIMITER + item.getKey(), item.getValue(), pathsMap);
173 pathsMap.put(path + PATH_DELIMITER + item.getKey(), item.getValue());
176 } else if (property instanceof List) {
177 for (Object item: (List<Object>)property) {
178 buildPathMappedToValue(path, item, pathsMap);
181 pathsMap.put(path, property);
187 //Sunny flow - covered with UT
188 public List<NodeTemplate> getServiceVlList() {
189 List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL);
190 return serviceVlList;
194 //Sunny flow - covered with UT
195 public List<NodeTemplate> getServiceVfList() {
196 List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF);
197 return serviceVfList;
201 //Sunny flow - covered with UT
202 public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) {
203 if (GeneralUtility.isEmptyString(metadataPropertyName)) {
204 log.error("getMetadataPropertyValue - the metadataPropertyName is null or empty");
207 if (metadata == null) {
208 log.error("getMetadataPropertyValue - the metadata is null");
211 String metadataPropertyValue = metadata.getValue(metadataPropertyName);
212 return metadataPropertyValue;
217 //Sunny flow - covered with UT
218 public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType) {
219 if (GeneralUtility.isEmptyString(nodeType)) {
220 log.error("getServiceNodeTemplatesByType - nodeType - is null or empty");
221 return new ArrayList<>();
224 List<NodeTemplate> res = new ArrayList<>();
225 List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
226 for (NodeTemplate nodeTemplate : nodeTemplates) {
227 if (nodeType.equals(nodeTemplate.getTypeDefinition().getType())) {
228 res.add(nodeTemplate);
237 public List<NodeTemplate> getServiceNodeTemplates() {
238 List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
239 return nodeTemplates;
243 //Sunny flow - covered with UT
244 public List<NodeTemplate> getVfcListByVf(String vfCustomizationId) {
245 if (GeneralUtility.isEmptyString(vfCustomizationId)) {
246 log.error("getVfcListByVf - vfCustomizationId - is null or empty");
247 return new ArrayList<>();
250 List<NodeTemplate> serviceVfList = getServiceVfList();
251 NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
252 List<NodeTemplate> vfcs = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC);
253 vfcs.addAll(getNodeTemplateBySdcType(vfInstance, SdcTypes.CVFC));
259 //Sunny flow - covered with UT
260 public List<Group> getVfModulesByVf(String vfCustomizationUuid) {
261 List<NodeTemplate> serviceVfList = getServiceVfList();
262 NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
263 if (nodeTemplateByCustomizationUuid != null) {
264 /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings();
265 if (substitutionMappings != null){
266 List<Group> groups = substitutionMappings.getGroups();
268 List<Group> collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList());
269 log.debug("getVfModulesByVf - VfModules are {}", collect);
273 String name = nodeTemplateByCustomizationUuid.getName();
274 String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name);
275 List<Group> serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups();
276 log.debug("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName);
277 if (serviceLevelGroups != null) {
278 List<Group> collect = serviceLevelGroups
280 .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName))
281 .collect(Collectors.toList());
285 return new ArrayList<>();
289 //Sunny flow - covered with UT
290 public String getServiceInputLeafValueOfDefault(String inputLeafValuePath) {
291 if (GeneralUtility.isEmptyString(inputLeafValuePath)) {
292 log.error("getServiceInputLeafValueOfDefault - inputLeafValuePath is null or empty");
296 String[] split = getSplittedPath(inputLeafValuePath);
297 if (split.length < 2 || !split[1].equals("default")) {
298 log.error("getServiceInputLeafValue - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] ");
302 List<Input> inputs = toscaTemplate.getInputs();
303 if (inputs != null) {
304 Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
305 if (findFirst.isPresent()) {
306 Input input = findFirst.get();
307 Object current = input.getDefault();
308 Object property = iterateProcessPath(2, current, split);
309 return property == null || property instanceof Function? null : String.valueOf(property);
312 log.error("getServiceInputLeafValue - value not found");
317 public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath) {
318 if (GeneralUtility.isEmptyString(inputLeafValuePath)) {
319 log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath is null or empty");
323 String[] split = getSplittedPath(inputLeafValuePath);
324 if (split.length < 2 || !split[1].equals("default")) {
325 log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] ");
329 List<Input> inputs = toscaTemplate.getInputs();
330 if (inputs != null) {
331 Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
332 if (findFirst.isPresent()) {
333 Input input = findFirst.get();
334 Object current = input.getDefault();
335 return iterateProcessPath(2, current, split);
338 log.error("getServiceInputLeafValueOfDefaultAsObject - value not found");
342 @SuppressWarnings({ "unchecked", "rawtypes" })
343 private Object iterateProcessPath(Integer index, Object current, String[] split) {
344 if (current == null) {
345 log.error("iterateProcessPath - this input has no default");
348 if (split.length > index) {
349 for (int i = index; i < split.length; i++) {
350 if (current instanceof Map) {
351 current = ((Map<String, Object>) current).get(split[i]);
352 } else if (current instanceof List) {
353 current = ((List) current).get(0);
357 log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type");
362 if (current != null) {
365 log.error("iterateProcessPath - Path not Found");
369 private String[] getSplittedPath(String inputLeafValuePath) {
370 return inputLeafValuePath.split(PATH_DELIMITER);
375 //Sunny flow - covered with UT
376 public String getServiceSubstitutionMappingsTypeName() {
377 SubstitutionMappings substitutionMappings = toscaTemplate.getTopologyTemplate().getSubstitutionMappings();
378 if (substitutionMappings == null) {
379 log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined");
383 NodeType nodeType = substitutionMappings.getNodeDefinition();
384 if (nodeType == null) {
385 log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined");
389 return nodeType.getType();
393 //Sunny flow - covered with UT
394 public Metadata getServiceMetadata() {
395 return toscaTemplate.getMetaData();
399 //Sunny flow - covered with UT
400 public Map<String, Object> getServiceMetadataProperties() {
401 if (toscaTemplate.getMetaData()==null){
404 return toscaTemplate.getMetaData().getPropertyMap();
408 //Sunny flow - covered with UT
409 public List<Input> getServiceInputs() {
410 return toscaTemplate.getInputs();
414 //Sunny flow - covered with UT
415 public String getGroupPropertyLeafValue(Group group, String leafValuePath) {
417 log.error("getGroupPropertyLeafValue - group is null");
421 if (GeneralUtility.isEmptyString(leafValuePath)) {
422 log.error("getGroupPropertyLeafValue - leafValuePath is null or empty");
426 String[] split = getSplittedPath(leafValuePath);
427 LinkedHashMap<String, Property> properties = group.getProperties();
428 Object property = processProperties(split, properties);
429 return property == null || property instanceof Function? null : String.valueOf(property);
433 public Object getGroupPropertyAsObject(Group group, String leafValuePath) {
435 log.error("getGroupPropertyAsObject - group is null");
439 if (GeneralUtility.isEmptyString(leafValuePath)) {
440 log.error("getGroupPropertyAsObject - leafValuePath is null or empty");
444 String[] split = getSplittedPath(leafValuePath);
445 LinkedHashMap<String, Property> properties = group.getProperties();
446 return processProperties(split, properties);
450 //Sunny flow - covered with UT
451 public List<NodeTemplate> getCpListByVf(String vfCustomizationId) {
452 List<NodeTemplate> cpList = new ArrayList<>();
453 if (GeneralUtility.isEmptyString(vfCustomizationId)) {
454 log.error("getCpListByVf vfCustomizationId string is empty");
458 List<NodeTemplate> serviceVfList = getServiceVfList();
459 if (serviceVfList == null || serviceVfList.size() == 0) {
460 log.error("getCpListByVf Vfs not exist for vfCustomizationId {}", vfCustomizationId);
463 NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
464 if (vfInstance == null) {
465 log.debug("getCpListByVf vf list is null");
468 cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP);
469 if (cpList == null || cpList.size() == 0)
470 log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId);
475 //Sunny flow - covered with UT
476 public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group serviceLevelVfModule) {
478 log.error("getMembersOfVfModule - vf is null");
479 return new ArrayList<>();
482 if (serviceLevelVfModule == null || serviceLevelVfModule.getMetadata() == null || serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID) == null) {
483 log.error("getMembersOfVfModule - vfModule or its metadata is null. Cannot match a VF group based on invariantUuid from missing metadata.");
484 return new ArrayList<>();
488 SubstitutionMappings substitutionMappings = vf.getSubMappingToscaTemplate();
489 if (substitutionMappings != null) {
490 List<Group> groups = substitutionMappings.getGroups();
491 if (groups != null) {
492 Optional<Group> findFirst = groups
494 .filter(x -> (x.getMetadata() != null && serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)))).findFirst();
495 if (findFirst.isPresent()) {
496 List<String> members = findFirst.get().getMembers();
497 if (members != null) {
498 List<NodeTemplate> collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList());
504 return new ArrayList<>();
508 //Sunny flow - covered with UT
509 @SuppressWarnings("unchecked")
510 public List<Pair<NodeTemplate, NodeTemplate>> getNodeTemplatePairsByReqName(
511 List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName) {
512 if (listOfReqNodeTemplates == null || listOfCapNodeTemplates == null || reqName == null) {
514 return new ArrayList<>();
517 List<Pair<NodeTemplate, NodeTemplate>> pairsList = new ArrayList<>();
519 if (listOfReqNodeTemplates != null) {
520 for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) {
521 List<Object> requirements = reqNodeTemplate.getRequirements();
522 for (Object reqEntry : requirements) {
523 LinkedHashMap<String, Object> reqEntryHash = (LinkedHashMap<String, Object>) reqEntry;
524 Map<String, Object> reqEntryMap = (Map<String, Object>) reqEntryHash.get(reqName);
525 if (reqEntryMap != null) {
526 Object node = reqEntryMap.get("node");
528 String nodeString = (String) node;
529 Optional<NodeTemplate> findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(nodeString)).findFirst();
530 if (findFirst.isPresent()) {
531 pairsList.add(new ImmutablePair<NodeTemplate, NodeTemplate>(reqNodeTemplate, findFirst.get()));
542 //Sunny flow - covered with UT
543 //TODO constant strings
544 public List<NodeTemplate> getAllottedResources() {
545 List<NodeTemplate> nodeTemplates = null;
546 nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
547 if (nodeTemplates.isEmpty()) {
548 log.error("getAllottedResources nodeTemplates not exist");
550 nodeTemplates = nodeTemplates.stream().filter(
551 x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource"))
552 .collect(Collectors.toList());
553 if (nodeTemplates.isEmpty()) {
554 log.debug("getAllottedResources - allotted resources not exist");
558 return nodeTemplates;
562 //Sunny flow - covered with UT
563 public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) {
564 if (nodeTemplate == null) {
566 log.error("getTypeOfNodeTemplate nodeTemplate is null");
569 return nodeTemplate.getTypeDefinition().getType();
573 public String getConformanceLevel() {
574 LinkedHashMap<String, Object> csarMeta = toscaTemplate.getMetaProperties("csar.meta");
575 if (csarMeta == null){
576 log.warn("No csar.meta file is found in CSAR - this file should hold the conformance level of the CSAR. This might be OK for older CSARs.");
580 Object conformanceLevel = csarMeta.get("SDC-TOSCA-Definitions-Version");
581 if (conformanceLevel != null){
582 String confLevelStr = conformanceLevel.toString();
583 log.debug("CSAR conformance level is {}", confLevelStr);
586 log.error("Invalid csar.meta file - no entry found for SDC-TOSCA-Definitions-Version key. This entry should hold the conformance level.");
593 public String getNodeTemplateCustomizationUuid(NodeTemplate nt) {
595 if (nt != null && nt.getMetaData() != null){
596 res = nt.getMetaData().getValue(CUSTOMIZATION_UUID);
598 log.error("Node template or its metadata is null");
603 public List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType) {
604 return getNodeTemplateBySdcType(parentNodeTemplate, sdcType, false);
607 private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType, boolean isVNF) {
609 if (parentNodeTemplate == null) {
610 log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty");
611 return new ArrayList<>();
614 if (sdcType == null) {
615 log.error("getNodeTemplateBySdcType - sdcType is null or empty");
616 return new ArrayList<>();
619 SubstitutionMappings substitutionMappings = parentNodeTemplate.getSubMappingToscaTemplate();
621 if (substitutionMappings != null) {
622 List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
623 if (nodeTemplates != null && nodeTemplates.size() > 0) {
624 if (sdcType.equals(SdcTypes.VFC) && isVNF) {
625 return nodeTemplates.stream()
626 .filter(x -> (x.getMetaData() != null &&
627 sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && isVNFType(x))
628 .collect(Collectors.toList());
631 return nodeTemplates.stream()
632 .filter(x -> (x.getMetaData() != null &&
633 sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && !isVNFType(x))
634 .collect(Collectors.toList());
638 log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist");
641 log.debug("getNodeTemplateBySdcType - SubstitutionMappings not exist");
643 return new ArrayList<>();
646 public Map<String, String> filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern) {
647 Map<String, String> filterMap = new HashMap<>();
649 if (nodeTemplate == null) {
650 log.error("filterNodeTemplatePropertiesByValue nodeTemplate is null");
654 if (filterType == null) {
655 log.error("filterNodeTemplatePropertiesByValue filterType is null");
659 if (GeneralUtility.isEmptyString(pattern)) {
660 log.error("filterNodeTemplatePropertiesByValue pattern string is empty");
664 Map<String, Property> ntProperties = nodeTemplate.getProperties();
666 if (ntProperties != null && ntProperties.size() > 0) {
668 for (Property current : ntProperties.values()) {
669 filterProperties(current.getValue(), current.getName(), filterType, pattern, filterMap);
673 log.trace("filterNodeTemplatePropertiesByValue - filterMap value: {}", filterMap);
678 public NodeTemplate getVnfConfig(String vfCustomizationUuid) {
680 if (GeneralUtility.isEmptyString(vfCustomizationUuid)) {
681 log.error("getVnfConfig - vfCustomizationId - is null or empty");
685 List<NodeTemplate> serviceVfList = getServiceVfList();
686 NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
687 NodeTemplate vnfConfig = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null);
692 public boolean hasTopology(NodeTemplate nodeTemplate) {
693 if (nodeTemplate == null) {
694 log.error("hasTopology - nodeTemplate - is null");
698 if (nodeTemplate.getMetaData() != null) {
699 String type = nodeTemplate.getMetaData().getValue("type");
700 log.debug("hasTopology - node template {} is a {} type", nodeTemplate.getName(), type);
701 return SdcTypes.isComplex(SdcTypes.valueOf(type));
708 public List<NodeTemplate> getNodeTemplateChildren(NodeTemplate nodeTemplate) {
709 if (nodeTemplate == null) {
710 log.error("getNodeTemplateChildren - nodeTemplate - is null");
711 return new ArrayList<>();
714 SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate();
715 if (substitutionMappings != null) {
716 List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
717 if (nodeTemplates != null && nodeTemplates.size() > 0) {
719 return nodeTemplates.stream()
720 .filter(x -> !isVNFType(x))
721 .collect(Collectors.toList());
724 log.debug("getNodeTemplateChildren - SubstitutionMappings' node Templates not exist");
727 log.debug("getNodeTemplateChildren - SubstitutionMappings not exist");
729 return new ArrayList<>();
732 /************************************* helper functions ***********************************/
733 private boolean isVNFType(NodeTemplate nt) {
734 return nt.getType().endsWith("VnfConfiguration");
737 @SuppressWarnings("unchecked")
738 private Map<String, String> filterProperties(Object property, String path, FilterType filterType, String pattern, Map<String, String> filterMap) {
740 if (property instanceof Map) {
741 for (Map.Entry<String, Object> item: ((Map<String, Object>) property).entrySet()) {
742 if (item.getKey().equals("get_input")) {
743 String itemToStr = item.getKey() + ":" + item.getValue().toString();
744 filterProperties(itemToStr, path, filterType, pattern, filterMap);
746 path += PATH_DELIMITER + item.getKey();
747 filterProperties(item.getValue(), path, filterType, pattern, filterMap);
750 } else if (property instanceof List) {
751 for (Object item: (List<Object>)property) {
752 filterProperties(item, path, filterType, pattern, filterMap);
754 } else if (property instanceof Function) {
755 if (filterType.isMatch(property.toString(), pattern)) {
756 filterMap.put(path, property.toString());
759 if (filterType.isMatch(property.toString(), pattern)) {
760 filterMap.put(path, property.toString());
767 public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType) {
768 if (sdcType == null) {
769 log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty");
770 return new ArrayList<>();
773 TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
774 return getNodeTemplateBySdcType(topologyTemplate, sdcType);
778 /************************************* helper functions ***********************************/
779 private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, SdcTypes sdcType) {
780 if (sdcType == null) {
781 log.error("getNodeTemplateBySdcType - sdcType is null or empty");
782 return new ArrayList<>();
785 if (topologyTemplate == null) {
786 log.error("getNodeTemplateBySdcType - topologyTemplate is null");
787 return new ArrayList<>();
790 List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
792 if (nodeTemplates != null && nodeTemplates.size() > 0)
793 return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
795 log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist");
796 return new ArrayList<>();
799 //Assumed to be unique property for the list
800 private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId) {
801 if (customizationId != null) {
802 Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> (x.getMetaData() != null && customizationId.equals(x.getMetaData().getValue(PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst();
803 return findFirst.isPresent() ? findFirst.get() : null;
806 log.error("getNodeTemplateByCustomizationUuid - customizationId is null");
811 private Object processProperties(String[] split, LinkedHashMap<String, Property> properties) {
812 Optional<Entry<String, Property>> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst();
813 if (findFirst.isPresent()) {
814 Property property = findFirst.get().getValue();
815 Object current = property.getValue();
816 return iterateProcessPath(1, current, split);
818 String propName = (split != null && split.length > 0 ? split[0] : null);
819 log.error("processProperties - property {} not found", propName);