Search in sources :

Example 1 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class CoprocClusterManager method exec.

@Override
protected Pair<Integer, String> exec(String hostname, ServiceType service, String... cmd) throws IOException {
    if (!supportedServices.contains(service)) {
        throw unsupportedServiceType(service);
    }
    // We only support actions vs. Master or Region Server processes. We're issuing those actions
    // via the coprocessor that's running within those processes. Thus, there's no support for
    // honoring the configured service user.
    final String command = StringUtils.join(cmd, " ");
    LOG.info("Executing remote command: {}, hostname:{}", command, hostname);
    try (final AsyncConnection conn = ConnectionFactory.createAsyncConnection(getConf()).join()) {
        final AsyncAdmin admin = conn.getAdmin();
        final ShellExecRequest req = ShellExecRequest.newBuilder().setCommand(command).setAwaitResponse(false).build();
        final ShellExecResponse resp;
        switch(service) {
            case HBASE_MASTER:
                // What happens if the intended action was killing a backup master? Right now we have
                // no `RestartBackupMasterAction` so it's probably fine.
                resp = masterExec(admin, req);
                break;
            case HBASE_REGIONSERVER:
                final ServerName targetHost = resolveRegionServerName(admin, hostname);
                resp = regionServerExec(admin, req, targetHost);
                break;
            default:
                throw new RuntimeException("should not happen");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Executed remote command: {}, exit code:{} , output:{}", command, resp.getExitCode(), resp.getStdout());
        } else {
            LOG.info("Executed remote command: {}, exit code:{}", command, resp.getExitCode());
        }
        return new Pair<>(resp.getExitCode(), resp.getStdout());
    }
}
Also used : AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) ShellExecResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecResponse) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ShellExecRequest(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecRequest) Pair(org.apache.hadoop.hbase.util.Pair)

Example 2 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestShellExecEndpointCoprocessor method testShellExecForeground.

private void testShellExecForeground(final Consumer<ShellExecRequest.Builder> consumer) {
    final AsyncConnection conn = connectionRule.getConnection();
    final AsyncAdmin admin = conn.getAdmin();
    final String command = "echo -n \"hello world\"";
    final ShellExecRequest.Builder builder = ShellExecRequest.newBuilder().setCommand(command);
    consumer.accept(builder);
    final ShellExecResponse resp = admin.<ShellExecService.Stub, ShellExecResponse>coprocessorService(ShellExecService::newStub, (stub, controller, callback) -> stub.shellExec(controller, builder.build(), callback)).join();
    assertEquals(0, resp.getExitCode());
    assertEquals("hello world", resp.getStdout());
}
Also used : ShellExecService(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecService) Files(java.nio.file.Files) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) File(java.io.File) Consumer(java.util.function.Consumer) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ShellExecResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecResponse) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) Configuration(org.apache.hadoop.conf.Configuration) Optional(java.util.Optional) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Assert.assertEquals(org.junit.Assert.assertEquals) ShellExecRequest(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecRequest) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) ShellExecResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecResponse) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ShellExecRequest(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecRequest) ShellExecService(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecService)

Example 3 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestServerCrashProcedureStuck method test.

@Test
public void test() throws Exception {
    RegionServerThread rsThread = null;
    for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
        if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) {
            rsThread = t;
            break;
        }
    }
    HRegionServer rs = rsThread.getRegionServer();
    RegionInfo hri = rs.getRegions(TABLE_NAME).get(0).getRegionInfo();
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor();
    DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri);
    long procId = master.getMasterProcedureExecutor().submitProcedure(proc);
    proc.waitUntilArrive();
    try (AsyncConnection conn = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
        AsyncAdmin admin = conn.getAdmin();
        CompletableFuture<Void> future = admin.move(hri.getRegionName());
        rs.abort("For testing!");
        UTIL.waitFor(30000, () -> executor.getProcedures().stream().filter(p -> p instanceof TransitRegionStateProcedure).map(p -> (TransitRegionStateProcedure) p).anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName())));
        proc.resume();
        UTIL.waitFor(30000, () -> executor.isFinished(procId));
        // see whether the move region procedure can finish properly
        future.get(30, TimeUnit.SECONDS);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) TimeUnit(java.util.concurrent.TimeUnit) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) ClassRule(org.junit.ClassRule) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Bytes(org.apache.hadoop.hbase.util.Bytes) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Test(org.junit.Test)

Example 4 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestClientClusterMetrics method testAsyncClient.

