geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aba...@apache.org
Subject geode git commit: GEODE-182: Auto-generate member names if needed
Date Wed, 11 Jan 2017 22:31:38 GMT
Repository: geode
Updated Branches:
  refs/heads/develop e79e0103a -> feb2a0fcb


GEODE-182: Auto-generate member names if needed

When a user runs `start server` or `start locator` from gfsh
without specifying the member name, gfsh will automatically pick
a random member name. This is useful for automation.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/feb2a0fc
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/feb2a0fc
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/feb2a0fc

Branch: refs/heads/develop
Commit: feb2a0fcbff995e71c293ac2726f78081d366599
Parents: e79e010
Author: Anthony Baker <abaker@apache.org>
Authored: Sun Jan 8 18:06:14 2017 -0800
Committer: Anthony Baker <abaker@apache.org>
Committed: Wed Jan 11 14:14:17 2017 -0800

----------------------------------------------------------------------
 .../cli/commands/LauncherLifecycleCommands.java | 27 +++++++++--
 .../internal/cli/util/ThreePhraseGenerator.java | 50 ++++++++++++++++++++
 .../geode/distributed/ServerLauncherTest.java   | 11 -----
 .../cli/util/ThreePhraseGeneratorTest.java      | 35 ++++++++++++++
 .../cli/commands/golden-help-offline.properties | 12 ++---
 5 files changed, 113 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/feb2a0fc/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
index 09d0a67..922b94d 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
@@ -95,6 +95,7 @@ import org.apache.geode.management.internal.cli.util.CauseFinder;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.management.internal.cli.util.ConnectionEndpoint;
 import org.apache.geode.management.internal.cli.util.JConsoleNotFoundException;
+import org.apache.geode.management.internal.cli.util.ThreePhraseGenerator;
 import org.apache.geode.management.internal.cli.util.VisualVmNotFoundException;
 import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus;
 import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusRequest;
@@ -197,13 +198,19 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
     return ATTACH_API_AVAILABLE.get();
   }
 
