Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.accumulo.core.cli;

import org.apache.accumulo.start.spi.KeywordExecutable;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;

public abstract class ClientKeywordExecutable<OPTS extends ClientOpts>
implements KeywordExecutable {

private final OPTS options;

public ClientKeywordExecutable(OPTS options) {
this.options = options;
}

@Override
public final void execute(String[] args) throws Exception {
JCommander cl = new JCommander(this.options);
cl.setProgramName("accumulo "
+ (commandGroup().key().isBlank() ? "" : commandGroup().key() + " ") + keyword());
try {
cl.parse(args);
} catch (ParameterException e) {
cl.usage();
return;
}

if (this.options.help) {
cl.usage();
return;
}
execute(cl, options);
}

public abstract void execute(JCommander cl, OPTS options) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
import org.apache.accumulo.core.spi.crypto.CryptoService;
import org.apache.accumulo.core.util.TextUtil;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.apache.datasketches.quantiles.ItemsSketch;
import org.apache.datasketches.quantilescommon.QuantileSearchCriteria;
Expand Down Expand Up @@ -109,6 +111,11 @@ public String description() {
return "Generate split points from a set of 1 or more rfiles";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

public static void main(String[] args) throws Exception {
new GenerateSplits().execute(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.apache.accumulo.core.summary.SummaryReader;
import org.apache.accumulo.core.util.LocalityGroupUtil;
import org.apache.accumulo.core.util.NumUtil;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
Expand Down Expand Up @@ -150,6 +152,11 @@ public String description() {
return "Prints rfile info";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

protected Class<? extends BiFunction<Key,Value,String>> getFormatter(String formatterClazz)
throws ClassNotFoundException {
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.apache.accumulo.core.file.rfile.RFile.Writer;
import org.apache.accumulo.core.file.rfile.bcfile.BCFile;
import org.apache.accumulo.core.spi.crypto.CryptoService;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
Expand Down Expand Up @@ -69,6 +71,11 @@ public String description() {
return "Splits an RFile into large and small key/value files";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

@Override
public void execute(String[] args) throws Exception {
Configuration conf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.ClientProperty;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;

import com.beust.jcommander.Parameter;
Expand Down Expand Up @@ -76,6 +78,11 @@ public String description() {
return "Creates authentication token";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

@Override
public void execute(String[] args) {
Opts opts = new Opts();
Expand Down
18 changes: 14 additions & 4 deletions core/src/main/java/org/apache/accumulo/core/util/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,31 @@
*/
package org.apache.accumulo.core.util;

import org.apache.accumulo.core.cli.ClientKeywordExecutable;
import org.apache.accumulo.core.cli.ClientOpts;
import org.apache.accumulo.start.Main;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;

import com.beust.jcommander.JCommander;
import com.google.auto.service.AutoService;

@AutoService(KeywordExecutable.class)
public class Help implements KeywordExecutable {
public class Help extends ClientKeywordExecutable<ClientOpts> {

public Help() {
super(new ClientOpts());
}

@Override
public String keyword() {
return "help";
}

@Override
public UsageGroup usageGroup() {
return UsageGroup.CORE;
public CommandGroup commandGroup() {
return CommandGroups.CLIENT;
}

@Override
Expand All @@ -41,7 +51,7 @@ public String description() {
}

@Override
public void execute(final String[] args) {
public void execute(JCommander cl, ClientOpts options) throws Exception {
Main.printUsage();
}
}
17 changes: 13 additions & 4 deletions core/src/main/java/org/apache/accumulo/core/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,31 @@
*/
package org.apache.accumulo.core.util;

import org.apache.accumulo.core.cli.ClientKeywordExecutable;
import org.apache.accumulo.core.cli.ClientOpts;
import org.apache.accumulo.start.Main;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;

import com.beust.jcommander.JCommander;
import com.google.auto.service.AutoService;

@AutoService(KeywordExecutable.class)
public class Version implements KeywordExecutable {
public class Version extends ClientKeywordExecutable<ClientOpts> {

public Version() {
super(new ClientOpts());
}

@Override
public String keyword() {
return "version";
}

@Override
public UsageGroup usageGroup() {
return UsageGroup.CORE;
public CommandGroup commandGroup() {
return CommandGroups.CLIENT;
}

@Override
Expand All @@ -42,7 +51,7 @@ public String description() {
}

@Override
public void execute(final String[] args) throws Exception {
public void execute(JCommander cl, ClientOpts options) throws Exception {
Class<?> runTMP = Main.getClassLoader().loadClass("org.apache.accumulo.core.Constants");
System.out.println(runTMP.getField("VERSION").get(null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.accumulo.core.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Properties;
Expand Down Expand Up @@ -64,4 +65,14 @@ public void testPassword() {
assertTrue(opts.getToken().equals(new PasswordToken("mypass")));
assertEquals("myinst", props.getProperty("instance.name"));
}

@Test
public void testSasl() throws Exception {
ClientOpts opts = new ClientOpts();
String[] args =
new String[] {"--password", "mypass", "-u", "userabc", "-o", "instance.name=myinst", "-o",
"instance.zookeepers=zoo1,zoo2", "-o", "auth.principal=user123", "--sasl"};
assertThrows(IllegalArgumentException.class, () -> opts.parseArgs("test", args));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.apache.accumulo.miniclusterImpl;

import org.apache.accumulo.minicluster.MiniAccumuloRunner;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;

import com.google.auto.service.AutoService;
Expand All @@ -32,8 +34,8 @@ public String keyword() {
}

@Override
public UsageGroup usageGroup() {
return UsageGroup.PROCESS;
public CommandGroup commandGroup() {
return CommandGroups.PROCESS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.apache.accumulo.server.ServerDirs;
import org.apache.accumulo.server.fs.VolumeManagerImpl;
import org.apache.accumulo.server.util.adminCommand.SystemCheck.Check;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.apache.hadoop.conf.Configuration;

Expand All @@ -49,6 +51,11 @@ public String description() {
+ "'admin check run " + Check.SERVER_CONFIG + "'";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "intentional user-provided path")
@Override
public void execute(String[] args) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.apache.accumulo.core.util.ConfigurationImpl;
import org.apache.accumulo.core.util.compaction.CompactionPlannerInitParams;
import org.apache.accumulo.core.util.compaction.CompactionServicesConfig;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -78,6 +80,11 @@ public String description() {
return "Verifies compaction config within a given file";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

public static void main(String[] args) throws Exception {
new CheckCompactionConfig().execute(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
import org.apache.accumulo.server.conf.store.impl.ReadyMonitor;
import org.apache.accumulo.server.conf.store.impl.ZooPropStore;
import org.apache.accumulo.server.zookeeper.ZooAclUtil;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.ACL;
Expand Down Expand Up @@ -107,6 +109,11 @@ public String description() {
return "view Accumulo instance and property information stored in ZooKeeper";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

@Override
public void execute(String[] args) throws Exception {
nullWatcher = new NullWatcher(new ReadyMonitor(ZooInfoViewer.class.getSimpleName(), 20_000L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.apache.accumulo.server.conf.store.impl.ReadyMonitor;
import org.apache.accumulo.server.conf.store.impl.ZooPropStore;
import org.apache.accumulo.server.util.PropUtil;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -78,6 +80,11 @@ public String description() {
+ " Prefer using the shell if it is available";
}

@Override
public CommandGroup commandGroup() {
return CommandGroups.OTHER;
}

@Override
public void execute(String[] args) throws Exception {
nullWatcher = new NullWatcher(new ReadyMonitor(ZooInfoViewer.class.getSimpleName(), 20_000L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.apache.accumulo.server.fs.VolumeManagerImpl;
import org.apache.accumulo.server.security.SecurityUtil;
import org.apache.accumulo.server.util.SystemPropUtil;
import org.apache.accumulo.start.spi.CommandGroup;
import org.apache.accumulo.start.spi.CommandGroups;
import org.apache.accumulo.start.spi.KeywordExecutable;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -542,8 +544,8 @@ public String keyword() {
}

@Override
public UsageGroup usageGroup() {
return UsageGroup.CORE;
public CommandGroup commandGroup() {
return CommandGroups.CORE;
}

@Override
Expand Down
Loading