-
Notifications
You must be signed in to change notification settings - Fork 600
HDDS-14987. OM Web UI dashboard for Ozone Snapshot (list snapshot) #10055
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
96 changes: 96 additions & 0 deletions
96
...ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/SnapshotListJSONServlet.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,96 @@ | ||
| /* | ||
| * 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.om; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.SerializationFeature; | ||
| import java.io.IOException; | ||
| import java.io.PrintWriter; | ||
| import javax.servlet.ServletException; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.hadoop.ozone.OzoneConsts; | ||
| import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; | ||
| import org.apache.hadoop.ozone.snapshot.ListSnapshotResponse; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Provides REST access to Ozone Snapshot List. | ||
| */ | ||
| public class SnapshotListJSONServlet extends HttpServlet { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(SnapshotListJSONServlet.class); | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private transient OzoneManager om; | ||
|
|
||
| /** | ||
| * Jackson mix-in to ignore protobuf getter in SnapshotInfo. | ||
| */ | ||
| @JsonIgnoreProperties({"protobuf", "createTransactionInfo", "lastTransactionInfo"}) | ||
| abstract static class SnapshotInfoMixin { | ||
| } | ||
|
|
||
| @Override | ||
| public void init() throws ServletException { | ||
| this.om = (OzoneManager) getServletContext() | ||
| .getAttribute(OzoneConsts.OM_CONTEXT_ATTRIBUTE); | ||
| } | ||
|
|
||
| @Override | ||
| public void doGet(HttpServletRequest request, HttpServletResponse response) { | ||
| try { | ||
| String volume = request.getParameter("volume"); | ||
| String bucket = request.getParameter("bucket"); | ||
|
|
||
| if (volume == null || volume.isEmpty() || bucket == null || bucket.isEmpty()) { | ||
| response.setStatus(HttpServletResponse.SC_BAD_REQUEST); | ||
| response.getWriter().write("Both volume and bucket parameters are required."); | ||
| return; | ||
| } | ||
|
|
||
| String prefix = request.getParameter("prefix"); | ||
|
|
||
| final int maxKeys = 1000; | ||
|
|
||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| objectMapper.addMixIn(SnapshotInfo.class, SnapshotInfoMixin.class); | ||
| objectMapper.enable(SerializationFeature.INDENT_OUTPUT); | ||
| response.setContentType("application/json; charset=utf8"); | ||
| try (PrintWriter writer = response.getWriter()) { | ||
| String lastSnapshot = null; | ||
| do { | ||
| ListSnapshotResponse listSnapshotResponse = om.listSnapshot(volume, bucket, prefix, lastSnapshot, maxKeys); | ||
| writer.write(objectMapper.writeValueAsString(listSnapshotResponse.getSnapshotInfos())); | ||
| lastSnapshot = listSnapshotResponse.getLastSnapshot(); | ||
| } while (StringUtils.isNotEmpty(lastSnapshot)); | ||
| } | ||
| } catch (IOException e) { | ||
| LOG.error("Caught an exception while processing SnapshotList request", e); | ||
| response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
| } catch (Exception e) { | ||
| LOG.error("Unexpected error while processing SnapshotList request", e); | ||
| response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
| } | ||
| } | ||
| } | ||
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
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
57 changes: 57 additions & 0 deletions
57
...e/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotListJSONServlet.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,57 @@ | ||
| /* | ||
| * 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.om; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.util.Collections; | ||
| import java.util.UUID; | ||
| import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Test for SnapshotListJSONServlet. | ||
| */ | ||
| public class TestSnapshotListJSONServlet { | ||
|
|
||
| @Test | ||
| public void testSerialization() { | ||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| objectMapper.addMixIn(SnapshotInfo.class, | ||
| SnapshotListJSONServlet.SnapshotInfoMixin.class); | ||
|
|
||
| String snapName = "snap1"; | ||
| SnapshotInfo snapshotInfo = SnapshotInfo.newInstance("vol1", "bucket1", | ||
| snapName, UUID.randomUUID(), Time.now()); | ||
|
|
||
| String json = assertDoesNotThrow(() -> | ||
| objectMapper.writeValueAsString(Collections.singletonList(snapshotInfo))); | ||
|
|
||
| // Verify that the problematic fields are NOT in the JSON | ||
| assertFalse(json.contains("protobuf"), "JSON should not contain protobuf field"); | ||
| assertFalse(json.contains("createTransactionInfo"), "JSON should not contain createTransactionInfo field"); | ||
| assertFalse(json.contains("lastTransactionInfo"), "JSON should not contain lastTransactionInfo field"); | ||
|
|
||
| // Verify that the expected fields ARE in the JSON | ||
| assertTrue(json.contains("\"name\":\"" + snapName + "\""), "JSON should contain snapshot name"); | ||
| } | ||
| } |
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.
I am still a bit concerned about this logic.
This runs on OM. If there are tons of snapshots and/or client requests this endpoint a ton of times it would consume a lot of CPU and worsen young gen churn. Potential DoS.
The ideal way is for the client (web page) to request batch of snapshot on demand. OM can return only the ones that needs to be displayed on the web UI.
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 is on-demand itself right, The OM web UI access should only be with the admin so only when admin inputs the vol/bucket it will do a list snapshot request.
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.
@sadanand48 Good point. Let's merge it first then