Skip to content

Commit f676217

Browse files
authored
Use constants for URL parameters in monitor code (#5511)
* Use constants for URL parameters in monitor code Signed-off-by: Oleksandr Krutko <[email protected]>
1 parent b59d97c commit f676217

File tree

3 files changed

+63
-29
lines changed

3 files changed

+63
-29
lines changed

server/monitor/src/main/java/org/apache/accumulo/monitor/next/Endpoints.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757

5858
@Path("/")
5959
public class Endpoints {
60+
/**
61+
* A {@code String} constant representing supplied resource group in path parameter.
62+
*/
63+
private static final String GROUP_PARAM_KEY = "group";
64+
65+
/**
66+
* A {@code String} constant representing supplied tableId in path parameter.
67+
*/
68+
private static final String TABLEID_PARAM_KEY = "tableId";
6069

6170
@Target(ElementType.METHOD)
6271
@Retention(RetentionPolicy.RUNTIME)
@@ -166,10 +175,11 @@ public InstanceSummary getInstanceSummary() {
166175
}
167176

168177
@GET
169-
@Path("compactors/detail/{group}")
178+
@Path("compactors/detail/{" + GROUP_PARAM_KEY + "}")
170179
@Produces(MediaType.APPLICATION_JSON)
171180
@Description("Returns the metric responses for the Compactors in the supplied resource group")
172-
public Collection<MetricResponse> getCompactors(@PathParam("group") String resourceGroup) {
181+
public Collection<MetricResponse>
182+
getCompactors(@PathParam(GROUP_PARAM_KEY) String resourceGroup) {
173183
validateResourceGroup(resourceGroup);
174184
final Set<ServerId> servers = monitor.getInformationFetcher().getSummary()
175185
.getCompactorResourceGroupServers(resourceGroup);
@@ -180,11 +190,11 @@ public Collection<MetricResponse> getCompactors(@PathParam("group") String resou
180190
}
181191

182192
@GET
183-
@Path("compactors/summary/{group}")
193+
@Path("compactors/summary/{" + GROUP_PARAM_KEY + "}")
184194
@Produces(MediaType.APPLICATION_JSON)
185195
@Description("Returns an aggregate view of the metric responses for the Compactors in the supplied resource group")
186196
public Map<Id,CumulativeDistributionSummary>
187-
getCompactorResourceGroupMetricSummary(@PathParam("group") String resourceGroup) {
197+
getCompactorResourceGroupMetricSummary(@PathParam(GROUP_PARAM_KEY) String resourceGroup) {
188198
validateResourceGroup(resourceGroup);
189199
final Map<Id,CumulativeDistributionSummary> metrics = monitor.getInformationFetcher()
190200
.getSummary().getCompactorResourceGroupMetricSummary(resourceGroup);
@@ -203,10 +213,11 @@ public Map<Id,CumulativeDistributionSummary> getCompactorAllMetricSummary() {
203213
}
204214

205215
@GET
206-
@Path("sservers/detail/{group}")
216+
@Path("sservers/detail/{" + GROUP_PARAM_KEY + "}")
207217
@Produces(MediaType.APPLICATION_JSON)
208218
@Description("Returns the metric responses for the ScanServers in the supplied resource group")
209-
public Collection<MetricResponse> getScanServers(@PathParam("group") String resourceGroup) {
219+
public Collection<MetricResponse>
220+
getScanServers(@PathParam(GROUP_PARAM_KEY) String resourceGroup) {
210221
validateResourceGroup(resourceGroup);
211222
final Set<ServerId> servers =
212223
monitor.getInformationFetcher().getSummary().getSServerResourceGroupServers(resourceGroup);
@@ -217,11 +228,11 @@ public Collection<MetricResponse> getScanServers(@PathParam("group") String reso
217228
}
218229

219230
@GET
220-
@Path("sservers/summary/{group}")
231+
@Path("sservers/summary/{" + GROUP_PARAM_KEY + "}")
221232
@Produces(MediaType.APPLICATION_JSON)
222233
@Description("Returns an aggregate view of the metric responses for the ScanServers in the supplied resource group")
223234
public Map<Id,CumulativeDistributionSummary>
224-
getScanServerResourceGroupMetricSummary(@PathParam("group") String resourceGroup) {
235+
getScanServerResourceGroupMetricSummary(@PathParam(GROUP_PARAM_KEY) String resourceGroup) {
225236
validateResourceGroup(resourceGroup);
226237
final Map<Id,CumulativeDistributionSummary> metrics = monitor.getInformationFetcher()
227238
.getSummary().getSServerResourceGroupMetricSummary(resourceGroup);
@@ -240,10 +251,11 @@ public Map<Id,CumulativeDistributionSummary> getScanServerAllMetricSummary() {
240251
}
241252

242253
@GET
243-
@Path("tservers/detail/{group}")
254+
@Path("tservers/detail/{" + GROUP_PARAM_KEY + "}")
244255
@Produces(MediaType.APPLICATION_JSON)
245256
@Description("Returns the metric responses for the TabletServers in the supplied resource group")
246-
public Collection<MetricResponse> getTabletServers(@PathParam("group") String resourceGroup) {
257+
public Collection<MetricResponse>
258+
getTabletServers(@PathParam(GROUP_PARAM_KEY) String resourceGroup) {
247259
validateResourceGroup(resourceGroup);
248260
final Set<ServerId> servers =
249261
monitor.getInformationFetcher().getSummary().getTServerResourceGroupServers(resourceGroup);
@@ -254,11 +266,11 @@ public Collection<MetricResponse> getTabletServers(@PathParam("group") String re
254266
}
255267

256268
@GET
257-
@Path("tservers/summary/{group}")
269+
@Path("tservers/summary/{" + GROUP_PARAM_KEY + "}")
258270
@Produces(MediaType.APPLICATION_JSON)
259271
@Description("Returns an aggregate view of the metric responses for the TabletServers in the supplied resource group")
260272
public Map<Id,CumulativeDistributionSummary>
261-
getTabletServerResourceGroupMetricSummary(@PathParam("group") String resourceGroup) {
273+
getTabletServerResourceGroupMetricSummary(@PathParam(GROUP_PARAM_KEY) String resourceGroup) {
262274
validateResourceGroup(resourceGroup);
263275
final Map<Id,CumulativeDistributionSummary> metrics = monitor.getInformationFetcher()
264276
.getSummary().getTServerResourceGroupMetricSummary(resourceGroup);
@@ -298,10 +310,11 @@ public Map<String,List<TExternalCompaction>> getCompactions() {
298310
}
299311

300312
@GET
301-
@Path("compactions/detail/{group}")
313+
@Path("compactions/detail/{" + GROUP_PARAM_KEY + "}")
302314
@Produces(MediaType.APPLICATION_JSON)
303315
@Description("Returns a list of the 50 oldest running compactions in the supplied resource group")
304-
public List<TExternalCompaction> getCompactions(@PathParam("group") String resourceGroup) {
316+
public List<TExternalCompaction>
317+
getCompactions(@PathParam(GROUP_PARAM_KEY) String resourceGroup) {
305318
validateResourceGroup(resourceGroup);
306319
List<TExternalCompaction> compactions =
307320
monitor.getInformationFetcher().getSummary().getCompactions(resourceGroup);
@@ -320,10 +333,10 @@ public Map<TableId,TableSummary> getTables() {
320333
}
321334

322335
@GET
323-
@Path("tables/{tableId}")
336+
@Path("tables/{" + TABLEID_PARAM_KEY + "}")
324337
@Produces(MediaType.APPLICATION_JSON)
325338
@Description("Returns table details for the supplied TableId")
326-
public TableSummary getTable(@PathParam("tableId") String tableId) {
339+
public TableSummary getTable(@PathParam(TABLEID_PARAM_KEY) String tableId) {
327340
TableSummary ts =
328341
monitor.getInformationFetcher().getSummary().getTables().get(TableId.of(tableId));
329342
if (ts == null) {
@@ -333,10 +346,10 @@ public TableSummary getTable(@PathParam("tableId") String tableId) {
333346
}
334347

335348
@GET
336-
@Path("tables/{tableId}/tablets")
349+
@Path("tables/{" + TABLEID_PARAM_KEY + "}/tablets")
337350
@Produces(MediaType.APPLICATION_JSON)
338351
@Description("Returns tablet details for the supplied table name")
339-
public List<TabletInformation> getTablets(@PathParam("tableId") String tableId) {
352+
public List<TabletInformation> getTablets(@PathParam(TABLEID_PARAM_KEY) String tableId) {
340353
List<TabletInformation> ti =
341354
monitor.getInformationFetcher().getSummary().getTablets(TableId.of(tableId));
342355
if (ti == null) {

server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TablesResource.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
@Path("/tables")
6262
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
6363
public class TablesResource {
64+
/**
65+
* A {@code String} constant representing Table ID to find participating tservers, used in path
66+
* parameter.
67+
*/
68+
private static final String TABLEID_PARAM_KEY = "tableId";
6469

6570
@Inject
6671
private Monitor monitor;
@@ -120,10 +125,11 @@ public static TableInformationList getTables(Monitor monitor) {
120125
* @param tableIdStr Table ID to find participating tservers
121126
* @return List of participating tservers
122127
*/
123-
@Path("{tableId}")
128+
@Path("{" + TABLEID_PARAM_KEY + "}")
124129
@GET
125-
public TabletServers getParticipatingTabletServers(@PathParam("tableId") @NotNull @Pattern(
126-
regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) {
130+
public TabletServers
131+
getParticipatingTabletServers(@PathParam(TABLEID_PARAM_KEY) @NotNull @Pattern(
132+
regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) {
127133
TableId tableId = TableId.of(tableIdStr);
128134
ManagerMonitorInfo mmi = monitor.getMmi();
129135
// fail fast if unable to get monitor info

server/monitor/src/main/java/org/apache/accumulo/monitor/view/WebViews.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@
6060
@Path("/")
6161
@Produces(MediaType.TEXT_HTML)
6262
public class WebViews {
63+
/**
64+
* A {@code String} constant representing table to display its problem details, used in query
65+
* parameter.
66+
*/
67+
private static final String TABLE_PARAM_KEY = "table";
68+
69+
/**
70+
* A {@code String} constant representing tableId Table ID for participating tservers, used in
71+
* path parameter.
72+
*/
73+
private static final String TABLEID_PARAM_KEY = "tableId";
74+
75+
/**
76+
* A {@code String} constant representing TServer to show details for, used in query parameter.
77+
*/
78+
private static final String TSERVER_PARAM_KEY = "s";
6379

6480
private static final Logger log = LoggerFactory.getLogger(WebViews.class);
6581

@@ -149,8 +165,8 @@ public Map<String,Object> getManager() {
149165
@GET
150166
@Path("tservers")
151167
@Template(name = "/default.ftl")
152-
public Map<String,Object>
153-
getTabletServers(@QueryParam("s") @Pattern(regexp = HOSTNAME_PORT_REGEX) String server) {
168+
public Map<String,Object> getTabletServers(
169+
@QueryParam(TSERVER_PARAM_KEY) @Pattern(regexp = HOSTNAME_PORT_REGEX) String server) {
154170

155171
Map<String,Object> model = getModel();
156172
model.put("title", "Tablet Server Status");
@@ -283,11 +299,10 @@ public Map<String,Object> getTables() {
283299
* @return Participating tservers model
284300
*/
285301
@GET
286-
@Path("tables/{tableId}")
302+
@Path("tables/{" + TABLEID_PARAM_KEY + "}")
287303
@Template(name = "/default.ftl")
288-
public Map<String,Object> getTables(
289-
@PathParam("tableId") @NotNull @Pattern(regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableId)
290-
throws TableNotFoundException {
304+
public Map<String,Object> getTables(@PathParam(TABLEID_PARAM_KEY) @NotNull @Pattern(
305+
regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableId) throws TableNotFoundException {
291306
String tableName = monitor.getContext().getQualifiedTableName(TableId.of(tableId));
292307

293308
Map<String,Object> model = getModel();
@@ -310,8 +325,8 @@ public Map<String,Object> getTables(
310325
@GET
311326
@Path("problems")
312327
@Template(name = "/default.ftl")
313-
public Map<String,Object>
314-
getProblems(@QueryParam("table") @Pattern(regexp = ALPHA_NUM_REGEX_BLANK_OK) String table) {
328+
public Map<String,Object> getProblems(
329+
@QueryParam(TABLE_PARAM_KEY) @Pattern(regexp = ALPHA_NUM_REGEX_BLANK_OK) String table) {
315330

316331
Map<String,Object> model = getModel();
317332
model.put("title", "Per-Table Problem Report");

0 commit comments

Comments
 (0)