guruguha commented on a change in pull request #5718:
URL: https://github.com/apache/incubator-pinot/pull/5718#discussion_r460495237



##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentRestletResource.java
##########
@@ -485,4 +493,91 @@ private void deleteSegmentsInternal(String 
tableNameWithType, List<String> segme
       throw new ControllerApplicationException(LOGGER, e.getMessage(), 
Response.Status.FORBIDDEN);
     }
   }
+
+  @GET
+  @Path("segments/{tableName}/reload-status")
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Status of segment reload", notes = "Status of segment 
reload")
+  public Map<String, TableMetadataReader.TableReloadStatus> getReloadStatus(
+          @ApiParam(value = "Name of the table", required = true) 
@PathParam("tableName") String tableName,
+          @ApiParam(value = "OFFLINE|REALTIME") @QueryParam("type") String 
tableTypeStr) {
+    List<String> tableNamesWithType = getExistingTableNamesWithType(tableName, 
Constants.validateTableType(tableTypeStr));
+    Map<String, TableMetadataReader.TableReloadStatus> reloadStatusMap = new 
HashMap<>();
+    for (String tableNameWithType : tableNamesWithType) {
+      TableMetadataReader.TableReloadStatus tableReloadStatus = null;
+      try {
+        tableReloadStatus = getSegmentsReloadStatus(tableNameWithType);
+      } catch (InvalidConfigException e) {
+        throw new ControllerApplicationException(LOGGER,
+                "Failed to load segment reload status for table: " + 
tableName, Status.NOT_FOUND);
+      }
+      if (Objects.isNull(tableReloadStatus))
+        throw new ControllerApplicationException(LOGGER,
+                "Table: " + tableName + " not found.", Status.NOT_FOUND);
+      reloadStatusMap.put(tableNameWithType, tableReloadStatus);
+    }
+    return reloadStatusMap;
+  }
+
+  private TableMetadataReader.TableReloadStatus getSegmentsReloadStatus(String 
tableNameWithType)
+          throws InvalidConfigException {
+    final Map<String, List<String>> serversToSegmentsMap =
+            
_pinotHelixResourceManager.getServerToSegmentsMap(tableNameWithType);
+    TableMetadataReader tableMetadataReader =
+            new TableMetadataReader(_executor, _connectionManager, 
_pinotHelixResourceManager);
+    return tableMetadataReader.getReloadStatus(tableNameWithType, 
serversToSegmentsMap,
+            _controllerConf.getServerAdminRequestTimeoutSeconds() * 1000);
+  }
+
+  @GET
+  @Path("segments/{tableName}/metadata")
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Get the metadata for a segment", notes = "Get the 
metadata for a segment")
+  public Map<String, String> getServerMetadata(@ApiParam(value = "Name of the 
table", required = true) @PathParam("tableName") String tableName,
+                                               @ApiParam(value = 
"OFFLINE|REALTIME") @QueryParam("type") String tableTypeStr) {
+    TableType tableType = Constants.validateTableType(tableTypeStr);
+    if (tableType == TableType.REALTIME)
+      throw new ControllerApplicationException(LOGGER,
+              "Table type : " + tableTypeStr + " not yet supported.", 
Status.NOT_IMPLEMENTED);
+
+    List<String> tableNamesWithType = getExistingTableNamesWithType(tableName, 
Constants.validateTableType(tableTypeStr));
+    Map<String, String> segmentsMetadata = null;
+    try {
+      segmentsMetadata = 
getSegmentsMetadataFromServer(tableNamesWithType.get(0));
+    } catch (InvalidConfigException e) {
+      throw new ControllerApplicationException(LOGGER,
+              "Failed to load segment reload status for table: " + tableName, 
Status.NOT_FOUND);
+    } catch (IOException ioe) {
+      throw new ControllerApplicationException(LOGGER,
+              "Error parsing response to cluster config!", 
Response.Status.BAD_REQUEST, ioe);
+    }
+    if (segmentsMetadata == null)

Review comment:
       That exception has been updated to the propagated exception. Also, as 
mentioned before, the `segmentsMetadata` will not be `null`. 




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to