(final String command)
| 2314 | } |
| 2315 | |
| 2316 | private static void hbaseShell(final String command) throws Exception { |
| 2317 | final ProcessBuilder pb = new ProcessBuilder(); |
| 2318 | pb.command(HBASE_HOME + "/bin/hbase", "shell"); |
| 2319 | pb.environment().remove("HBASE_HOME"); |
| 2320 | LOG.info("Running HBase shell command: " + command); |
| 2321 | final Process shell = pb.start(); |
| 2322 | try { |
| 2323 | final OutputStream stdin = shell.getOutputStream(); |
| 2324 | stdin.write(command.getBytes()); |
| 2325 | stdin.write('\n'); |
| 2326 | stdin.flush(); // Technically the JDK doesn't guarantee that close() |
| 2327 | stdin.close(); // will flush(), so better do it explicitly to be safe. |
| 2328 | // Let's hope that the HBase shell doesn't print more than 4KB of shit |
| 2329 | // on stderr, otherwise we're getting deadlocked here. Yeah seriously. |
| 2330 | // Dealing with subprocesses in Java is such a royal PITA. |
| 2331 | printLines("stdout", shell.getInputStream()); // Confusing method name, |
| 2332 | printLines("stderr", shell.getErrorStream()); // courtesy of !@#$% JDK. |
| 2333 | final int rv = shell.waitFor(); |
| 2334 | if (rv != 0) { |
| 2335 | throw new RuntimeException("hbase shell returned " + rv); |
| 2336 | } |
| 2337 | } finally { |
| 2338 | shell.destroy(); // Required by the fucking JDK, no matter what. |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | private static void printLines(final String what, final InputStream in) |
| 2343 | throws Exception { |
no test coverage detected