HBASE-12518 Task 4 polish. Remove CM#{get,delete}Connection
Remove deleteConnection from everywhere except the two tests that ensure it does the right thing and from HCM and CM themselves. Undoes deleteConnection from tests and from the web ui
This commit is contained in:
parent
2e9597ffb7
commit
daff5e8d96
|
@ -18,7 +18,6 @@ limitations under the License.
|
|||
</%doc>
|
||||
<%args>
|
||||
HMaster master;
|
||||
HBaseAdmin admin;
|
||||
Map<String, Integer> frags = null;
|
||||
ServerName metaLocation = null;
|
||||
List<ServerName> servers = null;
|
||||
|
@ -42,7 +41,7 @@ org.apache.hadoop.hbase.HConstants;
|
|||
org.apache.hadoop.hbase.NamespaceDescriptor;
|
||||
org.apache.hadoop.hbase.ServerLoad;
|
||||
org.apache.hadoop.hbase.ServerName;
|
||||
org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
org.apache.hadoop.hbase.client.Admin;
|
||||
org.apache.hadoop.hbase.client.HConnectionManager;
|
||||
org.apache.hadoop.hbase.HTableDescriptor;
|
||||
org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
|
@ -307,8 +306,11 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
|
|||
|
||||
<%def catalogTables>
|
||||
<%java>
|
||||
HTableDescriptor[] sysTables = master.isInitialized() ? admin.listTableDescriptorsByNamespace(
|
||||
HTableDescriptor[] sysTables = null;
|
||||
try (Admin admin = master.getConnection().getAdmin()) {
|
||||
sysTables = master.isInitialized() ? admin.listTableDescriptorsByNamespace(
|
||||
NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR) : null;
|
||||
}
|
||||
</%java>
|
||||
<%if (sysTables != null && sysTables.length > 0)%>
|
||||
<table class="table table-striped">
|
||||
|
@ -347,7 +349,10 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
|
|||
|
||||
<%def userTables>
|
||||
<%java>
|
||||
HTableDescriptor[] tables = master.isInitialized() ? admin.listTables() : null;
|
||||
HTableDescriptor[] tables = null;
|
||||
try (Admin admin = master.getConnection().getAdmin()) {
|
||||
tables = master.isInitialized() ? admin.listTables() : null;
|
||||
}
|
||||
</%java>
|
||||
<%if (tables != null && tables.length > 0)%>
|
||||
<table class="table table-striped">
|
||||
|
@ -379,7 +384,10 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
|
|||
|
||||
<%def userSnapshots>
|
||||
<%java>
|
||||
List<SnapshotDescription> snapshots = master.isInitialized() ? admin.listSnapshots() : null;
|
||||
List<SnapshotDescription> snapshots = null;
|
||||
try (Admin admin = master.getConnection().getAdmin()) {
|
||||
snapshots = master.isInitialized() ? admin.listSnapshots() : null;
|
||||
}
|
||||
</%java>
|
||||
<%if (snapshots != null && snapshots.size() > 0)%>
|
||||
<table class="table table-striped">
|
||||
|
@ -436,7 +444,4 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
|
|||
</tr>
|
||||
</table>
|
||||
</%if>
|
||||
<%java>
|
||||
HConnectionManager.deleteConnection(admin.getConfiguration());
|
||||
</%java>
|
||||
</%def>
|
||||
|
|
|
@ -53,7 +53,6 @@ public class MasterStatusServlet extends HttpServlet {
|
|||
response.setContentType("text/html");
|
||||
|
||||
Configuration conf = master.getConfiguration();
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
|
||||
Map<String, Integer> frags = getFragmentationInfo(master, conf);
|
||||
ServerName metaLocation = null;
|
||||
|
@ -80,8 +79,7 @@ public class MasterStatusServlet extends HttpServlet {
|
|||
tmpl.setFilter(request.getParameter("filter"));
|
||||
if (request.getParameter("format") != null)
|
||||
tmpl.setFormat(request.getParameter("format"));
|
||||
tmpl.render(response.getWriter(),
|
||||
master, admin);
|
||||
tmpl.render(response.getWriter(), master);
|
||||
}
|
||||
|
||||
private ServerName getMetaLocationOrNull(HMaster master) {
|
||||
|
|
|
@ -34,10 +34,8 @@ public class RSStatusServlet extends HttpServlet {
|
|||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(
|
||||
HRegionServer.REGIONSERVER);
|
||||
throws ServletException, IOException {
|
||||
HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(HRegionServer.REGIONSERVER);
|
||||
assert hrs != null : "No RS in context!";
|
||||
|
||||
resp.setContentType("text/html");
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<%@ page contentType="text/html;charset=UTF-8"
|
||||
import="java.util.Date"
|
||||
import="org.apache.hadoop.conf.Configuration"
|
||||
import="org.apache.hadoop.hbase.client.HBaseAdmin"
|
||||
import="org.apache.hadoop.hbase.client.Admin"
|
||||
import="org.apache.hadoop.hbase.client.HConnectionManager"
|
||||
import="org.apache.hadoop.hbase.master.HMaster"
|
||||
import="org.apache.hadoop.hbase.snapshot.SnapshotInfo"
|
||||
|
@ -31,13 +31,13 @@
|
|||
<%
|
||||
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
|
||||
Configuration conf = master.getConfiguration();
|
||||
HBaseAdmin hbadmin = new HBaseAdmin(conf);
|
||||
boolean readOnly = conf.getBoolean("hbase.master.ui.readonly", false);
|
||||
String snapshotName = request.getParameter("name");
|
||||
SnapshotDescription snapshot = null;
|
||||
SnapshotInfo.SnapshotStats stats = null;
|
||||
TableName snapshotTable = null;
|
||||
for (SnapshotDescription snapshotDesc: hbadmin.listSnapshots()) {
|
||||
try (Admin admin = master.getConnection().getAdmin()) {
|
||||
for (SnapshotDescription snapshotDesc: admin.listSnapshots()) {
|
||||
if (snapshotName.equals(snapshotDesc.getName())) {
|
||||
snapshot = snapshotDesc;
|
||||
stats = SnapshotInfo.getSnapshotStats(conf, snapshot);
|
||||
|
@ -45,6 +45,7 @@
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String action = request.getParameter("action");
|
||||
String cloneName = request.getParameter("cloneName");
|
||||
|
@ -112,17 +113,19 @@
|
|||
</div>
|
||||
<p><hr><p>
|
||||
<%
|
||||
try (Admin admin = master.getConnection().getAdmin()) {
|
||||
if (action.equals("restore")) {
|
||||
hbadmin.restoreSnapshot(snapshotName);
|
||||
admin.restoreSnapshot(snapshotName);
|
||||
%> Restore Snapshot request accepted. <%
|
||||
} else if (action.equals("clone")) {
|
||||
if (cloneName != null && cloneName.length() > 0) {
|
||||
hbadmin.cloneSnapshot(snapshotName, cloneName);
|
||||
admin.cloneSnapshot(snapshotName, TableName.valueOf(cloneName));
|
||||
%> Clone from Snapshot request accepted. <%
|
||||
} else {
|
||||
%> Clone from Snapshot request failed, No table name specified. <%
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
<p>Go <a href="javascript:history.back()">Back</a>, or wait for the redirect.
|
||||
</div>
|
||||
|
@ -189,8 +192,6 @@
|
|||
<% } %>
|
||||
<%
|
||||
} // end else
|
||||
|
||||
HConnectionManager.deleteConnection(hbadmin.getConfiguration());
|
||||
%>
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
import="java.util.Map"
|
||||
import="org.apache.hadoop.conf.Configuration"
|
||||
import="org.apache.hadoop.hbase.client.HTable"
|
||||
import="org.apache.hadoop.hbase.client.HBaseAdmin"
|
||||
import="org.apache.hadoop.hbase.client.Admin"
|
||||
import="org.apache.hadoop.hbase.client.HConnectionManager"
|
||||
import="org.apache.hadoop.hbase.HRegionInfo"
|
||||
import="org.apache.hadoop.hbase.ServerName"
|
||||
|
@ -41,7 +41,6 @@
|
|||
<%
|
||||
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
|
||||
Configuration conf = master.getConfiguration();
|
||||
HBaseAdmin hbadmin = new HBaseAdmin(conf);
|
||||
MetaTableLocator metaTableLocator = new MetaTableLocator();
|
||||
String fqtn = request.getParameter("name");
|
||||
HTable table = new HTable(conf, fqtn);
|
||||
|
@ -125,22 +124,24 @@
|
|||
</div>
|
||||
<p><hr><p>
|
||||
<%
|
||||
try (Admin admin = master.getConnection().getAdmin()) {
|
||||
if (action.equals("split")) {
|
||||
if (key != null && key.length() > 0) {
|
||||
hbadmin.split(key);
|
||||
admin.splitRegion(Bytes.toBytes(key));
|
||||
} else {
|
||||
hbadmin.split(fqtn);
|
||||
admin.split(TableName.valueOf(fqtn));
|
||||
}
|
||||
|
||||
%> Split request accepted. <%
|
||||
} else if (action.equals("compact")) {
|
||||
if (key != null && key.length() > 0) {
|
||||
hbadmin.compact(key);
|
||||
admin.compactRegion(Bytes.toBytes(key));
|
||||
} else {
|
||||
hbadmin.compact(fqtn);
|
||||
admin.compact(TableName.valueOf(fqtn));
|
||||
}
|
||||
%> Compact request accepted. <%
|
||||
}
|
||||
}
|
||||
%>
|
||||
<p>Go <a href="javascript:history.back()">Back</a>, or wait for the redirect.
|
||||
</div>
|
||||
|
@ -220,6 +221,7 @@
|
|||
<% } %>
|
||||
</table>
|
||||
<%} else {
|
||||
Admin admin = master.getConnection().getAdmin();
|
||||
try { %>
|
||||
<h2>Table Attributes</h2>
|
||||
<table class="table table-striped">
|
||||
|
@ -230,7 +232,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>Enabled</td>
|
||||
<td><%= hbadmin.isTableEnabled(table.getTableName()) %></td>
|
||||
<td><%= admin.isTableEnabled(table.getName()) %></td>
|
||||
<td>Is the table enabled</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -238,7 +240,7 @@
|
|||
<td>
|
||||
<%
|
||||
try {
|
||||
CompactionState compactionState = hbadmin.getCompactionState(table.getTableName());
|
||||
CompactionState compactionState = admin.getCompactionState(table.getName());
|
||||
%>
|
||||
<%= compactionState %>
|
||||
<%
|
||||
|
@ -332,10 +334,10 @@
|
|||
<% }
|
||||
} catch(Exception ex) {
|
||||
ex.printStackTrace(System.err);
|
||||
} finally {
|
||||
admin.close();
|
||||
}
|
||||
} // end else
|
||||
|
||||
HConnectionManager.deleteConnection(hbadmin.getConfiguration());
|
||||
%>
|
||||
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@ import java.util.NavigableMap;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.HConnection;
|
||||
import org.apache.hadoop.hbase.client.HConnectionManager;
|
||||
import org.apache.hadoop.hbase.client.HConnectionTestingUtility;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController;
|
||||
|
@ -128,7 +126,7 @@ public class TestMetaTableAccessorNoCluster {
|
|||
// This is a servername we use in a few places below.
|
||||
ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
|
||||
|
||||
HConnection connection;
|
||||
ClusterConnection connection = null;
|
||||
try {
|
||||
// Mock an ClientProtocol. Our mock implementation will fail a few
|
||||
// times when we go to open a scanner.
|
||||
|
@ -204,7 +202,7 @@ public class TestMetaTableAccessorNoCluster {
|
|||
Mockito.verify(implementation, Mockito.times(6)).
|
||||
scan((RpcController)Mockito.any(), (ScanRequest)Mockito.any());
|
||||
} finally {
|
||||
HConnectionManager.deleteConnection(UTIL.getConfiguration());
|
||||
if (connection != null && !connection.isClosed()) connection.close();
|
||||
zkw.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,7 @@ import java.net.ConnectException;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.client.HConnection;
|
||||
import org.apache.hadoop.hbase.client.HConnectionManager;
|
||||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.HConnectionTestingUtility;
|
||||
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
|
||||
import org.apache.hadoop.hbase.master.RegionState;
|
||||
|
@ -101,9 +100,6 @@ public class TestMetaTableLocator {
|
|||
LOG.warn("Unable to delete hbase:meta location", e);
|
||||
}
|
||||
|
||||
// Clear out our doctored connection or could mess up subsequent tests.
|
||||
HConnectionManager.deleteConnection(UTIL.getConfiguration());
|
||||
|
||||
this.watcher.close();
|
||||
}
|
||||
|
||||
|
@ -182,7 +178,8 @@ public class TestMetaTableLocator {
|
|||
// Mock an ClientProtocol.
|
||||
final ClientProtos.ClientService.BlockingInterface implementation =
|
||||
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
|
||||
HConnection connection = mockConnection(null, implementation);
|
||||
|
||||
ClusterConnection connection = mockConnection(null, implementation);
|
||||
|
||||
// If a 'get' is called on mocked interface, throw connection refused.
|
||||
Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())).
|
||||
|
@ -242,14 +239,14 @@ public class TestMetaTableLocator {
|
|||
@Test
|
||||
public void testVerifyMetaRegionLocationFails()
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
HConnection connection = Mockito.mock(HConnection.class);
|
||||
ClusterConnection connection = Mockito.mock(ClusterConnection.class);
|
||||
ServiceException connectException =
|
||||
new ServiceException(new ConnectException("Connection refused"));
|
||||
final AdminProtos.AdminService.BlockingInterface implementation =
|
||||
Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
|
||||
Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(),
|
||||
(GetRegionInfoRequest)Mockito.any())).thenThrow(connectException);
|
||||
Mockito.when(connection.getAdmin(Mockito.any(ServerName.class), Mockito.anyBoolean())).
|
||||
Mockito.when(connection.getAdmin(Mockito.any(ServerName.class))).
|
||||
thenReturn(implementation);
|
||||
|
||||
ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
|
||||
|
@ -301,20 +298,17 @@ public class TestMetaTableLocator {
|
|||
* and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when
|
||||
* {@link HConnection#getAdmin(ServerName)} is called, returns the passed
|
||||
* {@link ClientProtos.ClientService.BlockingInterface} instance when
|
||||
* {@link HConnection#getClient(ServerName)} is called (Be sure to call
|
||||
* {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration)}
|
||||
* when done with this mocked Connection.
|
||||
* {@link HConnection#getClient(ServerName)} is called.
|
||||
* @throws IOException
|
||||
*/
|
||||
private HConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
|
||||
private ClusterConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
|
||||
final ClientProtos.ClientService.BlockingInterface client)
|
||||
throws IOException {
|
||||
HConnection connection =
|
||||
ClusterConnection connection =
|
||||
HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
|
||||
Mockito.doNothing().when(connection).close();
|
||||
// Make it so we return any old location when asked.
|
||||
final HRegionLocation anyLocation =
|
||||
new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
|
||||
final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
|
||||
Mockito.when(connection.getRegionLocation((TableName) Mockito.any(),
|
||||
(byte[]) Mockito.any(), Mockito.anyBoolean())).
|
||||
thenReturn(anyLocation);
|
||||
|
|
|
@ -292,6 +292,11 @@ public class TestFromClientSide {
|
|||
table.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Tests deprecated functionality. Remove when we are past 1.0.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Deprecated
|
||||
@Test
|
||||
public void testSharedZooKeeper() throws Exception {
|
||||
Configuration newConfig = new Configuration(TEST_UTIL.getConfiguration());
|
||||
|
|
|
@ -874,7 +874,9 @@ public class TestHCM {
|
|||
* Makes sure that there is no leaking of
|
||||
* {@link ConnectionManager.HConnectionImplementation} in the {@link HConnectionManager}
|
||||
* class.
|
||||
* @deprecated Tests deprecated functionality. Remove in 1.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Test
|
||||
public void testConnectionUniqueness() throws Exception {
|
||||
int zkmaxconnections = TEST_UTIL.getConfiguration().
|
||||
|
|
|
@ -195,9 +195,6 @@ public class TestCatalogJanitor {
|
|||
|
||||
@Override
|
||||
public void stop(String why) {
|
||||
if (this.connection != null) {
|
||||
HConnectionManager.deleteConnection(this.connection.getConfiguration());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -121,8 +121,7 @@ public class TestMasterStatusServlet {
|
|||
|
||||
@Test
|
||||
public void testStatusTemplateNoTables() throws IOException {
|
||||
new MasterStatusTmpl().render(new StringWriter(),
|
||||
master, admin);
|
||||
new MasterStatusTmpl().render(new StringWriter(), master);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,8 +130,7 @@ public class TestMasterStatusServlet {
|
|||
|
||||
new MasterStatusTmpl()
|
||||
.setMetaLocation(ServerName.valueOf("metaserver:123,12345"))
|
||||
.render(new StringWriter(),
|
||||
master, admin);
|
||||
.render(new StringWriter(), master);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -152,8 +150,7 @@ public class TestMasterStatusServlet {
|
|||
.setMetaLocation(ServerName.valueOf("metaserver:123,12345"))
|
||||
.setServers(servers)
|
||||
.setDeadServers(deadServers)
|
||||
.render(new StringWriter(),
|
||||
master, admin);
|
||||
.render(new StringWriter(), master);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue