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.validation.ResourceValidator;
12 import org.openecomp.sdc.validation.ValidationContext;
13 import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
14 import org.openecomp.sdc.validation.type.ValidatorConstants;
16 import java.util.List;
20 * Created by TALIO on 2/27/2017.
22 public class NeutronSecurityGroupResourceValidator implements ResourceValidator {
23 private static final ErrorMessageCode ERROR_CODE_HSG1 = new ErrorMessageCode("HSG1");
26 public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
27 GlobalValidationContext globalContext, ValidationContext validationContext) {
29 HeatResourceValidationContext heatResourceValidationContext =
30 (HeatResourceValidationContext) validationContext;
31 validateSecurityGroupIsUsed(fileName, resourceEntry, heatResourceValidationContext,
35 private void validateSecurityGroupIsUsed(String fileName,
36 Map.Entry<String, Resource> resourceEntry,
37 HeatResourceValidationContext
38 heatResourceValidationContext,
39 GlobalValidationContext globalContext) {
41 Map<String, Map<String, List<String>>> securityGroupsPointedByOtherResources =
42 heatResourceValidationContext.getFileLevelResourceDependencies()
43 .get(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
45 if (MapUtils.isEmpty(securityGroupsPointedByOtherResources)) {
49 Map<String, List<String>> resourcesPointingCurrSecurityGroup =
50 securityGroupsPointedByOtherResources.get(resourceEntry.getKey());
52 if (isSecurityGroupNotInUse(resourcesPointingCurrSecurityGroup)) {
53 globalContext.addMessage(
56 ErrorMessagesFormatBuilder
57 .getErrorWithParameters(
58 ERROR_CODE_HSG1, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
59 ValidatorConstants.Security_Group, resourceEntry.getKey()));
64 private boolean isSecurityGroupNotInUse(Map<String, List<String>>
65 referencingResourcesToCurrSecurityGroup) {
66 return MapUtils.isEmpty(referencingResourcesToCurrSecurityGroup);