Jackie-Jiang commented on code in PR #8828:
URL: https://github.com/apache/pinot/pull/8828#discussion_r934899690


##########
pinot-server/src/main/java/org/apache/pinot/server/api/resources/ControllerJobStatusResource.java:
##########
@@ -0,0 +1,92 @@
+/**
+ * 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.pinot.server.api.resources;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import java.util.List;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import org.apache.pinot.segment.local.data.manager.SegmentDataManager;
+import org.apache.pinot.segment.local.data.manager.TableDataManager;
+import org.apache.pinot.server.starter.ServerInstance;
+import org.apache.pinot.server.starter.helix.SegmentReloadStatusValue;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+@Api(tags = "Tasks")
+@Path("/")
+public class ControllerJobStatusResource {
+
+  @Inject
+  private ServerInstance _serverInstance;
+
+  @GET
+  @Path("/controllerJob/reloadStatus/{tableNameWithType}")
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Task status", notes = "Return status of the given 
task")
+  public String taskStatus(@PathParam("tableNameWithType") String 
tableNameWithType,

Review Comment:
   Revise the API doc and method name to reflect that this method is for the 
reload status check



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java:
##########
@@ -2366,16 +2382,56 @@ public void testJDBCClient()
     Assert.assertTrue(resultSet.getLong(1) > 0);
   }
 
-  private java.sql.Connection getJDBCConnectionFromController(int 
controllerPort) throws Exception {
+  private java.sql.Connection getJDBCConnectionFromController(int 
controllerPort)
+      throws Exception {
     PinotDriver pinotDriver = new PinotDriver();
     Properties jdbcProps = new Properties();
     return pinotDriver.connect("jdbc:pinot://localhost:" + controllerPort, 
jdbcProps);
   }
 
-  private java.sql.Connection getJDBCConnectionFromBrokers(int controllerPort, 
int brokerPort) throws Exception {
+  private java.sql.Connection getJDBCConnectionFromBrokers(int controllerPort, 
int brokerPort)
+      throws Exception {
     PinotDriver pinotDriver = new PinotDriver();
     Properties jdbcProps = new Properties();
     jdbcProps.put(PinotConnection.BROKER_LIST, "localhost:" + brokerPort);
     return pinotDriver.connect("jdbc:pinot://localhost:" + controllerPort, 
jdbcProps);
   }
+
+  private String reloadOfflineTableAndValidateResponse(String tableName, 
boolean forceDownload) {
+    String jobId = null;
+    try {
+      String response =
+          
sendPostRequest(_controllerRequestURLBuilder.forTableReload(tableName, 
TableType.OFFLINE, forceDownload),
+              null);
+      String tableNameWithType = 
TableNameBuilder.OFFLINE.tableNameWithType(tableName);
+      JsonNode tableLevelDetails =
+          
JsonUtils.stringToJsonNode(StringEscapeUtils.unescapeJava(response.split(": 
")[1])).get(tableNameWithType);
+      String isZKWriteSuccess = 
tableLevelDetails.get("reloadJobMetaZKStorageStatus").asText();
+
+      if (isZKWriteSuccess.equals("SUCCESS")) {
+        // We can validate reload status API now
+        jobId = tableLevelDetails.get("reloadJobId").asText();
+        String jobStatusResponse = 
sendGetRequest(_controllerRequestURLBuilder.forControllerJobStatus(jobId));
+        JsonNode jobStatus = JsonUtils.stringToJsonNode(jobStatusResponse);
+
+        // Validate all fields are present
+        assertEquals(jobStatus.get("metadata").get("jobId").asText(), jobId);
+        assertEquals(jobStatus.get("metadata").get("jobType").asText(), 
"RELOAD_ALL_SEGMENTS");
+        assertEquals(jobStatus.get("metadata").get("tableName").asText(), 
tableNameWithType);
+      }
+    } catch (Exception e) {

Review Comment:
   We don't need to catch the exception. Instead we may directly throwing it out



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java:
##########
@@ -427,6 +428,21 @@ public void testUploadSegmentRefreshOnly()
     cleanupTestTableDataManager(offlineTableName);
   }
 
+  @Test
+  public void testReloadStatusApi() {
+    String reloadJobId = reloadOfflineTableAndValidateResponse(getTableName(), 
false);
+    if (reloadJobId != null) {
+      // Spin until validated
+      TestUtils.waitForCondition(aVoid -> {
+        try {
+          return validateReloadJobSuccess(reloadJobId);

Review Comment:
   What I meant is that we can add the `validateReloadJobSuccess()` after every 
`reloadOfflineTableAndValidateResponse()` in other methods. All the segments 
should be successfully reloaded after the `TestUtils.waitForCondition()` check 
is passed



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java:
##########
@@ -2366,16 +2382,56 @@ public void testJDBCClient()
     Assert.assertTrue(resultSet.getLong(1) > 0);
   }
 
-  private java.sql.Connection getJDBCConnectionFromController(int 
controllerPort) throws Exception {
+  private java.sql.Connection getJDBCConnectionFromController(int 
controllerPort)
+      throws Exception {
     PinotDriver pinotDriver = new PinotDriver();
     Properties jdbcProps = new Properties();
     return pinotDriver.connect("jdbc:pinot://localhost:" + controllerPort, 
jdbcProps);
   }
 
-  private java.sql.Connection getJDBCConnectionFromBrokers(int controllerPort, 
int brokerPort) throws Exception {
+  private java.sql.Connection getJDBCConnectionFromBrokers(int controllerPort, 
int brokerPort)
+      throws Exception {
     PinotDriver pinotDriver = new PinotDriver();
     Properties jdbcProps = new Properties();
     jdbcProps.put(PinotConnection.BROKER_LIST, "localhost:" + brokerPort);
     return pinotDriver.connect("jdbc:pinot://localhost:" + controllerPort, 
jdbcProps);
   }
+
+  private String reloadOfflineTableAndValidateResponse(String tableName, 
boolean forceDownload) {
+    String jobId = null;
+    try {
+      String response =
+          
sendPostRequest(_controllerRequestURLBuilder.forTableReload(tableName, 
TableType.OFFLINE, forceDownload),
+              null);
+      String tableNameWithType = 
TableNameBuilder.OFFLINE.tableNameWithType(tableName);
+      JsonNode tableLevelDetails =
+          
JsonUtils.stringToJsonNode(StringEscapeUtils.unescapeJava(response.split(": 
")[1])).get(tableNameWithType);
+      String isZKWriteSuccess = 
tableLevelDetails.get("reloadJobMetaZKStorageStatus").asText();
+
+      if (isZKWriteSuccess.equals("SUCCESS")) {

Review Comment:
   Can we directly do `assertEquals()` here? It should return `SUCCESS` and we 
do want to verify this behavior



-- 
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: commits-unsubscr...@pinot.apache.org

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