ChenSammi commented on code in PR #4569:
URL: https://github.com/apache/ozone/pull/4569#discussion_r1177484407


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/SCMDBInsightEndPoint.java:
##########
@@ -0,0 +1,236 @@
+/**
+ * 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.api;
+
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.hdds.utils.db.DBStore;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.recon.api.types.ContainerBlocksInfoWrapper;
+import org.apache.hadoop.ozone.recon.api.types.DeletedContainerInfo;
+import org.apache.hadoop.ozone.recon.scm.ReconContainerManager;
+
+import javax.inject.Inject;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition.DELETED_BLOCKS;
+import static org.apache.hadoop.ozone.recon.ReconConstants.DEFAULT_FETCH_COUNT;
+import static 
org.apache.hadoop.ozone.recon.ReconConstants.PREV_BLOCK_ID_PENDING_FOR_DELETION_DEFAULT_VALUE;
+import static org.apache.hadoop.ozone.recon.ReconConstants.RECON_QUERY_LIMIT;
+import static org.apache.hadoop.ozone.recon.ReconConstants.RECON_QUERY_PREVKEY;
+
+/**
+ * Endpoint to get following information about containers and blocks under SCM
+ * DB Insight page of Recon.
+ * 1. Number of DELETED containers.
+ * 2. Number of blocks pending deletion.
+ *     - Blocks pending deletion for open/closing containers.
+ *     - Blocks pending deletion for closed containers.
+ */
+@Path("/containers")
+@Produces(MediaType.APPLICATION_JSON)
+@AdminOnly
+public class SCMDBInsightEndPoint {
+  private final DBStore scmDBStore;
+  private final ReconContainerManager containerManager;
+
+  @Inject
+  public SCMDBInsightEndPoint(OzoneStorageContainerManager reconSCM) {
+    this.containerManager =
+        (ReconContainerManager) reconSCM.getContainerManager();
+    this.scmDBStore = reconSCM.getScmDBStore();
+  }
+
+  /**
+   * This API will return all DELETED containers in SCM in below JSON format.
+   * {
+   * containers: [
+   * {
+   *  containerId: 1,
+   *  state: DELETED,
+   *  pipelineId: "a10ffab6-8ed5-414a-aaf5-79890ff3e8a1",
+   *  numOfKeys: 3,
+   *  inStateSince: <stateEnterTime>
+   * },
+   * {
+   *  containerId: 2,
+   *  state: DELETED,
+   *  pipelineId: "a10ffab6-8ed5-414a-aaf5-79890ff3e8a1",
+   *  numOfKeys: 6,
+   *  inStateSince: <stateEnterTime>
+   * }
+   * ]
+   * }
+   * @return Response of delete containers.
+   */
+  @GET
+  @Path("/deletedContainers")
+  public Response getSCMDeletedContainers() {

Review Comment:
   > > Is it better to move this getSCMDeletedContainers to 
ContainerEndpoint.java?
   > 
   > @ChenSammi - Is this suggestion to make sure that API path should be 
/api/v1/containers/deletedContainers ? . If yes, then path will be under 
containers only, so it is a standard practice in Rest API semantics that we can 
keep the APIs in different classes as long as API path follows the same 
namespace where they should logically belongs to. So I kept the code in 
different class in order not to make class lengthy and easy to review for 
anyone, however path is still "/api/v1/containers/deletedContainers". Kindly 
let me know your thoughts.
   
   @Devesh, thanks for explain the API path. My preference is put the close 
functions in one java class, so it would be easy to know which java class will 
probably have the implementation. If we look at all the existing endpoint, 
their class name and their API path match with each other.  From the consistent 
point of view, it'd better to follow the existing practice.  
   
   One question about this deleted containers, on the container page, all 
containers will be displayed, if we sort the container by their state(not sure 
if this support now), will we get the same result as this API? 
    



-- 
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]

Reply via email to