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


##########
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() {
+    List<DeletedContainerInfo> deletedContainerInfoList = new ArrayList<>();
+    try {
+      List<ContainerInfo> containers =
+          containerManager.getContainers(HddsProtos.LifeCycleState.DELETED);

Review Comment:
   @ChenSammi  thanks for your review. I initially thought of using same 
ContainerInfo object, however I see that we have few fields marked with 
"@JsonIgnore" annotation and those were done for purpose for some previous 
issues. So I didn't want to change the existing class annotations. 



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