You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by jm...@apache.org on 2021/08/11 21:32:25 UTC
[accumulo] branch main updated: Remove use of JLine outside of
accumulo-shell (#2228)
This is an automated email from the ASF dual-hosted git repository.
jmanno 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 7db0561 Remove use of JLine outside of accumulo-shell (#2228)
7db0561 is described below
commit 7db0561cac3d42ba09d1fb038dad1ff1a03afc46
Author: harjitdotsingh <75...@users.noreply.github.com>
AuthorDate: Wed Aug 11 17:32:19 2021 -0400
Remove use of JLine outside of accumulo-shell (#2228)
* Includes general refactors to Initialize.java
---
core/pom.xml | 4 -
.../org/apache/accumulo/core/util/CreateToken.java | 12 ++-
server/base/pom.xml | 4 -
.../apache/accumulo/server/init/Initialize.java | 86 +++++++++-------------
4 files changed, 40 insertions(+), 66 deletions(-)
diff --git a/core/pom.xml b/core/pom.xml
index 4388500..575bdd3 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -126,10 +126,6 @@
<artifactId>zookeeper-jute</artifactId>
</dependency>
<dependency>
- <groupId>org.jline</groupId>
- <artifactId>jline</artifactId>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
diff --git a/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java b/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java
index c92cdd2..8306f64 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java
@@ -18,7 +18,7 @@
*/
package org.apache.accumulo.core.util;
-import java.io.IOException;
+import java.io.Console;
import org.apache.accumulo.core.cli.ClientOpts.PasswordConverter;
import org.apache.accumulo.core.cli.Help;
@@ -28,8 +28,6 @@ import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Token
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.ClientProperty;
import org.apache.accumulo.start.spi.KeywordExecutable;
-import org.jline.reader.LineReader;
-import org.jline.reader.LineReaderBuilder;
import com.beust.jcommander.Parameter;
import com.google.auto.service.AutoService;
@@ -37,12 +35,12 @@ import com.google.auto.service.AutoService;
@AutoService(KeywordExecutable.class)
public class CreateToken implements KeywordExecutable {
- private LineReader reader = null;
+ private Console reader = null;
- private LineReader getConsoleReader() throws IOException {
+ private Console getConsoleReader() {
if (reader == null)
- reader = LineReaderBuilder.builder().build();
+ reader = System.console();
return reader;
}
@@ -113,7 +111,7 @@ public class CreateToken implements KeywordExecutable {
System.out.println("auth.type = " + opts.tokenClassName);
System.out.println("auth.principal = " + principal);
System.out.println("auth.token = " + ClientProperty.encodeToken(token));
- } catch (IOException | ReflectiveOperationException e) {
+ } catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
diff --git a/server/base/pom.xml b/server/base/pom.xml
index fda74eb..eca7744 100644
--- a/server/base/pom.xml
+++ b/server/base/pom.xml
@@ -93,10 +93,6 @@
<artifactId>zookeeper-jute</artifactId>
</dependency>
<dependency>
- <groupId>org.jline</groupId>
- <artifactId>jline</artifactId>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
diff --git a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
index 8521a8d..71f03dc 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
@@ -119,11 +119,6 @@ import org.apache.hadoop.io.Text;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs.Ids;
-import org.jline.reader.LineReader;
-import org.jline.reader.LineReaderBuilder;
-import org.jline.terminal.Terminal;
-import org.jline.terminal.TerminalBuilder;
-import org.jline.utils.InfoCmp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -144,18 +139,8 @@ public class Initialize implements KeywordExecutable {
private static final String DEFAULT_ROOT_USER = "root";
private static final String TABLE_TABLETS_TABLET_DIR = "table_info";
- private static LineReader reader = null;
- private static Terminal terminal = null;
private static ZooReaderWriter zoo = null;
- private static LineReader getLineReader() throws IOException {
- if (terminal == null)
- terminal = TerminalBuilder.builder().jansi(false).build();
- if (reader == null)
- reader = LineReaderBuilder.builder().terminal(terminal).build();
- return reader;
- }
-
/**
* Sets this class's ZooKeeper reader/writer.
*
@@ -279,18 +264,17 @@ public class Initialize implements KeywordExecutable {
return false;
}
if (sconf.get(Property.INSTANCE_SECRET).equals(Property.INSTANCE_SECRET.getDefaultValue())) {
- LineReader c = getLineReader();
- var w = c.getTerminal().writer();
- c.getTerminal().puts(InfoCmp.Capability.bell);
- w.println();
- w.println();
- w.println("Warning!!! Your instance secret is still set to the default,"
+
+ System.out.println();
+ System.out.println();
+ System.out.println("Warning!!! Your instance secret is still set to the default,"
+ " this is not secure. We highly recommend you change it.");
- w.println();
- w.println();
- w.println("You can change the instance secret in accumulo by using:");
- w.println(" bin/accumulo " + org.apache.accumulo.server.util.ChangeSecret.class.getName());
- w.println("You will also need to edit your secret in your configuration"
+ System.out.println();
+ System.out.println();
+ System.out.println("You can change the instance secret in accumulo by using:");
+ System.out.println(
+ " bin/accumulo " + org.apache.accumulo.server.util.ChangeSecret.class.getName());
+ System.out.println("You will also need to edit your secret in your configuration"
+ " file by adding the property instance.secret to your"
+ " accumulo.properties. Without this accumulo will not operate" + " correctly");
}
@@ -677,14 +661,13 @@ public class Initialize implements KeywordExecutable {
return Constants.ZROOT + Constants.ZINSTANCES + "/";
}
- private String getInstanceNamePath(Opts opts)
- throws IOException, KeeperException, InterruptedException {
+ private String getInstanceNamePath(Opts opts) throws KeeperException, InterruptedException {
// setup the instance name
String instanceName, instanceNamePath = null;
boolean exists = true;
do {
if (opts.cliInstanceName == null) {
- instanceName = getLineReader().readLine("Instance name : ");
+ instanceName = System.console().readLine("Instance name : ");
} else {
instanceName = opts.cliInstanceName;
}
@@ -702,7 +685,7 @@ public class Initialize implements KeywordExecutable {
// ACCUMULO-4401 setting exists=false is just as important as setting it to true
exists = zoo.exists(instanceNamePath);
if (exists) {
- String decision = getLineReader().readLine("Instance name \"" + instanceName
+ String decision = System.console().readLine("Instance name \"" + instanceName
+ "\" exists. Delete existing entry from zookeeper? [Y/N] : ");
if (decision == null) {
System.exit(0);
@@ -717,22 +700,22 @@ public class Initialize implements KeywordExecutable {
return instanceNamePath;
}
- private String getRootUserName(SiteConfiguration siteConfig, Opts opts) throws IOException {
+ private String getRootUserName(SiteConfiguration siteConfig, Opts opts) {
final String keytab = siteConfig.get(Property.GENERAL_KERBEROS_KEYTAB);
if (keytab.equals(Property.GENERAL_KERBEROS_KEYTAB.getDefaultValue())
|| !siteConfig.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
return DEFAULT_ROOT_USER;
}
- LineReader c = getLineReader();
- c.getTerminal().writer().println("Running against secured HDFS");
+ System.out.println("Running against secured HDFS");
if (opts.rootUser != null) {
return opts.rootUser;
}
do {
- String user = c.readLine("Principal (user) to grant administrative privileges to : ");
+ String user =
+ System.console().readLine("Principal (user) to grant administrative privileges to : ");
if (user == null) {
// should not happen
System.exit(1);
@@ -743,29 +726,30 @@ public class Initialize implements KeywordExecutable {
} while (true);
}
- private byte[] getRootPassword(SiteConfiguration siteConfig, Opts opts, String rootUser)
- throws IOException {
+ private byte[] getRootPassword(SiteConfiguration siteConfig, Opts opts, String rootUser) {
if (opts.cliPassword != null) {
return opts.cliPassword.getBytes(UTF_8);
}
- String rootpass;
- String confirmpass;
+ String strrootpass;
+ String strconfirmpass;
do {
- rootpass = getLineReader().readLine(
- "Enter initial password for " + rootUser + getInitialPasswordWarning(siteConfig), '*');
+ var rootpass = System.console().readPassword(
+ "Enter initial password for " + rootUser + getInitialPasswordWarning(siteConfig));
if (rootpass == null) {
System.exit(0);
}
- confirmpass =
- getLineReader().readLine("Confirm initial password for " + rootUser + ": ", '*');
+ var confirmpass =
+ System.console().readPassword("Confirm initial password for " + rootUser + ":");
if (confirmpass == null) {
System.exit(0);
}
- if (!rootpass.equals(confirmpass)) {
+ strrootpass = new String(rootpass);
+ strconfirmpass = new String(confirmpass);
+ if (!strrootpass.equals(strconfirmpass)) {
log.error("Passwords do not match");
}
- } while (!rootpass.equals(confirmpass));
- return rootpass.getBytes(UTF_8);
+ } while (!strrootpass.equals(strconfirmpass));
+ return strrootpass.getBytes(UTF_8);
}
/**
@@ -847,8 +831,8 @@ public class Initialize implements KeywordExecutable {
}
}
- private static void setMetadataReplication(int replication, String reason) throws IOException {
- String rep = getLineReader()
+ private static void setMetadataReplication(int replication, String reason) {
+ String rep = System.console()
.readLine("Your HDFS replication " + reason + " is not compatible with our default "
+ MetadataTable.NAME + " replication of 5. What do you want to set your "
+ MetadataTable.NAME + " replication to? (" + replication + ") ");
@@ -971,10 +955,10 @@ public class Initialize implements KeywordExecutable {
try (ServerContext context = new ServerContext(siteConfig)) {
if (isInitialized(fs, siteConfig)) {
if (!opts.forceResetSecurity) {
- LineReader c = getLineReader();
- String userEnteredName = c.readLine("WARNING: This will remove all"
- + " users from Accumulo! If you wish to proceed enter the instance"
- + " name: ");
+ String userEnteredName = System.console()
+ .readLine("WARNING: This will remove all"
+ + " users from Accumulo! If you wish to proceed enter the instance"
+ + " name: ");
if (userEnteredName != null && !context.getInstanceName().equals(userEnteredName)) {
log.error(
"Aborted reset security: Instance name did not match current instance.");