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.validation.impl.validators;
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.core.utilities.CommonMethods;
26 import org.openecomp.core.utilities.yaml.YamlUtil;
27 import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
28 import org.openecomp.core.validation.errors.Messages;
29 import org.openecomp.core.validation.interfaces.Validator;
30 import org.openecomp.core.validation.types.GlobalValidationContext;
31 import org.openecomp.sdc.common.utils.AsdcCommon;
32 import org.openecomp.sdc.datatypes.error.ErrorLevel;
33 import org.openecomp.sdc.datatypes.model.heat.ForbiddenHeatResourceTypes;
34 import org.openecomp.sdc.heat.datatypes.DefinedHeatParameterTypes;
35 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
36 import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
37 import org.openecomp.sdc.heat.datatypes.model.Environment;
38 import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
39 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
40 import org.openecomp.sdc.heat.datatypes.model.Resource;
41 import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions;
42 import org.openecomp.sdc.heat.services.HeatStructureUtil;
43 import org.openecomp.sdc.heat.services.manifest.ManifestUtil;
45 import java.util.ArrayList;
46 import java.util.Collection;
47 import java.util.Comparator;
48 import java.util.HashMap;
49 import java.util.HashSet;
50 import java.util.List;
52 import java.util.Objects;
54 import java.util.TreeMap;
55 import java.util.regex.Pattern;
57 public class EcompGuideLineValidator extends HeatValidator implements Validator {
59 public void validate(GlobalValidationContext globalContext) {
61 ManifestContent manifestContent;
63 manifestContent = checkValidationPreCondition(globalContext);
64 } catch (Exception exception) {
69 Set<String> baseFiles = validateManifest(manifestContent, globalContext);
71 Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
72 Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent);
76 .filter(fileName -> FileData
77 .isHeatFile(fileTypeMap.get(fileName)))
78 .forEach(fileName -> validate(fileName,
79 fileEnvMap.get(fileName) != null ? fileEnvMap.get(fileName).getFile() : null,
80 fileTypeMap, baseFiles, globalContext));
83 private void validate(String fileName, String envFileName, Map<String, FileData.Type> fileTypeMap,
84 Set<String> baseFiles, GlobalValidationContext globalContext) {
85 HeatOrchestrationTemplate heatOrchestrationTemplate =
86 checkHeatOrchestrationPreCondition(fileName, globalContext);
87 if (heatOrchestrationTemplate == null) {
91 validateBaseFile(fileName, baseFiles, heatOrchestrationTemplate, globalContext);
92 validateHeatVolumeFile(fileName, fileTypeMap, heatOrchestrationTemplate, globalContext);
93 validateHeatNamingConvention(fileName, heatOrchestrationTemplate, globalContext);
94 validateHeatNovaResource(fileName, envFileName, heatOrchestrationTemplate, globalContext);
95 validateResourceTypeIsForbidden(fileName, heatOrchestrationTemplate, globalContext);
96 validateFixedIpsNamingConvention(fileName, heatOrchestrationTemplate, globalContext);
99 private void validateHeatNovaResource(String fileName, String envFileName,
100 HeatOrchestrationTemplate heatOrchestrationTemplate,
101 GlobalValidationContext globalContext) {
102 Map<String, String> uniqueResourcePortNetworkRole = new HashMap<>();
103 //if no resources exist return
104 if (heatOrchestrationTemplate.getResources() == null
105 || heatOrchestrationTemplate.getResources().size() == 0) {
109 heatOrchestrationTemplate
113 .filter(entry -> entry.getValue().getType()
114 .equals(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource()))
115 .forEach(entry -> validateNovaServerResourceType(entry.getKey(), fileName, envFileName,
116 entry, uniqueResourcePortNetworkRole, heatOrchestrationTemplate, globalContext));
119 private void validateNovaServerResourceType(String resourceId, String fileName,
121 Map.Entry<String, Resource> resourceEntry,
122 Map<String, String> uniqueResourcePortNetworkRole,
123 HeatOrchestrationTemplate heatOrchestrationTemplate,
124 GlobalValidationContext globalValidationContext) {
125 validateNovaServerResourceMetaData(fileName, resourceId,
126 heatOrchestrationTemplate.getResources().get(resourceId), globalValidationContext);
127 validateNovaServerResourceNetworkUniqueRole(fileName, resourceId, heatOrchestrationTemplate,
128 globalValidationContext);
129 validateNovaServerNamingConvention(fileName, envFileName, resourceEntry,
130 globalValidationContext);
131 validateNovaServerAvailabilityZoneName(fileName, resourceEntry, globalValidationContext);
132 validateImageAndFlavorFromNovaServer(fileName, resourceEntry, globalValidationContext);
135 @SuppressWarnings("unchecked")
136 private void validateNovaServerResourceMetaData(String fileName, String resourceId,
138 GlobalValidationContext globalValidationContext) {
139 Map<String, Object> novaServerProp = resource.getProperties();
140 Object novaServerPropMetadata;
141 if (MapUtils.isNotEmpty(novaServerProp)) {
142 novaServerPropMetadata = novaServerProp.get("metadata");
143 if (novaServerPropMetadata == null) {
144 globalValidationContext.addMessage(
147 ErrorMessagesFormatBuilder
148 .getErrorWithParameters(Messages.MISSING_NOVA_SERVER_METADATA.getErrorMessage(),
150 } else if (novaServerPropMetadata instanceof Map) {
151 TreeMap<String, Object> propertyMap = new TreeMap(new Comparator<String>() {
154 public int compare(String o1, String o2) {
155 return o1.compareToIgnoreCase(o2);
159 public boolean equals(Object obj) {
163 propertyMap.putAll((Map) novaServerPropMetadata);
164 if (!propertyMap.containsKey("vf_module_id")) {
165 globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
166 ErrorMessagesFormatBuilder.getErrorWithParameters(
167 Messages.MISSING_NOVA_SERVER_VF_MODULE_ID.getErrorMessage(), resourceId));
169 if (!propertyMap.containsKey("vnf_id")) {
170 globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
171 ErrorMessagesFormatBuilder
172 .getErrorWithParameters(Messages.MISSING_NOVA_SERVER_VNF_ID.getErrorMessage(),
179 private void validateNovaServerResourceNetworkUniqueRole(String fileName, String resourceId,
180 HeatOrchestrationTemplate
181 heatOrchestrationTemplate,
182 GlobalValidationContext
183 globalValidationContext) {
187 Map<String, String> uniqueResourcePortNetworkRole = new HashMap<>();
189 Object propertyNetworkValue =
190 heatOrchestrationTemplate.getResources().get(resourceId).getProperties().get("networks");
191 if (propertyNetworkValue != null && propertyNetworkValue instanceof List) {
192 List<String> portResourceIdList =
193 getNovaNetworkPortResourceList(fileName, (List) propertyNetworkValue,
194 globalValidationContext);
195 for (String portResourceId : portResourceIdList) {
196 Resource portResource = heatOrchestrationTemplate.getResources().get(portResourceId);
197 if (portResource != null && portResource.getType()
198 .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) {
200 getPortNetwork(fileName, resourceId, portResource, globalValidationContext);
201 if (Objects.nonNull(portNetwork)) {
202 network = (String) portNetwork.get("get_param");
203 if (Objects.nonNull(network)) {
204 role = getNetworkRole(network);
205 if (role != null && uniqueResourcePortNetworkRole.containsKey(role)) {
206 globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
207 ErrorMessagesFormatBuilder.getErrorWithParameters(
208 Messages.RESOURCE_CONNECTED_TO_TWO_EXTERNAL_NETWORKS_WITH_SAME_ROLE
209 .getErrorMessage(), resourceId, role));
211 uniqueResourcePortNetworkRole.put(role, portResourceId);
221 private Map getPortNetwork(String fileName, String resourceId, Resource portResource,
222 GlobalValidationContext globalValidationContext) {
223 Object portNetwork = portResource.getProperties().get("network_id");
224 if (portNetwork == null) {
225 portNetwork = portResource.getProperties().get("network");
227 if (!(portNetwork instanceof Map)) {
228 globalValidationContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
229 .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(),
230 "network or network_id", resourceId));
233 return (Map) portNetwork;
236 private List<String> getNovaNetworkPortResourceList(String filename, List propertyNetworkValue,
237 GlobalValidationContext globalContext) {
238 List<String> portResourceIdList = new ArrayList<>();
239 for (Object propValue : propertyNetworkValue) {
240 Object portPropValue = ((Map) propValue).get("port");
241 Collection<String> portResourceIds = HeatStructureUtil
242 .getReferencedValuesByFunctionName(filename, "get_resource", portPropValue,
244 if (portResourceIds != null) {
245 portResourceIdList.addAll(portResourceIds);
249 return portResourceIdList;
252 private String getNetworkRole(String network) {
253 if (network == null) {
256 if (network.contains("_net_id")) {
257 return network.substring(0, network.indexOf("_net_id"));
258 } else if (network.contains("net_name")) {
259 return network.substring(0, network.indexOf("_net_name"));
260 } else if (network.contains("net_fqdn")) {
261 return network.substring(0, network.indexOf("_net_fqdn"));
266 private void validateHeatNamingConvention(String fileName,
267 HeatOrchestrationTemplate heatOrchestrationTemplate,
268 GlobalValidationContext globalContext) {
269 validatePortNetworkNamingConvention(fileName, heatOrchestrationTemplate, globalContext);
272 private void validatePortNetworkNamingConvention(String fileName,
273 HeatOrchestrationTemplate
274 heatOrchestrationTemplate,
275 GlobalValidationContext globalContext) {
276 if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
279 String[] regexList = new String[]{".*_net_id", ".*_net_name", ".*_net_fqdn"};
281 heatOrchestrationTemplate
285 .filter(entry -> entry.getValue().getType() != null && entry.getValue().getType()
286 .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()))
287 .forEach(entry -> entry.getValue()
291 .filter(propertyEntry -> propertyEntry != null
292 && (propertyEntry.getKey().toLowerCase().equals("network".toLowerCase())
294 propertyEntry.getKey().equals("network_id")))
295 .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(),
296 propertyEntry.getValue(), regexList,
297 Messages.NETWORK_PARAM_NOT_ALIGNED_WITH_GUIDE_LINE, globalContext)));
300 private void validateParamNamingConvention(String fileName, String resourceId,
301 Object propertyValue, String[] regexList,
303 GlobalValidationContext globalContext) {
305 if (propertyValue instanceof Map) {
306 paramName = ((Map) propertyValue).get("get_param");
307 if (paramName instanceof String) {
308 if (!evalPattern((String) paramName, regexList)) {
309 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
310 .getErrorWithParameters(message.getErrorMessage(), (String) paramName, resourceId));
314 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
315 .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(),
316 "network or network_id", resourceId));
320 private boolean evalPattern(Object paramVal, String[] regexList) {
322 if (paramVal instanceof String) {
323 value = ((String) paramVal);
325 if (paramVal instanceof Integer) {
326 value = paramVal.toString();
328 return evalPattern(value, regexList);
331 private boolean evalPattern(String paramVal, String[] regexList) {
333 for (String regex : regexList) {
334 if (Pattern.matches(regex, paramVal)) {
343 private void validateHeatVolumeFile(String fileName, Map<String, FileData.Type> fileTypeMap,
344 HeatOrchestrationTemplate heatOrchestrationTemplate,
345 GlobalValidationContext globalContext) {
346 //if not heat volume return
347 if (!fileTypeMap.get(fileName).equals(FileData.Type.HEAT_VOL)) {
351 //if no resources exist return
352 if (heatOrchestrationTemplate.getResources() == null
353 || heatOrchestrationTemplate.getResources().size() == 0) {
357 Set<String> expectedExposedResources = new HashSet<>();
358 Set<String> actualExposedResources = new HashSet<>();
359 heatOrchestrationTemplate.getResources()
362 .filter(entry -> entry.getValue().getType()
363 .equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()))
364 .forEach(entry -> expectedExposedResources.add(entry.getKey()));
366 if (heatOrchestrationTemplate.getOutputs() != null) {
368 heatOrchestrationTemplate.getOutputs().entrySet()
370 .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(),
372 .forEach(entry -> actualExposedResources.add(
373 getResourceIdFromPropertyValue(fileName, entry.getValue().getValue(),
377 actualExposedResources.stream().forEach(expectedExposedResources::remove);
379 if (expectedExposedResources.size() > 0) {
380 expectedExposedResources
382 .forEach(name -> globalContext.addMessage(fileName, ErrorLevel.WARNING,
383 ErrorMessagesFormatBuilder
384 .getErrorWithParameters(Messages.VOLUME_HEAT_NOT_EXPOSED.getErrorMessage(),
389 private void validateBaseFile(String fileName, Set<String> baseFiles,
390 HeatOrchestrationTemplate heatOrchestrationTemplate,
391 GlobalValidationContext globalContext) {
394 if (baseFiles == null || !baseFiles.contains(fileName)) {
398 //if no resources exist return
399 if (heatOrchestrationTemplate.getResources() == null
400 || heatOrchestrationTemplate.getResources().size() == 0) {
404 Set<String> expectedExposedResources = new HashSet<>();
405 Set<String> actualExposedResources = new HashSet<>();
406 heatOrchestrationTemplate.getResources()
409 .filter(entry -> isExpectedToBeExposed(entry.getValue().getType()))
410 .forEach(entry -> expectedExposedResources.add(entry.getKey()));
412 if (heatOrchestrationTemplate.getOutputs() != null) {
414 heatOrchestrationTemplate.getOutputs().entrySet()
416 .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(),
418 .forEach(entry -> actualExposedResources.add(
419 getResourceIdFromPropertyValue(fileName, entry.getValue().getValue(),
422 actualExposedResources.stream().forEach(expectedExposedResources::remove);
424 if (expectedExposedResources.size() > 0) {
425 expectedExposedResources
427 .forEach(name -> globalContext.addMessage(fileName, ErrorLevel.WARNING,
428 ErrorMessagesFormatBuilder
429 .getErrorWithParameters(Messages.RESOURCE_NOT_DEFINED_IN_OUTPUT.getErrorMessage(),
434 private void validateResourceTypeIsForbidden(String fileName,
435 HeatOrchestrationTemplate heatOrchestrationTemplate,
436 GlobalValidationContext globalContext) {
437 if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
441 heatOrchestrationTemplate.getResources()
445 ForbiddenHeatResourceTypes.findByForbiddenHeatResource(entry.getValue().getType())
447 .filter(entry -> ForbiddenHeatResourceTypes
448 .findByForbiddenHeatResource(entry.getValue().getType())
449 .equals(ForbiddenHeatResourceTypes.HEAT_FLOATING_IP_TYPE))
450 .forEach(entry -> globalContext.addMessage(fileName, ErrorLevel.WARNING,
451 ErrorMessagesFormatBuilder
452 .getErrorWithParameters(Messages.FLOATING_IP_NOT_IN_USE.getErrorMessage(),
457 private void validateFixedIpsNamingConvention(String fileName,
458 HeatOrchestrationTemplate heatOrchestrationTemplate,
459 GlobalValidationContext globalContext) {
460 if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
464 heatOrchestrationTemplate.getResources()
467 .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()) != null)
468 .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType())
469 .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
470 .forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
473 private void validateImageAndFlavorFromNovaServer(String fileName,
474 Map.Entry<String, Resource> resourceEntry,
475 GlobalValidationContext globalContext) {
476 if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
480 String[] imageOrFlavorAsParameters = new String[]{"image", "flavor"};
481 Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
483 for (String imageOrFlavor : imageOrFlavorAsParameters) {
484 checkImageAndFlavorNames(fileName, imageOrFlavor, resourceEntry.getKey(), propertiesMap,
489 private void checkImageAndFlavorNames(String fileName, String imageOrFlavor, String resourceId,
490 Map<String, Object> propertiesMap,
491 GlobalValidationContext globalContext) {
493 propertiesMap.get(imageOrFlavor) == null ? null : propertiesMap.get(imageOrFlavor);
494 String[] regexList = new String[]{".*_" + imageOrFlavor + "_name"};
496 if (Objects.nonNull(nameValue)) {
497 if (nameValue instanceof Map) {
498 String imageOrFlavorName = getWantedNameFromPropertyValueGetParam(nameValue);
499 if (Objects.nonNull(imageOrFlavorName)) {
500 if (!evalPattern(imageOrFlavorName, regexList)) {
501 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
502 .getErrorWithParameters(
503 Messages.WRONG_IMAGE_OR_FLAVOR_NAME_NOVA_SERVER.getErrorMessage(),
504 imageOrFlavor, resourceId));
508 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
509 .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(), imageOrFlavor,
516 @SuppressWarnings("unchecked")
517 private void checkNeutronPortFixedIpsName(String fileName,
518 Map.Entry<String, Resource> resourceEntry,
519 GlobalValidationContext globalContext) {
521 new String[]{"[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)",
522 "[^_]+_[^_]+_v6_ip_(\\d+)"};
524 if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
528 Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
529 Object fixedIps = propertiesMap.get("fixed_ips");
530 if (Objects.nonNull(fixedIps) && fixedIps instanceof List) {
531 List<Object> fixedIpsList = (List<Object>) fixedIps;
532 for (Object fixedIpsObject : fixedIpsList) {
533 Map.Entry<String, Object> fixedIpsEntry =
534 ((Map<String, Object>) fixedIpsObject).entrySet().iterator().next();
535 if (Objects.nonNull(fixedIpsEntry)) {
536 if (fixedIpsEntry.getValue() instanceof Map) {
537 String fixedIpsName = getWantedNameFromPropertyValueGetParam(fixedIpsEntry.getValue());
538 if (Objects.nonNull(fixedIpsName)) {
539 if (!evalPattern(fixedIpsName, regexList)) {
540 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
541 .getErrorWithParameters(
542 Messages.FIXED_IPS_NOT_ALIGNED_WITH_GUIDE_LINES.getErrorMessage(),
543 resourceEntry.getKey()));
547 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
548 .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(), "fixed_ips",
549 resourceEntry.getKey()));
557 private void validateNovaServerNamingConvention(String fileName, String envFileName,
558 Map.Entry<String, Resource> resourceEntry,
559 GlobalValidationContext globalContext) {
560 if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
564 checkIfNovaNameByGuidelines(fileName, envFileName, resourceEntry, globalContext);
567 private void checkIfNovaNameByGuidelines(String fileName, String envFileName,
568 Map.Entry<String, Resource> resourceEntry,
569 GlobalValidationContext globalContext) {
570 if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
574 Object novaServerName = resourceEntry.getValue().getProperties().get("name");
577 if (Objects.nonNull(novaServerName)) {
578 if (novaServerName instanceof Map) {
579 novaNameMap = (Map) novaServerName;
580 Object novaNameGetParam =
581 novaNameMap.get(ResourceReferenceFunctions.GET_PARAM.getFunction()) == null ? null
582 : novaNameMap.get(ResourceReferenceFunctions.GET_PARAM.getFunction());
583 if (Objects.nonNull(novaNameGetParam)) {
584 checkNovaNameGetParamValueMap(fileName, novaNameGetParam, resourceEntry, globalContext);
585 novaName = novaNameGetParam instanceof List ? (String) ((List) novaNameGetParam).get(0)
586 : (String) novaNameGetParam;
587 checkIfNovaNameParameterInEnvIsStringOrList(fileName, envFileName, resourceEntry,
588 novaName, globalContext);
591 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
592 .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(),
593 "nova server name", resourceEntry.getKey()));
599 private void checkIfNovaNameParameterInEnvIsStringOrList(String fileName, String envFileName,
600 Map.Entry<String, Resource>
602 String novaServerName,
603 GlobalValidationContext globalContext) {
604 if (Objects.nonNull(envFileName)) {
605 Environment environment = validateEnvContent(envFileName, globalContext);
607 if (environment != null && MapUtils.isNotEmpty(environment.getParameters())) {
608 Object novaServerNameEnvValue =
609 environment.getParameters().containsKey(novaServerName) ? environment.getParameters()
610 .get(novaServerName) : null;
611 if (Objects.nonNull(novaServerNameEnvValue)) {
612 if (!DefinedHeatParameterTypes
613 .isNovaServerEnvValueIsFromRightType(novaServerNameEnvValue)) {
614 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
615 .getErrorWithParameters(
616 Messages.NOVA_SERVER_NAME_NOT_ALIGNED_WITH_GUIDE_LINES.getErrorMessage(),
617 resourceEntry.getKey()));
625 private void validateNovaServerAvailabilityZoneName(String fileName,
626 Map.Entry<String, Resource> resourceEntry,
627 GlobalValidationContext globalContext) {
628 String[] regexList = new String[]{"availability_zone_(\\d+)"};
630 if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
634 Object availabilityZoneMap =
635 resourceEntry.getValue().getProperties().containsKey("availability_zone") ? resourceEntry
636 .getValue().getProperties().get("availability_zone") : null;
638 if (Objects.nonNull(availabilityZoneMap)) {
639 if (availabilityZoneMap instanceof Map) {
640 String availabilityZoneName = getWantedNameFromPropertyValueGetParam(availabilityZoneMap);
642 if (availabilityZoneName != null) {
643 if (!evalPattern(availabilityZoneName, regexList)) {
644 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
645 .getErrorWithParameters(
646 Messages.AVAILABILITY_ZONE_NOT_ALIGNED_WITH_GUIDE_LINES.getErrorMessage(),
647 resourceEntry.getKey()));
651 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
652 .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(),
653 "availability_zone", resourceEntry.getKey()));
659 @SuppressWarnings("unchecked")
660 private void checkNovaNameGetParamValueMap(String fileName, Object getParamValue,
661 Map.Entry<String, Resource> resourceEntry,
662 GlobalValidationContext globalContext) {
663 if (getParamValue instanceof List) {
664 List<Object> getParamNameList = (List) getParamValue;
665 String[] regexName = new String[]{".*_names"};
666 isNovaNameAsListLegal(fileName, getParamNameList, regexName, resourceEntry, globalContext);
667 } else if (getParamValue instanceof String) {
668 String[] regexName = new String[]{".*_name_(\\d+)"};
669 isNovaNameAsStringLegal(fileName, (String) getParamValue, regexName, resourceEntry,
676 private void isNovaNameAsListLegal(String fileName, List<Object> getParamNameList,
677 String[] regexName, Map.Entry<String, Resource> resourceEntry,
678 GlobalValidationContext globalContext) {
680 if (getParamNameList.size() != 2 || !evalPattern(getParamNameList.get(0), regexName)) {
681 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
682 .getErrorWithParameters(
683 Messages.NOVA_SERVER_NAME_NOT_ALIGNED_WITH_GUIDE_LINES.getErrorMessage(),
684 resourceEntry.getKey()));
688 private boolean isNovaNameAsStringLegal(String fileName, String novaName, String[] regexName,
689 Map.Entry<String, Resource> resourceEntry,
690 GlobalValidationContext globalContext) {
691 if (!evalPattern(novaName, regexName)) {
692 globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
693 .getErrorWithParameters(
694 Messages.NOVA_SERVER_NAME_NOT_ALIGNED_WITH_GUIDE_LINES.getErrorMessage(),
695 resourceEntry.getKey()));
701 private String getWantedNameFromPropertyValueGetParam(Object value) {
702 Set<String> paramName = HeatStructureUtil
703 .getReferencedValuesByFunctionName(null, ResourceReferenceFunctions.GET_PARAM.getFunction(),
705 if (paramName != null && CollectionUtils.isNotEmpty(paramName)) {
706 return (String) paramName.toArray()[0];
711 private String getResourceIdFromPropertyValue(String filename, Object value,
712 GlobalValidationContext globalContext) {
713 Set<String> referenceValues = HeatStructureUtil.getReferencedValuesByFunctionName(filename,
714 ResourceReferenceFunctions.GET_RESOURCE.getFunction(), value, globalContext);
715 if (referenceValues != null && CollectionUtils.isNotEmpty(referenceValues)) {
716 return (String) referenceValues.toArray()[0];
721 private boolean isPropertyValueGetResource(String filename, Object value,
722 GlobalValidationContext globalContext) {
723 Set<String> referenceValues = HeatStructureUtil.getReferencedValuesByFunctionName(filename,
724 ResourceReferenceFunctions.GET_RESOURCE.getFunction(), value, globalContext);
725 return referenceValues != null && (referenceValues.size() > 0);
728 private boolean isExpectedToBeExposed(String type) {
729 return HeatResourcesTypes.isResourceExpectedToBeExposed(type);
732 private Set<String> validateManifest(ManifestContent manifestContent,
733 GlobalValidationContext globalContext) {
734 Set<String> baseFiles = ManifestUtil.getBaseFiles(manifestContent);
735 if (baseFiles == null || baseFiles.size() == 0) {
736 globalContext.addMessage(
737 AsdcCommon.MANIFEST_NAME,
739 ErrorMessagesFormatBuilder
740 .getErrorWithParameters(Messages.MISSIN_BASE_HEAT_FILE.getErrorMessage()));
741 } else if (baseFiles.size() > 1) {
742 String baseFileList = getElementListAsString(baseFiles);
743 globalContext.addMessage(
744 AsdcCommon.MANIFEST_NAME,
746 ErrorMessagesFormatBuilder
747 .getErrorWithParameters(Messages.MULTI_BASE_HEAT_FILE.getErrorMessage(),
753 private String getElementListAsString(Set<String> elementCollection) {
755 return "[" + CommonMethods.collectionToCommaSeparatedString(elementCollection) + "]";
759 private Environment validateEnvContent(String envFileName,
760 GlobalValidationContext globalContext) {
761 Environment envContent;
764 new YamlUtil().yamlToObject(globalContext.getFileContent(envFileName), Environment.class);
765 } catch (Exception exception) {
771 private HeatOrchestrationTemplate checkHeatOrchestrationPreCondition(String fileName,
772 GlobalValidationContext
774 HeatOrchestrationTemplate heatOrchestrationTemplate;
776 heatOrchestrationTemplate = new YamlUtil()
777 .yamlToObject(globalContext.getFileContent(fileName), HeatOrchestrationTemplate.class);
779 } catch (Exception exception) {
782 return heatOrchestrationTemplate;