2828import io .swagger .annotations .ApiKeyAuthDefinition ;
2929import io .swagger .annotations .ApiOperation ;
3030import io .swagger .annotations .ApiParam ;
31+ import io .swagger .annotations .ApiResponse ;
32+ import io .swagger .annotations .ApiResponses ;
3133import io .swagger .annotations .Authorization ;
3234import io .swagger .annotations .SecurityDefinition ;
3335import io .swagger .annotations .SwaggerDefinition ;
9092import org .apache .pinot .controller .api .exception .InvalidTableConfigException ;
9193import org .apache .pinot .controller .api .exception .TableAlreadyExistsException ;
9294import org .apache .pinot .controller .helix .core .PinotHelixResourceManager ;
95+ import org .apache .pinot .controller .helix .core .PinotResourceManagerResponse ;
9396import org .apache .pinot .controller .helix .core .minion .PinotHelixTaskResourceManager ;
9497import org .apache .pinot .controller .helix .core .rebalance .RebalanceResult ;
9598import org .apache .pinot .controller .helix .core .rebalance .TableRebalanceProgressStats ;
@@ -363,9 +366,7 @@ private String listTableConfigs(String tableName, @Nullable String tableTypeStr)
363366 @ GET
364367 @ Produces (MediaType .APPLICATION_JSON )
365368 @ Path ("/tables/{tableName}" )
366- @ ApiOperation (value = "Get/Enable/Disable/Drop a table" ,
367- notes = "Get/Enable/Disable/Drop a table. If table name is the only parameter specified "
368- + ", the tableconfig will be printed" )
369+ @ ApiOperation (value = "Lists the table configs" )
369370 public String alterTableStateOrListTableConfig (
370371 @ ApiParam (value = "Name of the table" , required = true ) @ PathParam ("tableName" ) String tableName ,
371372 @ ApiParam (value = "enable|disable|drop" ) @ QueryParam ("state" ) String stateStr ,
@@ -376,6 +377,8 @@ public String alterTableStateOrListTableConfig(
376377 return listTableConfigs (tableName , tableTypeStr );
377378 }
378379
380+ // TODO: DO NOT allow toggling state with GET request
381+
379382 StateType stateType = Constants .validateState (stateStr );
380383 TableType tableType = Constants .validateTableType (tableTypeStr );
381384
@@ -717,6 +720,45 @@ public String getTableState(
717720 }
718721 }
719722
723+ @ PUT
724+ @ Path ("/tables/{tableName}/state" )
725+ @ Authenticate (AccessType .UPDATE )
726+ @ Produces (MediaType .APPLICATION_JSON )
727+ @ Consumes (MediaType .TEXT_PLAIN )
728+ @ ApiOperation (value = "Enable/disable a table" , notes = "Enable/disable a table" )
729+ @ ApiResponses (value = {
730+ @ ApiResponse (code = 200 , message = "Success" ),
731+ @ ApiResponse (code = 400 , message = "Bad Request" ),
732+ @ ApiResponse (code = 404 , message = "Table not found" ),
733+ @ ApiResponse (code = 500 , message = "Internal error" )
734+ })
735+ public SuccessResponse toggleTableState (
736+ @ ApiParam (value = "Table name" , required = true ) @ PathParam ("tableName" ) String tableName ,
737+ @ ApiParam (value = "realtime|offline" , required = true ) @ QueryParam ("type" ) String tableTypeStr ,
738+ @ ApiParam (value = "enable|disable" , required = true ) @ QueryParam ("state" ) String state ) {
739+ String tableNameWithType = constructTableNameWithType (tableName , tableTypeStr );
740+ StateType stateType ;
741+ if (StateType .ENABLE .name ().equalsIgnoreCase (state )) {
742+ stateType = StateType .ENABLE ;
743+ } else if (StateType .DISABLE .name ().equalsIgnoreCase (state )) {
744+ stateType = StateType .DISABLE ;
745+ } else {
746+ throw new ControllerApplicationException (LOGGER , "Unknown state '" + state + "'" , Response .Status .BAD_REQUEST );
747+ }
748+ if (!_pinotHelixResourceManager .hasTable (tableNameWithType )) {
749+ throw new ControllerApplicationException (LOGGER , "Table '" + tableName + "' does not exist" ,
750+ Response .Status .NOT_FOUND );
751+ }
752+ PinotResourceManagerResponse response = _pinotHelixResourceManager .toggleTableState (tableNameWithType , stateType );
753+ if (response .isSuccessful ()) {
754+ return new SuccessResponse ("Request to " + state + " table '" + tableNameWithType + "' is successful" );
755+ } else {
756+ throw new ControllerApplicationException (LOGGER ,
757+ "Failed to " + state + " table '" + tableNameWithType + "': " + response .getMessage (),
758+ Response .Status .INTERNAL_SERVER_ERROR );
759+ }
760+ }
761+
720762 @ GET
721763 @ Produces (MediaType .APPLICATION_JSON )
722764 @ Authenticate (AccessType .UPDATE )
0 commit comments