Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7f829bf
HDDS-10389
ArafatKhan2198 Feb 18, 2024
1276b14
Added license to the newly added classes
ArafatKhan2198 Feb 18, 2024
9b8b7b7
Removed unecessary instances from injector
ArafatKhan2198 Feb 18, 2024
4f60c61
Fixed checkstyle and findBugs
ArafatKhan2198 Feb 18, 2024
7e0838c
Added prefix based searching for FSO open keys
ArafatKhan2198 Mar 9, 2024
0dacee3
Gave a more structured search response
ArafatKhan2198 Mar 10, 2024
e64ec04
Added flags to include fso and non-fso key list
ArafatKhan2198 Mar 10, 2024
4dec798
Added more UT's
ArafatKhan2198 Mar 12, 2024
2be4136
Fixed the left out review comments
ArafatKhan2198 Mar 13, 2024
bf8e661
Added more changes and newer tests
ArafatKhan2198 Mar 13, 2024
12a540d
Minor changes
ArafatKhan2198 Mar 13, 2024
f692c66
Made review changes
ArafatKhan2198 Mar 17, 2024
61f3725
Did a bit of code refactoring
ArafatKhan2198 Mar 17, 2024
57ccc8e
Made review comments
ArafatKhan2198 Mar 20, 2024
132ed90
Adjusted the exception handling
ArafatKhan2198 Mar 20, 2024
dd61d74
Merge branch 'master' into HDDS-10389
ArafatKhan2198 Apr 30, 2024
fee245e
Removed the volumeID and bucketID initilisation from inside the loop …
ArafatKhan2198 May 6, 2024
9aa436f
Fixed the test cases and added new ones
ArafatKhan2198 May 19, 2024
47d9e7e
Did some refactoring
ArafatKhan2198 May 19, 2024
0eff02a
Merge branch 'master' into HDDS-10389
ArafatKhan2198 May 19, 2024
55f0e9e
Fixed merge conflict
ArafatKhan2198 May 19, 2024
a29befc
Added last key to response and limiting the search starting from Buck…
ArafatKhan2198 May 21, 2024
4ba887f
Fixed checkstyle issues
ArafatKhan2198 May 21, 2024
0999c2a
Added pagination logic
ArafatKhan2198 May 21, 2024
da9c468
Fixed bugs and checkstyle
ArafatKhan2198 May 21, 2024
8b984a2
Fixed checkstyle issues
ArafatKhan2198 May 22, 2024
2a57d5d
Made review comments on excpeitons thrown
ArafatKhan2198 May 27, 2024
80b0b3f
Merge branch 'master' into HDDS-10389
ArafatKhan2198 May 27, 2024
124773f
Added changes to accomodate key level search
ArafatKhan2198 May 28, 2024
55d0f89
Added more tests to the search endpoint and fixes issues with key lev…
ArafatKhan2198 May 29, 2024
ab4e22c
Fixed checksytle issues
ArafatKhan2198 May 30, 2024
2149e09
Fixed javadoc and added one more test case
ArafatKhan2198 May 30, 2024
e6ff273
Improved Java doc
ArafatKhan2198 Jul 16, 2024
4a09ffc
Made changes to javadoc
ArafatKhan2198 Jul 17, 2024
ec272c4
Removed unwanted file
ArafatKhan2198 Jul 17, 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
Expand Up @@ -43,12 +43,15 @@ private ReconConstants() {
public static final int DISK_USAGE_TOP_RECORDS_LIMIT = 30;
public static final String DEFAULT_OPEN_KEY_INCLUDE_NON_FSO = "false";
public static final String DEFAULT_OPEN_KEY_INCLUDE_FSO = "false";
public static final String DEFAULT_START_PREFIX = "/";
public static final String DEFAULT_FETCH_COUNT = "1000";
public static final String DEFAULT_BATCH_NUMBER = "1";
public static final String RECON_QUERY_BATCH_PARAM = "batchNum";
public static final String RECON_QUERY_PREVKEY = "prevKey";
public static final String RECON_OPEN_KEY_INCLUDE_NON_FSO = "includeNonFso";
public static final String RECON_OPEN_KEY_INCLUDE_FSO = "includeFso";
public static final String RECON_OPEN_KEY_DEFAULT_SEARCH_LIMIT = "1000";
public static final String RECON_OPEN_KEY_SEARCH_DEFAULT_PREV_KEY = "";
public static final String RECON_QUERY_FILTER = "missingIn";
public static final String PREV_CONTAINER_ID_DEFAULT_VALUE = "0";
public static final String PREV_DELETED_BLOCKS_TRANSACTION_ID_DEFAULT_VALUE =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.recon;

import com.google.inject.Singleton;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
* Recon API Response Utility class.
*/
@Singleton
public final class ReconResponseUtils {

// Declared a private constructor to avoid checkstyle issues.
private ReconResponseUtils() {

}

/**
* Returns a response indicating that no keys matched the search prefix.
*
* @param startPrefix The search prefix that was used.
* @return The response indicating that no keys matched the search prefix.
*/
public static Response noMatchedKeysResponse(String startPrefix) {
String jsonResponse = String.format(
"{\"message\": \"No keys matched the search prefix: '%s'.\"}",
startPrefix);
return Response.status(Response.Status.NOT_FOUND)
.entity(jsonResponse)
.type(MediaType.APPLICATION_JSON)
.build();
}

/**
* Utility method to create a bad request response with a custom message.
* Which means the request sent by the client to the server is incorrect
* or malformed and cannot be processed by the server.
*
* @param message The message to include in the response body.
* @return A Response object configured with the provided message.
*/
public static Response createBadRequestResponse(String message) {
String jsonResponse = String.format("{\"message\": \"%s\"}", message);
return Response.status(Response.Status.BAD_REQUEST)
.entity(jsonResponse)
.type(MediaType.APPLICATION_JSON)
.build();
}

/**
* Utility method to create an internal server error response with a custom message.
* Which means the server encountered an unexpected condition that prevented it
* from fulfilling the request.
*
* @param message The message to include in the response body.
* @return A Response object configured with the provided message.
*/
public static Response createInternalServerErrorResponse(String message) {
String jsonResponse = String.format("{\"message\": \"%s\"}", message);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(jsonResponse)
.type(MediaType.APPLICATION_JSON)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static org.jooq.impl.DSL.using;

import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.recon.api.types.NSSummary;
import org.apache.hadoop.ozone.recon.api.types.DUResponse;
Expand All @@ -80,6 +81,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.ws.Response;

/**
* Recon Utility class.
*/
Expand Down Expand Up @@ -352,6 +355,55 @@ public HttpURLConnection makeHttpCall(URLConnectionFactory connectionFactory,
return urlConnection;
}

/**
* Validates volume or bucket names according to specific rules.
*
* @param resName The name to validate (volume or bucket).
* @return A Response object if validation fails, or null if the name is valid.
*/
public static Response validateNames(String resName)
throws IllegalArgumentException {
if (resName.length() < OzoneConsts.OZONE_MIN_BUCKET_NAME_LENGTH ||
resName.length() > OzoneConsts.OZONE_MAX_BUCKET_NAME_LENGTH) {
throw new IllegalArgumentException(
"Bucket or Volume name length should be between " +
OzoneConsts.OZONE_MIN_BUCKET_NAME_LENGTH + " and " +
OzoneConsts.OZONE_MAX_BUCKET_NAME_LENGTH);
}

if (resName.charAt(0) == '.' || resName.charAt(0) == '-' ||
resName.charAt(resName.length() - 1) == '.' ||
resName.charAt(resName.length() - 1) == '-') {
throw new IllegalArgumentException(
"Bucket or Volume name cannot start or end with " +
"hyphen or period");
}

// Regex to check for lowercase letters, numbers, hyphens, underscores, and periods only.
if (!resName.matches("^[a-z0-9._-]+$")) {
throw new IllegalArgumentException(
"Bucket or Volume name can only contain lowercase " +
"letters, numbers, hyphens, underscores, and periods");
}

// If all checks pass, the name is valid
return null;
}

/**
* Constructs an object path with the given IDs.
*
* @param ids The IDs to construct the object path with.
* @return The constructed object path.
*/
public static String constructObjectPathWithPrefix(long... ids) {
StringBuilder pathBuilder = new StringBuilder();
for (long id : ids) {
pathBuilder.append(OM_KEY_PREFIX).append(id);
}
return pathBuilder.toString();
}

/**
* Load last known DB in Recon.
*
Expand Down
Loading