-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDDS-10634. Recon - listKeys API for listing keys with optional filte…
…rs (#6658)
- Loading branch information
Showing
12 changed files
with
2,304 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
84 changes: 84 additions & 0 deletions
84
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconResponseUtils.java
This file contains 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,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(); | ||
} | ||
} |
This file contains 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
This file contains 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.