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 fc611bc Replace minor cases of UUID with InstanceId, minor checkstyle suggestions (#2471) fc611bc is described below commit fc611bc0a82c3707b70007737d3cb6f503ca4ecd Author: EdColeman <d...@etcoleman.com> AuthorDate: Tue Feb 8 08:15:06 2022 -0500 Replace minor cases of UUID with InstanceId, minor checkstyle suggestions (#2471) --- .../core/client/ZooKeeperInstanceTest.java | 21 +++++++------- .../apache/accumulo/server/util/ListInstances.java | 33 +++++++++------------- .../org/apache/accumulo/server/util/AdminTest.java | 3 +- .../test/fate/zookeeper/ServiceLockIT.java | 3 +- .../accumulo/test/fate/zookeeper/ZooMutatorIT.java | 3 +- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java b/core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java index aac8ed6..bd50c64 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.UUID; import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.data.InstanceId; import org.apache.accumulo.fate.zookeeper.ZooCache; import org.apache.accumulo.fate.zookeeper.ZooCacheFactory; import org.easymock.EasyMock; @@ -37,20 +38,20 @@ import org.junit.Test; @Deprecated(since = "2.0.0") public class ZooKeeperInstanceTest { - private static final UUID IID = UUID.randomUUID(); - private static final String IID_STRING = IID.toString(); + private static final InstanceId IID = InstanceId.of(UUID.randomUUID()); + private static final String IID_STRING = IID.canonical(); private ZooCacheFactory zcf; private ZooCache zc; private ZooKeeperInstance zki; - private static org.apache.accumulo.core.client.ClientConfiguration.ClientProperty INSTANCE_ID = - org.apache.accumulo.core.client.ClientConfiguration.ClientProperty.INSTANCE_ID; - private static org.apache.accumulo.core.client.ClientConfiguration.ClientProperty INSTANCE_NAME = - org.apache.accumulo.core.client.ClientConfiguration.ClientProperty.INSTANCE_NAME; - private static org.apache.accumulo.core.client.ClientConfiguration.ClientProperty INSTANCE_ZK_HOST = - org.apache.accumulo.core.client.ClientConfiguration.ClientProperty.INSTANCE_ZK_HOST; - private static org.apache.accumulo.core.client.ClientConfiguration.ClientProperty INSTANCE_ZK_TIMEOUT = - org.apache.accumulo.core.client.ClientConfiguration.ClientProperty.INSTANCE_ZK_TIMEOUT; + private static final ClientConfiguration.ClientProperty INSTANCE_ID = + ClientConfiguration.ClientProperty.INSTANCE_ID; + private static final ClientConfiguration.ClientProperty INSTANCE_NAME = + ClientConfiguration.ClientProperty.INSTANCE_NAME; + private static final ClientConfiguration.ClientProperty INSTANCE_ZK_HOST = + ClientConfiguration.ClientProperty.INSTANCE_ZK_HOST; + private static final ClientConfiguration.ClientProperty INSTANCE_ZK_TIMEOUT = + ClientConfiguration.ClientProperty.INSTANCE_ZK_TIMEOUT; private void mockIdConstruction(ClientConfiguration config) { expect(config.get(INSTANCE_ID)).andReturn(IID_STRING); diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/ListInstances.java b/server/base/src/main/java/org/apache/accumulo/server/util/ListInstances.java index ab9d428..d516539 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/ListInstances.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/ListInstances.java @@ -26,12 +26,12 @@ import java.util.List; import java.util.Map.Entry; import java.util.TreeMap; import java.util.TreeSet; -import java.util.UUID; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.cli.Help; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.conf.SiteConfiguration; +import org.apache.accumulo.core.data.InstanceId; import org.apache.accumulo.fate.zookeeper.ServiceLock; import org.apache.accumulo.fate.zookeeper.ZooCache; import org.apache.accumulo.fate.zookeeper.ZooReader; @@ -86,20 +86,20 @@ public class ListInstances { ZooReader rdr = new ZooReader(keepers, ZOOKEEPER_TIMER_MILLIS); ZooCache cache = new ZooCache(keepers, ZOOKEEPER_TIMER_MILLIS); - TreeMap<String,UUID> instanceNames = getInstanceNames(rdr, printErrors); + TreeMap<String,InstanceId> instanceNames = getInstanceNames(rdr, printErrors); System.out.println(); printHeader(); - for (Entry<String,UUID> entry : instanceNames.entrySet()) { + for (Entry<String,InstanceId> entry : instanceNames.entrySet()) { printInstanceInfo(cache, entry.getKey(), entry.getValue(), printErrors); } - TreeSet<UUID> instancedIds = getInstanceIDs(rdr, printErrors); + TreeSet<InstanceId> instancedIds = getInstanceIDs(rdr, printErrors); instancedIds.removeAll(instanceNames.values()); if (printAll) { - for (UUID uuid : instancedIds) { + for (InstanceId uuid : instancedIds) { printInstanceInfo(cache, null, uuid, printErrors); } } else if (!instancedIds.isEmpty()) { @@ -126,12 +126,7 @@ public class ListInstances { @Override public void formatTo(Formatter formatter, int flags, int width, int precision) { - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < width; i++) { - sb.append(c); - } - formatter.format(sb.toString()); + formatter.format(String.valueOf(c).repeat(Math.max(0, width))); } } @@ -145,7 +140,7 @@ public class ListInstances { } - private static void printInstanceInfo(ZooCache cache, String instanceName, UUID iid, + private static void printInstanceInfo(ZooCache cache, String instanceName, InstanceId iid, boolean printErrors) { String manager = getManager(cache, iid, printErrors); if (instanceName == null) { @@ -160,7 +155,7 @@ public class ListInstances { "\"" + instanceName + "\"", iid, manager); } - private static String getManager(ZooCache cache, UUID iid, boolean printErrors) { + private static String getManager(ZooCache cache, InstanceId iid, boolean printErrors) { if (iid == null) { return null; @@ -180,11 +175,11 @@ public class ListInstances { } } - private static TreeMap<String,UUID> getInstanceNames(ZooReader zk, boolean printErrors) { + private static TreeMap<String,InstanceId> getInstanceNames(ZooReader zk, boolean printErrors) { String instancesPath = Constants.ZROOT + Constants.ZINSTANCES; - TreeMap<String,UUID> tm = new TreeMap<>(); + TreeMap<String,InstanceId> tm = new TreeMap<>(); List<String> names; @@ -198,7 +193,7 @@ public class ListInstances { for (String name : names) { String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name; try { - UUID iid = UUID.fromString(new String(zk.getData(instanceNamePath), UTF_8)); + InstanceId iid = InstanceId.of(new String(zk.getData(instanceNamePath), UTF_8)); tm.put(name, iid); } catch (Exception e) { handleException(e, printErrors); @@ -209,8 +204,8 @@ public class ListInstances { return tm; } - private static TreeSet<UUID> getInstanceIDs(ZooReader zk, boolean printErrors) { - TreeSet<UUID> ts = new TreeSet<>(); + private static TreeSet<InstanceId> getInstanceIDs(ZooReader zk, boolean printErrors) { + TreeSet<InstanceId> ts = new TreeSet<>(); try { List<String> children = zk.getChildren(Constants.ZROOT); @@ -220,7 +215,7 @@ public class ListInstances { continue; } try { - ts.add(UUID.fromString(iid)); + ts.add(InstanceId.of(iid)); } catch (Exception e) { log.error("Exception: ", e); } diff --git a/server/base/src/test/java/org/apache/accumulo/server/util/AdminTest.java b/server/base/src/test/java/org/apache/accumulo/server/util/AdminTest.java index 1197788..f4fba90 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/util/AdminTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/util/AdminTest.java @@ -25,6 +25,7 @@ import java.util.UUID; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.clientImpl.ClientContext; +import org.apache.accumulo.core.data.InstanceId; import org.apache.accumulo.fate.zookeeper.ZooCache; import org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat; import org.easymock.EasyMock; @@ -35,7 +36,7 @@ public class AdminTest { @Test public void testZooKeeperTserverPath() { ClientContext context = EasyMock.createMock(ClientContext.class); - String instanceId = UUID.randomUUID().toString(); + InstanceId instanceId = InstanceId.of(UUID.randomUUID()); EasyMock.expect(context.getZooKeeperRoot()).andReturn(Constants.ZROOT + "/" + instanceId); 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 cdb5c48..f6c5238 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 @@ -34,6 +34,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.LockSupport; +import org.apache.accumulo.core.data.InstanceId; import org.apache.accumulo.fate.zookeeper.ServiceLock; import org.apache.accumulo.fate.zookeeper.ServiceLock.AccumuloLockWatcher; import org.apache.accumulo.fate.zookeeper.ServiceLock.LockLossReason; @@ -66,7 +67,7 @@ public class ServiceLockIT { @BeforeClass public static void setup() throws Exception { szk = new ZooKeeperTestingServer(); - szk.initPaths("/accumulo/" + UUID.randomUUID()); + szk.initPaths("/accumulo/" + InstanceId.of(UUID.randomUUID())); } @AfterClass diff --git a/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooMutatorIT.java b/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooMutatorIT.java index 18cc386..3c42ce1 100644 --- a/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooMutatorIT.java +++ b/test/src/main/java/org/apache/accumulo/test/fate/zookeeper/ZooMutatorIT.java @@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import org.apache.accumulo.core.data.InstanceId; import org.apache.accumulo.fate.zookeeper.ZooReaderWriter; import org.apache.accumulo.test.categories.ZooKeeperTestingServerTests; import org.apache.accumulo.test.zookeeper.ZooKeeperTestingServer; @@ -75,7 +76,7 @@ public class ZooMutatorIT { public void concurrentMutatorTest() throws Exception { try (ZooKeeperTestingServer szk = new ZooKeeperTestingServer()) { - szk.initPaths("/accumulo/" + UUID.randomUUID()); + szk.initPaths("/accumulo/" + InstanceId.of(UUID.randomUUID())); ZooReaderWriter zk = new ZooReaderWriter(szk.getConn(), 10_0000, "aPasswd"); var executor = Executors.newFixedThreadPool(16);