You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2022/01/21 03:36:10 UTC
[accumulo] branch main updated: Centralize ZK auth digest construction (#2424)
This is an automated email from the ASF dual-hosted git repository.
ctubbsii 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 2b65a22 Centralize ZK auth digest construction (#2424)
2b65a22 is described below
commit 2b65a222c6b740567f62eecd20900bcd5965d6f5
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Thu Jan 20 22:36:03 2022 -0500
Centralize ZK auth digest construction (#2424)
---
.../org/apache/accumulo/fate/zookeeper/ZooSession.java | 2 +-
.../java/org/apache/accumulo/fate/zookeeper/ZooUtil.java | 10 ++++++++++
.../accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java | 2 ++
.../accumulo/server/replication/proto/Replication.java | 1 +
.../org/apache/accumulo/server/util/CleanZookeeper.java | 3 ++-
.../accumulo/test/fate/zookeeper/ServiceLockIT.java | 16 +++++++++-------
6 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
index 5966f4b..f5221aa 100644
--- a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
+++ b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
@@ -129,7 +129,7 @@ public class ZooSession {
for (int i = 0; i < connectTimeWait / TIME_BETWEEN_CONNECT_CHECKS_MS && tryAgain; i++) {
if (zooKeeper.getState().equals(States.CONNECTED)) {
if (auth != null)
- zooKeeper.addAuthInfo(scheme, auth);
+ ZooUtil.auth(zooKeeper, scheme, auth);
tryAgain = false;
} else
UtilWaitThread.sleep(TIME_BETWEEN_CONNECT_CHECKS_MS);
diff --git a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
index 80c46e9..269cd63 100644
--- a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
+++ b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
@@ -18,6 +18,8 @@
*/
package org.apache.accumulo.fate.zookeeper;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
@@ -121,4 +123,12 @@ public class ZooUtil {
}
}
+ public static void digestAuth(ZooKeeper zoo, String secret) {
+ auth(zoo, "digest", ("accumulo:" + secret).getBytes(UTF_8));
+ }
+
+ public static void auth(ZooKeeper zoo, String scheme, byte[] auth) {
+ zoo.addAuthInfo(scheme, auth);
+ }
+
}
diff --git a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java
index 1885bdc..e7592a0 100644
--- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java
@@ -110,6 +110,8 @@ public class MiniAccumuloConfigImpl {
/**
* Set directories and fully populate site config
+ *
+ * @return this
*/
MiniAccumuloConfigImpl initialize() {
diff --git a/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java b/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java
index 043ff72..1e67623 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java
@@ -472,6 +472,7 @@ package org.apache.accumulo.server.replication.proto;
return true;
}
+ @SuppressWarnings("unchecked")
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java b/server/base/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java
index 5125113..66fe43d 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java
@@ -24,6 +24,7 @@ import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.cli.Help;
import org.apache.accumulo.core.conf.SiteConfiguration;
import org.apache.accumulo.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.fate.zookeeper.ZooUtil;
import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
import org.apache.accumulo.server.ServerContext;
import org.apache.zookeeper.KeeperException;
@@ -57,7 +58,7 @@ public class CleanZookeeper {
String root = Constants.ZROOT;
ZooReaderWriter zk = context.getZooReaderWriter();
if (opts.auth != null) {
- zk.getZooKeeper().addAuthInfo("digest", ("accumulo:" + opts.auth).getBytes(UTF_8));
+ ZooUtil.digestAuth(zk.getZooKeeper(), opts.auth);
}
for (String child : zk.getChildren(root)) {
diff --git a/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ServiceLockIT.java b/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ServiceLockIT.java
index 28c90b7..2979a77 100644
--- a/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ServiceLockIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ServiceLockIT.java
@@ -40,6 +40,7 @@ import org.apache.accumulo.fate.zookeeper.ServiceLock.LockLossReason;
import org.apache.accumulo.fate.zookeeper.ServiceLock.ServiceLockPath;
import org.apache.accumulo.fate.zookeeper.ZooReaderWriter;
import org.apache.accumulo.fate.zookeeper.ZooSession;
+import org.apache.accumulo.fate.zookeeper.ZooUtil;
import org.apache.accumulo.test.categories.ZooKeeperTestingServerTests;
import org.apache.accumulo.test.zookeeper.ZooKeeperTestingServer;
import org.apache.zookeeper.CreateMode;
@@ -355,7 +356,7 @@ public class ServiceLockIT {
ConnectedWatcher watcher = new ConnectedWatcher();
try (ZooKeeper zk = new ZooKeeper(szk.getConn(), 30000, watcher)) {
- zk.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
+ ZooUtil.digestAuth(zk, "secret");
while (!watcher.isConnected()) {
Thread.sleep(200);
@@ -403,8 +404,8 @@ public class ServiceLockIT {
try (ZooKeeperWrapper zk1 = new ZooKeeperWrapper(szk.getConn(), 30000, watcher1);
ZooKeeperWrapper zk2 = new ZooKeeperWrapper(szk.getConn(), 30000, watcher2)) {
- zk1.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
- zk2.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
+ ZooUtil.digestAuth(zk1, "secret");
+ ZooUtil.digestAuth(zk2, "secret");
while (!watcher1.isConnected()) {
Thread.sleep(200);
@@ -515,7 +516,8 @@ public class ServiceLockIT {
try {
ConnectedWatcher watcher = new ConnectedWatcher();
try (ZooKeeperWrapper zk = new ZooKeeperWrapper(szk.getConn(), 30000, watcher)) {
- zk.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
+ ZooUtil.digestAuth(zk, "secret");
+
while (!watcher.isConnected()) {
Thread.sleep(50);
}
@@ -564,7 +566,7 @@ public class ServiceLockIT {
ConnectedWatcher watcher = new ConnectedWatcher();
try (ZooKeeperWrapper zk = new ZooKeeperWrapper(szk.getConn(), 30000, watcher)) {
- zk.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
+ ZooUtil.digestAuth(zk, "secret");
while (!watcher.isConnected()) {
Thread.sleep(50);
@@ -639,7 +641,7 @@ public class ServiceLockIT {
ConnectedWatcher watcher = new ConnectedWatcher();
try (ZooKeeper zk = new ZooKeeper(szk.getConn(), 30000, watcher)) {
- zk.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
+ ZooUtil.digestAuth(zk, "secret");
while (!watcher.isConnected()) {
Thread.sleep(200);
@@ -676,7 +678,7 @@ public class ServiceLockIT {
ServiceLock.path("/zltestChangeData-" + this.hashCode() + "-l" + pdCount.incrementAndGet());
ConnectedWatcher watcher = new ConnectedWatcher();
try (ZooKeeper zk = new ZooKeeper(szk.getConn(), 30000, watcher)) {
- zk.addAuthInfo("digest", "accumulo:secret".getBytes(UTF_8));
+ ZooUtil.digestAuth(zk, "secret");
while (!watcher.isConnected()) {
Thread.sleep(200);