Skip to content

Commit

Permalink
HBASE-29026 Replace deprecated calls in JSP files
Browse files Browse the repository at this point in the history
- Replaced the following deprecated methods in JSP files:
  - java.net.URLEncoder.encode(String) -> java.net.URLEncoder.encode(String, Charset)
  - StringUtils.humanReadableInt(long) -> StringUtils.TraditionalBinaryPrefix.long2String(long, "", 1)
  - org.apache.hadoop.fs.FileSystem.getLength(Path) -> getFileStatus(Path).getLen()
  - org.apache.hadoop.hbase.ServerName.getStartcode() -> org.apache.hadoop.hbase.ServerName.getStartCode()
- Also removed unused imports in the touched JSP files.
  • Loading branch information
PDavid committed Jan 20, 2025
1 parent 6f8db78 commit 09cf7db
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,17 @@
import="static org.apache.commons.lang3.StringEscapeUtils.escapeXml"
import="java.util.Collections"
import="java.util.Comparator"
import="java.util.ArrayList"
import="java.util.Date"
import="java.util.List"
import="java.util.Set"
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv"
import="org.apache.hadoop.hbase.procedure2.LockedResource"
import="org.apache.hadoop.hbase.procedure2.Procedure"
import="org.apache.hadoop.hbase.procedure2.ProcedureExecutor"
import="org.apache.hadoop.hbase.procedure2.util.StringUtils"
import="org.apache.hadoop.util.StringUtils.TraditionalBinaryPrefix"
%>
<%@ page import="org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure" %>
<%@ page import="org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure" %>
<%@ page import="org.apache.hadoop.hbase.master.assignment.OpenRegionProcedure" %>
<%@ page import="org.apache.hadoop.hbase.master.assignment.CloseRegionProcedure" %>
<%@ page import="org.apache.hadoop.hbase.metrics.OperationMetrics" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.hadoop.hbase.master.MetricsAssignmentManagerSource" %>
<%@ page import="org.apache.hadoop.hbase.master.MetricsAssignmentManager" %>
<%@ page import="org.apache.hadoop.hbase.procedure2.ProcedureMetrics" %>
<%@ page import="org.apache.hadoop.hbase.metrics.Snapshot" %>
<%@ page import="org.apache.hadoop.hbase.metrics.Histogram" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="org.apache.hadoop.hbase.metrics.impl.HistogramImpl" %>
Expand Down Expand Up @@ -90,7 +78,7 @@
<h1>Procedure Time Statistics</h1>
</div>
</div>
<p>We list proceduces completed successfully of the following types only: ServerCrashProcedure, TransitRegionStateProcedure,
<p>We list procedures completed successfully of the following types only: ServerCrashProcedure, TransitRegionStateProcedure,
OpenRegionProcedure, CloseRegionProcedure.</p>
<table class="table table-striped" width="90%" >
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import="java.util.concurrent.TimeUnit"
import="java.util.ArrayList"
import="java.util.List"
import="org.apache.hadoop.conf.Configuration"
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.quotas.MasterQuotaManager"
import="org.apache.hadoop.hbase.quotas.QuotaRetriever"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import="java.util.List"
import="java.util.Map"
import="java.util.function.Function"
import="java.util.regex.Pattern"
import="java.util.stream.Stream"
import="java.util.stream.Collectors"
import="org.apache.hadoop.hbase.ServerName"
import="org.apache.hadoop.hbase.TableName"
Expand Down Expand Up @@ -169,7 +167,7 @@
totalRequestsPerSecond += sl.getRequestCountPerSecond();
lastContact = (System.currentTimeMillis() - sl.getReportTimestamp())/1000;
}
long startcode = serverName.getStartcode();
long startcode = serverName.getStartCode();
int infoPort = master.getRegionServerInfoPort(serverName);
String url = "//" + serverName.getHostname() + ":" + infoPort + "/rs-status";%>
<tr>
Expand Down
18 changes: 15 additions & 3 deletions hbase-server/src/main/resources/hbase-webapps/master/snapshot.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
import="org.apache.hadoop.util.StringUtils"
import="org.apache.hadoop.hbase.TableName"
%>
<%!
/**
* Note: This method was taken from org.apache.hadoop.util.StringUtils.humanReadableInt(long).
* Given an integer, return a string that is in an approximate, but human
* readable format.
* @param number the number to format
* @return a human readable form of the integer
*/
private static String humanReadableInt(long number) {
return StringUtils.TraditionalBinaryPrefix.long2String(number, "", 1);
}
%>
<%
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
Configuration conf = master.getConfiguration();
Expand Down Expand Up @@ -134,14 +146,14 @@
<div class="row">
<div class="span12">
<%= stats.getStoreFilesCount() %> HFiles (<%= stats.getArchivedStoreFilesCount() %> in archive),
total size <%= StringUtils.humanReadableInt(stats.getStoreFilesSize()) %>
total size <%= humanReadableInt(stats.getStoreFilesSize()) %>
(<%= stats.getSharedStoreFilePercentage() %>&#37;
<%= StringUtils.humanReadableInt(stats.getSharedStoreFilesSize()) %> shared with the source
<%= humanReadableInt(stats.getSharedStoreFilesSize()) %> shared with the source
table)
</div>
<div class="span12">
<%= stats.getLogsCount() %> Logs, total size
<%= StringUtils.humanReadableInt(stats.getLogsSize()) %>
<%= humanReadableInt(stats.getLogsSize()) %>
</div>
</div>
<% if (stats.isSnapshotCorrupted()) { %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
import="org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription"
%>
<%@ page import="org.apache.hadoop.hbase.util.PrettyPrinter" %>
<%!
/**
* Note: This method was taken from org.apache.hadoop.util.StringUtils.humanReadableInt(long).
* Given an integer, return a string that is in an approximate, but human
* readable format.
* @param number the number to format
* @return a human readable form of the integer
*/
private static String humanReadableInt(long number) {
return StringUtils.TraditionalBinaryPrefix.long2String(number, "", 1);
}
%>
<%
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
Configuration conf = master.getConfiguration();
Expand Down Expand Up @@ -99,18 +111,18 @@
<td>
<%= SnapshotDescriptionUtils.isExpiredSnapshot(snapshotDesc.getTtl(), snapshotDesc.getCreationTime(), System.currentTimeMillis()) ? "Yes" : "No" %>
</td>
<td><%= StringUtils.humanReadableInt(stats.getSharedStoreFilesSize()) %></td>
<td><%= StringUtils.humanReadableInt(stats.getMobStoreFilesSize()) %></td>
<td><%= StringUtils.humanReadableInt(stats.getArchivedStoreFileSize()) %>
(<%= StringUtils.humanReadableInt(stats.getNonSharedArchivedStoreFilesSize()) %>)</td>
<td><%= humanReadableInt(stats.getSharedStoreFilesSize()) %></td>
<td><%= humanReadableInt(stats.getMobStoreFilesSize()) %></td>
<td><%= humanReadableInt(stats.getArchivedStoreFileSize()) %>
(<%= humanReadableInt(stats.getNonSharedArchivedStoreFilesSize()) %>)</td>
</tr>
<% } %>
<p><%= snapshots.size() %> snapshot(s) in set.</p>
<p>Total Storefile Size: <%= StringUtils.humanReadableInt(totalSize) %></p>
<p>Total Shared Storefile Size: <%= StringUtils.humanReadableInt(totalSharedSize.get()) %>,
Total Mob Storefile Size: <%= StringUtils.humanReadableInt(totalMobSize.get()) %>,
Total Archived Storefile Size: <%= StringUtils.humanReadableInt(totalArchivedSize.get()) %>
(<%= StringUtils.humanReadableInt(totalUnsharedArchivedSize) %>)</p>
<p>Total Storefile Size: <%= humanReadableInt(totalSize) %></p>
<p>Total Shared Storefile Size: <%= humanReadableInt(totalSharedSize.get()) %>,
Total Mob Storefile Size: <%= humanReadableInt(totalMobSize.get()) %>,
Total Archived Storefile Size: <%= humanReadableInt(totalArchivedSize.get()) %>
(<%= humanReadableInt(totalUnsharedArchivedSize) %>)</p>
<p>Shared Storefile Size is the Storefile size shared between snapshots and active tables.
Mob Storefile Size is the Mob Storefile size shared between snapshots and active tables.
Archived Storefile Size is the Storefile size in Archive.
Expand Down
19 changes: 9 additions & 10 deletions hbase-server/src/main/resources/hbase-webapps/master/table.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<%@ page import="org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas" %>
<%@ page import="org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%!
/**
* @return An empty region load stamped with the passed in <code>regionInfo</code>
Expand Down Expand Up @@ -110,15 +111,15 @@
* @return an <td> tag contents server name links to server rs-status page.
*/
private static String buildRegionDeployedServerTag(RegionInfo regionInfo, HMaster master,
Map<RegionInfo, ServerName> regionsToServer) {
Map<RegionInfo, ServerName> regionsToServer) {
ServerName serverName = regionsToServer.get(regionInfo);
if (serverName == null) {
return "<td class=\"undeployed-region\">not deployed</td>";
}
String hostName = serverName.getHostname();
String hostNameEncoded = URLEncoder.encode(hostName);
String hostNameEncoded = URLEncoder.encode(hostName, StandardCharsets.UTF_8);
// This port might be wrong if RS actually ended up using something else.
int serverInfoPort = master.getRegionServerInfoPort(serverName);
String urlRegionServer = "//" + hostNameEncoded + ":" + serverInfoPort + "/rs-status";
Expand All @@ -132,7 +133,7 @@
*/
private static String moreRegionsToRender(int numRegionsRendered, int numRegions, String fqtn) {
if (numRegions > numRegionsRendered) {
String allRegionsUrl = "?name=" + URLEncoder.encode(fqtn) + "&numRegions=all";
String allRegionsUrl = "?name=" + URLEncoder.encode(fqtn, StandardCharsets.UTF_8) + "&numRegions=all";
return "This table has <b>" + numRegions
+ "</b> regions in total, in order to improve the page load time, only <b>"
Expand Down Expand Up @@ -345,7 +346,7 @@
if (metaLocation != null) {
ServerMetrics sl = master.getServerManager().getLoad(metaLocation);
// The host name portion should be safe, but I don't know how we handle IDNs so err on the side of failing safely.
hostAndPort = URLEncoder.encode(metaLocation.getHostname()) + ":" + master.getRegionServerInfoPort(metaLocation);
hostAndPort = URLEncoder.encode(metaLocation.getHostname(), StandardCharsets.UTF_8) + ":" + master.getRegionServerInfoPort(metaLocation);
if (sl != null) {
Map<byte[], RegionMetrics> map = sl.getRegionMetrics();
if (map.containsKey(meta.getRegionName())) {
Expand Down Expand Up @@ -415,7 +416,7 @@
if (metaLocation != null) {
ServerMetrics sl = master.getServerManager().getLoad(metaLocation);
hostAndPort = URLEncoder.encode(metaLocation.getHostname()) + ":" + master.getRegionServerInfoPort(metaLocation);
hostAndPort = URLEncoder.encode(metaLocation.getHostname(), StandardCharsets.UTF_8) + ":" + master.getRegionServerInfoPort(metaLocation);
if (sl != null) {
Map<byte[], RegionMetrics> map = sl.getRegionMetrics();
if (map.containsKey(meta.getRegionName())) {
Expand Down Expand Up @@ -468,7 +469,7 @@
if (metaLocation != null) {
ServerMetrics sl = master.getServerManager().getLoad(metaLocation);
hostAndPort = URLEncoder.encode(metaLocation.getHostname()) + ":" + master.getRegionServerInfoPort(metaLocation);
hostAndPort = URLEncoder.encode(metaLocation.getHostname(), StandardCharsets.UTF_8) + ":" + master.getRegionServerInfoPort(metaLocation);
if (sl != null) {
Map<byte[], RegionMetrics> map = sl.getRegionMetrics();
if (map.containsKey(meta.getRegionName())) {
Expand Down Expand Up @@ -1054,11 +1055,9 @@
numRegionsRendered = 0;
for (Map.Entry<RegionInfo, RegionMetrics> hriEntry : entryList) {
RegionInfo regionInfo = hriEntry.getKey();
ServerName addr = regionsToServer.get(regionInfo);
RegionMetrics load = hriEntry.getValue();
float locality = 0.0f;
float localityForSsd = 0.0f;
String state = "N/A";
if (load != null) {
locality = load.getDataLocality();
localityForSsd = load.getDataLocalityForSsd();
Expand Down Expand Up @@ -1146,11 +1145,11 @@
<%
for (Map.Entry<ServerName, Integer> rdEntry : regDistribution.entrySet()) {
ServerName addr = rdEntry.getKey();
String url = "//" + URLEncoder.encode(addr.getHostname()) + ":"
String url = "//" + URLEncoder.encode(addr.getHostname(), StandardCharsets.UTF_8) + ":"
+ master.getRegionServerInfoPort(addr) + "/rs-status";
%>
<tr>
<td><a href="<%= url %>"><%= StringEscapeUtils.escapeHtml4(addr.getHostname().toString())
<td><a href="<%= url %>"><%= StringEscapeUtils.escapeHtml4(addr.getHostname())
+ ":" + master.getRegionServerInfoPort(addr) %></a></td>
<td><%= rdEntry.getValue()%></td>
<td><%= primaryRegDistribution.get(addr) == null ? 0 : primaryRegDistribution.get(addr)%></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
--%>
<%@ page contentType="text/html;charset=UTF-8"
import="static org.apache.commons.lang3.StringEscapeUtils.escapeXml"
import="java.io.IOException"
import="java.util.ArrayList"
import="java.util.List"
import="java.util.Map"
%>
<%@ page import="org.apache.hadoop.hbase.client.TableDescriptor" %>
<%@ page import="org.apache.hadoop.hbase.master.HMaster" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import="org.apache.hadoop.fs.FileSystem"
import="org.apache.hadoop.fs.FileStatus"
import="org.apache.hadoop.fs.Path"
import="org.apache.hadoop.hbase.HConstants"
import="org.apache.hadoop.hbase.client.RegionInfo"
import="org.apache.hadoop.hbase.client.RegionInfoDisplay"
import="org.apache.hadoop.hbase.mob.MobUtils"
Expand All @@ -35,6 +34,7 @@
import="org.apache.hadoop.hbase.regionserver.HRegion"
import="org.apache.hadoop.hbase.regionserver.HStore"
%>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%
String regionName = request.getParameter("name");
HRegionServer rs = (HRegionServer) getServletContext().getAttribute(HRegionServer.REGIONSERVER);
Expand Down Expand Up @@ -95,7 +95,7 @@
count ++; %>
<tr>
<td><a href="storeFile.jsp?name=<%= sf.getEncodedPath() %>"><%= sf.getPath() %></a></td>
<td><%= (int) (fs.getLength(sf.getPath()) / 1024 / 1024) %></td>
<td><%= (int) (fs.getFileStatus(sf.getPath()).getLen() / 1024 / 1024) %></td>
<td><%= new Date(sf.getModificationTimestamp()) %></td>
<td><%= String.format("%,1d", sf.getFileInfo().getHFileInfo().getLenOfBiggestCell()) %></td>
<td><%= sf.getFileInfo().getHFileInfo().getKeyOfBiggestCell() %></td>
Expand Down Expand Up @@ -130,7 +130,7 @@
mobCnt ++;
FileStatus status = rs.getFileSystem().getFileStatus(mobPath);
String mobPathStr = mobPath.toString();
String encodedStr = URLEncoder.encode(mobPathStr, HConstants.UTF8_ENCODING); %>
String encodedStr = URLEncoder.encode(mobPathStr, StandardCharsets.UTF_8); %>

<tr>
<td><a href="storeFile.jsp?name=<%= encodedStr%>"><%= mobPathStr%></a></td>
Expand Down

0 comments on commit 09cf7db

Please sign in to comment.