Search in sources :

Example 1 with ShellExecService

use of org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecService 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 2 with ShellExecService

use of org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecService in project hbase by apache.

the class TestShellExecEndpointCoprocessor method testShellExecBackground.

@Test
public void testShellExecBackground() throws IOException {
    final AsyncConnection conn = connectionRule.getConnection();
    final AsyncAdmin admin = conn.getAdmin();
    final File testDataDir = ensureTestDataDirExists(miniClusterRule.getTestingUtility());
    final File testFile = new File(testDataDir, "shell_exec_background.txt");
    assertTrue(testFile.createNewFile());
    assertEquals(0, testFile.length());
    final String command = "echo \"hello world\" >> " + testFile.getAbsolutePath();
    final ShellExecRequest req = ShellExecRequest.newBuilder().setCommand(command).setAwaitResponse(false).build();
    final ShellExecResponse resp = admin.<ShellExecService.Stub, ShellExecResponse>coprocessorService(ShellExecService::newStub, (stub, controller, callback) -> stub.shellExec(controller, req, callback)).join();
    assertFalse("the response from a background task should have no exit code", resp.hasExitCode());
    assertFalse("the response from a background task should have no stdout", resp.hasStdout());
    assertFalse("the response from a background task should have no stderr", resp.hasStderr());
    Waiter.waitFor(conn.getConfiguration(), 5_000, () -> testFile.length() > 0);
    final String content = new String(Files.readAllBytes(testFile.toPath())).trim();
    assertEquals("hello world", content);
}
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) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 Optional (java.util.Optional)2 Consumer (java.util.function.Consumer)2 Configuration (org.apache.hadoop.conf.Configuration)2 AsyncAdmin (org.apache.hadoop.hbase.client.AsyncAdmin)2 AsyncConnection (org.apache.hadoop.hbase.client.AsyncConnection)2 ShellExecRequest (org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecRequest)2 ShellExecResponse (org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecResponse)2 ShellExecService (org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecService)2 MediumTests (org.apache.hadoop.hbase.testclassification.MediumTests)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ClassRule (org.junit.ClassRule)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2