@Test
public void testAsyncClient() throws Exception {
    try (AsyncConnection asyncConnect = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
        AsyncAdmin asyncAdmin = asyncConnect.getAdmin();
        CompletableFuture<ClusterMetrics> originFuture = asyncAdmin.getClusterMetrics();
        CompletableFuture<ClusterMetrics> defaultsFuture = asyncAdmin.getClusterMetrics(EnumSet.allOf(Option.class));
        ClusterMetrics origin = originFuture.get();
        ClusterMetrics defaults = defaultsFuture.get();
        Assert.assertEquals(origin.getHBaseVersion(), defaults.getHBaseVersion());
        Assert.assertEquals(origin.getClusterId(), defaults.getClusterId());
        Assert.assertEquals(origin.getHBaseVersion(), defaults.getHBaseVersion());
        Assert.assertEquals(origin.getClusterId(), defaults.getClusterId());
        Assert.assertEquals(origin.getAverageLoad(), defaults.getAverageLoad(), 0);
        Assert.assertEquals(origin.getBackupMasterNames().size(), defaults.getBackupMasterNames().size());
        Assert.assertEquals(origin.getDeadServerNames().size(), defaults.getDeadServerNames().size());
        Assert.assertEquals(origin.getRegionCount(), defaults.getRegionCount());
        Assert.assertEquals(origin.getLiveServerMetrics().size(), defaults.getLiveServerMetrics().size());
        Assert.assertEquals(origin.getMasterInfoPort(), defaults.getMasterInfoPort());
        Assert.assertEquals(origin.getServersName().size(), defaults.getServersName().size());
        origin.getTableRegionStatesCount().forEach(((tableName, regionStatesCount) -> {
            RegionStatesCount defaultRegionStatesCount = defaults.getTableRegionStatesCount().get(tableName);
            Assert.assertEquals(defaultRegionStatesCount, regionStatesCount);
        }));
    }
}
Also used : UserProvider(org.apache.hadoop.hbase.security.UserProvider) FilterAllFilter(org.apache.hadoop.hbase.filter.FilterAllFilter) BeforeClass(org.junit.BeforeClass) Result(org.apache.hadoop.hbase.client.Result) CompletableFuture(java.util.concurrent.CompletableFuture) User(org.apache.hadoop.hbase.security.User) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) MasterCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment) MetricsUserAggregateFactory(org.apache.hadoop.hbase.regionserver.MetricsUserAggregateFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) TaskMonitor(org.apache.hadoop.hbase.monitoring.TaskMonitor) ClassRule(org.junit.ClassRule) EnumSet(java.util.EnumSet) Option(org.apache.hadoop.hbase.ClusterMetrics.Option) Bytes(org.apache.hadoop.hbase.util.Bytes) AfterClass(org.junit.AfterClass) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Predicate(org.apache.hadoop.hbase.Waiter.Predicate) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) Put(org.apache.hadoop.hbase.client.Put) Get(org.apache.hadoop.hbase.client.Get) IOException(java.io.IOException) Test(org.junit.Test) RegionStatesCount(org.apache.hadoop.hbase.client.RegionStatesCount) PrivilegedAction(java.security.PrivilegedAction) Category(org.junit.experimental.categories.Category) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) Scan(org.apache.hadoop.hbase.client.Scan) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) MasterObserver(org.apache.hadoop.hbase.coprocessor.MasterObserver) List(java.util.List) Admin(org.apache.hadoop.hbase.client.Admin) ClusterConnectionFactory(org.apache.hadoop.hbase.client.ClusterConnectionFactory) MasterCoprocessor(org.apache.hadoop.hbase.coprocessor.MasterCoprocessor) Connection(org.apache.hadoop.hbase.client.Connection) ObserverContext(org.apache.hadoop.hbase.coprocessor.ObserverContext) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) Optional(java.util.Optional) Table(org.apache.hadoop.hbase.client.Table) CoprocessorHost(org.apache.hadoop.hbase.coprocessor.CoprocessorHost) Assert(org.junit.Assert) RegionInfoBuilder(org.apache.hadoop.hbase.client.RegionInfoBuilder) HMaster(org.apache.hadoop.hbase.master.HMaster) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) Option(org.apache.hadoop.hbase.ClusterMetrics.Option) RegionStatesCount(org.apache.hadoop.hbase.client.RegionStatesCount) Test(org.junit.Test)

Example 5 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestClearRegionBlockCache method testClearBlockCacheFromAsyncAdmin.

@Test
public void testClearBlockCacheFromAsyncAdmin() throws Exception {
    try (AsyncConnection conn = ConnectionFactory.createAsyncConnection(HTU.getConfiguration()).get()) {
        AsyncAdmin admin = conn.getAdmin();
        BlockCache blockCache1 = rs1.getBlockCache().get();
        BlockCache blockCache2 = rs2.getBlockCache().get();
        long initialBlockCount1 = blockCache1.getBlockCount();
        long initialBlockCount2 = blockCache2.getBlockCount();
        // scan will cause blocks to be added in BlockCache
        scanAllRegionsForRS(rs1);
        assertEquals(blockCache1.getBlockCount() - initialBlockCount1, HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY));
        scanAllRegionsForRS(rs2);
        assertEquals(blockCache2.getBlockCount() - initialBlockCount2, HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY));
        CacheEvictionStats stats = admin.clearBlockCache(TABLE_NAME).get();
        assertEquals(stats.getEvictedBlocks(), HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY) + HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY));
        assertEquals(initialBlockCount1, blockCache1.getBlockCount());
        assertEquals(initialBlockCount2, blockCache2.getBlockCount());
    }
}
Also used : AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) CacheEvictionStats(org.apache.hadoop.hbase.CacheEvictionStats) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) BlockCache(org.apache.hadoop.hbase.io.hfile.BlockCache) Test(org.junit.Test)

Aggregations

AsyncAdmin (org.apache.hadoop.hbase.client.AsyncAdmin)9 Test (org.junit.Test)8 AsyncConnection (org.apache.hadoop.hbase.client.AsyncConnection)7 ClassRule (org.junit.ClassRule)6 Category (org.junit.experimental.categories.Category)6 MediumTests (org.apache.hadoop.hbase.testclassification.MediumTests)5 IOException (java.io.IOException)4 Optional (java.util.Optional)4 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)4 Bytes (org.apache.hadoop.hbase.util.Bytes)4 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)4 AfterClass (org.junit.AfterClass)4 BeforeClass (org.junit.BeforeClass)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 TimeUnit (java.util.concurrent.TimeUnit)3 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)3 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)3 TableName (org.apache.hadoop.hbase.TableName)3 ConnectionFactory (org.apache.hadoop.hbase.client.ConnectionFactory)3