-
Notifications
You must be signed in to change notification settings - Fork 475
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-8489. Refactor GET request to POST for OM DB snapshot #4695
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f3176f3
Add POST endpoint and extract common logic from GET endpoint for the …
mladjan-gadzic 85c9ddc
Use POST endpoint on client side and form data parameters instead of …
mladjan-gadzic 17ea715
Add tests for server and client side for snapshot download
mladjan-gadzic 65d920b
Set charset instead of default one and add package-info
mladjan-gadzic 6b17abe
Fix charset
mladjan-gadzic a737f64
Merge remote-tracking branch 'upstream/master' into HDDS-8489
mladjan-gadzic 6ffb03c
Use 2 sst file names as an example instead of 1
mladjan-gadzic 2d9399c
Parametrize endpoint tests with HTTP method and use JUnit5 instead of…
mladjan-gadzic da4e997
Merge remote-tracking branch 'upstream/master' into HDDS-8489
mladjan-gadzic b3d20d5
Revert removal of final modifier
mladjan-gadzic 5204f7f
Create constructor instead of using a spy
mladjan-gadzic c92835b
Address PR comments
mladjan-gadzic e5bde2e
Merge remote-tracking branch 'upstream/master' into HDDS-8489
mladjan-gadzic e8e3baa
Fix import
mladjan-gadzic 50c7ff6
Merge remote-tracking branch 'upstream/master' into HDDS-8489
mladjan-gadzic File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,6 +33,10 @@ | |||||
import java.util.Objects; | ||||||
import java.util.stream.Collectors; | ||||||
|
||||||
import org.apache.commons.fileupload.FileItemIterator; | ||||||
import org.apache.commons.fileupload.FileItemStream; | ||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload; | ||||||
import org.apache.commons.fileupload.util.Streams; | ||||||
import org.apache.hadoop.hdds.server.OzoneAdmins; | ||||||
import org.apache.hadoop.hdds.utils.db.DBCheckpoint; | ||||||
import org.apache.hadoop.hdds.utils.db.DBStore; | ||||||
|
@@ -94,15 +98,13 @@ private boolean hasPermission(UserGroupInformation user) { | |||||
} | ||||||
|
||||||
/** | ||||||
* Process a GET request for the DB checkpoint snapshot. | ||||||
* | ||||||
* @param request The servlet request we are processing | ||||||
* @param response The servlet response we are creating | ||||||
* Generates Snapshot checkpoint as tar ball. | ||||||
* @param request the HTTP servlet request | ||||||
* @param response the HTTP servlet response | ||||||
* @param isFormData indicator whether request is form data | ||||||
*/ | ||||||
@Override | ||||||
public void doGet(HttpServletRequest request, HttpServletResponse response) { | ||||||
|
||||||
LOG.info("Received request to obtain DB checkpoint snapshot"); | ||||||
private void generateSnapshotCheckpoint(HttpServletRequest request, | ||||||
HttpServletResponse response, boolean isFormData) { | ||||||
if (dbStore == null) { | ||||||
LOG.error( | ||||||
"Unable to process metadata snapshot request. DB Store is null"); | ||||||
|
@@ -151,7 +153,8 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) { | |||||
|
||||||
List<String> receivedSstList = new ArrayList<>(); | ||||||
List<String> excludedSstList = new ArrayList<>(); | ||||||
String[] sstParam = request.getParameterValues( | ||||||
String[] sstParam = isFormData ? | ||||||
parseFormDataParameters(request) : request.getParameterValues( | ||||||
OZONE_DB_CHECKPOINT_REQUEST_TO_EXCLUDE_SST); | ||||||
if (sstParam != null) { | ||||||
receivedSstList.addAll( | ||||||
|
@@ -216,6 +219,68 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) { | |||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* Parses request form data parameters. | ||||||
* @param request the HTTP servlet request | ||||||
* @return array of parsed sst form data parameters for exclusion | ||||||
*/ | ||||||
private static String[] parseFormDataParameters(HttpServletRequest request) { | ||||||
String fieldName = OZONE_DB_CHECKPOINT_REQUEST_TO_EXCLUDE_SST + "[]"; | ||||||
ServletFileUpload upload = new ServletFileUpload(); | ||||||
List<String> sstParam = new ArrayList<>(); | ||||||
|
||||||
try { | ||||||
FileItemIterator iter = upload.getItemIterator(request); | ||||||
while (iter.hasNext()) { | ||||||
FileItemStream item = iter.next(); | ||||||
if (!item.isFormField()) { | ||||||
continue; | ||||||
} | ||||||
|
||||||
if (!item.getFieldName().equals(fieldName)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: if conditions can be combined to one.
Suggested change
to avoid NPE because we know fieldName is constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditions are combined and comparation is reversed. |
||||||
continue; | ||||||
} | ||||||
|
||||||
sstParam.add(Streams.asString(item.openStream())); | ||||||
} | ||||||
} catch (Exception e) { | ||||||
LOG.warn("Exception occured during form data parsing {}", e.getMessage()); | ||||||
} | ||||||
|
||||||
return sstParam.size() == 0 ? null : sstParam.toArray(new String[0]); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Process a GET request for the DB checkpoint snapshot. | ||||||
* | ||||||
* @param request The servlet request we are processing | ||||||
* @param response The servlet response we are creating | ||||||
*/ | ||||||
@Override | ||||||
public void doGet(HttpServletRequest request, HttpServletResponse response) { | ||||||
LOG.info("Received GET request to obtain DB checkpoint snapshot"); | ||||||
|
||||||
generateSnapshotCheckpoint(request, response, false); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Process a POST request for the DB checkpoint snapshot. | ||||||
* | ||||||
* @param request The servlet request we are processing | ||||||
* @param response The servlet response we are creating | ||||||
*/ | ||||||
@Override | ||||||
public void doPost(HttpServletRequest request, HttpServletResponse response) { | ||||||
LOG.info("Received POST request to obtain DB checkpoint snapshot"); | ||||||
|
||||||
if (!ServletFileUpload.isMultipartContent(request)) { | ||||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); | ||||||
return; | ||||||
} | ||||||
|
||||||
generateSnapshotCheckpoint(request, response, true); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Write checkpoint to the stream. | ||||||
* | ||||||
|
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
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
21 changes: 21 additions & 0 deletions
21
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/package-info.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,21 @@ | ||
/* | ||
* 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 info tests. | ||
*/ | ||
package org.apache.hadoop.hdds.scm; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIELD_NAME
constant is created.