Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,37 @@
<%@ page import="org.apache.hadoop.hbase.master.janitor.CatalogJanitorReport" %>
<%@ page import="java.util.Optional" %>
<%@ page import="org.apache.hadoop.hbase.util.EnvironmentEdgeManager" %>
<%@ page import="org.apache.hbase.thirdparty.com.google.protobuf.ServiceException" %>
<%@ page import="java.io.IOException" %>
<%@ page import="org.apache.hadoop.hbase.http.InfoServer" %>
<%
final String cacheParameterValue = request.getParameter("cache");
final HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
pageContext.setAttribute("pageTitle", "HBase Master HBCK Report: " + master.getServerName());
String hbckChoreErrorMessage = null;
final boolean canModifyUI =
InfoServer.canUserModifyUI(request, getServletContext(), master.getConfiguration());
String catalogJanitorErrorMessage = null;
if (!Boolean.parseBoolean(cacheParameterValue)) {
// Run the two reporters inline w/ drawing of the page. If exception, will show in page draw.
try {
master.getMasterRpcServices().runHbckChore(null, null);
} catch (ServiceException se) {
hbckChoreErrorMessage = "Failed generating a new hbck_chore report; using cache; try again or run hbck_chore_run in the shell: " + se.getMessage();
}
try {
master.getMasterRpcServices().runCatalogScan(null, null);
} catch (ServiceException se) {
catalogJanitorErrorMessage = "Failed generating a new catalogjanitor report; using cache; try again or run catalogjanitor_run in the shell: " + se.getMessage();
}
String triggerSkippedMessage = null;
final HbckChore hbckChore = master.getHbckChore();
final CatalogJanitor cj = master.getCatalogJanitor();
if (!Boolean.parseBoolean(cacheParameterValue) && master.isInitialized()) {
if (!canModifyUI) {
triggerSkippedMessage = "This master UI is read-only or you are not authorized to modify it; "
+ "showing cached reports. Run hbck_chore_run and catalogjanitor_run from the HBase shell "
+ "as an authorized user to generate new reports.";
} else {
// Run the two reporters inline w/ drawing of the page. If exception, will show in page draw.
if (hbckChore != null) {
hbckChore.runChore();
}
if (cj != null) {
try {
cj.scan();
} catch (IOException ioe) {
catalogJanitorErrorMessage = "Failed generating a new catalogjanitor report; using cache; try again or run catalogjanitor_run in the shell: " + ioe.getMessage();
}
}
}
}
HbckChore hbckChore = master.getHbckChore();
HbckReport hbckReport = hbckChore == null ? null : hbckChore.getLastReport();
String hbckReportStartTime = Optional.ofNullable(hbckReport)
.map(HbckReport::getCheckingStartTimestamp)
Expand All @@ -71,7 +81,6 @@
.map(start -> ZonedDateTime.ofInstant(start, ZoneId.systemDefault()))
.map(zdt -> zdt.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME))
.orElse(null);
CatalogJanitor cj = master.getCatalogJanitor();
CatalogJanitorReport cjReport = cj == null? null: cj.getLastReport();
final ServerManager serverManager = master.getServerManager();
%>
Expand All @@ -94,15 +103,20 @@
<p><span>This page displays two reports: the <em>HBCK Chore Report</em> and
the <em>CatalogJanitor Consistency Issues</em> report. Only report titles
show if there are no problems to list. Note some conditions are
<strong>transitory</strong> as regions migrate. Reports are generated
when you invoke this page unless you add <em>?cache=true</em> to the URL. Then
we display the reports cached from the last time the reports were run.
Reports are run by Chores that are hosted by the Master on a cadence.
<strong>transitory</strong> as regions migrate. When the UI is writable and you are
authorized to modify it, reports are generated when you invoke this page unless you
add <em>?cache=true</em> to the URL; otherwise the reports cached from the last run are
displayed. Reports are also run by Chores that are hosted by the Master on a cadence.
You can also run them on demand from the hbase shell: invoke <em>catalogjanitor_run</em>
and/or <em>hbck_chore_run</em>.
ServerNames will be links if server is live, italic if dead, and plain if unknown.</span></p>
</div>
</div>
<% if (triggerSkippedMessage != null) { %>
<div class="alert alert-info" role="alert">
<%= triggerSkippedMessage %>
</div>
<% } %>
<div class="row">
<div class="page-header">
<h1>HBCK Chore Report</h1>
Expand All @@ -122,12 +136,6 @@
</div>
</div>

<% if(hbckChoreErrorMessage != null) { %>
<div class="alert alert-danger" role="alert">
<%= hbckChoreErrorMessage %>
</div>
<% } %>

