You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/11/09 00:45:09 UTC

[GitHub] [incubator-pinot] mcvsubbu commented on a change in pull request #4806: Refactor segments admin rest APIs

mcvsubbu commented on a change in pull request #4806: Refactor segments admin rest APIs
URL: https://github.com/apache/incubator-pinot/pull/4806#discussion_r344416330
 
 

 ##########
 File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentRestletResource.java
 ##########
 @@ -19,255 +19,409 @@
 package org.apache.pinot.controller.api.resources;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.inject.Inject;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 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 javax.ws.rs.core.Response.Status;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.store.zk.ZkHelixPropertyStore;
 import org.apache.pinot.common.config.TableNameBuilder;
 import org.apache.pinot.common.metadata.ZKMetadataProvider;
 import org.apache.pinot.common.metadata.segment.OfflineSegmentZKMetadata;
 import org.apache.pinot.common.metadata.segment.RealtimeSegmentZKMetadata;
-import org.apache.pinot.common.utils.CommonConstants;
+import org.apache.pinot.common.utils.CommonConstants.Helix.TableType;
 import org.apache.pinot.common.utils.JsonUtils;
+import org.apache.pinot.common.utils.URIUtils;
 import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
 import org.apache.pinot.controller.helix.core.PinotResourceManagerResponse;
-import org.apache.pinot.common.utils.URIUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.pinot.controller.api.resources.Constants.TABLE_NAME;
-import static org.apache.pinot.controller.api.resources.FileUploadPathProvider.STATE;
-
 
 /**
- * Current URI Mappings:
+ * Segment admin rest APIs:
  * <ul>
  *   <li>
- *     "/tables/{tableName}/segments/{segmentName}":
- *     "/tables/{tableName}/segments/{segmentName}/metadata":
- *     Get segment metadata for a given segment
- *   </li>
- *   <li>
- *     "/tables/{tableName}/segments":
- *     "/tables/{tableName}/segments/metadata":
- *     List segment metadata for a given table
- *   </li>
- *   <li>
- *      "/tables/{tableName}/segments/crc":
- *      Get crc information for a given table
+ *     GET requests:
+ *     <ul>
+ *       <li>"/segments/{tableName}": get all segment names</li>
+ *       <li>"/segments/{tableName}/servers": get the map from server to segments</li>
+ *       <li>"/segments/{tableName}/crc": get the map from segment to CRC</li>
+ *       <li>"/segments/{tableName}/{segmentName}/metadata: get the segment metadata</li>
+ *     </ul>
  *   </li>
  *   <li>
- *     "/tables/{tableName}/segments/{segmentName}?state={state}":
- *     Change the state of the segment to specified {state} (enable|disable|drop)
+ *     POST requests:
+ *     <ul>
+ *       <li>"/segments/{tableName}/{segmentName}/reload": reload a segment</li>
+ *       <li>"/segments/{tableName}/reload": reload all segments</li>
+ *     </ul>
  *   </li>
  *   <li>
- *     "/tables/{tableName}/segments?state={state}":
- *     Change the state of all segments of the table to specified {state} (enable|disable|drop)
+ *     DELETE requests:
+ *     <ul>
+ *       <li>"/segments/{tableName}/{segmentName}": delete a segment</li>
+ *       <li>"/segments/{tableName}: delete all segments</li>
+ *     </ul>
  *   </li>
  *   <li>
- *     "/tables/{tableName}/segments/{segmentName}/reload":
- *     Reload the segment
+ *     All requests (except for crc fetch which only apply to OFFLINE table) take an optional query parameter "type"
+ *     (OFFLINE or REALTIME) for table type. The request will be performed to tables that match the table name and type,
+ *     e.g. "foobar_OFFLINE" matches ("foobar_OFFLINE", null), ("foobar_OFFLINE", OFFLINE), ("foobar", null),
+ *     ("foobar", OFFLINE), but does not match ("foo", null), ("foobar_REALTIME", null), ("foobar_REALTIME", OFFLINE),
+ *     ("foobar_OFFLINE", REALTIME).
  *   </li>
  *   <li>
- *     "/tables/{tableName}/segments/reload":
- *     Reload all segments of the table
+ *     Deprecated APIs:
+ *     <ul>
+ *       <li>"GET /tables/{tableName}/segments"</li>
+ *       <li>"GET /tables/{tableName}/segments/metadata"</li>
+ *       <li>"GET /tables/{tableName}/segments/crc"</li>
+ *       <li>"GET /tables/{tableName}/segments/{segmentName}"</li>
+ *       <li>"GET /tables/{tableName}/segments/{segmentName}/metadata"</li>
+ *       <li>"GET /tables/{tableName}/segments/{segmentName}/reload"</li>
+ *       <li>"POST /tables/{tableName}/segments/{segmentName}/reload"</li>
+ *       <li>"GET /tables/{tableName}/segments/reload"</li>
+ *       <li>"POST /tables/{tableName}/segments/reload"</li>
+ *     </ul>
  *   </li>
  * </ul>
- *
- * {@inheritDoc}
  */
-
-@Api(tags = Constants.TABLE_TAG)
+@Api(tags = Constants.SEGMENT_TAG)
 @Path("/")
 public class PinotSegmentRestletResource {
-  public static Logger LOGGER = LoggerFactory.getLogger(PinotSegmentRestletResource.class);
-  public static final Response.Status BAD_REQUEST = Response.Status.BAD_REQUEST;
-  public static final Response.Status INTERNAL_ERROR = Response.Status.INTERNAL_SERVER_ERROR;
-
-  private static final long _offlineToOnlineTimeoutInseconds = 5L;
+  private static Logger LOGGER = LoggerFactory.getLogger(PinotSegmentRestletResource.class);
 
   @Inject
   PinotHelixResourceManager _pinotHelixResourceManager;
 
   @GET
-  @Path("tables/{tableName}/segments")
   @Produces(MediaType.APPLICATION_JSON)
-  @ApiOperation(value = "Lists metadata or toggles segment states", notes = "Toggles segment states if 'state' is specified in query param, otherwise lists metadata")
-  // TODO: when state is not specified, this method returns the map from server to segments instead of segment metadata
-  public String toggleStateOrListMetadataForAllSegments(
+  @Path("/segments/{tableName}")
+  @ApiOperation(value = "Lists all segments", notes = "List all segments")
+  public List<Map<TableType, List<String>>> getSegments(
       @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName,
-      @ApiParam(value = "enable|disable|drop", required = false) @QueryParam("state") String stateStr,
-      @ApiParam(value = "realtime|offline", required = false) @QueryParam("type") String tableTypeStr) {
-    CommonConstants.Helix.TableType tableType = Constants.validateTableType(tableTypeStr);
-    StateType state = Constants.validateState(stateStr);
+      @ApiParam(value = "OFFLINE|REALTIME") @QueryParam("type") String tableTypeStr) {
+    List<String> tableNamesWithType =
+        getExistingTableNamesWithType(tableName, Constants.validateTableType(tableTypeStr));
+    List<Map<TableType, List<String>>> resultList = new ArrayList<>(tableNamesWithType.size());
+    for (String tableNameWithType : tableNamesWithType) {
+      TableType tableType = TableNameBuilder.getTableTypeFromTableName(tableNameWithType);
 
 Review comment:
   If the table type is specified in the input, then we should list only the segments of that table type

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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