1 package org.openecomp.sdc.validation.impl.validators.heatresource;
3 import org.apache.commons.collections4.MapUtils;
4 import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
5 import org.openecomp.core.validation.types.GlobalValidationContext;
6 import org.openecomp.sdc.common.errors.Messages;
7 import org.openecomp.sdc.datatypes.error.ErrorLevel;
8 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
9 import org.openecomp.sdc.heat.datatypes.model.Resource;
10 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
11 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
12 import org.openecomp.sdc.validation.ResourceValidator;
13 import org.openecomp.sdc.validation.ValidationContext;
14 import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
15 import org.openecomp.sdc.validation.type.ValidatorConstants;
17 import java.util.List;
21 * Created by TALIO on 2/27/2017.
23 public class NeutronSecurityGroupResourceValidator implements ResourceValidator {
25 public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
26 GlobalValidationContext globalContext, ValidationContext validationContext) {
28 HeatResourceValidationContext heatResourceValidationContext =
29 (HeatResourceValidationContext) validationContext;
30 validateSecurityGroupIsUsed(fileName, resourceEntry, heatResourceValidationContext, globalContext);
33 public void validateSecurityGroupIsUsed(String fileName, Map.Entry<String, Resource> resourceEntry,
34 HeatResourceValidationContext
35 heatResourceValidationContext,
36 GlobalValidationContext globalContext) {
38 Map<String, Map<String, List<String>>> securityGroupsPointedByOtherResources =
39 heatResourceValidationContext.getFileLevelResourceDependencies().
40 get(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
42 if (MapUtils.isEmpty(securityGroupsPointedByOtherResources)) {
46 Map<String, List<String>> resourcesPointingCurrSecurityGroup =
47 securityGroupsPointedByOtherResources.get(resourceEntry.getKey());
49 if(isSecurityGroupNotInUse(resourcesPointingCurrSecurityGroup)){
50 globalContext.addMessage(
53 ErrorMessagesFormatBuilder
54 .getErrorWithParameters(
55 Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
56 ValidatorConstants.Security_Group, resourceEntry.getKey()),
57 LoggerTragetServiceName.VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE,
58 LoggerErrorDescription.SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE);
63 public boolean isSecurityGroupNotInUse(Map<String, List<String>>
64 referencingResourcesToCurrSecurityGroup){
65 return MapUtils.isEmpty(referencingResourcesToCurrSecurityGroup);