geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sai_boorlaga...@apache.org
Subject [geode] branch develop updated: GEODE-4858: refactor JndiBinding commands (#1935)
Date Wed, 09 May 2018 22:02:23 GMT
This is an automated email from the ASF dual-hosted git repository.

sai_boorlagadda 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 06079fc  GEODE-4858: refactor JndiBinding commands (#1935)
06079fc is described below

commit 06079fc531b141e8f8b728d6f3c181fb884b5da7
Author: Sai Boorlagadda <sai.boorlagadda@gmail.com>
AuthorDate: Wed May 9 15:02:18 2018 -0700

    GEODE-4858: refactor JndiBinding commands (#1935)
---
 .../cli/commands/CreateJndiBindingCommand.java     | 37 +++++----------
 .../cli/commands/DestroyJndiBindingCommand.java    | 53 ++++++++++------------
 .../cli/commands/ListJndiBindingCommand.java       | 28 +++++-------
 .../cli/functions/CreateJndiBindingFunction.java   | 10 ++--
 .../cli/functions/DestroyJndiBindingFunction.java  | 16 +++----
 .../cli/functions/ListJndiBindingFunction.java     | 12 ++---
 .../internal/cli/remote/CommandExecutor.java       |  2 +
 .../cli/commands/CreateJndiBindingCommandTest.java | 32 +++++++++----
 .../commands/DestroyJndiBindingCommandTest.java    | 41 ++++++++++++-----
 .../commands/ListJndiBindingCommandDUnitTest.java  |  4 +-
 10 files changed, 120 insertions(+), 115 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommand.java
index e542b14..cbb1c21 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommand.java
@@ -14,8 +14,6 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.management.internal.cli.result.ResultBuilder.buildResult;
-
 import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
@@ -32,16 +30,16 @@ import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
 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.cli.SingleGfshCommand;
 import org.apache.geode.management.internal.cli.exceptions.EntityExistsException;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.functions.CreateJndiBindingFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.ResultBuilder;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
 
-public class CreateJndiBindingCommand extends InternalGfshCommand {
+public class CreateJndiBindingCommand extends SingleGfshCommand {
   private static final Logger logger = LogService.getLogger();
 
   static final String CREATE_JNDIBINDING = "create jndi-binding";
@@ -100,7 +98,7 @@ public class CreateJndiBindingCommand extends InternalGfshCommand {
   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result createJDNIBinding(
+  public ResultModel createJDNIBinding(
       @CliOption(key = BLOCKING_TIMEOUT_SECONDS,
           help = BLOCKING_TIMEOUT_SECONDS__HELP) Integer blockingTimeout,
       @CliOption(key = CONNECTION_POOLED_DATASOURCE_CLASS,
@@ -146,8 +144,6 @@ public class CreateJndiBindingCommand extends InternalGfshCommand {
     if (dsConfigProperties != null && dsConfigProperties.length > 0)
       configuration.getConfigProperty().addAll(Arrays.asList(dsConfigProperties));
 
-    Result result;
-    boolean persisted = false;
     InternalConfigurationPersistenceService service =
         (InternalConfigurationPersistenceService) getConfigurationPersistenceService();
 
@@ -162,32 +158,23 @@ public class CreateJndiBindingCommand extends InternalGfshCommand {
               ifNotExists);
         }
       }
-
-      service.updateCacheConfig("cluster", config -> {
-        config.getJndiBindings().add(configuration);
-        return config;
-      });
-      persisted = true;
     }
 
     Set<DistributedMember> targetMembers = findMembers(null, null);
     if (targetMembers.size() > 0) {
       List<CliFunctionResult> jndiCreationResult = executeAndGetFunctionResult(
           new CreateJndiBindingFunction(), configuration, targetMembers);
-      result = buildResult(jndiCreationResult);
+      ResultModel result = ResultModel.createMemberStatusResult(jndiCreationResult);
+      result.setConfigObject(configuration);
+      return result;
     } else {
-      if (persisted) {
-        result = ResultBuilder.createInfoResult(CliStrings.format(
-            "No members found. Cluster configuration is updated with jndi-binding \"{0}\".",
-            jndiName));
-      } else {
-        result = ResultBuilder.createInfoResult("No members found.");
-      }
+      return ResultModel.createInfo("No members found.");
     }
+  }
 
-    result.setCommandPersisted(persisted);
-
-    return result;
+  @Override
+  public void updateClusterConfig(String group, CacheConfig config, Object element) {
+    config.getJndiBindings().add((JndiBindingsType.JndiBinding) element);
   }
 
   public enum DATASOURCE_TYPE {
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommand.java
index f40328d..b2769d8 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommand.java
@@ -14,7 +14,6 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.management.internal.cli.result.ResultBuilder.buildResult;
 
 import java.util.List;
 import java.util.Set;
@@ -22,21 +21,22 @@ import java.util.Set;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
+import org.apache.geode.cache.configuration.CacheConfig;
 import org.apache.geode.cache.configuration.CacheElement;
 import org.apache.geode.cache.configuration.JndiBindingsType;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
 import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.cli.SingleGfshCommand;
 import org.apache.geode.management.internal.cli.exceptions.EntityNotFoundException;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.functions.DestroyJndiBindingFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.ResultBuilder;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
 
-public class DestroyJndiBindingCommand extends InternalGfshCommand {
+public class DestroyJndiBindingCommand extends SingleGfshCommand {
   static final String DESTROY_JNDIBINDING = "destroy jndi-binding";
   static final String DESTROY_JNDIBINDING__HELP =
       "Destroy a JNDI binding that holds the configuration for an XA datasource.";
@@ -51,45 +51,40 @@ public class DestroyJndiBindingCommand extends InternalGfshCommand {
   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result destroyJDNIBinding(
+  public ResultModel destroyJDNIBinding(
       @CliOption(key = JNDI_NAME, mandatory = true, help = JNDI_NAME__HELP) String jndiName,
       @CliOption(key = CliStrings.IFEXISTS, help = IFEXISTS_HELP, specifiedDefaultValue =
"true",
           unspecifiedDefaultValue = "false") boolean ifExists) {
 
-    Result result;
-    boolean persisted = false;
     InternalConfigurationPersistenceService service =
         (InternalConfigurationPersistenceService) getConfigurationPersistenceService();
     if (service != null) {
-      service.updateCacheConfig("cluster", cc -> {
-        List<JndiBindingsType.JndiBinding> bindings = cc.getJndiBindings();
-        JndiBindingsType.JndiBinding binding = CacheElement.findElement(bindings, jndiName);
-        if (binding == null) {
-          throw new EntityNotFoundException(
-              CliStrings.format("Jndi binding with jndi-name \"{0}\" does not exist.", jndiName),
-              ifExists);
-        }
-        bindings.remove(binding);
-        return cc;
-      });
-      persisted = true;
+      List<JndiBindingsType.JndiBinding> bindings =
+          service.getCacheConfig("cluster").getJndiBindings();
+      JndiBindingsType.JndiBinding binding = CacheElement.findElement(bindings, jndiName);
+      // fail fast when CC is running and if required binding not found assuming that
+      // when CC is running then every configuration goes through CC
+      if (binding == null) {
+        throw new EntityNotFoundException(
+            CliStrings.format("Jndi binding with jndi-name \"{0}\" does not exist.", jndiName),
+            ifExists);
+      }
     }
 
     Set<DistributedMember> targetMembers = findMembers(null, null);
     if (targetMembers.size() > 0) {
       List<CliFunctionResult> jndiCreationResult =
           executeAndGetFunctionResult(new DestroyJndiBindingFunction(), jndiName, targetMembers);
-      return buildResult(jndiCreationResult);
+      ResultModel result = ResultModel.createMemberStatusResult(jndiCreationResult);
+      result.setConfigObject(jndiName);
+      return result;
     } else {
-      if (persisted) {
-        result = ResultBuilder.createInfoResult(CliStrings.format(
-            "No members found. Jndi-binding \"{0}\" is removed from cluster configuration.",
-            jndiName));
-      } else {
-        result = ResultBuilder.createInfoResult("No members found.");
-      }
+      return ResultModel.createInfo("No members found.");
     }
-    result.setCommandPersisted(persisted);
-    return result;
+  }
+
+  @Override
+  public void updateClusterConfig(String group, CacheConfig config, Object element) {
+    CacheElement.removeElement(config.getJndiBindings(), (String) element);
   }
 }
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 21f24af..e6a1a81 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
@@ -28,12 +28,10 @@ import org.apache.geode.cache.execute.Function;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
 import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.functions.ListJndiBindingFunction;
-import org.apache.geode.management.internal.cli.result.CompositeResultData;
-import org.apache.geode.management.internal.cli.result.ResultBuilder;
-import org.apache.geode.management.internal.cli.result.TabularResultData;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
+import org.apache.geode.management.internal.cli.result.model.TabularResultModel;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
 
@@ -48,16 +46,14 @@ public class ListJndiBindingCommand extends InternalGfshCommand {
   @CliCommand(value = LIST_JNDIBINDING, help = LIST_JNDIBINDING__HELP)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.READ)
-  public Result listJndiBinding() {
-    CompositeResultData resultData = ResultBuilder.createCompositeResultData();
-    CompositeResultData.SectionResultData resultSection = resultData.addSection();
-    TabularResultData configTable = null;
-    TabularResultData memberTable = null;
+  public ResultModel listJndiBinding() {
+    ResultModel resultModel = new ResultModel();
+    TabularResultModel configTable = null;
 
     InternalConfigurationPersistenceService ccService =
         (InternalConfigurationPersistenceService) getConfigurationPersistenceService();
     if (ccService != null) {
-      configTable = resultSection.addTable();
+      configTable = resultModel.addTable("clusterConfiguration");
       // we don't support creating jndi binding with random group name yet
       CacheConfig cacheConfig = ccService.getCacheConfig("cluster");
       List<JndiBindingsType.JndiBinding> jndiBindings = cacheConfig.getJndiBindings();
@@ -77,13 +73,13 @@ public class ListJndiBindingCommand extends InternalGfshCommand {
 
     if (members.size() == 0) {
       if (configTable == null) {
-        return ResultBuilder.createUserErrorResult("No members found");
+        return ResultModel.createError("No members found");
       }
       configTable.setFooter("No members found");
-      return ResultBuilder.buildResult(resultData);
+      return resultModel;
     }
 
-    memberTable = resultSection.addTable();
+    TabularResultModel memberTable = resultModel.addTable("memberConfiguration");
     List<CliFunctionResult> rc = executeAndGetFunctionResult(LIST_BINDING_FUNCTION,
null, members);
 
     memberTable.setHeader("Active JNDI bindings found on each member: ");
@@ -91,10 +87,10 @@ public class ListJndiBindingCommand extends InternalGfshCommand {
       Serializable[] serializables = oneResult.getSerializables();
       for (int i = 0; i < serializables.length; i += 2) {
         memberTable.accumulate("Member", oneResult.getMemberIdOrName());
-        memberTable.accumulate("JNDI Name", serializables[i]);
-        memberTable.accumulate("JDBC Driver Class", serializables[i + 1]);
+        memberTable.accumulate("JNDI Name", (String) serializables[i]);
+        memberTable.accumulate("JDBC Driver Class", (String) serializables[i + 1]);
       }
     }
-    return ResultBuilder.buildResult(resultData);
+    return resultModel;
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/CreateJndiBindingFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/CreateJndiBindingFunction.java
index 2765713..e94d333 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/CreateJndiBindingFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/CreateJndiBindingFunction.java
@@ -22,25 +22,25 @@ import java.util.stream.Collectors;
 import org.apache.geode.cache.configuration.JndiBindingsType;
 import org.apache.geode.cache.execute.FunctionContext;
 import org.apache.geode.cache.execute.ResultSender;
-import org.apache.geode.internal.cache.execute.InternalFunction;
 import org.apache.geode.internal.datasource.ConfigProperty;
 import org.apache.geode.internal.jndi.JNDIInvoker;
+import org.apache.geode.management.cli.CliFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 
-public class CreateJndiBindingFunction implements InternalFunction<JndiBindingsType.JndiBinding>
{
+public class CreateJndiBindingFunction extends CliFunction<JndiBindingsType.JndiBinding>
{
 
   static final String RESULT_MESSAGE =
       "Initiated jndi binding \"{0}\" on \"{1}\". See server logs to verify.";
 
   @Override
-  public void execute(FunctionContext<JndiBindingsType.JndiBinding> context) {
+  public CliFunctionResult executeFunction(FunctionContext<JndiBindingsType.JndiBinding>
context) {
     ResultSender<Object> resultSender = context.getResultSender();
     JndiBindingsType.JndiBinding configuration = context.getArguments();
     JNDIInvoker.mapDatasource(getParamsAsMap(configuration),
         convert(configuration.getConfigProperty()));
 
-    resultSender.lastResult(new CliFunctionResult(context.getMemberName(), true,
-        CliStrings.format(RESULT_MESSAGE, configuration.getJndiName(), context.getMemberName())));
+    return new CliFunctionResult(context.getMemberName(), true,
+        CliStrings.format(RESULT_MESSAGE, configuration.getJndiName(), context.getMemberName()));
   }
 
   static Map getParamsAsMap(JndiBindingsType.JndiBinding binding) {
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DestroyJndiBindingFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DestroyJndiBindingFunction.java
index aada3c7..51bb130 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DestroyJndiBindingFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DestroyJndiBindingFunction.java
@@ -17,28 +17,26 @@ package org.apache.geode.management.internal.cli.functions;
 import javax.naming.NamingException;
 
 import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.cache.execute.ResultSender;
-import org.apache.geode.internal.cache.execute.InternalFunction;
 import org.apache.geode.internal.jndi.JNDIInvoker;
+import org.apache.geode.management.cli.CliFunction;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 
-public class DestroyJndiBindingFunction implements InternalFunction {
+public class DestroyJndiBindingFunction extends CliFunction<String> {
 
   static final String RESULT_MESSAGE = "Jndi binding \"{0}\" destroyed on \"{1}\"";
   static final String EXCEPTION_RESULT_MESSAGE = "Jndi binding \"{0}\" not found on \"{1}\"";
 
   @Override
-  public void execute(FunctionContext context) {
-    ResultSender<Object> resultSender = context.getResultSender();
+  public CliFunctionResult executeFunction(FunctionContext context) {
     String jndiName = (String) context.getArguments();
 
     try {
       JNDIInvoker.unMapDatasource(jndiName);
-      resultSender.lastResult(new CliFunctionResult(context.getMemberName(), true,
-          CliStrings.format(RESULT_MESSAGE, jndiName, context.getMemberName())));
+      return new CliFunctionResult(context.getMemberName(), true,
+          CliStrings.format(RESULT_MESSAGE, jndiName, context.getMemberName()));
     } catch (NamingException e) {
-      resultSender.lastResult(new CliFunctionResult(context.getMemberName(), true,
-          CliStrings.format(EXCEPTION_RESULT_MESSAGE, jndiName, context.getMemberName())));
+      return new CliFunctionResult(context.getMemberName(), true,
+          CliStrings.format(EXCEPTION_RESULT_MESSAGE, jndiName, context.getMemberName()));
     }
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListJndiBindingFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListJndiBindingFunction.java
index b79edbe..079c984 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListJndiBindingFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListJndiBindingFunction.java
@@ -24,18 +24,16 @@ import java.util.stream.Collectors;
 import javax.naming.Context;
 
 import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.cache.execute.ResultSender;
-import org.apache.geode.internal.cache.execute.InternalFunction;
 import org.apache.geode.internal.jndi.JNDIInvoker;
+import org.apache.geode.management.cli.CliFunction;
 
-public class ListJndiBindingFunction implements InternalFunction {
+public class ListJndiBindingFunction extends CliFunction<Void> {
 
   private static final long serialVersionUID = 5254506785395069200L;
 
   @Override
-  public void execute(FunctionContext context) {
+  public CliFunctionResult executeFunction(FunctionContext context) {
     CliFunctionResult result;
-
     try {
       Context ctx = JNDIInvoker.getJNDIContext();
       Map<String, String> bindings = JNDIInvoker.getBindingNamesRecursively(ctx);
@@ -48,8 +46,6 @@ public class ListJndiBindingFunction implements InternalFunction {
       result =
           new CliFunctionResult(context.getMemberName(), e, "Unable to retrieve JNDI bindings");
     }
-
-    ResultSender<Object> sender = context.getResultSender();
-    sender.lastResult(result);
+    return result;
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutor.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutor.java
index 247286e..65642f0 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutor.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutor.java
@@ -136,6 +136,8 @@ public class CommandExecutor {
       ccService.updateCacheConfig(group, cc -> {
         try {
           gfshCommand.updateClusterConfig(group, cc, resultModel.getConfigObject());
+          infoResultModel
+              .addLine("Changes to configuration for group '" + group + "' is persisted.");
         } catch (Exception e) {
           String message = "failed to update cluster config for " + group;
           logger.error(message, e);
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
index d827788..5248672 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
@@ -16,6 +16,8 @@ package org.apache.geode.management.internal.cli.commands;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -29,9 +31,9 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.function.UnaryOperator;
 
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
 
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -138,8 +140,7 @@ public class CreateJndiBindingCommandTest {
   }
 
   @Test
-  public void skipsIfBindingAlreadyExistsAndIfSpecifiedTrue()
-      throws ParserConfigurationException, SAXException, IOException {
+  public void skipsIfBindingAlreadyExistsAndIfSpecifiedTrue() {
     InternalConfigurationPersistenceService clusterConfigService =
         mock(InternalConfigurationPersistenceService.class);
     CacheConfig cacheConfig = mock(CacheConfig.class);
@@ -180,7 +181,8 @@ public class CreateJndiBindingCommandTest {
 
     gfsh.executeAndAssertThat(command,
         COMMAND + " --type=SIMPLE --name=name --jdbc-driver-class=driver --connection-url=url")
-        .statusIsSuccess().containsOutput("No members found").hasFailToPersistError();
+        .statusIsSuccess().containsOutput("No members found").containsOutput(
+            "Cluster configuration service is not running. Configuration change is not persisted.");
   }
 
   @Test
@@ -193,14 +195,19 @@ public class CreateJndiBindingCommandTest {
     doReturn(clusterConfigService).when(command).getConfigurationPersistenceService();
     doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any());
 
+    doAnswer(invocation -> {
+      UnaryOperator<CacheConfig> mutator = invocation.getArgument(1);
+      mutator.apply(cacheConfig);
+      return null;
+    }).when(clusterConfigService).updateCacheConfig(any(), any());
+
     gfsh.executeAndAssertThat(command,
         COMMAND + " --type=SIMPLE --name=name --jdbc-driver-class=driver --connection-url=url")
-        .statusIsSuccess()
-        .containsOutput(
-            "No members found. Cluster configuration is updated with jndi-binding \\\"name\\\".")
-        .hasNoFailToPersistError();
+        .statusIsSuccess().containsOutput("No members found.")
+        .containsOutput("Changes to configuration for group 'cluster' is persisted.");
 
     verify(clusterConfigService).updateCacheConfig(any(), any());
+    verify(command).updateClusterConfig(eq("cluster"), eq(cacheConfig), any());
   }
 
   @Test
@@ -240,8 +247,7 @@ public class CreateJndiBindingCommandTest {
   }
 
   @Test
-  public void whenMembersFoundAndClusterConfigRunningThenUpdateClusterConfigAndInvokeFunction()
-      throws IOException, ParserConfigurationException, SAXException, TransformerException
{
+  public void whenMembersFoundAndClusterConfigRunningThenUpdateClusterConfigAndInvokeFunction()
{
     Set<DistributedMember> members = new HashSet<>();
     members.add(mock(DistributedMember.class));
 
@@ -257,6 +263,11 @@ public class CreateJndiBindingCommandTest {
     doReturn(clusterConfigService).when(command).getConfigurationPersistenceService();
     doReturn(results).when(command).executeAndGetFunctionResult(any(), any(), any());
     doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any());
+    doAnswer(invocation -> {
+      UnaryOperator<CacheConfig> mutator = invocation.getArgument(1);
+      mutator.apply(cacheConfig);
+      return null;
+    }).when(clusterConfigService).updateCacheConfig(any(), any());
 
     gfsh.executeAndAssertThat(command,
         COMMAND
@@ -266,6 +277,7 @@ public class CreateJndiBindingCommandTest {
             "Tried creating jndi binding \"name\" on \"server1\"");
 
     verify(clusterConfigService).updateCacheConfig(any(), any());
+    verify(command).updateClusterConfig(eq("cluster"), eq(cacheConfig), any());
 
     ArgumentCaptor<CreateJndiBindingFunction> function =
         ArgumentCaptor.forClass(CreateJndiBindingFunction.class);
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommandTest.java
index b647cf8..3e003b5 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommandTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyJndiBindingCommandTest.java
@@ -16,8 +16,8 @@ package org.apache.geode.management.internal.cli.commands;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doCallRealMethod;
-import static org.mockito.Mockito.doNothing;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.function.UnaryOperator;
 
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -39,6 +40,7 @@ import org.mockito.ArgumentCaptor;
 
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.cache.configuration.JndiBindingsType;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
 import org.apache.geode.internal.cache.InternalCache;
@@ -70,10 +72,15 @@ public class DestroyJndiBindingCommandTest {
     cacheConfig = mock(CacheConfig.class);
     ccService = mock(InternalConfigurationPersistenceService.class);
 
-
+    doReturn(Collections.emptySet()).when(command).findMembers(any(), any());
     doReturn(ccService).when(command).getConfigurationPersistenceService();
     when(ccService.getCacheConfig(any())).thenReturn(cacheConfig);
-    doCallRealMethod().when(ccService).updateCacheConfig(any(), any());
+    doAnswer(invocation -> {
+      UnaryOperator<CacheConfig> mutator = invocation.getArgument(1);
+      mutator.apply(cacheConfig);
+      return null;
+    }).when(ccService).updateCacheConfig(any(), any());
+
     when(ccService.getConfigurationRegion()).thenReturn(mock(Region.class));
     when(ccService.getConfiguration(any())).thenReturn(mock(Configuration.class));
   }
@@ -113,20 +120,24 @@ public class DestroyJndiBindingCommandTest {
     doReturn(null).when(command).getConfigurationPersistenceService();
 
     gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess()
-        .containsOutput("No members found").hasFailToPersistError();
+        .containsOutput("No members found").containsOutput(
+            "Cluster configuration service is not running. Configuration change is not persisted.");
   }
 
   @Test
   public void whenNoMembersFoundAndClusterConfigRunningThenUpdateClusterConfig() {
-    doNothing().when(ccService).updateCacheConfig(any(), any());
-    doReturn(Collections.emptySet()).when(command).findMembers(any(), any());
+    List<JndiBindingsType.JndiBinding> bindings = new ArrayList<>();
+    JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding();
+    jndiBinding.setJndiName("name");
+    bindings.add(jndiBinding);
+    doReturn(bindings).when(cacheConfig).getJndiBindings();
 
     gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess()
-        .containsOutput(
-            "No members found. Jndi-binding \\\"name\\\" is removed from cluster configuration.")
-        .hasNoFailToPersistError();
+        .containsOutput("No members found.")
+        .containsOutput("Changes to configuration for group 'cluster' is persisted.");
 
     verify(ccService).updateCacheConfig(any(), any());
+    verify(command).updateClusterConfig(eq("cluster"), eq(cacheConfig), any());
   }
 
   @Test
@@ -164,6 +175,12 @@ public class DestroyJndiBindingCommandTest {
 
   @Test
   public void whenMembersFoundAndClusterConfigRunningThenUpdateClusterConfigAndInvokeFunction()
{
+    List<JndiBindingsType.JndiBinding> bindings = new ArrayList<>();
+    JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding();
+    jndiBinding.setJndiName("name");
+    bindings.add(jndiBinding);
+    doReturn(bindings).when(cacheConfig).getJndiBindings();
+
     Set<DistributedMember> members = new HashSet<>();
     members.add(mock(DistributedMember.class));
 
@@ -174,12 +191,14 @@ public class DestroyJndiBindingCommandTest {
 
     doReturn(members).when(command).findMembers(any(), any());
     doReturn(results).when(command).executeAndGetFunctionResult(any(), any(), any());
-    doNothing().when(ccService).updateCacheConfig(any(), any());
 
     gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess()
         .tableHasColumnOnlyWithValues("Member", "server1")
         .tableHasColumnOnlyWithValues("Status", "Jndi binding \"name\" destroyed on \"server1\"");
 
+    assertThat(cacheConfig.getJndiBindings().isEmpty()).isTrue();
+    verify(command).updateClusterConfig(eq("cluster"), eq(cacheConfig), any());
+
     ArgumentCaptor<CreateJndiBindingFunction> function =
         ArgumentCaptor.forClass(CreateJndiBindingFunction.class);
     ArgumentCaptor<String> jndiName = ArgumentCaptor.forClass(String.class);
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommandDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommandDUnitTest.java
index 7fa50ea..90cc096 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommandDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListJndiBindingCommandDUnitTest.java
@@ -72,8 +72,8 @@ public class ListJndiBindingCommandDUnitTest {
         .tableHasRowCount("Group Name", 1);
 
     // member table
-    List<String> jndiNames =
-        commandResultAssert.getCommandResult().getColumnFromTableContent("JNDI Name", "0",
"1");
+    List<String> jndiNames = commandResultAssert.getCommandResult()
+        .getColumnFromTableContent("JNDI Name", "memberConfiguration");
     assertThat(jndiNames.size()).isEqualTo(3);
     assertThat(jndiNames).containsExactlyInAnyOrder("java:jndi1", "java:UserTransaction",
         "java:TransactionManager");

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

Mime
View raw message