sadanand48 commented on code in PR #10055: URL: https://github.com/apache/ozone/pull/10055#discussion_r3122660413
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/SnapshotListJSONServlet.java: ########## @@ -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 = 100; + + 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)); Review Comment: 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