+  private final ThreePhraseGenerator nameGenerator;
+
+  public LauncherLifecycleCommands() {
+    nameGenerator = new ThreePhraseGenerator();
+  }
+
   @CliCommand(value = CliStrings.START_LOCATOR, help = CliStrings.START_LOCATOR__HELP)
   @CliMetaData(shellOnly = true,
       relatedTopic = {CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE})
   public Result startLocator(
-      @CliOption(key = CliStrings.START_LOCATOR__MEMBER_NAME, mandatory = true,
+      @CliOption(key = CliStrings.START_LOCATOR__MEMBER_NAME, mandatory = false,
           unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
-          help = CliStrings.START_LOCATOR__MEMBER_NAME__HELP) final String memberName,
+          help = CliStrings.START_LOCATOR__MEMBER_NAME__HELP) String memberName,
       @CliOption(key = CliStrings.START_LOCATOR__BIND_ADDRESS,
           unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
           help = CliStrings.START_LOCATOR__BIND_ADDRESS__HELP) final String bindAddress,
@@ -271,6 +278,11 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
       @CliOption(key = CliStrings.START_LOCATOR__CLUSTER__CONFIG__DIR, unspecifiedDefaultValue
= "",
           help = CliStrings.START_LOCATOR__CLUSTER__CONFIG__DIR__HELP) final String clusterConfigDir)
{
     try {
+      if (StringUtils.isBlank(memberName)) {
+        // when the user doesn't give us a name, we make one up!
+        memberName = nameGenerator.generate('-');
+      }
+
       if (workingDirectory == null) {
         // attempt to use or make sub-directory using memberName...
         File locatorWorkingDirectory = new File(memberName);
@@ -1333,6 +1345,9 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
   @CliMetaData(shellOnly = true,
       relatedTopic = {CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_LIFECYCLE})
   public Result startServer(
+      @CliOption(key = CliStrings.START_SERVER__NAME, mandatory = false,
+          unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
+          help = CliStrings.START_SERVER__NAME__HELP) String memberName,
       @CliOption(key = CliStrings.START_SERVER__ASSIGN_BUCKETS, unspecifiedDefaultValue =
"false",
           specifiedDefaultValue = "true",
           help = CliStrings.START_SERVER__ASSIGN_BUCKETS__HELP) final Boolean assignBuckets,
@@ -1444,9 +1459,6 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
       @CliOption(key = CliStrings.START_SERVER__MESSAGE__TIME__TO__LIVE,
           unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
           help = CliStrings.START_SERVER__MESSAGE__TIME__TO__LIVE__HELP) final Integer messageTimeToLive,
-      @CliOption(key = CliStrings.START_SERVER__NAME, mandatory = true,
-          unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
-          help = CliStrings.START_SERVER__NAME__HELP) final String memberName,
       @CliOption(key = CliStrings.START_SERVER__OFF_HEAP_MEMORY_SIZE,
           unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
           help = CliStrings.START_SERVER__OFF_HEAP_MEMORY_SIZE__HELP) final String offHeapMemorySize,
@@ -1494,6 +1506,11 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
   // NOTICE: keep the parameters in alphabetical order based on their CliStrings.START_SERVER_*
text
   {
     try {
+      if (StringUtils.isBlank(memberName)) {
+        // when the user doesn't give us a name, we make one up!
+        memberName = nameGenerator.generate('-');
+      }
+
       // prompt for password is username is specified in the command
       if (!StringUtils.isBlank(userName)) {
         if (StringUtils.isBlank(passwordToUse)) {

http://git-wip-us.apache.org/repos/asf/geode/blob/feb2a0fc/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThreePhraseGenerator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThreePhraseGenerator.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThreePhraseGenerator.java
new file mode 100644
index 0000000..5033255
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThreePhraseGenerator.java
@@ -0,0 +1,50 @@
+/*
+ * 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
+ *
+ * http://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.geode.management.internal.cli.util;
+
+import java.security.SecureRandom;
+import java.util.Random;
+
+/**
+ * Picks a random three word phrase based on simple word lists with over 80k possible combinations.
+ */
+public class ThreePhraseGenerator {
+  private static final String[] adjectives =
+      "agreeable, alive, better, brave, calm, careful, clever, dead, delightful, eager, easy,
faithful, famous, gentle, gifted, happy, helpful, important, inexpensive, jolly, kind, lively,
mushy, nice, obedient, odd, powerful, proud, relieved, rich, shy, silly, tender, thankful,
uninterested, vast, victorious, witty, wrong, zealous"
+          .split(", ");
+
+  private static final String[] nouns =
+      "ball, bat, bed, book, boy, bun, can, cake, cap, car, cat, cow, cub, cup, dad, day,
dog, doll, dust, fan, feet, girl, gun, hall, hat, hen, jar, kite, man, map, men, mom, pan,
pet, pie, pig, pot, rat, son, sun, toe, tub, van"
+          .split(", ");
+
+  private static final String[] verbs =
+      "add, allow, bake, bang, call, chase, damage, drop, end, escape, fasten, fix, gather,
grab, hang, hug, imagine, itch, jog, jump, kick, knit, land, lock, march, mix, name, notice,
obey, open, pass, promise, question, reach, rinse, scatter, stay, talk, turn, untie, use,
vanish, visit, walk, work, yawn, yell, zip, zoom"
+          .split(", ");
+
+  private final Random prng;
+
+  public ThreePhraseGenerator() {
+    prng = new SecureRandom();
+  }
+
+  public String generate(char separator) {
+    return new StringBuilder().append(select(verbs)).append(separator).append(select(adjectives))
+        .append(separator).append(select(nouns)).toString();
+  }
+
+  private String select(String[] dictionary) {
+    return dictionary[prng.nextInt(dictionary.length)];
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/feb2a0fc/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherTest.java
b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherTest.java
index 2ddc810..85bed3e 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherTest.java
@@ -519,17 +519,6 @@ public class ServerLauncherTest {
     assertNull(launcher.getMemberName());
   }
 
-  @Test(expected = IllegalStateException.class)
-  public void testBuildNoMemberNameOnStart() {
-    try {
-      new Builder().setCommand(Command.START).build();
-    } catch (IllegalStateException expected) {
-      assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE
-          .toLocalizedString("Server"), expected.getMessage());
-      throw expected;
-    }
-  }
-
   @Test
   public void testIsServing() {
     final Cache mockCache = mockContext.mock(Cache.class, "Cache");

http://git-wip-us.apache.org/repos/asf/geode/blob/feb2a0fc/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThreePhraseGeneratorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThreePhraseGeneratorTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThreePhraseGeneratorTest.java
new file mode 100644
index 0000000..fca2a71
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThreePhraseGeneratorTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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
+ *
+ * http://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.geode.management.internal.cli.util;
+
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class ThreePhraseGeneratorTest {
+  @Test
+  public void testGenerate() {
+    ThreePhraseGenerator tpg = new ThreePhraseGenerator();
+    String phrase = tpg.generate('-');
+
+    assertNotNull(phrase);
+    assertNotEquals("", phrase);
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/feb2a0fc/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
index f4f9496..91d545f 100644
--- a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
+++ b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
@@ -2413,7 +2413,7 @@ IS AVAILABLE\n\
 SYNOPSIS\n\
 \ \ \ \ Start a Locator.\n\
 SYNTAX\n\
-\ \ \ \ start locator --name=value [--bind-address=value] [--classpath=value] [--force(=value)?]\n\
+\ \ \ \ start locator [--name=value] [--bind-address=value] [--classpath=value] [--force(=value)?]\n\
 \ \ \ \ [--group=value] [--hostname-for-clients=value] [--include-system-classpath(=value)?]\n\
 \ \ \ \ [--locators=value] [--log-level=value] [--mcast-address=value] [--mcast-port=value]\n\
 \ \ \ \ [--port=value] [--dir=value] [--properties-file=value] [--security-properties-file=value]\n\
@@ -2423,7 +2423,7 @@ SYNTAX\n\
 PARAMETERS\n\
 \ \ \ \ name\n\
 \ \ \ \ \ \ \ \ The member name to give this Locator in the Geode cluster.\n\
-\ \ \ \ \ \ \ \ Required: true\n\
+\ \ \ \ \ \ \ \ Required: false\n\
 \ \ \ \ bind-address\n\
 \ \ \ \ \ \ \ \ IP address on which the Locator will be bound.  By default, the Locator is
bound to all\n\
 \ \ \ \ \ \ \ \ local addresses.\n\
@@ -2536,7 +2536,7 @@ IS AVAILABLE\n\
 SYNOPSIS\n\
 \ \ \ \ Start a Geode Cache Server.\n\
 SYNTAX\n\
-\ \ \ \ start server --name=value [--assign-buckets(=value)?] [--bind-address=value]\n\
+\ \ \ \ start server [--name=value] [--assign-buckets(=value)?] [--bind-address=value]\n\
 \ \ \ \ [--cache-xml-file=value] [--classpath=value] [--critical-heap-percentage=value]\n\
 \ \ \ \ [--critical-off-heap-percentage=value] [--dir=value] [--disable-default-server(=value)?]\n\
 \ \ \ \ [--disable-exit-when-out-of-memory(=value)?] [--enable-time-statistics(=value)?]\n\
@@ -2554,6 +2554,9 @@ SYNTAX\n\
 \ \ \ \ [--start-rest-api(=value)?] [--http-service-port=value] [--http-service-bind-address=value]\n\
 \ \ \ \ [--user=value] [--password=value]\n\
 PARAMETERS\n\
+\ \ \ \ name\n\
+\ \ \ \ \ \ \ \ The member name to give this Cache Server in the Geode cluster.\n\
+\ \ \ \ \ \ \ \ Required: false\n\
 \ \ \ \ assign-buckets\n\
 \ \ \ \ \ \ \ \ Whether to assign buckets to the partitioned regions of the cache on server
start.\n\
 \ \ \ \ \ \ \ \ Required: false\n\
@@ -2703,9 +2706,6 @@ PARAMETERS\n\
 \ \ \ \ message-time-to-live\n\
 \ \ \ \ \ \ \ \ Sets the time (in seconds ) after which a message in the client queue will
expire\n\
 \ \ \ \ \ \ \ \ Required: false\n\
-\ \ \ \ name\n\
-\ \ \ \ \ \ \ \ The member name to give this Cache Server in the Geode cluster.\n\
-\ \ \ \ \ \ \ \ Required: true\n\
 \ \ \ \ off-heap-memory-size\n\
 \ \ \ \ \ \ \ \ The total size of off-heap memory specified as off-heap-memory-size=<n>[g|m].
<n> is the\n\
 \ \ \ \ \ \ \ \ size. [g|m] indicates whether the size should be interpreted as gigabytes
or megabytes. A\n\


Mime
View raw message