<% if (hbckReport != null && hbckReport.getInconsistentRegions().size() > 0) { %>
<div class="row">
<div class="page-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,45 @@
*/
--%>
<%@ page contentType="text/html;charset=UTF-8"
import="java.util.Date"
import="java.util.Collections"
import="java.util.List"
import="org.apache.hadoop.conf.Configuration"
import="org.apache.hadoop.hbase.client.Admin"
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.util.StringUtils"
import="org.apache.hadoop.hbase.client.ServerType"
import="org.apache.hadoop.hbase.client.LogEntry"
import="org.apache.hadoop.hbase.client.BalancerRejection"
import="org.apache.hadoop.hbase.client.BalancerDecision"
import="org.apache.hadoop.hbase.namequeues.BalancerDecisionDetails"
import="org.apache.hadoop.hbase.namequeues.BalancerRejectionDetails"
import="org.apache.hadoop.hbase.namequeues.NamedQueueRecorder"
import="org.apache.hadoop.hbase.namequeues.request.NamedQueueGetRequest"
import="org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse"
import="org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos"
import="org.apache.hadoop.hbase.shaded.protobuf.generated.RecentLogs"
%>
<%
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
pageContext.setAttribute("pageTitle", "HBase Master Operation Details: " + master.getServerName());
Configuration conf = master.getConfiguration();
List<RecentLogs.BalancerRejection> logList = Collections.emptyList();
List<RecentLogs.BalancerDecision> decisionList = Collections.emptyList();
if (master.isInitialized()) {
NamedQueueRecorder namedQueueRecorder = master.getNamedQueueRecorder();
if (namedQueueRecorder != null) {
NamedQueueGetRequest rejectionRequest = new NamedQueueGetRequest();
rejectionRequest.setNamedQueueEvent(BalancerRejectionDetails.BALANCER_REJECTION_EVENT);
rejectionRequest.setBalancerRejectionsRequest(
MasterProtos.BalancerRejectionsRequest.newBuilder().setLimit(250).build());
NamedQueueGetResponse rejectionResponse =
namedQueueRecorder.getNamedQueueRecords(rejectionRequest);
if (rejectionResponse != null && rejectionResponse.getBalancerRejections() != null) {
logList = rejectionResponse.getBalancerRejections();
}

List<BalancerRejection> logList = null;
List<BalancerDecision> decisionList = null;
if(master.isInitialized()) {
try (Admin admin = master.getConnection().getAdmin()) {
logList = (List<BalancerRejection>)(List<?>)admin.getLogEntries(null, "BALANCER_REJECTION", ServerType.MASTER, 250, null);
decisionList = (List<BalancerDecision>)(List<?>)admin.getLogEntries(null, "BALANCER_DECISION", ServerType.MASTER, 250, null);
NamedQueueGetRequest decisionRequest = new NamedQueueGetRequest();
decisionRequest.setNamedQueueEvent(BalancerDecisionDetails.BALANCER_DECISION_EVENT);
decisionRequest.setBalancerDecisionsRequest(
MasterProtos.BalancerDecisionsRequest.newBuilder().setLimit(250).build());
NamedQueueGetResponse decisionResponse =
namedQueueRecorder.getNamedQueueRecords(decisionRequest);
if (decisionResponse != null && decisionResponse.getBalancerDecisions() != null) {
decisionList = decisionResponse.getBalancerDecisions();
}
}
}
%>
Expand Down Expand Up @@ -74,9 +91,7 @@
<th>Reason</th>
<th>CostFunctions Details</th>
</tr>
<% if (logList == null) { %>
<% } else { %>
<% for (BalancerRejection entry: logList) { %>
<% for (RecentLogs.BalancerRejection entry: logList) { %>
<tr>
<td><%=entry.getReason()%></td>
<td>
Expand All @@ -91,7 +106,6 @@
</td>
</tr>
<% } %>
<% } %>
</table>
</div>
<div class="tab-pane" id="tab_named_queue2" role="tabpanel">
Expand All @@ -105,20 +119,18 @@
<th>Computed Steps</th>
<th>Region Plans</th>
</tr>
<% if (decisionList == null) { %>
<% } else { %>
<% for (BalancerDecision decision: decisionList) { %>
<% for (RecentLogs.BalancerDecision decision: decisionList) { %>
<tr>
<td><%=decision.getInitialFunctionCosts()%></td>
<td><%=decision.getFinalFunctionCosts()%></td>
<td><%=StringUtils.format("%.2f", decision.getInitTotalCost())%></td>
<td><%=StringUtils.format("%.2f", decision.getComputedTotalCost())%></td>
<td><%=decision.getComputedSteps()%></td>
<%
List<String> regionPlans = decision.getRegionPlans();
if ( regionPlans == null) {%>
List<String> regionPlans = decision.getRegionPlansList();
if (regionPlans == null || regionPlans.isEmpty()) { %>
<td></td>
<% } else { %>
<% } else { %>
<td>
<table>
<% for (String plan : regionPlans) { %>
Expand All @@ -129,7 +141,7 @@
<% } %>
</tr>
<% } %>
<% } %>
</table>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public void testMasterServerReadOnly(TestInfo testInfo) throws Exception {
new URL("http://localhost:" + port + "/table.jsp?name=" + tableName), "Actions:");
}

@Test
public void testHbckAndOperationDetailsReadOnly() throws Exception {
int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
URL hbckUrl = new URL("http://localhost:" + port + "/hbck.jsp");
assertContainsContent(hbckUrl,
"This master UI is read-only or you are not authorized to modify it");
assertContainsContent(hbckUrl, "No Report created.");
assertDoesNotContainContent(hbckUrl, "alert-danger");
assertDoesNotContainContent(hbckUrl, "Insufficient permissions");
URL operationDetailsUrl = new URL("http://localhost:" + port + "/operationDetails.jsp");
assertContainsContent(operationDetailsUrl, "Operations Details");
assertDoesNotContainContent(operationDetailsUrl, "Insufficient permissions");
}

private void assertContainsContent(final URL u, final String expected) throws IOException {
LOG.info("Testing " + u.toString() + " has " + expected);
String content = getUrlContent(u);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,52 @@ public Void run() throws Exception {
});
}

@Test
public void testHbckPagePermissions() throws Exception {
final String readOnlyMessage =
"This master UI is read-only or you are not authorized to modify it";
UserGroupInformation admin = UserGroupInformation
.loginUserFromKeytabAndReturnUGI(USER_ADMIN_STR, KEYTAB_FILE.getAbsolutePath());
admin.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
Pair<Integer, String> pair = getHbckPage();
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
assertFalse(pair.getSecond().contains(readOnlyMessage),
"admin should be allowed to trigger HBCK chores, content=" + pair.getSecond());
assertFalse(pair.getSecond().contains("alert-danger"),
"admin page should not show an error, content=" + pair.getSecond());
assertFalse(pair.getSecond().contains("Insufficient permissions"),
"admin page should not have ACL errors, content=" + pair.getSecond());
assertFalse(pair.getSecond().contains("No Report created."),
"admin page should have generated a report, content=" + pair.getSecond());
Pair<Integer, String> opDetailsPair = getOperationDetailsPage();
assertEquals(HttpURLConnection.HTTP_OK, opDetailsPair.getFirst().intValue());
assertTrue(opDetailsPair.getSecond().contains("Operations Details"),
"expected Operations Details, content=" + opDetailsPair.getSecond());
assertFalse(opDetailsPair.getSecond().contains("Insufficient permissions"),
"operation details page should not have ACL errors, content="
+ opDetailsPair.getSecond());
return null;
}
});

UserGroupInformation nonAdmin = UserGroupInformation
.loginUserFromKeytabAndReturnUGI(USER_NONE_STR, KEYTAB_FILE.getAbsolutePath());
nonAdmin.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
Pair<Integer, String> pair = getHbckPage();
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
assertTrue(pair.getSecond().contains(readOnlyMessage),
"non-admin should see the read-only/cached report message, content=" + pair.getSecond());
assertFalse(pair.getSecond().contains("alert-danger"),
"non-admin page should not show an error, content=" + pair.getSecond());
return null;
}
});
}

@Test
public void testLogsAvailableForAdmins() throws Exception {
final String expectedAuthorizedContent = "Directory: /logs/";
Expand Down Expand Up @@ -395,6 +441,16 @@ private Pair<Integer, String> getTablePage(TableName tn) throws Exception {
return getUrlContent(url);
}

private Pair<Integer, String> getHbckPage() throws Exception {
URL url = new URL(getInfoServerHostAndPort() + "/hbck.jsp");
return getUrlContent(url);
}

private Pair<Integer, String> getOperationDetailsPage() throws Exception {
URL url = new URL(getInfoServerHostAndPort() + "/operationDetails.jsp");
return getUrlContent(url);
}

private Pair<Integer, String> getLogsPage() throws Exception {
URL url = new URL(getInfoServerHostAndPort() + "/logs/");
return getUrlContent(url);
Expand Down