This is an automated email from the ASF dual-hosted git repository. domgarguilo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new f676217e75 Use constants for URL parameters in monitor code (#5511) f676217e75 is described below commit f676217e757d823aff0499ff5af1beda2abc5f13 Author: Oleksandr Krutko <46520164+arsena...@users.noreply.github.com> AuthorDate: Fri May 2 16:33:11 2025 +0200 Use constants for URL parameters in monitor code (#5511) * Use constants for URL parameters in monitor code Signed-off-by: Oleksandr Krutko <alexander.kru...@gmail.com> --- .../apache/accumulo/monitor/next/Endpoints.java | 49 ++++++++++++++-------- .../monitor/rest/tables/TablesResource.java | 12 ++++-- .../org/apache/accumulo/monitor/view/WebViews.java | 31 ++++++++++---- 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/next/Endpoints.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/next/Endpoints.java index 629b3fa512..6f41e66cec 100644 --- a/server/monitor/src/main/java/org/apache/accumulo/monitor/next/Endpoints.java +++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/next/Endpoints.java @@ -57,6 +57,15 @@ import io.micrometer.core.instrument.cumulative.CumulativeDistributionSummary; @Path("/") public class Endpoints { + /** + * A {@code String} constant representing supplied resource group in path parameter. + */ + private static final String GROUP_PARAM_KEY = "group"; + + /** + * A {@code String} constant representing supplied tableId in path parameter. + */ + private static final String TABLEID_PARAM_KEY = "tableId"; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @@ -166,10 +175,11 @@ public class Endpoints { } @GET - @Path("compactors/detail/{group}") + @Path("compactors/detail/{" + GROUP_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns the metric responses for the Compactors in the supplied resource group") - public Collection<MetricResponse> getCompactors(@PathParam("group") String resourceGroup) { + public Collection<MetricResponse> + getCompactors(@PathParam(GROUP_PARAM_KEY) String resourceGroup) { validateResourceGroup(resourceGroup); final Set<ServerId> servers = monitor.getInformationFetcher().getSummary() .getCompactorResourceGroupServers(resourceGroup); @@ -180,11 +190,11 @@ public class Endpoints { } @GET - @Path("compactors/summary/{group}") + @Path("compactors/summary/{" + GROUP_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns an aggregate view of the metric responses for the Compactors in the supplied resource group") public Map<Id,CumulativeDistributionSummary> - getCompactorResourceGroupMetricSummary(@PathParam("group") String resourceGroup) { + getCompactorResourceGroupMetricSummary(@PathParam(GROUP_PARAM_KEY) String resourceGroup) { validateResourceGroup(resourceGroup); final Map<Id,CumulativeDistributionSummary> metrics = monitor.getInformationFetcher() .getSummary().getCompactorResourceGroupMetricSummary(resourceGroup); @@ -203,10 +213,11 @@ public class Endpoints { } @GET - @Path("sservers/detail/{group}") + @Path("sservers/detail/{" + GROUP_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns the metric responses for the ScanServers in the supplied resource group") - public Collection<MetricResponse> getScanServers(@PathParam("group") String resourceGroup) { + public Collection<MetricResponse> + getScanServers(@PathParam(GROUP_PARAM_KEY) String resourceGroup) { validateResourceGroup(resourceGroup); final Set<ServerId> servers = monitor.getInformationFetcher().getSummary().getSServerResourceGroupServers(resourceGroup); @@ -217,11 +228,11 @@ public class Endpoints { } @GET - @Path("sservers/summary/{group}") + @Path("sservers/summary/{" + GROUP_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns an aggregate view of the metric responses for the ScanServers in the supplied resource group") public Map<Id,CumulativeDistributionSummary> - getScanServerResourceGroupMetricSummary(@PathParam("group") String resourceGroup) { + getScanServerResourceGroupMetricSummary(@PathParam(GROUP_PARAM_KEY) String resourceGroup) { validateResourceGroup(resourceGroup); final Map<Id,CumulativeDistributionSummary> metrics = monitor.getInformationFetcher() .getSummary().getSServerResourceGroupMetricSummary(resourceGroup); @@ -240,10 +251,11 @@ public class Endpoints { } @GET - @Path("tservers/detail/{group}") + @Path("tservers/detail/{" + GROUP_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns the metric responses for the TabletServers in the supplied resource group") - public Collection<MetricResponse> getTabletServers(@PathParam("group") String resourceGroup) { + public Collection<MetricResponse> + getTabletServers(@PathParam(GROUP_PARAM_KEY) String resourceGroup) { validateResourceGroup(resourceGroup); final Set<ServerId> servers = monitor.getInformationFetcher().getSummary().getTServerResourceGroupServers(resourceGroup); @@ -254,11 +266,11 @@ public class Endpoints { } @GET - @Path("tservers/summary/{group}") + @Path("tservers/summary/{" + GROUP_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns an aggregate view of the metric responses for the TabletServers in the supplied resource group") public Map<Id,CumulativeDistributionSummary> - getTabletServerResourceGroupMetricSummary(@PathParam("group") String resourceGroup) { + getTabletServerResourceGroupMetricSummary(@PathParam(GROUP_PARAM_KEY) String resourceGroup) { validateResourceGroup(resourceGroup); final Map<Id,CumulativeDistributionSummary> metrics = monitor.getInformationFetcher() .getSummary().getTServerResourceGroupMetricSummary(resourceGroup); @@ -298,10 +310,11 @@ public class Endpoints { } @GET - @Path("compactions/detail/{group}") + @Path("compactions/detail/{" + GROUP_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns a list of the 50 oldest running compactions in the supplied resource group") - public List<TExternalCompaction> getCompactions(@PathParam("group") String resourceGroup) { + public List<TExternalCompaction> + getCompactions(@PathParam(GROUP_PARAM_KEY) String resourceGroup) { validateResourceGroup(resourceGroup); List<TExternalCompaction> compactions = monitor.getInformationFetcher().getSummary().getCompactions(resourceGroup); @@ -320,10 +333,10 @@ public class Endpoints { } @GET - @Path("tables/{tableId}") + @Path("tables/{" + TABLEID_PARAM_KEY + "}") @Produces(MediaType.APPLICATION_JSON) @Description("Returns table details for the supplied TableId") - public TableSummary getTable(@PathParam("tableId") String tableId) { + public TableSummary getTable(@PathParam(TABLEID_PARAM_KEY) String tableId) { TableSummary ts = monitor.getInformationFetcher().getSummary().getTables().get(TableId.of(tableId)); if (ts == null) { @@ -333,10 +346,10 @@ public class Endpoints { } @GET - @Path("tables/{tableId}/tablets") + @Path("tables/{" + TABLEID_PARAM_KEY + "}/tablets") @Produces(MediaType.APPLICATION_JSON) @Description("Returns tablet details for the supplied table name") - public List<TabletInformation> getTablets(@PathParam("tableId") String tableId) { + public List<TabletInformation> getTablets(@PathParam(TABLEID_PARAM_KEY) String tableId) { List<TabletInformation> ti = monitor.getInformationFetcher().getSummary().getTablets(TableId.of(tableId)); if (ti == null) { diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TablesResource.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TablesResource.java index 83e1cdaa82..3121b65715 100644 --- a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TablesResource.java +++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TablesResource.java @@ -61,6 +61,11 @@ import org.apache.accumulo.server.util.TableInfoUtil; @Path("/tables") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public class TablesResource { + /** + * A {@code String} constant representing Table ID to find participating tservers, used in path + * parameter. + */ + private static final String TABLEID_PARAM_KEY = "tableId"; @Inject private Monitor monitor; @@ -120,10 +125,11 @@ public class TablesResource { * @param tableIdStr Table ID to find participating tservers * @return List of participating tservers */ - @Path("{tableId}") + @Path("{" + TABLEID_PARAM_KEY + "}") @GET - public TabletServers getParticipatingTabletServers(@PathParam("tableId") @NotNull @Pattern( - regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) { + public TabletServers + getParticipatingTabletServers(@PathParam(TABLEID_PARAM_KEY) @NotNull @Pattern( + regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) { TableId tableId = TableId.of(tableIdStr); ManagerMonitorInfo mmi = monitor.getMmi(); // fail fast if unable to get monitor info diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/view/WebViews.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/view/WebViews.java index ecc3b5961b..8311b37555 100644 --- a/server/monitor/src/main/java/org/apache/accumulo/monitor/view/WebViews.java +++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/view/WebViews.java @@ -60,6 +60,22 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Path("/") @Produces(MediaType.TEXT_HTML) public class WebViews { + /** + * A {@code String} constant representing table to display its problem details, used in query + * parameter. + */ + private static final String TABLE_PARAM_KEY = "table"; + + /** + * A {@code String} constant representing tableId Table ID for participating tservers, used in + * path parameter. + */ + private static final String TABLEID_PARAM_KEY = "tableId"; + + /** + * A {@code String} constant representing TServer to show details for, used in query parameter. + */ + private static final String TSERVER_PARAM_KEY = "s"; private static final Logger log = LoggerFactory.getLogger(WebViews.class); @@ -149,8 +165,8 @@ public class WebViews { @GET @Path("tservers") @Template(name = "/default.ftl") - public Map<String,Object> - getTabletServers(@QueryParam("s") @Pattern(regexp = HOSTNAME_PORT_REGEX) String server) { + public Map<String,Object> getTabletServers( + @QueryParam(TSERVER_PARAM_KEY) @Pattern(regexp = HOSTNAME_PORT_REGEX) String server) { Map<String,Object> model = getModel(); model.put("title", "Tablet Server Status"); @@ -283,11 +299,10 @@ public class WebViews { * @return Participating tservers model */ @GET - @Path("tables/{tableId}") + @Path("tables/{" + TABLEID_PARAM_KEY + "}") @Template(name = "/default.ftl") - public Map<String,Object> getTables( - @PathParam("tableId") @NotNull @Pattern(regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableId) - throws TableNotFoundException { + public Map<String,Object> getTables(@PathParam(TABLEID_PARAM_KEY) @NotNull @Pattern( + regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableId) throws TableNotFoundException { String tableName = monitor.getContext().getQualifiedTableName(TableId.of(tableId)); Map<String,Object> model = getModel(); @@ -310,8 +325,8 @@ public class WebViews { @GET @Path("problems") @Template(name = "/default.ftl") - public Map<String,Object> - getProblems(@QueryParam("table") @Pattern(regexp = ALPHA_NUM_REGEX_BLANK_OK) String table) { + public Map<String,Object> getProblems( + @QueryParam(TABLE_PARAM_KEY) @Pattern(regexp = ALPHA_NUM_REGEX_BLANK_OK) String table) { Map<String,Object> model = getModel(); model.put("title", "Per-Table Problem Report");