You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2018/04/02 21:05:53 UTC

[geode] branch develop updated: GEODE-4386: Return 'not found' if the JNDI binding does not exist (#1713)

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

jensdeppe 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 00ffcf5  GEODE-4386: Return 'not found' if the JNDI binding does not exist (#1713)
00ffcf5 is described below

commit 00ffcf5b9b13f085dd0657ebe6cf21aa0e080381
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Mon Apr 2 14:05:48 2018 -0700

    GEODE-4386: Return 'not found' if the JNDI binding does not exist (#1713)
---
 .../internal/cli/commands/CommandAvailabilityIndicator.java |  3 ++-
 .../internal/cli/commands/DescribeJndiBindingCommand.java   | 13 +++++++++++--
 .../cli/commands/DescribeJndiBindingCommandDUnitTest.java   |  6 ++++++
 3 files changed, 19 insertions(+), 3 deletions(-)

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 a38a9e1..02938c1 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
@@ -50,7 +50,8 @@ 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,
-      CreateJndiBindingCommand.CREATE_JNDIBINDING, DestroyJndiBindingCommand.DESTROY_JNDIBINDING})
+      CreateJndiBindingCommand.CREATE_JNDIBINDING, DestroyJndiBindingCommand.DESTROY_JNDIBINDING,
+      DescribeJndiBindingCommand.DESCRIBE_JNDI_BINDING})
   public boolean clientCommandsAvailable() {
     Gfsh gfsh = Gfsh.getCurrentInstance();
 
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
index 963845c..cc2f086 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
@@ -26,6 +26,7 @@ import org.apache.geode.cache.configuration.JndiBindingsType;
 import org.apache.geode.cache.execute.Function;
 import org.apache.geode.distributed.internal.InternalClusterConfigurationService;
 import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.functions.ListJndiBindingFunction;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
@@ -36,12 +37,13 @@ import org.apache.geode.security.ResourcePermission;
 public class DescribeJndiBindingCommand extends InternalGfshCommand {
   private static final Logger logger = LogService.getLogger();
 
-  private static final String DESCRIBE_JNDI_BINDING = "describe jndi-binding";
+  static final String DESCRIBE_JNDI_BINDING = "describe jndi-binding";
   private static final String DESCRIBE_JNDIBINDING__HELP =
-      "Describe the given active jndi binding. An active binding is one that is bound to the server's jndi context.";
+      "Describe the configuration of the given jndi binding.";
   private static final Function LIST_BINDING_FUNCTION = new ListJndiBindingFunction();
 
   @CliCommand(value = DESCRIBE_JNDI_BINDING, help = DESCRIBE_JNDIBINDING__HELP)
+  @CliMetaData
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.READ)
   public Result describeJndiBinding(@CliOption(key = "name", mandatory = true,
@@ -54,6 +56,13 @@ public class DescribeJndiBindingCommand extends InternalGfshCommand {
     if (ccService != null) {
       CacheConfig cacheConfig = ccService.getCacheConfig("cluster");
       List<JndiBindingsType.JndiBinding> jndiBindings = cacheConfig.getJndiBindings();
+
+      if (jndiBindings.stream().noneMatch(b -> b.getJndiName().equals(bindingName)
+          || b.getJndiName().equals("java:" + bindingName))) {
+        return ResultBuilder
+            .createUserErrorResult(String.format("JNDI binding : %s not found", bindingName));
+      }
+
       for (JndiBindingsType.JndiBinding binding : jndiBindings) {
         if (binding.getJndiName().equals(bindingName)
             || binding.getJndiName().equals("java:" + bindingName)) {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandDUnitTest.java
index b15b08e..92c046c 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandDUnitTest.java
@@ -137,4 +137,10 @@ public class DescribeJndiBindingCommandDUnitTest {
         .tableHasRowWithValues("Property", "Value", "login-timeout-seconds", "7")
         .tableHasRowWithValues("Property", "Value", "prop1", "value1");
   }
+
+  @Test
+  public void describeJndiBindingDoesNotExist() {
+    gfsh.executeAndAssertThat("describe jndi-binding --name=unknown").statusIsError()
+        .containsOutput("JNDI binding : unknown not found");
+  }
 }

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