summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java201
1 files changed, 81 insertions, 120 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java
index 016b911c81..d1b3d9bad3 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
@@ -27,138 +29,97 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.impl.util.HeatValidationService;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
public class VirtualMachineInterfaceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_VLAN1 = new ErrorMessageCode("VLAN1");
- private static final ErrorMessageCode ERROR_CODE_VLAN2 = new ErrorMessageCode("VLAN2");
-
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- HeatResourceValidationContext heatResourceValidationContext =
- (HeatResourceValidationContext) validationContext;
- final ValidityStatus status = calculateValidityStatus(resourceEntry.getValue());
- switch (status) {
- case BOTH_PROPERTIES_PRESENT:
- validateHasSingleParentPort(fileName, resourceEntry, globalContext,
- heatResourceValidationContext);
- break;
- case REFS_PROPERTY_MISSING:
- globalContext
- .addMessage(fileName, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_VLAN2,
- Messages.VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY.getErrorMessage(),
- resourceEntry.getKey()));
- break;
- case VLAN_TAG_PROPERTY_MISSING:
- globalContext
- .addMessage(fileName, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_VLAN2,
- Messages.VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY.getErrorMessage(),
- resourceEntry.getKey()));
- validateHasSingleParentPort(fileName, resourceEntry, globalContext,
- heatResourceValidationContext);
- break;
- case BOTH_PROPERTIES_MISSING:
- // this is a port and not a VLAN, no further validation required
- break;
- default :
- throw new IllegalArgumentException("Received a value for which no handling is " +
- "available " + status);
- }
- }
-
- private ValidityStatus calculateValidityStatus(Resource resource) {
- Optional<Object> refsPropertyValue = getRefsPropertyValue(resource);
- Optional<Object> tagPropertyValue = getVlanTagPropertyValue(resource);
-
- if (refsPropertyValue.isPresent() && tagPropertyValue.isPresent()) {
- return ValidityStatus.BOTH_PROPERTIES_PRESENT;
- }
- if (!refsPropertyValue.isPresent() && !tagPropertyValue.isPresent()) {
- return ValidityStatus.BOTH_PROPERTIES_MISSING;
+ private static final ErrorMessageCode ERROR_CODE_VLAN1 = new ErrorMessageCode("VLAN1");
+ private static final ErrorMessageCode ERROR_CODE_VLAN2 = new ErrorMessageCode("VLAN2");
+
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ HeatResourceValidationContext heatResourceValidationContext = (HeatResourceValidationContext) validationContext;
+ final ValidityStatus status = calculateValidityStatus(resourceEntry.getValue());
+ switch (status) {
+ case BOTH_PROPERTIES_PRESENT:
+ validateHasSingleParentPort(fileName, resourceEntry, globalContext, heatResourceValidationContext);
+ break;
+ case REFS_PROPERTY_MISSING:
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_VLAN2, Messages.VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY.getErrorMessage(),
+ resourceEntry.getKey()));
+ break;
+ case VLAN_TAG_PROPERTY_MISSING:
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_VLAN2, Messages.VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY.getErrorMessage(),
+ resourceEntry.getKey()));
+ validateHasSingleParentPort(fileName, resourceEntry, globalContext, heatResourceValidationContext);
+ break;
+ case BOTH_PROPERTIES_MISSING:
+ // this is a port and not a VLAN, no further validation required
+ break;
+ default:
+ throw new IllegalArgumentException("Received a value for which no handling is " + "available " + status);
+ }
}
- return refsPropertyValue.map(o -> ValidityStatus.VLAN_TAG_PROPERTY_MISSING)
- .orElse(ValidityStatus.REFS_PROPERTY_MISSING);
- }
-
- private void validateHasSingleParentPort(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- HeatResourceValidationContext heatResourceValidationContext) {
- Object refsPropertyValue = resourceEntry.getValue().getProperties()
- .get(HeatConstants.VMI_REFS_PROPERTY_NAME);
- if (Objects.isNull(refsPropertyValue)) {
- return;
- }
- boolean hasSingleParentPort = HeatValidationService.hasSingleParentPort(fileName, globalContext,
- heatResourceValidationContext,
- refsPropertyValue);
- if (!hasSingleParentPort) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_VLAN1,
- Messages.VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT.getErrorMessage(),
- resourceEntry.getKey()));
+ private ValidityStatus calculateValidityStatus(Resource resource) {
+ Optional<Object> refsPropertyValue = getRefsPropertyValue(resource);
+ Optional<Object> tagPropertyValue = getVlanTagPropertyValue(resource);
+ if (refsPropertyValue.isPresent() && tagPropertyValue.isPresent()) {
+ return ValidityStatus.BOTH_PROPERTIES_PRESENT;
+ }
+ if (!refsPropertyValue.isPresent() && !tagPropertyValue.isPresent()) {
+ return ValidityStatus.BOTH_PROPERTIES_MISSING;
+ }
+ return refsPropertyValue.map(o -> ValidityStatus.VLAN_TAG_PROPERTY_MISSING).orElse(ValidityStatus.REFS_PROPERTY_MISSING);
}
-
- }
-
-
- private Optional<Object> getVlanTagPropertyValue(Resource resource) {
- Object vmiProperties = resource.getProperties()
- .get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME);
- if (Objects.nonNull(vmiProperties) && vmiProperties instanceof Map) {
- return Optional.ofNullable(((Map) vmiProperties)
- .get(HeatConstants.VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME));
+ private void validateHasSingleParentPort(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ HeatResourceValidationContext heatResourceValidationContext) {
+ Object refsPropertyValue = resourceEntry.getValue().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
+ if (Objects.isNull(refsPropertyValue)) {
+ return;
+ }
+ boolean hasSingleParentPort = HeatValidationService
+ .hasSingleParentPort(fileName, globalContext, heatResourceValidationContext, refsPropertyValue);
+ if (!hasSingleParentPort) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_VLAN1, Messages.VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT.getErrorMessage(), resourceEntry.getKey()));
+ }
}
- return Optional.empty();
- }
-
- private Optional<Object> getRefsPropertyValue(Resource resource) {
- Object refsProperty = resource.getProperties()
- .get(HeatConstants.VMI_REFS_PROPERTY_NAME);
- return Optional.ofNullable(refsProperty);
-
- }
+ private Optional<Object> getVlanTagPropertyValue(Resource resource) {
+ Object vmiProperties = resource.getProperties().get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME);
+ if (Objects.nonNull(vmiProperties) && vmiProperties instanceof Map) {
+ return Optional.ofNullable(((Map) vmiProperties).get(HeatConstants.VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME));
+ }
+ return Optional.empty();
+ }
- private enum ValidityStatus {
- BOTH_PROPERTIES_MISSING,
- BOTH_PROPERTIES_PRESENT,
- REFS_PROPERTY_MISSING,
- VLAN_TAG_PROPERTY_MISSING
+ private Optional<Object> getRefsPropertyValue(Resource resource) {
+ Object refsProperty = resource.getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
+ return Optional.ofNullable(refsProperty);
+ }
- }
+ private enum ValidityStatus {BOTH_PROPERTIES_MISSING, BOTH_PROPERTIES_PRESENT, REFS_PROPERTY_MISSING, VLAN_TAG_PROPERTY_MISSING}
- private enum Messages {
- VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT(
- "More than one parent port found, there should be only one parent port for a VLAN sub-interface ID [%s]"),
- VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY("VLAN Tag property " +
- "virtual_machine_interface_properties_sub_interface_vlan_tag is missing in VLAN Resource ID [%s]"),
- VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY("Parent port property virtual_machine_interface_refs " +
- "is missing in VLAN Resource ID [%s]");
+ private enum Messages {
+ // @formatter:off
+ VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT("More than one parent port found, there should be only one parent port for "
+ + "a VLAN sub-interface ID [%s]"),
+ VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY("VLAN Tag property virtual_machine_interface_properties_sub_interface_vlan_tag is missing "
+ + "in VLAN Resource ID [%s]"),
+ VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY("Parent port property virtual_machine_interface_refs is missing in VLAN Resource ID [%s]");
+ // @formatter:on
- String getErrorMessage() {
- return errorMessage;
- }
+ private final String errorMessage;
- private final String errorMessage;
+ Messages(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
- Messages(String errorMessage) {
- this.errorMessage = errorMessage;
+ String getErrorMessage() {
+ return errorMessage;
+ }
}
-
- }
-
}