use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.
the class TestCoprocessorConfiguration method testRegionCoprocessorHostAllDisabled.
@Test
public void testRegionCoprocessorHostAllDisabled() throws Exception {
Configuration conf = new Configuration(CONF);
conf.setBoolean(CoprocessorHost.COPROCESSORS_ENABLED_CONF_KEY, false);
HRegion region = mock(HRegion.class);
when(region.getRegionInfo()).thenReturn(REGIONINFO);
when(region.getTableDescriptor()).thenReturn(TABLEDESC);
RegionServerServices rsServices = mock(RegionServerServices.class);
systemCoprocessorLoaded.set(false);
tableCoprocessorLoaded.set(false);
new RegionCoprocessorHost(region, rsServices, conf);
assertFalse("System coprocessors should not have been loaded", systemCoprocessorLoaded.get());
assertFalse("Table coprocessors should not have been loaded", tableCoprocessorLoaded.get());
}
use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.
the class TokenProvider method start.
@Override
public void start(CoprocessorEnvironment env) {
// if running at region
if (env instanceof RegionCoprocessorEnvironment) {
RegionCoprocessorEnvironment regionEnv = (RegionCoprocessorEnvironment) env;
/* Getting the RpcServer from a RegionCE is wrong. There cannot be an expectation that Region
is hosted inside a RegionServer. If you need RpcServer, then pass in a RegionServerCE.
TODO: FIX.
*/
RegionServerServices rss = ((HasRegionServerServices) regionEnv).getRegionServerServices();
RpcServerInterface server = rss.getRpcServer();
SecretManager<?> mgr = ((RpcServer) server).getSecretManager();
if (mgr instanceof AuthenticationTokenSecretManager) {
secretManager = (AuthenticationTokenSecretManager) mgr;
}
}
}
use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.
the class TestRegionServerSpaceQuotaManager method testExceptionOnPolicyEnforcementDisable.
@Test
public void testExceptionOnPolicyEnforcementDisable() throws Exception {
final TableName tableName = TableName.valueOf("foo");
final SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 2048L);
RegionServerServices rss = mock(RegionServerServices.class);
SpaceViolationPolicyEnforcementFactory factory = mock(SpaceViolationPolicyEnforcementFactory.class);
SpaceViolationPolicyEnforcement enforcement = mock(SpaceViolationPolicyEnforcement.class);
RegionServerSpaceQuotaManager realManager = new RegionServerSpaceQuotaManager(rss, factory);
when(factory.create(rss, tableName, snapshot)).thenReturn(enforcement);
doNothing().when(enforcement).enable();
doThrow(new IOException("Failed for test!")).when(enforcement).disable();
// Enabling should work
realManager.enforceViolationPolicy(tableName, snapshot);
Map<TableName, SpaceViolationPolicyEnforcement> enforcements = realManager.copyActiveEnforcements();
assertEquals(1, enforcements.size());
// If the disable fails, we should still treat it as "active"
realManager.disableViolationPolicyEnforcement(tableName);
enforcements = realManager.copyActiveEnforcements();
assertEquals(1, enforcements.size());
}
use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.
the class CoprocessorHConnection method getConnectionForEnvironment.
/**
* Create a {@link ClusterConnection} based on the environment in which we are running the
* coprocessor. The {@link ClusterConnection} must be externally cleaned up
* (we bypass the usual HTable cleanup mechanisms since we own everything).
* @param env environment hosting the {@link ClusterConnection}
* @return instance of {@link ClusterConnection}.
* @throws IOException if we cannot create the connection
*/
public static ClusterConnection getConnectionForEnvironment(CoprocessorEnvironment env) throws IOException {
// this bit is a little hacky - just trying to get it going for the moment
if (env instanceof RegionCoprocessorEnvironment) {
RegionCoprocessorEnvironment e = (RegionCoprocessorEnvironment) env;
RegionServerServices services = e.getRegionServerServices();
if (services instanceof HRegionServer) {
return new CoprocessorHConnection((HRegionServer) services);
}
}
return (ClusterConnection) ConnectionFactory.createConnection(env.getConfiguration());
}
use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.
the class TestCoprocessorConfiguration method testRegionCoprocessorHostTableLoadingDisabled.
@Test
public void testRegionCoprocessorHostTableLoadingDisabled() throws Exception {
Configuration conf = new Configuration(CONF);
// if defaults change
conf.setBoolean(CoprocessorHost.COPROCESSORS_ENABLED_CONF_KEY, true);
conf.setBoolean(CoprocessorHost.USER_COPROCESSORS_ENABLED_CONF_KEY, false);
HRegion region = mock(HRegion.class);
when(region.getRegionInfo()).thenReturn(REGIONINFO);
when(region.getTableDescriptor()).thenReturn(TABLEDESC);
RegionServerServices rsServices = mock(RegionServerServices.class);
systemCoprocessorLoaded.set(false);
tableCoprocessorLoaded.set(false);
new RegionCoprocessorHost(region, rsServices, conf);
assertTrue("System coprocessors should have been loaded", systemCoprocessorLoaded.get());
assertFalse("Table coprocessors should not have been loaded", tableCoprocessorLoaded.get());
}
Aggregations