You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by go...@apache.org on 2018/05/14 23:56:00 UTC

[geode] 05/07: GEODE-5194: Relax Gfsh connection version check to exclude patch version (#1942)

This is an automated email from the ASF dual-hosted git repository.

gosullivan pushed a commit to branch support/9.5
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 98349df20920e3b10d2a77126d94890b3c1c5b22
Author: Kenneth Howe <kh...@pivotal.io>
AuthorDate: Thu May 10 06:56:12 2018 -0700

    GEODE-5194: Relax Gfsh connection version check to exclude patch version (#1942)
    
    (cherry picked from commit 5367fa520b4542b1f681dd6220e7625b68a82607)
---
 .../internal/cli/commands/ConnectCommand.java      | 13 ++++++-
 .../internal/cli/commands/ConnectCommandTest.java  | 45 +++++++++++++++++++++-
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConnectCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConnectCommand.java
index e5e834a..bc672dd 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConnectCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConnectCommand.java
@@ -74,6 +74,9 @@ public class ConnectCommand extends InternalGfshCommand {
   // millis that connect --locator will wait for a response from the locator.
   static final int CONNECT_LOCATOR_TIMEOUT_MS = 60000; // see bug 45971
 
+  private static final int VERSION_MAJOR = 0;
+  private static final int VERSION_MINOR = 1;
+
   private static final UserInputProperty[] USER_INPUT_PROPERTIES =
       {UserInputProperty.KEYSTORE, UserInputProperty.KEYSTORE_PASSWORD,
           UserInputProperty.KEYSTORE_TYPE, UserInputProperty.TRUSTSTORE,
@@ -169,7 +172,10 @@ public class ConnectCommand extends InternalGfshCommand {
     String remoteVersion = null;
     try {
       remoteVersion = invoker.getRemoteVersion();
-      if (remoteVersion.equalsIgnoreCase(gfshVersion)) {
+      if (versionComponent(remoteVersion, VERSION_MAJOR)
+          .equalsIgnoreCase(versionComponent(gfshVersion, VERSION_MAJOR))
+          && versionComponent(remoteVersion, VERSION_MINOR)
+              .equalsIgnoreCase(versionComponent(gfshVersion, VERSION_MINOR))) {
         return result;
       }
     } catch (Exception e) {
@@ -187,6 +193,11 @@ public class ConnectCommand extends InternalGfshCommand {
     }
   }
 
+  private String versionComponent(String version, int component) {
+    String[] versionComponents = StringUtils.split(version, '.');
+    return versionComponents.length >= component + 1 ? versionComponents[component] : "";
+  }
+
   /**
    * @param useSsl if true, and no files/options passed, we would still insist on prompting for ssl
    *        config (considered only when the last three parameters are null)
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java
index 7d6eecf..ac5e152 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java
@@ -302,7 +302,17 @@ public class ConnectCommandTest {
   }
 
   @Test
-  public void connectToManagerWithDifferentVersion() {
+  public void connectToManagerWithDifferentMajorVersion() {
+    when(gfsh.getVersion()).thenReturn("2.2");
+    when(operationInvoker.getRemoteVersion()).thenReturn("1.2");
+    when(operationInvoker.isConnected()).thenReturn(true);
+    gfshParserRule.executeAndAssertThat(connectCommand, "connect --locator=localhost:4040")
+        .statusIsError()
+        .containsOutput("Cannot use a 2.2 gfsh client to connect to a 1.2 cluster.");
+  }
+
+  @Test
+  public void connectToManagerWithDifferentMinorVersion() {
     when(gfsh.getVersion()).thenReturn("1.2");
     when(operationInvoker.getRemoteVersion()).thenReturn("1.3");
     when(operationInvoker.isConnected()).thenReturn(true);
@@ -312,6 +322,39 @@ public class ConnectCommandTest {
   }
 
   @Test
+  public void connectToManagerWithGreaterPatchVersion() {
+    when(gfsh.getVersion()).thenReturn("1.5.1");
+    when(operationInvoker.getRemoteVersion()).thenReturn("1.5.2");
+    when(operationInvoker.isConnected()).thenReturn(true);
+    when(result.getStatus()).thenReturn(Result.Status.OK);
+
+    gfshParserRule.executeAndAssertThat(connectCommand, "connect --locator=localhost:4040")
+        .statusIsSuccess();
+  }
+
+  @Test
+  public void connectToManagerWithNoPatchVersion() {
+    when(gfsh.getVersion()).thenReturn("1.5.1");
+    when(operationInvoker.getRemoteVersion()).thenReturn("1.5");
+    when(operationInvoker.isConnected()).thenReturn(true);
+    when(result.getStatus()).thenReturn(Result.Status.OK);
+
+    gfshParserRule.executeAndAssertThat(connectCommand, "connect --locator=localhost:4040")
+        .statusIsSuccess();
+  }
+
+  @Test
+  public void connectToManagerWithLessorPatchVersion() {
+    when(gfsh.getVersion()).thenReturn("1.5.1");
+    when(operationInvoker.getRemoteVersion()).thenReturn("1.5.0");
+    when(operationInvoker.isConnected()).thenReturn(true);
+    when(result.getStatus()).thenReturn(Result.Status.OK);
+
+    gfshParserRule.executeAndAssertThat(connectCommand, "connect --locator=localhost:4040")
+        .statusIsSuccess();
+  }
+
+  @Test
   public void connectToOlderManagerWithNewerGfsh() {
     when(gfsh.getVersion()).thenReturn("1.5");
     when(operationInvoker.getRemoteVersion())

-- 
To stop receiving notification emails like this one, please contact
gosullivan@apache.org.