-
Notifications
You must be signed in to change notification settings - Fork 510
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-11963. Unify client version and layout version under one interface to accomodate in the request validator framework #7598
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Versioned.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.ozone; | ||
|
||
|
||
/** | ||
* Base class defining the version in the entire system. | ||
*/ | ||
public interface Versioned { | ||
int version(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.apache.hadoop.ozone.om.request.validation; | ||
|
||
import org.apache.hadoop.ozone.ClientVersion; | ||
import org.apache.hadoop.ozone.Versioned; | ||
import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; | ||
import org.apache.hadoop.ozone.upgrade.LayoutVersionManager; | ||
|
||
/** | ||
* Class to extract version out of OM request. | ||
*/ | ||
public enum VersionExtractor { | ||
/** | ||
* Extracts current metadata layout version. | ||
*/ | ||
LAYOUT_VERSION_EXTRACTOR { | ||
@Override | ||
public Versioned extractVersion(OMRequest req, ValidationContext ctx) { | ||
LayoutVersionManager layoutVersionManager = ctx.versionManager(); | ||
return ctx.versionManager().getFeature(layoutVersionManager.getMetadataLayoutVersion()); | ||
} | ||
|
||
@Override | ||
public Class<OMLayoutFeature> getVersionClass() { | ||
return OMLayoutFeature.class; | ||
} | ||
}, | ||
|
||
/** | ||
* Extracts client version from the OMRequests. | ||
*/ | ||
CLIENT_VERSION_EXTRACTOR { | ||
@Override | ||
public Versioned extractVersion(OMRequest req, ValidationContext ctx) { | ||
return req.getVersion() > ClientVersion.CURRENT_VERSION ? | ||
ClientVersion.FUTURE_VERSION : ClientVersion.fromProtoValue(req.getVersion()); | ||
} | ||
|
||
@Override | ||
public Class<ClientVersion> getVersionClass() { | ||
return ClientVersion.class; | ||
} | ||
}; | ||
|
||
public abstract Versioned extractVersion(OMRequest req, ValidationContext ctx); | ||
public abstract Class<? extends Versioned> getVersionClass(); | ||
} |
66 changes: 66 additions & 0 deletions
66
...ger/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.apache.hadoop.ozone.om.request.validation; | ||
|
||
import org.apache.hadoop.ozone.ClientVersion; | ||
import org.apache.hadoop.ozone.Versioned; | ||
import org.apache.hadoop.ozone.om.exceptions.OMException; | ||
import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature; | ||
import org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; | ||
import org.apache.hadoop.ozone.upgrade.LayoutVersionManager; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class TestVersionExtractor { | ||
|
||
@ParameterizedTest | ||
@EnumSource(OMLayoutFeature.class) | ||
void testLayoutVersionExtractor(OMLayoutFeature layoutVersionValue) throws OMException { | ||
ValidationContext context = mock(ValidationContext.class); | ||
LayoutVersionManager layoutVersionManager = new OMLayoutVersionManager(layoutVersionValue.version()); | ||
when(context.versionManager()).thenReturn(layoutVersionManager); | ||
Versioned version = VersionExtractor.LAYOUT_VERSION_EXTRACTOR.extractVersion(null, context); | ||
assertEquals(layoutVersionValue, version); | ||
assertEquals(OMLayoutFeature.class, VersionExtractor.LAYOUT_VERSION_EXTRACTOR.getVersionClass()); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(ClientVersion.class) | ||
void testClientVersionExtractor(ClientVersion expectedClientVersion) { | ||
OMRequest request = mock(OMRequest.class); | ||
when(request.getVersion()).thenReturn(expectedClientVersion.version()); | ||
Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); | ||
assertEquals(expectedClientVersion, version); | ||
assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {1, 2, 5, 10, 1000, 10000}) | ||
void testClientVersionExtractorForFutureValues(int futureVersion) { | ||
OMRequest request = mock(OMRequest.class); | ||
when(request.getVersion()).thenReturn(ClientVersion.CURRENT_VERSION + futureVersion); | ||
Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); | ||
assertEquals(ClientVersion.FUTURE_VERSION, version); | ||
assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: move assertion about classes to separate test case |
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: