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-10608. Recon can't get full key when using Recon API. #6492

Merged
merged 22 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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 Apr 7, 2024
4dbab9a
HDDS-10608. Recon can't get full key when using Recon API.
ArafatKhan2198 Apr 7, 2024
f75aac2
Fixed bugs and checkstyle issues
ArafatKhan2198 Apr 7, 2024
a14592c
Merge branch 'master' into HDDS-10608
ArafatKhan2198 Apr 17, 2024
ee97fa6
Added Integration Tests to ContainerEndpoint
ArafatKhan2198 Apr 17, 2024
7faa2e1
Rebuilding tree to prevent backwards compatability
ArafatKhan2198 Apr 29, 2024
0d03da5
Finished the changes for preventing compatability issues
ArafatKhan2198 Apr 29, 2024
dd1016d
Revised the backporting strategy
ArafatKhan2198 Apr 29, 2024
0e7baa8
Made review changes
ArafatKhan2198 Apr 29, 2024
76f0e41
Made 2nd review changes
ArafatKhan2198 May 3, 2024
89f5d1e
Added command to terminate the thread
ArafatKhan2198 May 6, 2024
1c41bc6
Removed the unnecessary synchronised block
ArafatKhan2198 May 6, 2024
5773c18
Made final review comments
ArafatKhan2198 May 7, 2024
415d315
Added more logs and removed the boolean flag
ArafatKhan2198 May 7, 2024
f2e8511
Fixed checkstyle issues
ArafatKhan2198 May 7, 2024
5cb1cc5
Fixed failing integration teasrt
ArafatKhan2198 May 8, 2024
248a375
Added tests to check for backporting
ArafatKhan2198 May 8, 2024
047ac8b
Fixed checkstyle issues
ArafatKhan2198 May 8, 2024
fafc2e3
Fixed the missed checkstyle
ArafatKhan2198 May 8, 2024
50ac78f
Fixed the final review comments
ArafatKhan2198 May 8, 2024
d802e67
Changed the java doc as well
ArafatKhan2198 May 8, 2024
4c93221
Fixed find bugs
ArafatKhan2198 May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
/*
* 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.AfterEach;
import org.junit.jupiter.api.BeforeEach;
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.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Integration test fo recon container endpoint.
*/
public class TestReconContainerEndpoint {

private static OzoneClient client;
private static MiniOzoneCluster cluster = null;
private static OzoneConfiguration conf;
private static ObjectStore store;

@BeforeEach
public 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();
}

@AfterEach
public 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
OmBucketInfo bucketInfo = cluster.getOzoneManager().getBucketInfo(volName, bucketName);
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/fsobucket/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/fsobucket/file1", keyMetadata.getCompletePath());
}

@Test
public void testContainerEndpointForOBSBucket() throws Exception {
String volumeName = "testvol2";
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
OmBucketInfo bucketInfo = cluster.getOzoneManager().getBucketInfo(volumeName, obsBucketName);
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("testvol2/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));
}
}

}
Loading