You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/04/17 15:42:17 UTC

[geode] branch develop updated: GEODE-5048: add missing availability indicators for certain commands (#1800)

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

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 575659c  GEODE-5048: add missing availability indicators for certain commands (#1800)
575659c is described below

commit 575659c13d57d253c654f74e90761a4ac3a1b2fc
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Tue Apr 17 08:42:12 2018 -0700

    GEODE-5048: add missing availability indicators for certain commands (#1800)
---
 .../jdbc/internal/cli/CreateConnectionCommand.java | 12 ++++++
 .../internal/cli/JDBCCommandsAvailabilityTest.java | 48 ++++++++++++++++++++++
 .../apache/geode/management/cli/GfshCommand.java   | 10 +++++
 .../cli/commands/CommandAvailabilityIndicator.java | 20 +++------
 .../cli/commands/ListJndiBindingCommand.java       |  2 +-
 .../commands/CommandAvailabilityIndicatorTest.java | 26 ++++++++----
 6 files changed, 95 insertions(+), 23 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateConnectionCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateConnectionCommand.java
index e0e7da1..67bee90 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateConnectionCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateConnectionCommand.java
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
@@ -112,4 +113,15 @@ public class CreateConnectionCommand extends InternalGfshCommand {
       return ResultBuilder.createInfoResult("");
     }
   }
+
+  @CliAvailabilityIndicator({AlterConnectionCommand.ALTER_JDBC_CONNECTION,
+      AlterMappingCommand.ALTER_MAPPING, CreateConnectionCommand.CREATE_CONNECTION,
+      CreateMappingCommand.CREATE_MAPPING, DescribeConnectionCommand.DESCRIBE_CONNECTION,
+      DescribeMappingCommand.DESCRIBE_MAPPING, DestroyConnectionCommand.DESTROY_CONNECTION,
+      DestroyMappingCommand.DESTROY_MAPPING, ListConnectionCommand.LIST_JDBC_CONNECTION,
+      ListMappingCommand.LIST_MAPPING})
+
+  public boolean available() {
+    return isOnlineCommandAvailable();
+  }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/JDBCCommandsAvailabilityTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/JDBCCommandsAvailabilityTest.java
new file mode 100644
index 0000000..1c02c3a
--- /dev/null
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/JDBCCommandsAvailabilityTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.connectors.jdbc.internal.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.springframework.shell.core.CommandMarker;
+
+import org.apache.geode.management.internal.cli.CommandManager;
+import org.apache.geode.management.internal.cli.commands.CommandAvailabilityIndicatorTest;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+
+@Category(UnitTest.class)
+public class JDBCCommandsAvailabilityTest {
+
+  @Test
+  public void jdbcCommandsAvailable() {
+    CommandManager manager = new CommandManager();
+    Set<Class<? extends CommandMarker>> collections = manager.getCommandMarkers().stream()
+        .map(CommandMarker::getClass).collect(Collectors.toSet());
+
+    // make sure the jdbc commands are loaded
+    assertThat(collections).contains(CreateConnectionCommand.class);
+
+    CommandAvailabilityIndicatorTest.assertOnlineCommandsHasAvailabilityIndicator(manager);
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java b/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java
index 3cfdb11..7cd822b 100644
--- a/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/cli/GfshCommand.java
@@ -48,6 +48,16 @@ public abstract class GfshCommand implements CommandMarker {
     return gfsh != null && gfsh.isConnectedAndReady();
   }
 
+  public boolean isOnlineCommandAvailable() {
+    Gfsh gfsh = Gfsh.getCurrentInstance();
+    // command should always be available on the server
+    if (gfsh == null) {
+      return true;
+    }
+    // if in gfshVM, only when gfsh is connected and ready
+    return gfsh.isConnectedAndReady();
+  }
+
   public void authorize(ResourcePermission.Resource resource,
       ResourcePermission.Operation operation, ResourcePermission.Target target) {
     cache.getSecurityService().authorize(resource, operation, target);
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicator.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicator.java
index 02938c1..48724c0 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicator.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicator.java
@@ -15,13 +15,12 @@
 
 package org.apache.geode.management.internal.cli.commands;
 
-import org.springframework.shell.core.CommandMarker;
 import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
 
+import org.apache.geode.management.cli.GfshCommand;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.shell.Gfsh;
 
-public class CommandAvailabilityIndicator implements CommandMarker {
+public class CommandAvailabilityIndicator extends GfshCommand {
 
   @CliAvailabilityIndicator({CliStrings.LIST_CLIENTS, CliStrings.DESCRIBE_CLIENT,
       CliStrings.DESCRIBE_CONFIG, CliStrings.EXPORT_CONFIG, CliStrings.ALTER_RUNTIME_CONFIG,
@@ -50,17 +49,10 @@ public class CommandAvailabilityIndicator implements CommandMarker {
       CliStrings.STOP_GATEWAYRECEIVER, CliStrings.LIST_GATEWAY, CliStrings.STATUS_GATEWAYSENDER,
       CliStrings.STATUS_GATEWAYRECEIVER, CliStrings.LOAD_BALANCE_GATEWAYSENDER,
       CliStrings.DESTROY_GATEWAYSENDER, AlterAsyncEventQueueCommand.COMMAND_NAME,
+      DestroyAsyncEventQueueCommand.DESTROY_ASYNC_EVENT_QUEUE,
       CreateJndiBindingCommand.CREATE_JNDIBINDING, DestroyJndiBindingCommand.DESTROY_JNDIBINDING,
-      DescribeJndiBindingCommand.DESCRIBE_JNDI_BINDING})
-  public boolean clientCommandsAvailable() {
-    Gfsh gfsh = Gfsh.getCurrentInstance();
-
-    // command should always be available on the server
-    if (gfsh == null) {
-      return true;
-    }
-
-    // if in gfshVM, only when gfsh is connected and ready
-    return gfsh.isConnectedAndReady();
+      DescribeJndiBindingCommand.DESCRIBE_JNDI_BINDING, ListJndiBindingCommand.LIST_JNDIBINDING})
+  public boolean available() {
+    return isOnlineCommandAvailable();
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java
index 9b352d7..54b7571 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommand.java
@@ -40,7 +40,7 @@ import org.apache.geode.security.ResourcePermission;
 public class ListJndiBindingCommand extends InternalGfshCommand {
   private static final Logger logger = LogService.getLogger();
 
-  private static final String LIST_JNDIBINDING = "list jndi-binding";
+  public static final String LIST_JNDIBINDING = "list jndi-binding";
   private static final String LIST_JNDIBINDING__HELP =
       "List all jndi bindings, active and configured. An active binding is one that is bound to the server's jndi context (and also listed in the cluster config). A configured binding is one that is listed in the cluster config, but may not be active on the servers.";
   private static final Function LIST_BINDING_FUNCTION = new ListJndiBindingFunction();
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicatorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicatorTest.java
index 83d183e..a458783 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicatorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CommandAvailabilityIndicatorTest.java
@@ -25,6 +25,7 @@ import org.junit.experimental.categories.Category;
 import org.springframework.shell.core.CommandMarker;
 import org.springframework.shell.core.annotation.CliCommand;
 
+import org.apache.geode.internal.cache.extension.mock.MockExtensionCommands;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.GfshCommand;
 import org.apache.geode.management.internal.cli.CommandManager;
@@ -35,31 +36,40 @@ import org.apache.geode.test.junit.categories.UnitTest;
 public class CommandAvailabilityIndicatorTest {
 
   @Test
-  public void allOnlineCommandsHaveAvailabilityIndicator() throws Exception {
+  public void allOnlineCommandsHaveAvailabilityIndicator() {
     CommandManager manager = new CommandManager();
-    List<CommandMarker> commandMarkers = manager.getCommandMarkers();
+    assertOnlineCommandsHasAvailabilityIndicator(manager);
+  }
 
+  public static void assertOnlineCommandsHasAvailabilityIndicator(CommandManager manager) {
+    List<CommandMarker> commandMarkers = manager.getCommandMarkers();
     for (CommandMarker commandMarker : commandMarkers) {
       // ignore all the other commands beside GfshCommand
       if (!GfshCommand.class.isAssignableFrom(commandMarker.getClass())) {
         continue;
       }
 
+      if (commandMarker instanceof MockExtensionCommands) {
+        continue;
+      }
+
       for (Method method : commandMarker.getClass().getMethods()) {
         CliCommand cliCommand = method.getAnnotation(CliCommand.class);
-        CliMetaData cliMetaData = method.getAnnotation(CliMetaData.class);
+        if (cliCommand == null) {
+          // the method is not a command method
+          continue;
+        }
 
+        CliMetaData cliMetaData = method.getAnnotation(CliMetaData.class);
         // all the online commands have availability indicator defined in the commandManager
-        if (cliMetaData != null && !cliMetaData.shellOnly()) {
+        if (cliMetaData == null || cliMetaData != null && !cliMetaData.shellOnly()) {
           assertThat(manager.getHelper().hasAvailabilityIndicator(cliCommand.value()[0]))
-              .describedAs(cliCommand.value()[0] + " has no availability indicator defined. "
+              .describedAs(cliCommand.value()[0] + " in " + commandMarker.getClass()
+                  + " has no availability indicator defined. "
                   + "Please add the command in the CommandAvailabilityIndicator")
               .isTrue();
         }
       }
     }
   }
-
-
-
 }

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