diff --git a/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java b/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java index cb006fd438a..0b4822caa15 100644 --- a/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java +++ b/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java @@ -201,7 +201,7 @@ public String getClientPropertiesFile() { File file = new File(path); if (file.isFile() && file.canRead()) { clientConfigFile = file.getAbsolutePath(); - System.out.println("Loading configuration from " + clientConfigFile); + Shell.log.info("Loading configuration from {}", clientConfigFile); break; } } diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/FateCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/FateCommand.java index d0e82b8b889..9ac7342d974 100644 --- a/shell/src/main/java/org/apache/accumulo/shell/commands/FateCommand.java +++ b/shell/src/main/java/org/apache/accumulo/shell/commands/FateCommand.java @@ -22,6 +22,7 @@ import static org.apache.accumulo.core.fate.FateTxId.parseTidFromUserInput; import java.io.IOException; +import java.io.PrintWriter; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Base64; @@ -159,25 +160,25 @@ public int execute(final String fullCommand, final CommandLine cl, final Shell s if (cl.hasOption(cancel.getOpt())) { String[] txids = cl.getOptionValues(cancel.getOpt()); validateArgs(txids); - System.out.println( + throw new ParseException( "Option not available. Use 'accumulo admin fate -c " + String.join(" ", txids) + "'"); } else if (cl.hasOption(fail.getOpt())) { String[] txids = cl.getOptionValues(fail.getOpt()); validateArgs(txids); - failedCommand = failTx(admin, zs, zk, managerLockPath, txids); + failedCommand = failTx(shellState.getWriter(), admin, zs, zk, managerLockPath, txids); } else if (cl.hasOption(delete.getOpt())) { String[] txids = cl.getOptionValues(delete.getOpt()); validateArgs(txids); - failedCommand = deleteTx(admin, zs, zk, managerLockPath, txids); + failedCommand = deleteTx(shellState.getWriter(), admin, zs, zk, managerLockPath, txids); } else if (cl.hasOption(list.getOpt())) { printTx(shellState, admin, zs, zk, tableLocksPath, cl.getOptionValues(list.getOpt()), cl); } else if (cl.hasOption(print.getOpt())) { printTx(shellState, admin, zs, zk, tableLocksPath, cl.getOptionValues(print.getOpt()), cl); } else if (cl.hasOption(summary.getOpt())) { - System.out.println("Option not available. Use 'accumulo admin fate --summary'"); + throw new ParseException("Option not available. Use 'accumulo admin fate --summary'"); } else if (cl.hasOption(dump.getOpt())) { String output = dumpTx(zs, cl.getOptionValues(dump.getOpt())); - System.out.println(output); + shellState.getWriter().println(output); } else { throw new ParseException("Invalid command option"); } @@ -234,14 +235,14 @@ protected void printTx(Shell shellState, AdminUtil admin, ZooStore< !cl.hasOption(disablePaginationOpt.getOpt())); } - protected boolean deleteTx(AdminUtil admin, ZooStore zs, - ZooReaderWriter zk, ServiceLockPath zLockManagerPath, String[] args) + protected boolean deleteTx(PrintWriter out, AdminUtil admin, + ZooStore zs, ZooReaderWriter zk, ServiceLockPath zLockManagerPath, String[] args) throws InterruptedException, KeeperException { for (int i = 1; i < args.length; i++) { if (admin.prepDelete(zs, zk, zLockManagerPath, args[i])) { admin.deleteLocks(zk, zLockManagerPath, args[i]); } else { - System.out.printf("Could not delete transaction: %s%n", args[i]); + out.printf("Could not delete transaction: %s%n", args[i]); return false; } } @@ -254,12 +255,12 @@ private void validateArgs(String[] args) throws ParseException { } } - public boolean failTx(AdminUtil admin, ZooStore zs, ZooReaderWriter zk, - ServiceLockPath managerLockPath, String[] args) { + public boolean failTx(PrintWriter out, AdminUtil admin, ZooStore zs, + ZooReaderWriter zk, ServiceLockPath managerLockPath, String[] args) { boolean success = true; for (int i = 1; i < args.length; i++) { if (!admin.prepFail(zs, zk, managerLockPath, args[i])) { - System.out.printf("Could not fail transaction: %s%n", args[i]); + out.printf("Could not fail transaction: %s%n", args[i]); return !success; } } diff --git a/shell/src/test/java/org/apache/accumulo/shell/commands/FateCommandTest.java b/shell/src/test/java/org/apache/accumulo/shell/commands/FateCommandTest.java index 379dd5b5b12..856c7cb7e98 100644 --- a/shell/src/test/java/org/apache/accumulo/shell/commands/FateCommandTest.java +++ b/shell/src/test/java/org/apache/accumulo/shell/commands/FateCommandTest.java @@ -33,6 +33,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.PrintStream; +import java.io.PrintWriter; import java.nio.file.Files; import java.util.List; import java.util.concurrent.TimeUnit; @@ -96,15 +97,15 @@ String dumpTx(ZooStore zs, String[] args) { } @Override - protected boolean deleteTx(AdminUtil admin, ZooStore zs, - ZooReaderWriter zk, ServiceLockPath zLockManagerPath, String[] args) - throws InterruptedException, KeeperException { + protected boolean deleteTx(PrintWriter out, AdminUtil admin, + ZooStore zs, ZooReaderWriter zk, ServiceLockPath zLockManagerPath, + String[] args) throws InterruptedException, KeeperException { deleteCalled = true; return true; } @Override - public boolean failTx(AdminUtil admin, ZooStore zs, + public boolean failTx(PrintWriter out, AdminUtil admin, ZooStore zs, ZooReaderWriter zk, ServiceLockPath managerLockPath, String[] args) { failCalled = true; return true; @@ -154,9 +155,10 @@ public void testFailTx() throws Exception { FateCommand cmd = new FateCommand(); // require number for Tx - assertFalse(cmd.failTx(helper, zs, zk, managerLockPath, new String[] {"fail", "tx1"})); + var out = new PrintWriter(System.out); + assertFalse(cmd.failTx(out, helper, zs, zk, managerLockPath, new String[] {"fail", "tx1"})); // fail the long configured above - assertTrue(cmd.failTx(helper, zs, zk, managerLockPath, new String[] {"fail", "12345"})); + assertTrue(cmd.failTx(out, helper, zs, zk, managerLockPath, new String[] {"fail", "12345"})); verify(zs); }