This is an automated email from the ASF dual-hosted git repository. mmiller pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new ed69b0d26d Adding RestoreZookeeper utility to accumulo admin command (#2816) ed69b0d26d is described below commit ed69b0d26d9bdbabaa3aaddb26c308c8213be3f1 Author: Christopher L. Shannon <christopher.l.shan...@gmail.com> AuthorDate: Fri Aug 12 09:28:56 2022 -0400 Adding RestoreZookeeper utility to accumulo admin command (#2816) Issue #2807 --- .../accumulo/fate/zookeeper/ZooReaderWriter.java | 4 ++-- .../java/org/apache/accumulo/server/util/Admin.java | 14 ++++++++++++++ .../accumulo/server/util/RestoreZookeeper.java | 21 +++++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java index 4637034fce..9a86bc0fac 100644 --- a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java +++ b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java @@ -24,8 +24,8 @@ import static java.util.Objects.requireNonNull; import java.util.List; import org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException; +import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.Property; -import org.apache.accumulo.core.conf.SiteConfiguration; import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy; import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy; import org.apache.zookeeper.CreateMode; @@ -40,7 +40,7 @@ public class ZooReaderWriter extends ZooReader { byte[] mutate(byte[] currentValue) throws AcceptableThriftTableOperationException; } - public ZooReaderWriter(SiteConfiguration conf) { + public ZooReaderWriter(AccumuloConfiguration conf) { this(conf.get(Property.INSTANCE_ZK_HOST), (int) conf.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT), conf.get(Property.INSTANCE_SECRET)); diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java index 168530b9ee..002eb9fbe0 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java @@ -182,6 +182,15 @@ public class Admin implements KeywordExecutable { String instance; } + @Parameters(commandDescription = "Restore Zookeeper data from a file.") + static class RestoreZooCommand { + @Parameter(names = "--overwrite") + boolean overwrite = false; + + @Parameter(names = "--file") + String file; + } + public static void main(String[] args) { new Admin().execute(args); } @@ -219,6 +228,9 @@ public class Admin implements KeywordExecutable { DeleteZooInstanceCommand deleteZooInstanceOpts = new DeleteZooInstanceCommand(); cl.addCommand("deleteZooInstance", deleteZooInstanceOpts); + RestoreZooCommand restoreZooOpts = new RestoreZooCommand(); + cl.addCommand("restoreZoo", restoreZooOpts); + ListInstancesCommand listIntancesOpts = new ListInstancesCommand(); cl.addCommand("listInstances", listIntancesOpts); @@ -302,6 +314,8 @@ public class Admin implements KeywordExecutable { ChangeSecret.changeSecret(context, conf); } else if (cl.getParsedCommand().equals("deleteZooInstance")) { DeleteZooInstance.deleteZooInstance(deleteZooInstanceOpts.instance); + } else if (cl.getParsedCommand().equals("restoreZoo")) { + RestoreZookeeper.restoreZookeeper(conf, restoreZooOpts.file, restoreZooOpts.overwrite); } else { everything = cl.getParsedCommand().equals("stopAll"); diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java b/server/base/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java index 319c59c322..51016448ab 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java @@ -29,6 +29,7 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.accumulo.core.cli.Help; +import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.SiteConfiguration; import org.apache.accumulo.fate.zookeeper.ZooReaderWriter; import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy; @@ -116,15 +117,13 @@ public class RestoreZookeeper { @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "code runs in same security context as user who provided input") - public static void main(String[] args) throws Exception { - Opts opts = new Opts(); - opts.parseArgs(RestoreZookeeper.class.getName(), args); - - var zoo = new ZooReaderWriter(SiteConfiguration.auto()); + public static void restoreZookeeper(final AccumuloConfiguration conf, final String file, + final boolean overwrite) throws Exception { + var zoo = new ZooReaderWriter(conf); InputStream in = System.in; - if (opts.file != null) { - in = new FileInputStream(opts.file); + if (file != null) { + in = new FileInputStream(file); } SAXParserFactory factory = SAXParserFactory.newInstance(); @@ -132,7 +131,13 @@ public class RestoreZookeeper { // is a simple switch to remove any chance of external entities causing problems. factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); SAXParser parser = factory.newSAXParser(); - parser.parse(in, new Restore(zoo, opts.overwrite)); + parser.parse(in, new Restore(zoo, overwrite)); in.close(); } + + public static void main(String[] args) throws Exception { + Opts opts = new Opts(); + opts.parseArgs(RestoreZookeeper.class.getName(), args); + restoreZookeeper(SiteConfiguration.auto(), opts.file, opts.overwrite); + } }