|
29 | 29 | import io.swagger.annotations.Authorization; |
30 | 30 | import io.swagger.annotations.SecurityDefinition; |
31 | 31 | import io.swagger.annotations.SwaggerDefinition; |
| 32 | +import java.util.Arrays; |
32 | 33 | import java.util.HashMap; |
33 | 34 | import java.util.HashSet; |
| 35 | +import java.util.List; |
34 | 36 | import java.util.Map; |
35 | 37 | import java.util.Set; |
36 | 38 | import java.util.UUID; |
37 | 39 | import java.util.concurrent.Executor; |
| 40 | +import java.util.stream.Collectors; |
38 | 41 | import javax.inject.Inject; |
39 | 42 | import javax.ws.rs.DefaultValue; |
40 | 43 | import javax.ws.rs.GET; |
@@ -123,6 +126,38 @@ public Response pauseConsumption( |
123 | 126 | } |
124 | 127 | } |
125 | 128 |
|
| 129 | + @POST |
| 130 | + @Path("/tables/{tableName}/pauseTopicConsumption") |
| 131 | + @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action = Actions.Table.PAUSE_CONSUMPTION) |
| 132 | + @Produces(MediaType.APPLICATION_JSON) |
| 133 | + @ApiOperation(value = "Pause consumption of some topics of a realtime table", notes = "Pause the consumption of " |
| 134 | + + "some topics of a realtime table.") |
| 135 | + public Response pauseTopicConsumption( |
| 136 | + @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName, |
| 137 | + @ApiParam(value = "Comma separated list of index of the topics", required = true) @QueryParam("topicIndices") |
| 138 | + String topicIndices, |
| 139 | + @Context HttpHeaders headers) { |
| 140 | + tableName = DatabaseUtils.translateTableName(tableName, headers); |
| 141 | + String tableNameWithType = TableNameBuilder.REALTIME.tableNameWithType(tableName); |
| 142 | + validateTable(tableNameWithType); |
| 143 | + List<Integer> topicIndexList; |
| 144 | + try { |
| 145 | + topicIndexList = Arrays.stream(topicIndices.split(",")) |
| 146 | + .map(String::trim) |
| 147 | + .map(idx -> Integer.parseInt(idx)) |
| 148 | + .collect(Collectors.toList()); |
| 149 | + } catch (NumberFormatException nfe) { |
| 150 | + throw new ControllerApplicationException(LOGGER, "topicIndices should be a comma separated list of integers", |
| 151 | + Response.Status.BAD_REQUEST, nfe); |
| 152 | + } |
| 153 | + try { |
| 154 | + return Response.ok(_pinotLLCRealtimeSegmentManager.pauseTopicsConsumption(tableNameWithType, topicIndexList)) |
| 155 | + .build(); |
| 156 | + } catch (Exception e) { |
| 157 | + throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, e); |
| 158 | + } |
| 159 | + } |
| 160 | + |
126 | 161 | @POST |
127 | 162 | @Path("/tables/{tableName}/resumeConsumption") |
128 | 163 | @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action = Actions.Table.RESUME_CONSUMPTION) |
@@ -160,6 +195,39 @@ public Response resumeConsumption( |
160 | 195 | } |
161 | 196 | } |
162 | 197 |
|
| 198 | + @POST |
| 199 | + @Path("/tables/{tableName}/resumeTopicConsumption") |
| 200 | + @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action = Actions.Table.RESUME_CONSUMPTION) |
| 201 | + @Produces(MediaType.APPLICATION_JSON) |
| 202 | + @ApiOperation(value = "Resume consumption of some topics of a realtime table", notes = |
| 203 | + "Resume the consumption for some topics of a realtime table. There are two independent pause mechanism, " |
| 204 | + + "table pause and topic pause. The topics is resumed only if both table and topics are resumed.") |
| 205 | + public Response resumeTopicConsumption( |
| 206 | + @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName, |
| 207 | + @ApiParam(value = "Comma separated list of index of the topics", required = true) @QueryParam("topicIndices") |
| 208 | + String topicIndices, |
| 209 | + @Context HttpHeaders headers) { |
| 210 | + tableName = DatabaseUtils.translateTableName(tableName, headers); |
| 211 | + String tableNameWithType = TableNameBuilder.REALTIME.tableNameWithType(tableName); |
| 212 | + validateTable(tableNameWithType); |
| 213 | + List<Integer> topicIndexList; |
| 214 | + try { |
| 215 | + topicIndexList = Arrays.stream(topicIndices.split(",")) |
| 216 | + .map(String::trim) |
| 217 | + .map(idx -> Integer.parseInt(idx)) |
| 218 | + .collect(Collectors.toList()); |
| 219 | + } catch (NumberFormatException nfe) { |
| 220 | + throw new ControllerApplicationException(LOGGER, "topicIndices should be a comma separated list of integers", |
| 221 | + Response.Status.BAD_REQUEST, nfe); |
| 222 | + } |
| 223 | + try { |
| 224 | + return Response.ok(_pinotLLCRealtimeSegmentManager.resumeTopicsConsumption( |
| 225 | + tableNameWithType, topicIndexList)).build(); |
| 226 | + } catch (Exception e) { |
| 227 | + throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, e); |
| 228 | + } |
| 229 | + } |
| 230 | + |
163 | 231 | @POST |
164 | 232 | @Path("/tables/{tableName}/forceCommit") |
165 | 233 | @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action = Actions.Table.FORCE_COMMIT) |
|
0 commit comments