HBASE-6951 Allow the master info server to be started in a read only mode.

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1400956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
eclark 2012-10-22 17:09:58 +00:00
parent 7efd1694dc
commit d115205c13
2 changed files with 51 additions and 14 deletions

View File

@ -42,6 +42,7 @@
String tableHeader = "<h2>Table Regions</h2><table class=\"table table-striped\"><tr><th>Name</th><th>Region Server</th><th>Start Key</th><th>End Key</th><th>Requests</th></tr>"; String tableHeader = "<h2>Table Regions</h2><table class=\"table table-striped\"><tr><th>Name</th><th>Region Server</th><th>Start Key</th><th>End Key</th><th>Requests</th></tr>";
ServerName rl = master.getCatalogTracker().getRootLocation(); ServerName rl = master.getCatalogTracker().getRootLocation();
boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false); boolean showFragmentation = conf.getBoolean("hbase.master.ui.fragmentation.enabled", false);
boolean readOnly = conf.getBoolean("hbase.master.ui.readonly", false);
Map<String, Integer> frags = null; Map<String, Integer> frags = null;
if (showFragmentation) { if (showFragmentation) {
frags = FSUtils.getTableFragmentation(master); frags = FSUtils.getTableFragmentation(master);
@ -62,7 +63,7 @@
<% <%
String action = request.getParameter("action"); String action = request.getParameter("action");
String key = request.getParameter("key"); String key = request.getParameter("key");
if ( action != null ) { if ( !readOnly && action != null ) {
%> %>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -320,6 +321,8 @@
HConnectionManager.deleteConnection(hbadmin.getConfiguration(), false); HConnectionManager.deleteConnection(hbadmin.getConfiguration(), false);
%> %>
<% if (!readOnly) { %>
<p><hr><p> <p><hr><p>
Actions: Actions:
<p> <p>
@ -357,6 +360,7 @@ Actions:
</center> </center>
<p> <p>
</div> </div>
<% } %>
<% <%
} }
%> %>

View File

@ -27,6 +27,7 @@ import java.net.URL;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -47,6 +48,9 @@ public class TestInfoServers {
// Set them to ephemeral ports so they will start // Set them to ephemeral ports so they will start
UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0); UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0);
UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, 0); UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, 0);
//We need to make sure that the server can be started as read only.
UTIL.getConfiguration().setBoolean("hbase.master.ui.readonly", true);
UTIL.startMiniCluster(); UTIL.startMiniCluster();
} }
@ -63,12 +67,12 @@ public class TestInfoServers {
// give the cluster time to start up // give the cluster time to start up
new HTable(UTIL.getConfiguration(), ".META.").close(); new HTable(UTIL.getConfiguration(), ".META.").close();
int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort(); int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
assertHasExpectedContent(new URL("http://localhost:" + port + assertContainsContent(new URL("http://localhost:" + port +
"/index.html"), "master-status"); "/index.html"), "master-status");
port = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer(). port = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer().
getInfoServer().getPort(); getInfoServer().getPort();
assertHasExpectedContent(new URL("http://localhost:" + port + assertContainsContent(new URL("http://localhost:" + port +
"/index.html"), "rs-status"); "/index.html"), "rs-status");
} }
/** /**
@ -83,17 +87,49 @@ public class TestInfoServers {
// give the cluster time to start up // give the cluster time to start up
new HTable(UTIL.getConfiguration(), ".META.").close(); new HTable(UTIL.getConfiguration(), ".META.").close();
int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort(); int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
assertHasExpectedContent(new URL("http://localhost:" + port + assertContainsContent(new URL("http://localhost:" + port +
"/master-status"), "META"); "/master-status"), "META");
port = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer(). port = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer().
getInfoServer().getPort(); getInfoServer().getPort();
assertHasExpectedContent(new URL("http://localhost:" + port + assertContainsContent(new URL("http://localhost:" + port +
"/rs-status"), "META"); "/rs-status"), "META");
} }
private void assertHasExpectedContent(final URL u, final String expected) @Test
public void testMasterServerReadOnly() throws Exception {
String sTableName = "testMasterServerReadOnly";
byte[] tableName = Bytes.toBytes(sTableName);
byte[] cf = Bytes.toBytes("d");
UTIL.createTable(tableName, cf);
new HTable(UTIL.getConfiguration(), tableName).close();
int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
assertDoesNotContainContent(
new URL("http://localhost:" + port + "/table.jsp?name=" + sTableName + "&action=split&key="),
"Table action request accepted");
assertDoesNotContainContent(
new URL("http://localhost:" + port + "/table.jsp?name=" + sTableName),
"Actions:");
}
private void assertContainsContent(final URL u, final String expected)
throws IOException { throws IOException {
LOG.info("Testing " + u.toString() + " has " + expected); LOG.info("Testing " + u.toString() + " has " + expected);
String content = getUrlContent(u);
assertTrue("expected=" + expected + ", content=" + content,
content.contains(expected));
}
private void assertDoesNotContainContent(final URL u, final String expected)
throws IOException {
LOG.info("Testing " + u.toString() + " has " + expected);
String content = getUrlContent(u);
assertTrue("Does Not Contain =" + expected + ", content=" + content,
!content.contains(expected));
}
private String getUrlContent(URL u) throws IOException {
java.net.URLConnection c = u.openConnection(); java.net.URLConnection c = u.openConnection();
c.connect(); c.connect();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -103,9 +139,6 @@ public class TestInfoServers {
sb.append(new String(bytes, 0, read)); sb.append(new String(bytes, 0, read));
} }
bis.close(); bis.close();
String content = sb.toString(); return sb.toString();
assertTrue("expected=" + expected + ", content=" + content,
content.contains(expected));
} }
} }