Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11149. Have a generic version Validator for validating Requests #6932

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
HDDS-11149. Fix findbugs & rat failures
Change-Id: I05265cad5f26082351c6926c24866b20a50b26d2
  • Loading branch information
swamirishi committed Jul 17, 2024
commit ca3746d10de6060d3fc42622cfa04bd4e2db6116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you have added the methods to validate the max version, but those methods are not used anywhere in the processor itself, therefore if an invalid value is present (FUTURE_VERSION), the processor does not emit an error message in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the annotation processor to validate all that? I would rather put this check someplace else. Probably in a place like https://github.com/swamirishi/ozone/blob/fc57929908cbb05a6304366e67f64317dbf9505d/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/request/validation/ValidatorRegistry.java#L85-L88 where instead of just a set of allowedVersionTypes. I would pass a Map of version class to the allowed values. What do you think of that?

Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public class OmRequestFeatureValidatorProcessor extends AbstractProcessor {
public static final String VALIDATION_CONTEXT_CLASS_NAME =
"org.apache.hadoop.ozone.om.request.validation.ValidationContext";


public static final List<String> ANNOTATION_SIMPLE_NAMES = Arrays.asList("OMClientVersionValidator",
private static final List<String> ANNOTATION_SIMPLE_NAMES = Arrays.asList("OMClientVersionValidator",
"OMLayoutVersionValidator");
public static final String ANNOTATION_CONDITIONS_PROPERTY_NAME = "conditions";
public static final String ANNOTATION_PROCESSING_PHASE_PROPERTY_NAME =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.hadoop.hdds.ComponentVersion;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;

import static java.util.function.Function.identity;
Expand Down Expand Up @@ -49,8 +50,6 @@ public enum ClientVersion implements ComponentVersion {
FUTURE_VERSION(-1, "Used internally when the server side is older and an"
+ " unknown client version has arrived from the client.");

public static final String ERASURE_CODING_SUPPORT_NAME = ERASURE_CODING_SUPPORT.name();

public static final ClientVersion CURRENT = latest();
public static final int CURRENT_VERSION = CURRENT.version;

Expand Down Expand Up @@ -81,8 +80,8 @@ public static ClientVersion fromProtoValue(int value) {
}

private static ClientVersion latest() {
ClientVersion[] versions = ClientVersion.values();
return versions[versions.length - 2];
return Arrays.stream(ClientVersion.values())
.max(Comparator.comparingInt(ComponentVersion::toProtoValue)).orElse(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public Class<? extends Enum<? extends Version>> getVersionClass() {
CLIENT_VERSION_EXTRACTOR {
@Override
public Version extractVersion(OMRequest req, ValidationContext ctx) {
return ClientVersion.fromProtoValue(req.getVersion());
return req.getVersion() > ClientVersion.CURRENT_VERSION ?
ClientVersion.CURRENT : ClientVersion.fromProtoValue(req.getVersion());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,6 @@ public void testValidatorMethodCanBeProtected() {
assertThat(compile(source)).succeeded();
}

@Test
public void testEmptyValidationConditionListDoesNotCompile() {
List<String> source = generateSourceOfValidatorMethodWith(
annotationOf(preProcess(), aReqType()),
modifiers("public", "static"),
returnValue("OMRequest"),
parameters("OMRequest rq", "ValidationContext ctx"),
exceptions());
}

@Test
public void testNullValidationConditionListDoesNotCompile() {
List<String> source = generateSourceOfValidatorMethodWith(
annotationOf(preProcess(), aReqType()),
modifiers("public", "static"),
returnValue("OMRequest"),
parameters("OMRequest rq", "ValidationContext ctx"),
exceptions());
}

@Test
public void testNotEnoughParametersForPreProcess() {
List<String> source = generateSourceOfValidatorMethodWith(
Expand Down