1 package org.openecomp.sdc.validation.impl.validators.heatresource;
3 import org.apache.commons.collections4.MapUtils;
4 import org.openecomp.core.validation.ErrorMessageCode;
5 import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
6 import org.openecomp.core.validation.types.GlobalValidationContext;
7 import org.openecomp.sdc.common.errors.Messages;
8 import org.openecomp.sdc.datatypes.error.ErrorLevel;
9 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
10 import org.openecomp.sdc.heat.datatypes.model.Resource;
11 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
12 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
13 import org.openecomp.sdc.validation.ResourceValidator;
14 import org.openecomp.sdc.validation.ValidationContext;
15 import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
16 import org.openecomp.sdc.validation.type.ValidatorConstants;
18 import java.util.List;
22 * Created by TALIO on 2/27/2017.
24 public class NeutronSecurityGroupResourceValidator implements ResourceValidator {
25 private static final ErrorMessageCode ERROR_CODE_HSG1 = new ErrorMessageCode("HSG1");
28 public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
29 GlobalValidationContext globalContext, ValidationContext validationContext) {
31 HeatResourceValidationContext heatResourceValidationContext =
32 (HeatResourceValidationContext) validationContext;
33 validateSecurityGroupIsUsed(fileName, resourceEntry, heatResourceValidationContext,
37 private void validateSecurityGroupIsUsed(String fileName,
38 Map.Entry<String, Resource> resourceEntry,
39 HeatResourceValidationContext
40 heatResourceValidationContext,
41 GlobalValidationContext globalContext) {
43 Map<String, Map<String, List<String>>> securityGroupsPointedByOtherResources =
44 heatResourceValidationContext.getFileLevelResourceDependencies()
45 .get(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
47 if (MapUtils.isEmpty(securityGroupsPointedByOtherResources)) {
51 Map<String, List<String>> resourcesPointingCurrSecurityGroup =
52 securityGroupsPointedByOtherResources.get(resourceEntry.getKey());
54 if (isSecurityGroupNotInUse(resourcesPointingCurrSecurityGroup)) {
55 globalContext.addMessage(
58 ErrorMessagesFormatBuilder
59 .getErrorWithParameters(
60 ERROR_CODE_HSG1, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
61 ValidatorConstants.Security_Group, resourceEntry.getKey()),
62 LoggerTragetServiceName.VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE,
63 LoggerErrorDescription.SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE);
68 private boolean isSecurityGroupNotInUse(Map<String, List<String>>
69 referencingResourcesToCurrSecurityGroup) {
70 return MapUtils.isEmpty(referencingResourcesToCurrSecurityGroup);