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=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.be.components.csar;
24 import com.google.common.collect.Lists;
25 import com.google.common.collect.Maps;
26 import com.google.gson.Gson;
27 import fj.data.Either;
28 import org.apache.commons.collections.CollectionUtils;
29 import org.apache.commons.collections.MapUtils;
30 import org.apache.commons.lang.StringUtils;
31 import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
32 import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
33 import org.openecomp.sdc.be.components.impl.ImportUtils;
34 import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator;
35 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
36 import org.openecomp.sdc.be.config.BeEcompErrorManager;
37 import org.openecomp.sdc.be.dao.api.ActionStatus;
38 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
39 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
42 import org.openecomp.sdc.be.model.CapabilityDefinition;
43 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
44 import org.openecomp.sdc.be.model.GroupDefinition;
45 import org.openecomp.sdc.be.model.GroupTypeDefinition;
46 import org.openecomp.sdc.be.model.InputDefinition;
47 import org.openecomp.sdc.be.model.NodeTypeInfo;
48 import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
49 import org.openecomp.sdc.be.model.UploadArtifactInfo;
50 import org.openecomp.sdc.be.model.UploadCapInfo;
51 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
52 import org.openecomp.sdc.be.model.UploadPropInfo;
53 import org.openecomp.sdc.be.model.UploadReqInfo;
54 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
55 import org.openecomp.sdc.be.utils.TypeUtils;
56 import org.openecomp.sdc.common.log.wrappers.Logger;
57 import org.springframework.stereotype.Component;
58 import org.yaml.snakeyaml.parser.ParserException;
60 import java.util.ArrayList;
61 import java.util.Collection;
62 import java.util.HashMap;
63 import java.util.List;
66 import java.util.regex.Pattern;
67 import java.util.stream.Collectors;
69 import static java.util.stream.Collectors.toList;
70 import static org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
71 import static org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
72 import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaListElement;
73 import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMapElement;
74 import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement;
75 import static org.openecomp.sdc.be.components.impl.ImportUtils.loadYamlAsStrictMap;
76 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
77 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.CAPABILITIES;
78 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.CAPABILITY;
79 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT_VALUE;
80 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
81 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.FILE;
82 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.GET_INPUT;
83 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.GROUPS;
84 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.IS_PASSWORD;
85 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MEMBERS;
86 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE;
87 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES;
88 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.PROPERTIES;
89 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIREMENTS;
90 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS;
91 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE;
92 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
93 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES;
96 * A handler class designed to parse the YAML file of the service template for a JAVA object
99 public class YamlTemplateParsingHandler {
101 private static final Pattern propertyValuePattern = Pattern.compile("[ ]*\\{[ ]*(str_replace=|token=|get_property=|concat=|get_attribute=)+");
102 private static final int SUB_MAPPING_CAPABILITY_OWNER_NAME_IDX = 0;
103 private static final int SUB_MAPPING_CAPABILITY_NAME_IDX = 1;
104 private static final Logger log = Logger.getLogger(YamlTemplateParsingHandler.class);
107 private Gson gson = new Gson();
108 private JanusGraphDao janusGraphDao;
109 private GroupTypeBusinessLogic groupTypeBusinessLogic;
110 private AnnotationBusinessLogic annotationBusinessLogic;
112 public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao,
113 GroupTypeBusinessLogic groupTypeBusinessLogic, AnnotationBusinessLogic annotationBusinessLogic) {
114 this.janusGraphDao = janusGraphDao;
115 this.groupTypeBusinessLogic = groupTypeBusinessLogic;
116 this.annotationBusinessLogic = annotationBusinessLogic;
119 public ParsedToscaYamlInfo parseResourceInfoFromYAML(String fileName, String resourceYml, Map<String, String> createdNodesToscaResourceNames,
120 Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName) {
121 log.debug("#parseResourceInfoFromYAML - Going to parse yaml {} ", fileName);
122 Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName);
123 ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
124 findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL)
126 .on(err -> failIfNotTopologyTemplate(fileName));
128 parsedToscaYamlInfo.setInputs(getInputs(mappedToscaTemplate));
129 parsedToscaYamlInfo.setInstances(getInstances(fileName, mappedToscaTemplate, createdNodesToscaResourceNames));
130 parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate));
131 log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName);
132 return parsedToscaYamlInfo;
135 private Map<String, Object> getMappedToscaTemplate(String fileName, String resourceYml, Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName) {
136 Map<String, Object> mappedToscaTemplate;
137 if (isNodeExist(nodeTypesInfo, nodeName)) {
138 mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate();
140 mappedToscaTemplate = loadYaml(fileName, resourceYml);
142 return mappedToscaTemplate;
145 private Map<String, Object> loadYaml(String fileName, String resourceYml) {
146 Map<String, Object> mappedToscaTemplate = null;
148 mappedToscaTemplate = loadYamlAsStrictMap(resourceYml);
149 } catch (ParserException e) {
150 log.debug("#getMappedToscaTemplate - Failed to load YAML file {}", fileName, e);
151 rollbackWithException(ActionStatus.TOSCA_PARSE_ERROR, fileName, e.getMessage());
153 return mappedToscaTemplate;
156 private boolean isNodeExist(Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName) {
157 return nodeTypesInfo != null && nodeName != null && nodeTypesInfo.containsKey(nodeName);
160 private Map<String, InputDefinition> getInputs(Map<String, Object> toscaJson) {
161 Map<String, InputDefinition> inputs = ImportUtils.getInputs(toscaJson, annotationBusinessLogic.getAnnotationTypeOperations())
163 .on(err -> new HashMap<>());
164 annotationBusinessLogic.validateAndMergeAnnotationsAndAssignToInput(inputs);
168 private Map<String, UploadComponentInstanceInfo> getInstances(String yamlName, Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames) {
170 Map<String, Object> nodeTemlates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES)
172 .on(err -> failIfNoNodeTemplates(yamlName));
174 return getInstances(toscaJson, createdNodesToscaResourceNames, nodeTemlates);
177 private Map<String, UploadComponentInstanceInfo> getInstances(Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames, Map<String, Object> nodeTemlates) {
178 Map<String, UploadComponentInstanceInfo> moduleComponentInstances;
179 Map<String, Object> substitutionMappings = getSubstitutionMappings(toscaJson);
180 moduleComponentInstances = nodeTemlates.entrySet()
182 .map(node -> buildModuleComponentInstanceInfo(node, substitutionMappings, createdNodesToscaResourceNames))
183 .collect(Collectors.toMap(UploadComponentInstanceInfo::getName, i -> i));
184 return moduleComponentInstances;
187 private Map<String, Object> getSubstitutionMappings(Map<String, Object> toscaJson) {
188 Map<String, Object> substitutionMappings = null;
189 Either<Map<String, Object>, ResultStatusEnum> eitherSubstitutionMappings = findFirstToscaMapElement(toscaJson, SUBSTITUTION_MAPPINGS);
190 if (eitherSubstitutionMappings.isLeft()) {
191 substitutionMappings = eitherSubstitutionMappings.left().value();
193 return substitutionMappings;
196 @SuppressWarnings("unchecked")
197 private Map<String, GroupDefinition> getGroups(String fileName, Map<String, Object> toscaJson) {
199 Map<String, Object> foundGroups = findFirstToscaMapElement(toscaJson, GROUPS)
201 .on(err -> logGroupsNotFound(fileName));
203 if (MapUtils.isNotEmpty(foundGroups)) {
204 Map<String, GroupDefinition> groups = foundGroups
207 .map(this::createGroup)
208 .collect(Collectors.toMap(GroupDefinition::getName, g -> g));
209 Map<String, Object> substitutionMappings = getSubstitutionMappings(toscaJson);
210 if (capabilitiesSubstitutionMappingsExist(substitutionMappings)) {
211 groups.entrySet().forEach(entry -> updateCapabilitiesNames(entry.getValue(), getNamesToUpdate(entry.getKey(),
212 (Map<String, List<String>>) substitutionMappings.get(CAPABILITIES.getElementName()))));
216 return new HashMap<>();
219 private Map<String, Object> logGroupsNotFound(String fileName) {
220 log.debug("#logGroupsNotFound - Groups were not found in the yaml template {}.", fileName);
221 return new HashMap<>();
224 private void updateCapabilitiesNames(GroupDefinition group, Map<String, String> capabilityNames) {
225 if (MapUtils.isNotEmpty(group.getCapabilities())) {
226 group.getCapabilities().values()
228 .flatMap(Collection::stream)
229 .filter(cap -> capabilityNames.containsKey(cap.getName()))
230 .forEach(cap -> cap.setName(capabilityNames.get(cap.getName())));
234 private Map<String, String> getNamesToUpdate(String name, Map<String, List<String>> pair) {
235 return pair.entrySet().stream()
236 .filter(e -> e.getValue().get(SUB_MAPPING_CAPABILITY_OWNER_NAME_IDX).equalsIgnoreCase(name))
237 .collect(Collectors.toMap(e -> e.getValue().get(SUB_MAPPING_CAPABILITY_NAME_IDX), Map.Entry::getKey, (n1 ,n2) -> n1));
240 private boolean capabilitiesSubstitutionMappingsExist(Map<String, Object> substitutionMappings) {
241 return substitutionMappings != null && substitutionMappings.containsKey(CAPABILITIES.getElementName());
244 private GroupDefinition createGroup(Map.Entry<String, Object> groupNameValue) {
245 GroupDefinition group = new GroupDefinition();
246 group.setName(groupNameValue.getKey());
248 if (groupNameValue.getValue() != null && groupNameValue.getValue() instanceof Map) {
249 Map<String, Object> groupTemplateJsonMap = (Map<String, Object>) groupNameValue.getValue();
250 validateAndFillGroup(group, groupTemplateJsonMap);
251 validateUpdateGroupProperties(group, groupTemplateJsonMap);
252 validateUpdateGroupCapabilities(group, groupTemplateJsonMap);
254 rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
256 } catch (ClassCastException e) {
257 log.debug("#createGroup - Failed to create the group {}. The exception occure", groupNameValue.getKey(), e);
258 rollbackWithException(ActionStatus.INVALID_YAML);
263 private Map<String, CapabilityDefinition> addCapabilities(Map<String, CapabilityDefinition> cap, Map<String, CapabilityDefinition> otherCap) {
264 cap.putAll(otherCap);
268 private Map<String, CapabilityDefinition> addCapability(CapabilityDefinition cap) {
269 Map<String, CapabilityDefinition> map = Maps.newHashMap();
270 map.put(cap.getName(), cap);
274 private void setMembers(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap) {
275 if (groupTemplateJsonMap.containsKey(MEMBERS.getElementName())) {
276 Object members = groupTemplateJsonMap.get(MEMBERS.getElementName());
277 if (members != null) {
278 if (members instanceof List) {
279 setMembersFromList(groupInfo, (List<?>) members);
281 log.debug("The 'members' member is not of type list under group {}", groupInfo.getName());
282 rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
288 private void setMembersFromList(GroupDefinition groupInfo, List<?> membersAsList) {
289 groupInfo.setMembers(membersAsList
291 .collect(Collectors.toMap(Object::toString, member -> "")));
294 @SuppressWarnings("unchecked")
295 private void validateUpdateGroupProperties(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap) {
296 if (groupTemplateJsonMap.containsKey(PROPERTIES.getElementName())) {
297 Object propertiesElement = groupTemplateJsonMap.get(PROPERTIES.getElementName());
298 if (propertiesElement instanceof Map){
299 mergeGroupProperties(groupInfo, (Map<String, Object>) propertiesElement);
304 private void mergeGroupProperties(GroupDefinition groupInfo, Map<String, Object> parsedProperties) {
305 if(CollectionUtils.isNotEmpty(groupInfo.getProperties())){
306 validateGroupProperties(parsedProperties, groupInfo);
307 groupInfo.getProperties().forEach(p -> mergeGroupProperty(p, parsedProperties));
311 private void mergeGroupProperty(PropertyDataDefinition property, Map<String, Object> parsedProperties) {
312 if(parsedProperties.containsKey(property.getName())){
313 Object propValue = parsedProperties.get(property.getName());
314 if (valueNotContainsPattern(propertyValuePattern, propValue)) {
315 setPropertyValueAndGetInputsValues(property, propValue);
320 private void setPropertyValueAndGetInputsValues(PropertyDataDefinition property, Object propValue) {
321 if(propValue != null){
322 UploadPropInfo uploadPropInfo = buildProperty(property.getName(), propValue);
323 property.setValue(convertPropertyValue(ToscaPropertyType.isValidType(property.getType()), uploadPropInfo.getValue()));
324 property.setGetInputValues(uploadPropInfo.getGet_input());
328 private String convertPropertyValue(ToscaPropertyType type, Object value) {
329 String convertedValue = null;
331 if (type == null || value instanceof Map || value instanceof List) {
332 convertedValue = gson.toJson(value);
334 convertedValue = value.toString();
337 return convertedValue;
340 private void setDescription(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap) {
341 if (groupTemplateJsonMap.containsKey(DESCRIPTION.getElementName())) {
342 groupInfo.setDescription(
343 (String) groupTemplateJsonMap.get(DESCRIPTION.getElementName()));
347 private void validateAndFillGroup(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap) {
348 String type = (String) groupTemplateJsonMap.get(TYPE.getElementName());
349 if(StringUtils.isEmpty(type)){
350 log.debug("#validateAndFillGroup - The 'type' member is not found under group {}", groupInfo.getName());
351 rollbackWithException(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupInfo.getName());
353 groupInfo.setType(type);
354 GroupTypeDefinition groupType = groupTypeBusinessLogic.getLatestGroupTypeByType(type);
355 if (groupType == null) {
356 log.debug("#validateAndFillGroup - The group type {} not found", groupInfo.getName());
357 rollbackWithException(ActionStatus.GROUP_TYPE_IS_INVALID, type);
359 groupInfo.convertFromGroupProperties(groupType.getProperties());
360 groupInfo.convertCapabilityDefinitions(groupType.getCapabilities());
361 setDescription(groupInfo, groupTemplateJsonMap);
362 setMembers(groupInfo, groupTemplateJsonMap);
365 @SuppressWarnings("unchecked")
366 private void validateUpdateGroupCapabilities(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap) {
368 if (groupTemplateJsonMap.containsKey(CAPABILITIES.getElementName())) {
369 Object capabilities = groupTemplateJsonMap.get(CAPABILITIES.getElementName());
370 if (capabilities instanceof List) {
371 validateUpdateCapabilities(groupInfo, ((List<Object>) capabilities).stream()
372 .map(o -> buildGroupCapability(groupInfo, o))
373 .collect(Collectors.toMap(CapabilityDefinition::getType, this::addCapability, this::addCapabilities)));
374 } else if (capabilities instanceof Map) {
375 validateUpdateCapabilities(groupInfo, ((Map<String, Object>) capabilities).entrySet()
377 .map(e -> buildGroupCapability(groupInfo, e))
378 .collect(Collectors.toMap(CapabilityDefinition::getType, this::addCapability, this::addCapabilities)));
380 log.debug("#setCapabilities - Failed to import the capabilities of the group {}. ", groupInfo.getName());
381 rollbackWithException(ActionStatus.INVALID_YAML);
386 private void validateUpdateCapabilities(GroupDefinition groupInfo, Map<String, Map<String, CapabilityDefinition>> capabilityInfo) {
387 validateGroupCapabilities(groupInfo, capabilityInfo);
388 groupInfo.updateCapabilitiesProperties(capabilityInfo);
391 private void validateGroupCapabilities(GroupDefinition group, Map<String, Map<String, CapabilityDefinition>> parsedCapabilities) {
392 if (MapUtils.isNotEmpty(parsedCapabilities)) {
393 if (MapUtils.isEmpty(group.getCapabilities())) {
394 failOnMissingCapabilityTypes(group, Lists.newArrayList(parsedCapabilities.keySet()));
396 List<String> missingCapTypes = parsedCapabilities.keySet().stream().filter(ct -> !group.getCapabilities().containsKey(ct)).collect(toList());
397 if (CollectionUtils.isNotEmpty(missingCapTypes)) {
398 failOnMissingCapabilityTypes(group, missingCapTypes);
400 group.getCapabilities().entrySet().forEach(e -> validateCapabilities(group, e.getValue(), parsedCapabilities.get(e.getKey())));
404 private void validateCapabilities(GroupDefinition group, List<CapabilityDefinition> capabilities, Map<String, CapabilityDefinition> parsedCapabilities) {
405 List<String> allowedCapNames = capabilities.stream().map(CapabilityDefinition::getName).distinct().collect(toList());
406 List<String> missingCapNames = parsedCapabilities.keySet().stream().filter(c -> !allowedCapNames.contains(c)).collect(toList());
407 if (CollectionUtils.isNotEmpty(missingCapNames)) {
408 failOnMissingCapabilityNames(group, missingCapNames);
410 validateCapabilitiesProperties(capabilities, parsedCapabilities);
413 private void validateCapabilitiesProperties(List<CapabilityDefinition> capabilities, Map<String, CapabilityDefinition> parsedCapabilities) {
414 capabilities.forEach(c -> validateCapabilityProperties(c, parsedCapabilities.get(c.getName())));
417 private void validateCapabilityProperties(CapabilityDefinition capability, CapabilityDefinition parsedCapability) {
418 if(parsedCapability != null && parsedCapability.getProperties() != null){
419 List<String> parsedPropertiesNames = parsedCapability.getProperties()
421 .map(ComponentInstanceProperty::getName).collect(toList());
422 validateProperties(capability.getProperties().stream().map(PropertyDataDefinition::getName).collect(toList()), parsedPropertiesNames, ActionStatus.PROPERTY_NOT_FOUND, capability.getName(), capability.getType());
426 private void validateGroupProperties(Map<String, Object> parsedProperties, GroupDefinition groupInfo) {
427 List<String> parsedPropertiesNames = parsedProperties.entrySet()
429 .map(Map.Entry::getKey).collect(toList());
430 validateProperties(groupInfo.getProperties().stream().map(PropertyDataDefinition::getName).collect(toList()), parsedPropertiesNames, ActionStatus.GROUP_PROPERTY_NOT_FOUND, groupInfo.getName(), groupInfo.getType());
433 private void validateProperties(List<String> validProperties, List<String> parsedProperties, ActionStatus actionStatus, String name, String type) {
434 if (CollectionUtils.isNotEmpty(parsedProperties)) {
435 verifyMissingProperties(actionStatus, name, type, parsedProperties
437 .filter(n -> !validProperties.contains(n))
442 private void verifyMissingProperties(ActionStatus actionStatus, String name, String type, List<String> missingProperties) {
443 if (CollectionUtils.isNotEmpty(missingProperties)) {
444 log.debug("#validateProperties - Failed to validate properties. The properties {} are missing on {} of the type {}. ", missingProperties.toString(), name, type);
445 rollbackWithException(actionStatus, missingProperties.toString(), missingProperties.toString(), name, type);
449 @SuppressWarnings("unchecked")
450 private CapabilityDefinition buildGroupCapability(GroupDefinition groupInfo, Object capObject) {
451 if (!(capObject instanceof Map)) {
452 log.debug("#convertToGroupCapability - Failed to import the capability {}. ", capObject);
453 rollbackWithException(ActionStatus.INVALID_YAML);
455 return buildGroupCapability(groupInfo, ((Map<String, Object>) capObject).entrySet().iterator().next());
458 @SuppressWarnings("unchecked")
459 private CapabilityDefinition buildGroupCapability(GroupDefinition groupInfo, Map.Entry<String, Object> capEntry) {
460 CapabilityDefinition capability = new CapabilityDefinition();
461 capability.setOwnerType(CapabilityDataDefinition.OwnerType.GROUP);
462 capability.setName(capEntry.getKey());
463 capability.setParentName(capEntry.getKey());
464 capability.setOwnerId(groupInfo.getName());
465 if (!(capEntry.getValue() instanceof Map)) {
466 log.debug("#convertMapEntryToCapabilityDefinition - Failed to import the capability {}. ", capEntry.getKey());
467 rollbackWithException(ActionStatus.INVALID_YAML);
469 Map<String, Object> capabilityValue = (Map<String, Object>) capEntry.getValue();
470 String type = (String) capabilityValue.get(TYPE.getElementName());
471 if (StringUtils.isEmpty(type)) {
472 log.debug("#convertMapEntryToCapabilityDefinition - Failed to import the capability {}. Missing capability type. ", capEntry.getKey());
473 rollbackWithException(ActionStatus.INVALID_YAML);
475 capability.setType(type);
476 if (!(capabilityValue.get(PROPERTIES.getElementName()) instanceof Map)) {
477 log.debug("#convertMapEntryToCapabilityDefinition - Failed to import the capability {}. ", capEntry.getKey());
478 rollbackWithException(ActionStatus.INVALID_YAML);
480 Map<String, Object> properties = (Map<String, Object>) capabilityValue.get(PROPERTIES.getElementName());
481 capability.setProperties(properties.entrySet().stream().map(this::convertToProperty).collect(toList()));
485 private ComponentInstanceProperty convertToProperty(Map.Entry<String, Object> e) {
486 ComponentInstanceProperty property = new ComponentInstanceProperty();
487 property.setName(e.getKey());
488 property.setValue((String) e.getValue());
492 @SuppressWarnings("unchecked")
493 private UploadComponentInstanceInfo buildModuleComponentInstanceInfo(
494 Map.Entry<String, Object> nodeTemplateJsonEntry, Map<String, Object> substitutionMappings,
495 Map<String, String> createdNodesToscaResourceNames) {
497 UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
498 nodeTemplateInfo.setName(nodeTemplateJsonEntry.getKey());
500 if (nodeTemplateJsonEntry.getValue() instanceof String) {
501 String nodeTemplateJsonString = (String) nodeTemplateJsonEntry.getValue();
502 nodeTemplateInfo.setType(nodeTemplateJsonString);
503 } else if (nodeTemplateJsonEntry.getValue() instanceof Map) {
504 Map<String, Object> nodeTemplateJsonMap = (Map<String, Object>) nodeTemplateJsonEntry.getValue();
505 setToscaResourceType(createdNodesToscaResourceNames, nodeTemplateInfo, nodeTemplateJsonMap);
506 setRequirements(nodeTemplateInfo, nodeTemplateJsonMap);
507 setCapabilities(nodeTemplateInfo, nodeTemplateJsonMap);
508 setArtifacts(nodeTemplateInfo, nodeTemplateJsonMap);
509 updateProperties(nodeTemplateInfo, nodeTemplateJsonMap);
510 setDirectives(nodeTemplateInfo, nodeTemplateJsonMap);
511 setNodeFilter(nodeTemplateInfo, nodeTemplateJsonMap);
512 setSubstitutions(substitutionMappings, nodeTemplateInfo);
514 rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
516 } catch (ClassCastException e) {
517 BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create capability");
518 log.debug("error when creating capability, message:{}", e.getMessage(), e);
519 rollbackWithException(ActionStatus.INVALID_YAML);
521 return nodeTemplateInfo;
524 @SuppressWarnings("unchecked")
525 private void setSubstitutions(Map<String, Object> substitutionMappings, UploadComponentInstanceInfo nodeTemplateInfo) {
526 if (substitutionMappings != null) {
527 if (substitutionMappings.containsKey(CAPABILITIES.getElementName())) {
528 nodeTemplateInfo.setCapabilitiesNamesToUpdate(getNamesToUpdate(nodeTemplateInfo.getName(), (Map<String, List<String>>) substitutionMappings
529 .get(CAPABILITIES.getElementName())));
531 if (substitutionMappings.containsKey(REQUIREMENTS.getElementName())) {
532 nodeTemplateInfo.setRequirementsNamesToUpdate(getNamesToUpdate(
533 nodeTemplateInfo.getName(), (Map<String, List<String>>) substitutionMappings
534 .get(REQUIREMENTS.getElementName())));
539 private void updateProperties(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
540 if (nodeTemplateJsonMap.containsKey(PROPERTIES.getElementName())) {
541 Map<String, List<UploadPropInfo>> properties = buildPropModuleFromYaml(nodeTemplateJsonMap);
542 if (!properties.isEmpty()) {
543 nodeTemplateInfo.setProperties(properties);
548 private void setCapabilities(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
549 if (nodeTemplateJsonMap.containsKey(CAPABILITIES.getElementName())) {
550 Map<String, List<UploadCapInfo>> eitherCapRes = createCapModuleFromYaml(nodeTemplateJsonMap);
551 if (!eitherCapRes.isEmpty()) {
552 nodeTemplateInfo.setCapabilities(eitherCapRes);
557 private void setArtifacts(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
558 if (nodeTemplateJsonMap.containsKey(ARTIFACTS.getElementName())) {
559 Map<String, Map<String, UploadArtifactInfo>> eitherArtifactsRes = createArtifactsModuleFromYaml(nodeTemplateJsonMap);
560 if (!eitherArtifactsRes.isEmpty()) {
561 nodeTemplateInfo.setArtifacts(eitherArtifactsRes);
566 private void setRequirements(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
567 if (nodeTemplateJsonMap.containsKey(REQUIREMENTS.getElementName())) {
568 Map<String, List<UploadReqInfo>> regResponse = createReqModuleFromYaml(nodeTemplateJsonMap);
569 if (!regResponse.isEmpty()) {
570 nodeTemplateInfo.setRequirements(regResponse);
575 private void setToscaResourceType(Map<String, String> createdNodesToscaResourceNames,
576 UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
577 if (nodeTemplateJsonMap.containsKey(TYPE.getElementName())) {
578 String toscaResourceType = (String) nodeTemplateJsonMap.get(TYPE.getElementName());
579 if (createdNodesToscaResourceNames.containsKey(toscaResourceType)) {
580 toscaResourceType = createdNodesToscaResourceNames.get(toscaResourceType);
582 nodeTemplateInfo.setType(toscaResourceType);
586 private void setDirectives(UploadComponentInstanceInfo nodeTemplateInfo,
587 Map<String, Object> nodeTemplateJsonMap) {
588 List<String> directives =
589 (List<String>) nodeTemplateJsonMap.get(TypeUtils.ToscaTagNamesEnum.DIRECTIVES.getElementName());
590 nodeTemplateInfo.setDirectives(directives);
593 private void setNodeFilter(UploadComponentInstanceInfo nodeTemplateInfo,
594 Map<String, Object> nodeTemplateJsonMap) {
595 if (nodeTemplateJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_FILTER.getElementName())) {
596 nodeTemplateInfo.setUploadNodeFilterInfo(
597 new NodeFilterUploadCreator().createNodeFilterData(nodeTemplateJsonMap.get(
598 TypeUtils.ToscaTagNamesEnum.NODE_FILTER.getElementName())));
602 @SuppressWarnings("unchecked")
603 private Map<String, List<UploadReqInfo>> createReqModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
604 Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<>();
605 Either<List<Object>, ResultStatusEnum> requirementsListRes =
606 findFirstToscaListElement(nodeTemplateJsonMap, REQUIREMENTS);
608 if (requirementsListRes.isLeft()) {
609 for (Object jsonReqObj : requirementsListRes.left().value()) {
610 String reqName = ((Map<String, Object>) jsonReqObj).keySet().iterator().next();
611 Object reqJson = ((Map<String, Object>) jsonReqObj).get(reqName);
612 addModuleNodeTemplateReq(moduleRequirements, reqJson, reqName);
615 Either<Map<String, Object>, ResultStatusEnum> requirementsMapRes =
616 findFirstToscaMapElement(nodeTemplateJsonMap, REQUIREMENTS);
617 if (requirementsMapRes.isLeft()) {
618 for (Map.Entry<String, Object> entry : requirementsMapRes.left().value().entrySet()) {
619 String reqName = entry.getKey();
620 Object reqJson = entry.getValue();
621 addModuleNodeTemplateReq(moduleRequirements, reqJson, reqName);
625 return moduleRequirements;
628 private void addModuleNodeTemplateReq(Map<String, List<UploadReqInfo>> moduleRequirements, Object requirementJson, String requirementName) {
630 UploadReqInfo requirement = buildModuleNodeTemplateReg(requirementJson);
631 requirement.setName(requirementName);
632 if (moduleRequirements.containsKey(requirementName)) {
633 moduleRequirements.get(requirementName).add(requirement);
635 List<UploadReqInfo> list = new ArrayList<>();
636 list.add(requirement);
637 moduleRequirements.put(requirementName, list);
641 @SuppressWarnings("unchecked")
642 private Map<String, Map<String, UploadArtifactInfo>> createArtifactsModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
643 Map<String, Map<String, UploadArtifactInfo>> moduleArtifacts = new HashMap<>();
644 Either<List<Object>, ResultStatusEnum> ArtifactsListRes =
645 findFirstToscaListElement(nodeTemplateJsonMap, ARTIFACTS);
646 if (ArtifactsListRes.isLeft()) {
647 for (Object jsonArtifactObj : ArtifactsListRes.left().value()) {
648 String key = ((Map<String, Object>) jsonArtifactObj).keySet().iterator().next();
649 Object artifactJson = ((Map<String, Object>) jsonArtifactObj).get(key);
650 addModuleNodeTemplateArtifacts(moduleArtifacts, artifactJson, key);
653 Either<Map<String, Map<String, Object>>, ResultStatusEnum> ArtifactsMapRes =
654 findFirstToscaMapElement(nodeTemplateJsonMap, ARTIFACTS);
655 if (ArtifactsMapRes.isLeft()) {
656 for (Map.Entry<String, Map<String, Object>> entry : ArtifactsMapRes.left().value().entrySet()) {
657 String artifactName = entry.getKey();
658 Object artifactJson = entry.getValue();
659 addModuleNodeTemplateArtifacts(moduleArtifacts, artifactJson, artifactName);
663 return moduleArtifacts;
666 private void addModuleNodeTemplateArtifacts(Map<String, Map<String, UploadArtifactInfo>> moduleArtifacts, Object artifactJson, String artifactName) {
668 UploadArtifactInfo artifact = buildModuleNodeTemplateArtifact(artifactJson);
669 artifact.setName(artifactName);
670 if (moduleArtifacts.containsKey(ARTIFACTS.getElementName())) {
671 moduleArtifacts.get(ARTIFACTS.getElementName()).put(artifactName, artifact);
673 Map<String, UploadArtifactInfo> map = new HashMap<>();
674 map.put(artifactName, artifact);
675 moduleArtifacts.put(ARTIFACTS.getElementName(), map);
679 @SuppressWarnings("unchecked")
680 private UploadArtifactInfo buildModuleNodeTemplateArtifact(Object artifactObject) {
681 UploadArtifactInfo artifactTemplateInfo = new UploadArtifactInfo();
682 if (artifactObject instanceof Map) {
683 fillArtifact(artifactTemplateInfo, (Map<String, Object>) artifactObject);
685 return artifactTemplateInfo;
688 private void fillArtifact(UploadArtifactInfo artifactTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
689 if (nodeTemplateJsonMap.containsKey(TYPE.getElementName())) {
690 artifactTemplateInfo.setType((String) nodeTemplateJsonMap.get(TYPE.getElementName()));
692 if (nodeTemplateJsonMap.containsKey(FILE.getElementName())) {
693 artifactTemplateInfo.setFile((String) nodeTemplateJsonMap.get(FILE.getElementName()));
698 @SuppressWarnings("unchecked")
699 private Map<String, List<UploadCapInfo>> createCapModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
700 Map<String, List<UploadCapInfo>> moduleCap = new HashMap<>();
701 Either<List<Object>, ResultStatusEnum> capabilitiesListRes =
702 findFirstToscaListElement(nodeTemplateJsonMap, CAPABILITIES);
703 if (capabilitiesListRes.isLeft()) {
704 for (Object jsonCapObj : capabilitiesListRes.left().value()) {
705 String key = ((Map<String, Object>) jsonCapObj).keySet().iterator().next();
706 Object capJson = ((Map<String, Object>) jsonCapObj).get(key);
707 addModuleNodeTemplateCap(moduleCap, capJson, key);
710 Either<Map<String, Object>, ResultStatusEnum> capabilitiesMapRes =
711 findFirstToscaMapElement(nodeTemplateJsonMap, CAPABILITIES);
712 if (capabilitiesMapRes.isLeft()) {
713 for (Map.Entry<String, Object> entry : capabilitiesMapRes.left().value().entrySet()) {
714 String capName = entry.getKey();
715 Object capJson = entry.getValue();
716 addModuleNodeTemplateCap(moduleCap, capJson, capName);
723 private void addModuleNodeTemplateCap(Map<String, List<UploadCapInfo>> moduleCap, Object capJson, String key) {
725 UploadCapInfo capabilityDef = buildModuleNodeTemplateCap(capJson);
726 capabilityDef.setKey(key);
727 if (moduleCap.containsKey(key)) {
728 moduleCap.get(key).add(capabilityDef);
730 List<UploadCapInfo> list = new ArrayList<>();
731 list.add(capabilityDef);
732 moduleCap.put(key, list);
736 @SuppressWarnings("unchecked")
737 private UploadCapInfo buildModuleNodeTemplateCap(Object capObject) {
738 UploadCapInfo capTemplateInfo = new UploadCapInfo();
740 if (capObject instanceof String) {
741 String nodeTemplateJsonString = (String) capObject;
742 capTemplateInfo.setNode(nodeTemplateJsonString);
743 } else if (capObject instanceof Map) {
744 fillCapability(capTemplateInfo, (Map<String, Object>) capObject);
746 return capTemplateInfo;
749 private void fillCapability(UploadCapInfo capTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
750 if (nodeTemplateJsonMap.containsKey(NODE.getElementName())) {
751 capTemplateInfo.setNode((String) nodeTemplateJsonMap.get(NODE.getElementName()));
753 if (nodeTemplateJsonMap.containsKey(TYPE.getElementName())) {
754 capTemplateInfo.setType((String) nodeTemplateJsonMap.get(TYPE.getElementName()));
756 if (nodeTemplateJsonMap.containsKey(VALID_SOURCE_TYPES.getElementName())) {
757 Either<List<Object>, ResultStatusEnum> validSourceTypesRes =
758 findFirstToscaListElement(nodeTemplateJsonMap, VALID_SOURCE_TYPES);
759 if (validSourceTypesRes.isLeft()) {
760 capTemplateInfo.setValidSourceTypes(validSourceTypesRes.left().value().stream()
761 .map(Object::toString).collect(toList()));
764 if (nodeTemplateJsonMap.containsKey(PROPERTIES.getElementName())) {
765 Map<String, List<UploadPropInfo>> props = buildPropModuleFromYaml(nodeTemplateJsonMap);
766 if (!props.isEmpty()) {
767 List<UploadPropInfo> properties = props.values().stream().flatMap(Collection::stream).collect(toList());
768 capTemplateInfo.setProperties(properties);
773 @SuppressWarnings("unchecked")
774 private UploadReqInfo buildModuleNodeTemplateReg(Object regObject) {
776 UploadReqInfo regTemplateInfo = new UploadReqInfo();
777 if (regObject instanceof String) {
778 String nodeTemplateJsonString = (String) regObject;
779 regTemplateInfo.setNode(nodeTemplateJsonString);
780 } else if (regObject instanceof Map) {
781 Map<String, Object> nodeTemplateJsonMap = (Map<String, Object>) regObject;
782 if (nodeTemplateJsonMap.containsKey(NODE.getElementName())) {
783 regTemplateInfo.setNode((String) nodeTemplateJsonMap.get(NODE.getElementName()));
785 if (nodeTemplateJsonMap.containsKey(CAPABILITY.getElementName())) {
786 regTemplateInfo.setCapabilityName(
787 (String) nodeTemplateJsonMap.get(CAPABILITY.getElementName()));
790 return regTemplateInfo;
793 private Map<String, List<UploadPropInfo>> buildPropModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
795 Map<String, List<UploadPropInfo>> moduleProp = new HashMap<>();
796 Either<Map<String, Object>, ResultStatusEnum> toscaProperties =
797 findFirstToscaMapElement(nodeTemplateJsonMap, PROPERTIES);
798 if (toscaProperties.isLeft()) {
799 Map<String, Object> jsonProperties = toscaProperties.left().value();
800 for (Map.Entry<String, Object> jsonPropObj : jsonProperties.entrySet()) {
801 if (valueNotContainsPattern(propertyValuePattern, jsonPropObj.getValue())) {
802 addProperty(moduleProp, jsonPropObj);
809 private void addProperty(Map<String, List<UploadPropInfo>> moduleProp, Map.Entry<String, Object> jsonPropObj) {
810 UploadPropInfo propertyDef = buildProperty(jsonPropObj.getKey(), jsonPropObj.getValue());
811 if (moduleProp.containsKey(propertyDef.getName())) {
812 moduleProp.get(propertyDef.getName()).add(propertyDef);
814 List<UploadPropInfo> list = new ArrayList<>();
815 list.add(propertyDef);
816 moduleProp.put(propertyDef.getName(), list);
820 @SuppressWarnings("unchecked")
821 private UploadPropInfo buildProperty(String propName, Object propValue) {
823 UploadPropInfo propertyDef = new UploadPropInfo();
824 propertyDef.setValue(propValue);
825 propertyDef.setName(propName);
826 if (propValue instanceof Map) {
827 if (((Map<String, Object>) propValue).containsKey(TYPE.getElementName())) {
828 propertyDef.setType(((Map<String, Object>) propValue)
829 .get(TYPE.getElementName()).toString());
831 if (containsGetInput(propValue)) {
832 fillInputRecursively(propName, (Map<String, Object>) propValue, propertyDef);
835 if (((Map<String, Object>) propValue).containsKey(DESCRIPTION.getElementName())) {
836 propertyDef.setDescription(((Map<String, Object>) propValue)
837 .get(DESCRIPTION.getElementName()).toString());
839 if (((Map<String, Object>) propValue)
840 .containsKey(DEFAULT_VALUE.getElementName())) {
841 propertyDef.setValue(((Map<String, Object>) propValue)
842 .get(DEFAULT_VALUE.getElementName()));
844 if (((Map<String, Object>) propValue).containsKey(IS_PASSWORD.getElementName())) {
845 propertyDef.setPassword(Boolean.getBoolean(((Map<String, Object>) propValue)
846 .get(IS_PASSWORD.getElementName()).toString()));
848 propertyDef.setValue(propValue);
850 } else if (propValue instanceof List) {
851 List<Object> propValueList = (List<Object>) propValue;
853 fillInputsListRecursively(propertyDef, propValueList);
854 propertyDef.setValue(propValue);
860 @SuppressWarnings("unchecked")
861 private boolean containsGetInput(Object propValue) {
862 return ((Map<String, Object>) propValue).containsKey(GET_INPUT.getElementName())
863 || ImportUtils.containsGetInput(propValue);
866 @SuppressWarnings("unchecked")
867 private void fillInputsListRecursively(UploadPropInfo propertyDef, List<Object> propValueList) {
868 for (Object objValue : propValueList) {
870 if (objValue instanceof Map) {
871 Map<String, Object> objMap = (Map<String, Object>) objValue;
872 if (objMap.containsKey(GET_INPUT.getElementName())) {
873 fillInputRecursively(propertyDef.getName(), objMap, propertyDef);
875 Set<String> keys = objMap.keySet();
876 findAndFillInputsListRecursively(propertyDef, objMap, keys);
878 } else if (objValue instanceof List) {
879 List<Object> propSubValueList = (List<Object>) objValue;
880 fillInputsListRecursively(propertyDef, propSubValueList);
885 @SuppressWarnings("unchecked")
886 private void findAndFillInputsListRecursively(UploadPropInfo propertyDef, Map<String, Object> objMap,
888 for (String key : keys) {
889 Object value = objMap.get(key);
890 if (value instanceof Map) {
891 fillInputRecursively(key, (Map<String, Object>) value, propertyDef);
892 } else if (value instanceof List) {
893 List<Object> propSubValueList = (List<Object>) value;
894 fillInputsListRecursively(propertyDef, propSubValueList);
899 private void fillInputRecursively(String propName, Map<String, Object> propValue, UploadPropInfo propertyDef) {
901 if (propValue.containsKey(GET_INPUT.getElementName())) {
902 Object getInput = propValue.get(GET_INPUT.getElementName());
903 GetInputValueDataDefinition getInputInfo = new GetInputValueDataDefinition();
904 List<GetInputValueDataDefinition> getInputs = propertyDef.getGet_input();
905 if (getInputs == null) {
906 getInputs = new ArrayList<>();
908 if (getInput instanceof String) {
910 getInputInfo.setInputName((String) getInput);
911 getInputInfo.setPropName(propName);
913 } else if (getInput instanceof List) {
914 fillInput(propName, getInput, getInputInfo);
916 getInputs.add(getInputInfo);
917 propertyDef.setGet_input(getInputs);
918 propertyDef.setValue(propValue);
920 findAndFillInputRecursively(propValue, propertyDef);
924 @SuppressWarnings("unchecked")
925 private void findAndFillInputRecursively(Map<String, Object> propValue, UploadPropInfo propertyDef) {
926 for (String propName : propValue.keySet()) {
927 Object value = propValue.get(propName);
928 if (value instanceof Map) {
929 fillInputRecursively(propName, (Map<String, Object>) value, propertyDef);
931 } else if (value instanceof List) {
932 fillInputsRecursively(propertyDef, propName, (List<Object>) value);
937 private void fillInputsRecursively(UploadPropInfo propertyDef, String propName, List<Object> inputs) {
939 .filter(o -> o instanceof Map)
940 .forEach(o -> fillInputRecursively(propName, (Map<String, Object>)o, propertyDef));
943 @SuppressWarnings("unchecked")
944 private void fillInput(String propName, Object getInput, GetInputValueDataDefinition getInputInfo) {
945 List<Object> getInputList = (List<Object>) getInput;
946 getInputInfo.setPropName(propName);
947 getInputInfo.setInputName((String) getInputList.get(0));
948 if (getInputList.size() > 1) {
949 Object indexObj = getInputList.get(1);
950 if (indexObj instanceof Integer) {
951 getInputInfo.setIndexValue((Integer) indexObj);
952 } else if (indexObj instanceof Float) {
953 int index = ((Float) indexObj).intValue();
954 getInputInfo.setIndexValue(index);
955 } else if (indexObj instanceof Map && ((Map<String, Object>) indexObj)
956 .containsKey(GET_INPUT.getElementName())) {
957 Object index = ((Map<String, Object>) indexObj)
958 .get(GET_INPUT.getElementName());
959 GetInputValueDataDefinition getInputInfoIndex = new GetInputValueDataDefinition();
960 getInputInfoIndex.setInputName((String) index);
961 getInputInfoIndex.setPropName(propName);
962 getInputInfo.setGetInputIndex(getInputInfoIndex);
964 getInputInfo.setList(true);
968 private boolean valueNotContainsPattern(Pattern pattern, Object propValue) {
969 return propValue == null || !pattern.matcher(propValue.toString()).find();
972 private Map<String, Object> failIfNoNodeTemplates(String fileName) {
973 janusGraphDao.rollback();
974 throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName);
977 private Object failIfNotTopologyTemplate(String fileName) {
978 janusGraphDao.rollback();
979 throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName);
982 private void rollbackWithException(ActionStatus actionStatus, String... params) {
983 janusGraphDao.rollback();
984 throw new ByActionStatusComponentException(actionStatus, params);
987 private void failOnMissingCapabilityTypes(GroupDefinition groupDefinition, List<String> missingCapTypes) {
988 log.debug("#failOnMissingCapabilityTypes - Failed to validate the capabilities of the group {}. The capability types {} are missing on the group type {}. ", groupDefinition.getName(), missingCapTypes.toString(), groupDefinition.getType());
989 if(CollectionUtils.isNotEmpty(missingCapTypes)) {
990 rollbackWithException(ActionStatus.MISSING_CAPABILITY_TYPE, missingCapTypes.toString());
994 private void failOnMissingCapabilityNames(GroupDefinition groupDefinition, List<String> missingCapNames) {
995 log.debug("#failOnMissingCapabilityNames - Failed to validate the capabilities of the group {}. The capabilities with the names {} are missing on the group type {}. ", groupDefinition.getName(), missingCapNames.toString(), groupDefinition.getType());
996 rollbackWithException(ActionStatus.MISSING_CAPABILITIES, missingCapNames.toString(), CapabilityDataDefinition.OwnerType.GROUP.getValue(), groupDefinition.getName());