-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-10608. Recon can't get full key when using Recon API. #6492
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f66979f
Adding a new parameter to NSSummary and exposing it
ArafatKhan2198 4dbab9a
HDDS-10608. Recon can't get full key when using Recon API.
ArafatKhan2198 f75aac2
Fixed bugs and checkstyle issues
ArafatKhan2198 a14592c
Merge branch 'master' into HDDS-10608
ArafatKhan2198 ee97fa6
Added Integration Tests to ContainerEndpoint
ArafatKhan2198 7faa2e1
Rebuilding tree to prevent backwards compatability
ArafatKhan2198 0d03da5
Finished the changes for preventing compatability issues
ArafatKhan2198 dd1016d
Revised the backporting strategy
ArafatKhan2198 0e7baa8
Made review changes
ArafatKhan2198 76f0e41
Made 2nd review changes
ArafatKhan2198 89f5d1e
Added command to terminate the thread
ArafatKhan2198 1c41bc6
Removed the unnecessary synchronised block
ArafatKhan2198 5773c18
Made final review comments
ArafatKhan2198 415d315
Added more logs and removed the boolean flag
ArafatKhan2198 f2e8511
Fixed checkstyle issues
ArafatKhan2198 5cb1cc5
Fixed failing integration teasrt
ArafatKhan2198 248a375
Added tests to check for backporting
ArafatKhan2198 047ac8b
Fixed checkstyle issues
ArafatKhan2198 fafc2e3
Fixed the missed checkstyle
ArafatKhan2198 50ac78f
Fixed the final review comments
ArafatKhan2198 d802e67
Changed the java doc as well
ArafatKhan2198 4c93221
Fixed find bugs
ArafatKhan2198 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
225 changes: 225 additions & 0 deletions
225
...egration-test/src/test/java/org/apache/hadoop/ozone/recon/TestReconContainerEndpoint.java
This file contains hidden or 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,225 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * 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.recon; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager; | ||
| import org.apache.hadoop.ozone.MiniOzoneCluster; | ||
| import org.apache.hadoop.ozone.client.BucketArgs; | ||
| import org.apache.hadoop.ozone.client.ObjectStore; | ||
| import org.apache.hadoop.ozone.client.OzoneClient; | ||
| import org.apache.hadoop.ozone.client.OzoneVolume; | ||
| import org.apache.hadoop.ozone.client.io.OzoneOutputStream; | ||
| import org.apache.hadoop.ozone.om.OMConfigKeys; | ||
| import org.apache.hadoop.ozone.om.helpers.BucketLayout; | ||
| import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; | ||
| import org.apache.hadoop.ozone.recon.api.ContainerEndpoint; | ||
| import org.apache.hadoop.ozone.recon.api.types.KeyMetadata; | ||
| import org.apache.hadoop.ozone.recon.api.types.KeysResponse; | ||
| import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager; | ||
| import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager; | ||
| import org.apache.hadoop.ozone.recon.scm.ReconContainerManager; | ||
| import java.nio.charset.StandardCharsets; | ||
| import org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import javax.ws.rs.core.Response; | ||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| public class TestReconContainerEndpoint { | ||
|
|
||
| private static OzoneClient client; | ||
| private static MiniOzoneCluster cluster = null; | ||
| private static OzoneConfiguration conf; | ||
| private static ObjectStore store; | ||
|
|
||
| @BeforeAll | ||
| public static void init() throws Exception { | ||
| conf = new OzoneConfiguration(); | ||
| conf.set(OMConfigKeys.OZONE_DEFAULT_BUCKET_LAYOUT, | ||
| OMConfigKeys.OZONE_BUCKET_LAYOUT_FILE_SYSTEM_OPTIMIZED); | ||
| cluster = MiniOzoneCluster.newBuilder(conf) | ||
| .setNumDatanodes(3) | ||
| .includeRecon(true) | ||
| .build(); | ||
| cluster.waitForClusterToBeReady(); | ||
| client = cluster.newClient(); | ||
| store = client.getObjectStore(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void shutdown() throws IOException { | ||
| if (client != null) { | ||
| client.close(); | ||
| } | ||
| if (cluster != null) { | ||
| cluster.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testContainerEndpointForFSOLayout() throws Exception { | ||
| // Setup: Create multiple volumes, buckets, and key hierarchies | ||
| String volName = "testvol"; | ||
| String bucketName = "fsobucket"; | ||
| // Scenario 1: Deeply nested directories | ||
| String nestedDirKey = "dir1/dir2/dir3/file1"; | ||
| // Scenario 2: Single file in a bucket | ||
| String singleFileKey = "file1"; | ||
|
|
||
| // Create volume and bucket | ||
| store.createVolume(volName); | ||
| OzoneVolume volume = store.getVolume(volName); | ||
| volume.createBucket(bucketName, BucketArgs.newBuilder() | ||
| .setBucketLayout(BucketLayout.FILE_SYSTEM_OPTIMIZED).build()); | ||
|
|
||
| // Write keys to the bucket | ||
| writeTestData(volName, bucketName, nestedDirKey, "data1"); | ||
| writeTestData(volName, bucketName, singleFileKey, "data2"); | ||
|
|
||
| // Synchronize data from OM to Recon | ||
| OzoneManagerServiceProviderImpl impl = (OzoneManagerServiceProviderImpl) | ||
| cluster.getReconServer().getOzoneManagerServiceProvider(); | ||
| impl.syncDataFromOM(); | ||
|
|
||
| //Search for the bucket from the bucket table and verify its FSO | ||
| String buckKey = "/" + volName + "/" + bucketName; | ||
| OmBucketInfo bucketInfo = | ||
| cluster.getReconServer().getOzoneManagerServiceProvider() | ||
| .getOMMetadataManagerInstance().getBucketTable().get(buckKey); | ||
| assertNotNull(bucketInfo); | ||
| assertEquals(BucketLayout.FILE_SYSTEM_OPTIMIZED, | ||
| bucketInfo.getBucketLayout()); | ||
|
|
||
| // Assuming a known container ID that these keys have been written into | ||
| long testContainerID = 1L; | ||
|
|
||
| // Query the ContainerEndpoint for the keys in the specified container | ||
| Response response = getContainerEndpointResponse(testContainerID); | ||
|
|
||
| assertNotNull(response, "Response should not be null."); | ||
| assertEquals(Response.Status.OK.getStatusCode(), response.getStatus(), | ||
| "Expected HTTP 200 OK response."); | ||
|
|
||
| KeysResponse data = (KeysResponse) response.getEntity(); | ||
| Collection<KeyMetadata> keyMetadataList = data.getKeys(); | ||
|
|
||
| assertEquals(1, data.getTotalCount()); | ||
| assertEquals(1, keyMetadataList.size()); | ||
|
|
||
| // Assert the file name and the complete path. | ||
| KeyMetadata keyMetadata = keyMetadataList.iterator().next(); | ||
| assertEquals("file1", keyMetadata.getKey()); | ||
| assertEquals("testvol/testbucket/dir1/dir2/dir3/file1", | ||
| keyMetadata.getCompletePath()); | ||
|
|
||
| testContainerID = 2L; | ||
| response = getContainerEndpointResponse(testContainerID); | ||
| data = (KeysResponse) response.getEntity(); | ||
| keyMetadataList = data.getKeys(); | ||
| assertEquals(1, data.getTotalCount()); | ||
| assertEquals(1, keyMetadataList.size()); | ||
|
|
||
| // Assert the file name and the complete path. | ||
| keyMetadata = keyMetadataList.iterator().next(); | ||
| assertEquals("file1", keyMetadata.getKey()); | ||
| assertEquals("testvol/testbucket/file1", keyMetadata.getCompletePath()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testContainerEndpointForOBSBucket() throws Exception { | ||
| String volumeName = "testvol"; | ||
| String obsBucketName = "obsbucket"; | ||
| String obsSingleFileKey = "file1"; | ||
|
|
||
| // Setup volume and OBS bucket | ||
| store.createVolume(volumeName); | ||
| OzoneVolume volume = store.getVolume(volumeName); | ||
| volume.createBucket(obsBucketName, | ||
| BucketArgs.newBuilder().setBucketLayout(BucketLayout.OBJECT_STORE) | ||
| .build()); | ||
|
|
||
| // Write a single file to the OBS bucket | ||
| writeTestData(volumeName, obsBucketName, obsSingleFileKey, "Hello OBS!"); | ||
|
|
||
| OzoneManagerServiceProviderImpl impl = | ||
| (OzoneManagerServiceProviderImpl) cluster.getReconServer() | ||
| .getOzoneManagerServiceProvider(); | ||
| impl.syncDataFromOM(); | ||
|
|
||
| // Search for the bucket from the bucket table and verify its OBS | ||
| String bucketKey = "/" + volumeName + "/" + obsBucketName; | ||
| OmBucketInfo bucketInfo = | ||
| cluster.getReconServer().getOzoneManagerServiceProvider() | ||
| .getOMMetadataManagerInstance().getBucketTable().get(bucketKey); | ||
| assertNotNull(bucketInfo); | ||
| assertEquals(BucketLayout.OBJECT_STORE, bucketInfo.getBucketLayout()); | ||
|
|
||
| // Initialize the ContainerEndpoint | ||
| long containerId = 1L; | ||
| Response response = getContainerEndpointResponse(containerId); | ||
|
|
||
| assertNotNull(response, "Response should not be null."); | ||
| assertEquals(Response.Status.OK.getStatusCode(), response.getStatus(), | ||
| "Expected HTTP 200 OK response."); | ||
| KeysResponse data = (KeysResponse) response.getEntity(); | ||
| Collection<KeyMetadata> keyMetadataList = data.getKeys(); | ||
|
|
||
| assertEquals(1, data.getTotalCount()); | ||
| assertEquals(1, keyMetadataList.size()); | ||
|
|
||
| KeyMetadata keyMetadata = keyMetadataList.iterator().next(); | ||
| assertEquals("file1", keyMetadata.getKey()); | ||
| assertEquals("testvol/obsbucket/file1", keyMetadata.getCompletePath()); | ||
| } | ||
|
|
||
| private Response getContainerEndpointResponse(long containerId) { | ||
| OzoneStorageContainerManager reconSCM = | ||
| cluster.getReconServer().getReconStorageContainerManager(); | ||
| ReconContainerManager reconContainerManager = | ||
| (ReconContainerManager) reconSCM.getContainerManager(); | ||
| ContainerHealthSchemaManager containerHealthSchemaManager = | ||
| reconContainerManager.getContainerSchemaManager(); | ||
| ReconOMMetadataManager omMetadataManagerInstance = | ||
| (ReconOMMetadataManager) | ||
| cluster.getReconServer().getOzoneManagerServiceProvider() | ||
| .getOMMetadataManagerInstance(); | ||
| ContainerEndpoint containerEndpoint = | ||
| new ContainerEndpoint(reconSCM, containerHealthSchemaManager, | ||
| cluster.getReconServer().getReconNamespaceSummaryManager(), | ||
| cluster.getReconServer().getReconContainerMetadataManager(), | ||
| omMetadataManagerInstance); | ||
| return containerEndpoint.getKeysForContainer(containerId, 10, ""); | ||
| } | ||
|
|
||
| private void writeTestData(String volumeName, String bucketName, | ||
| String keyPath, String data) throws Exception { | ||
| try (OzoneOutputStream out = client.getObjectStore().getVolume(volumeName) | ||
| .getBucket(bucketName) | ||
| .createKey(keyPath, data.length())) { | ||
| out.write(data.getBytes(StandardCharsets.UTF_8)); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.