You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Russole (via GitHub)" <gi...@apache.org> on 2025/12/13 03:25:40 UTC
[PR] Hdds-14104. Refactor RequestContext creation [ozone]
Russole opened a new pull request, #9493:
URL: https://github.com/apache/ozone/pull/9493
## What changes were proposed in this pull request?
Refactored RequestContext to use a builder-only construction pattern.
* Removed multiple public constructors and redundant getBuilder helpers from RequestContext.
* Adopted builder-only construction by making the Builder constructor private.
* Declared RequestContext and its Builder as final.
* Updated tests to use RequestContext.newBuilder().
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-14104
## How was this patch tested?
All CI checks passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14104. Refactor RequestContext creation [ozone]
Posted by "Russole (via GitHub)" <gi...@apache.org>.
Russole commented on PR #9493:
URL: https://github.com/apache/ozone/pull/9493#issuecomment-3649153083
Thanks @adoroszlai for the review and suggestions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14104. Refactor RequestContext creation [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #9493:
URL: https://github.com/apache/ozone/pull/9493#issuecomment-3649498335
Thanks @Russole for updating the patch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] Hdds-14104. Refactor RequestContext creation [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #9493:
URL: https://github.com/apache/ozone/pull/9493#discussion_r2616157029
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/security/acl/TestRequestContext.java:
##########
@@ -51,7 +51,7 @@ public void testRecursiveAccessFlag() throws IOException {
assertFalse(context.isRecursiveAccessCheck(),
"Wrongly sets recursiveAccessCheck flag value");
- RequestContext.Builder builder = new RequestContext.Builder();
+ RequestContext.Builder builder = RequestContext.newBuilder();
assertFalse(builder.build().isRecursiveAccessCheck(),
"Wrongly sets recursive flag value");
Review Comment:
`testRecursiveAccessFlag()` has also been testing constructor, builder and `getBuilder`. Now there are only 3 possible combinations:
- default value (without explicit `setRecursiveAccessCheck`)
- `setRecursiveAccessCheck(false)`
- `setRecursiveAccessCheck(true)`
So we can simplify this test case further:
```java
@Test
void testRecursiveAccessFlag() {
RequestContext.Builder builder = RequestContext.newBuilder();
assertFalse(builder.build().isRecursiveAccessCheck(), "default value");
builder.setRecursiveAccessCheck(true);
assertTrue(builder.build().isRecursiveAccessCheck());
builder.setRecursiveAccessCheck(false);
assertFalse(builder.build().isRecursiveAccessCheck());
}
```
`getUserRequestContext()` and `baseBuilder()` can be removed, as well as unused imports.
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/security/acl/TestRequestContext.java:
##########
@@ -60,56 +60,63 @@ public void testRecursiveAccessFlag() throws IOException {
assertTrue(builder.build().isRecursiveAccessCheck(),
"Wrongly sets recursive flag value");
- context = new RequestContext("host", null,
- null, "serviceId",
- IAccessAuthorizer.ACLIdentityType.GROUP,
- IAccessAuthorizer.ACLType.CREATE, "owner");
- assertFalse(context.isRecursiveAccessCheck(),
- "Wrongly sets recursive flag value");
+ context = baseBuilder().build();
+ assertFalse(context.isRecursiveAccessCheck());
- context = new RequestContext("host", null,
- null, "serviceId",
- IAccessAuthorizer.ACLIdentityType.GROUP,
- IAccessAuthorizer.ACLType.CREATE, "owner", false);
- assertFalse(context.isRecursiveAccessCheck(),
- "Wrongly sets recursive flag value");
+ context = baseBuilder().setRecursiveAccessCheck(false).build();
+ assertFalse(context.isRecursiveAccessCheck());
- context = new RequestContext("host", null,
- null, "serviceId",
- IAccessAuthorizer.ACLIdentityType.GROUP,
- IAccessAuthorizer.ACLType.CREATE, "owner", true);
- assertTrue(context.isRecursiveAccessCheck(),
- "Wrongly sets recursive flag value");
+ context = baseBuilder().setRecursiveAccessCheck(true).build();
+ assertTrue(context.isRecursiveAccessCheck());
}
@Test
public void testSessionPolicy() {
- final RequestContext.Builder builder = new RequestContext.Builder();
- RequestContext context = builder.build();
+ RequestContext context = RequestContext.newBuilder()
+ .build();
assertNull(context.getSessionPolicy(), "sessionPolicy should default to null");
final String policy = "{\"Statement\":[]}";
- context = new RequestContext.Builder()
+ context = RequestContext.newBuilder()
.setSessionPolicy(policy)
.build();
assertEquals(policy, context.getSessionPolicy(), "sessionPolicy should be set via builder");
- context = new RequestContext(
- "host", null, null, "serviceId", IAccessAuthorizer.ACLIdentityType.GROUP,
- IAccessAuthorizer.ACLType.CREATE, "owner", true, policy);
+ context = RequestContext.newBuilder()
+ .setHost("host")
+ .setIp(null)
+ .setClientUgi(null)
+ .setServiceId("serviceId")
+ .setAclType(IAccessAuthorizer.ACLIdentityType.GROUP)
+ .setAclRights(IAccessAuthorizer.ACLType.CREATE)
+ .setOwnerName("owner")
+ .setRecursiveAccessCheck(true)
+ .setSessionPolicy(policy)
+ .build();
assertTrue(context.isRecursiveAccessCheck(), "recursiveAccessCheck should be true");
assertEquals(policy, context.getSessionPolicy(), "sessionPolicy should be set via constructor");
Review Comment:
Looks like `testSessionPolicy()` has been testing `sessionPolicy` for various ways of creating `RequestContext`. Now constructor is private and `getBuilder` no longer exists, so all variants are testing the builder. We can remove the parts that perform duplicate verifications, and simplify this to:
```java
@Test
void testSessionPolicy() {
RequestContext.Builder builder = RequestContext.newBuilder();
assertNull(builder.build().getSessionPolicy(), "default value");
final String policy = "{\"Statement\":[]}";
builder.setSessionPolicy(policy);
assertEquals(policy, builder.build().getSessionPolicy());
}
```
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/security/acl/TestVolumeOwner.java:
##########
@@ -245,9 +245,15 @@ public void testKeyOps() throws Exception {
private RequestContext getUserRequestContext(String username,
IAccessAuthorizer.ACLType type, boolean isOwner, String ownerName) {
- return RequestContext.getBuilder(
- UserGroupInformation.createRemoteUser(username), null, null,
- type, ownerName).build();
+ return RequestContext.newBuilder()
+ .setClientUgi(UserGroupInformation.createRemoteUser(username))
+ .setIp(null)
+ .setHost(null)
Review Comment:
nit: `null` is the default value in the builder for these properties, so this can be removed.
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14104. Refactor RequestContext creation [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #9493:
URL: https://github.com/apache/ozone/pull/9493
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org