shuan1026 opened a new pull request, #12233:
URL: https://github.com/apache/ozone/pull/12233

   
   ## What changes were proposed in this pull request?
   
   Implement the S3 `GetObjectRetention` operation (`GET 
/{bucket}/{key}?retention`). It returns the key's retention: `Mode`, 
`RetainUntilDate`, and the event hold (`EventHold` / `EventHoldDuration`). 
Until now every HTTP method of `?retention` was rejected with `NotImplemented` 
by `ObjectOperationNotImplementedHandler`. The key-level model 
(`OmKeyInfo#getRetention`, `ObjectRetention`, `EventHold`, `RetentionUtil`) 
comes from HDDS-16485.
   
   The read path follows `GetObjectTagging` layer by layer:
   
   ```text
   ObjectRetentionHandler (S3 Gateway, GET only)
     ClientProtocol#getObjectRetention(null, bucket, key)     volume is 
resolved from the S3 context
       OzoneManagerProtocolClientSideTranslatorPB             
Type.GetObjectRetention, read-only
         OzoneManagerRequestHandler#handleReadRequest
           OmMetadataReader#getObjectRetention                bucket link 
resolution, key READ, audit, metrics
             KeyManagerImpl#getObjectRetention
   ```
   
   `KeyManagerImpl#getObjectRetention` decides the result:
   
   ```text
   bucket does not exist                      -> BUCKET_NOT_FOUND
   bucket does not have Object Lock enabled   -> INVALID_REQUEST
   key does not exist                         -> KEY_NOT_FOUND
   key has no retention                       -> OBJECT_LOCK_CONFIG_NOT_FOUND 
(new)
   event hold is enabled                      -> retentionDate = 
max(retentionDate, now + duration)
   otherwise                                  -> the stored retention; an 
expired date is still returned
   ```
   
   It does not call `RetentionUtil.validateObjectRetention`, which rejects past 
dates.
   
   What S3 clients see:
   
   | Key | Response |
   | --- | --- |
   | Fixed retention, never had an event hold | `Mode`, `RetainUntilDate`; no 
`EventHold` element |
   | Event hold `ON` | `Mode`, calculated `RetainUntilDate`, `EventHold=ON`, 
`EventHoldDuration` (`Days` or `Years`) |
   | Event hold released | `Mode`, `RetainUntilDate`, `EventHold=OFF`; no 
`EventHoldDuration` |
   | No retention | `404 NoSuchObjectLockConfiguration` (new) |
   | Missing key | `404 NoSuchKey` |
   | Bucket without Object Lock | `400 InvalidRequest` |
   
   This patch:
   
   * adds the read-only request type `GetObjectRetention` to 
`OmClientProtocol.proto` (`GetObjectRetentionRequest { KeyArgs }`, 
`GetObjectRetentionResponse { KeyRetention retention }`) and the status 
`OBJECT_LOCK_CONFIG_NOT_FOUND`, and registers the type in `OmUtils.isReadOnly` 
and `OmUtils.shouldSendToFollower`, as for `GetObjectTagging`. While the event 
hold is `ON`, the returned date uses the clock of the OM that serves the read;
   * adds `ObjectRetentionHandler` to the `ObjectEndpoint` handler chain. It 
handles `GET` and, like the other subresource handlers, rejects the HTTP 
methods it does not support itself, so `PUT ?retention` and `DELETE ?retention` 
keep returning `NotImplemented` instead of falling through to `PutObject` / 
`DeleteObject`. `retention` is therefore removed from the subresources of 
`ObjectOperationNotImplementedHandler`;
   * adds the S3 action mapping for this API (moved here from HDDS-16486): 
`S3GAction.GET_OBJECT_RETENTION`, mapped to `GetObjectRetention` in 
`S3GActionIamMapper`, and 
`IamSessionPolicyResolver.S3Action.GET_OBJECT_RETENTION` with `READ` at volume, 
bucket and object level;
   * adds the client API `OzoneBucket#getObjectRetention(String keyName)` with 
`ClientProtocol`, `RpcClient` and `S3ClientProtocol`;
   * adds audit (`OMAction.GET_OBJECT_RETENTION`) and metrics 
(`NumGetObjectRetention` / `NumGetObjectRetentionFails` in OM, 
`getObjectRetentionSuccess` / `getObjectRetentionFailure` in S3 Gateway).
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-16490
   
   ## How was this patch tested?
   
   No API can enable Object Lock on a bucket or set retention on a key yet 
(HDDS-16487, HDDS-16489), so the tests write `OmBucketInfo` and `OmKeyInfo` 
directly. SDK and acceptance tests can follow once the write APIs are in.
   
   - New `TestKeyManagerUnit#testGetObjectRetention`, 
`#testGetObjectRetentionWithEventHold` and `#testGetObjectRetentionFailures`: 
fixed retention with an expired date; released event hold; event hold `ON` 
without a stored date (the result is between `now + duration` taken before and 
after the call) and with a later stored date (the stored date is returned); 
bucket without Object Lock, key without retention, missing key and missing 
bucket.
   - New `TestObjectRetentionGet`: the response entity and the marshalled XML 
for fixed retention, event hold `ON` in days and in years, and a released event 
hold; `NoSuchObjectLockConfiguration`, `InvalidRequest`, `NoSuchKey` and 
`NoSuchBucket`; the handler calls `ClientProtocol#getObjectRetention` without a 
bucket lookup.
   - `TestObjectNotImplemented`: `GET ?retention` is no longer expected to 
return `NotImplemented`; `PUT ?retention` and `DELETE ?retention` still are, 
and do not overwrite or delete the object.
   - New 
`TestOzoneManagerProtocolClientSideTranslatorPB#getObjectRetentionSendsS3ContextFlag`
 and `TestS3GatewayMetrics#testGetObjectRetentionSuccess` / 
`#testGetObjectRetentionFailure`; `TestIamSessionPolicyResolver` and 
`TestS3GActionIamMapper` cover the new action.
   - CI: https://github.com/shuan1026/ozone/actions/runs/47098655548
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to