You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sa...@apache.org on 2018/03/13 23:44:47 UTC
[geode] branch develop updated: GEODE-4384: gfsh command to destroy
jndi binding (#1588)
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 2f2a73c GEODE-4384: gfsh command to destroy jndi binding (#1588)
2f2a73c is described below
commit 2f2a73cdd26c83d70fe201681e1642b508124489
Author: Sai Boorlagadda <sa...@gmail.com>
AuthorDate: Tue Mar 13 16:44:44 2018 -0700
GEODE-4384: gfsh command to destroy jndi binding (#1588)
support for --if-exists option
---
.../cli/commands/CreateJndiBindingCommand.java | 2 +-
.../cli/commands/DestroyJndiBindingCommand.java | 12 ++++++--
.../commands/DestroyJndiBindingCommandTest.java | 32 +++++++++++++++++++++-
3 files changed, 41 insertions(+), 5 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 39dd6e3..bccff97 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
@@ -100,7 +100,7 @@ public class CreateJndiBindingCommand extends GfshCommand {
static final String XA_DATASOURCE_CLASS__HELP =
"The fully qualified name of the javax.sql.XADataSource implementation class.";
static final String IFNOTEXISTS__HELP =
- "Skip the create operation when a Jndi binding with the same name already exists. The default is to overwrite the entry (false).";
+ "Skip the create operation when a jndi binding with the same name already exists. Without specifying this option, this command execution results into an error.";
static final String DATASOURCE_CONFIG_PROPERTIES = "datasource-config-properties";
static final String DATASOURCE_CONFIG_PROPERTIES_HELP =
"Properties for the custom XSDataSource driver. Append json string containing (name, type, value) to set any property. Eg: --datasource-config-properties={'name':'name1','type':'type1','value':'value1'},{'name':'name2','type':'type2','value':'value2'}";
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 21cdeef..ab9b8b7 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
@@ -34,6 +34,7 @@ import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.Result;
+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;
@@ -49,13 +50,17 @@ public class DestroyJndiBindingCommand extends GfshCommand {
"Destroy a jndi binding that holds the configuration for the XA datasource.";
static final String JNDI_NAME = "name";
static final String JNDI_NAME__HELP = "Name of the binding to be destroyed.";
+ static final String IFEXISTS_HELP =
+ "Skip the destroy operation when a jndi binding with the same name does not exists. Without specifying this option, this command execution results into an error.";
@CliCommand(value = CREATE_JNDIBINDING, help = CREATE_JNDIBINDING__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
operation = ResourcePermission.Operation.MANAGE)
public Result destroyJDNIBinding(
- @CliOption(key = JNDI_NAME, mandatory = true, help = JNDI_NAME__HELP) String jndiName)
+ @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)
throws IOException, SAXException, ParserConfigurationException, TransformerException {
Result result;
@@ -65,8 +70,9 @@ public class DestroyJndiBindingCommand extends GfshCommand {
Element existingBinding =
service.getXmlElement("cluster", "jndi-binding", "jndi-name", jndiName);
if (existingBinding == null) {
- return ResultBuilder.createUserErrorResult(
- CliStrings.format("Jndi binding with jndi-name \"{0}\" does not exist.", jndiName));
+ throw new EntityNotFoundException(
+ CliStrings.format("Jndi binding with jndi-name \"{0}\" does not exist.", jndiName),
+ ifExists);
}
removeJndiBindingFromXml(jndiName);
persisted = true;
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 0538e62..faae121 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
@@ -83,7 +83,7 @@ public class DestroyJndiBindingCommandTest {
}
@Test
- public void returnsErrorIfNoBindingExistsWithGivenName()
+ public void returnsErrorIfBindingDoesNotExistAndIfExistsUnspecified()
throws ParserConfigurationException, SAXException, IOException {
ClusterConfigurationService clusterConfigService = mock(ClusterConfigurationService.class);
doReturn(clusterConfigService).when(command).getSharedConfiguration();
@@ -93,6 +93,36 @@ public class DestroyJndiBindingCommandTest {
}
@Test
+ public void skipsIfBindingDoesNotExistAndIfExistsSpecified()
+ throws ParserConfigurationException, SAXException, IOException {
+ ClusterConfigurationService clusterConfigService = mock(ClusterConfigurationService.class);
+ doReturn(clusterConfigService).when(command).getSharedConfiguration();
+ doReturn(null).when(clusterConfigService).getXmlElement(any(), any(), any(), any());
+ gfsh.executeAndAssertThat(command, COMMAND + " --name=name --if-exists").statusIsSuccess()
+ .containsOutput("does not exist.");
+ }
+
+ @Test
+ public void skipsIfBindingDoesNotExistAndIfExistsSpecifiedTrue()
+ throws ParserConfigurationException, SAXException, IOException {
+ ClusterConfigurationService clusterConfigService = mock(ClusterConfigurationService.class);
+ doReturn(clusterConfigService).when(command).getSharedConfiguration();
+ doReturn(null).when(clusterConfigService).getXmlElement(any(), any(), any(), any());
+ gfsh.executeAndAssertThat(command, COMMAND + " --name=name --if-exists=true").statusIsSuccess()
+ .containsOutput("does not exist.");
+ }
+
+ @Test
+ public void returnsErrorIfBindingDoesNotExistAndIfExistsSpecifiedFalse()
+ throws ParserConfigurationException, SAXException, IOException {
+ ClusterConfigurationService clusterConfigService = mock(ClusterConfigurationService.class);
+ doReturn(clusterConfigService).when(command).getSharedConfiguration();
+ doReturn(null).when(clusterConfigService).getXmlElement(any(), any(), any(), any());
+ gfsh.executeAndAssertThat(command, COMMAND + " --name=name --if-exists=false").statusIsError()
+ .containsOutput("does not exist.");
+ }
+
+ @Test
public void removeJndiBindingFromXmlShouldRemoveBindingFromClusterConfiguration()
throws IOException, ParserConfigurationException, SAXException, TransformerException {
ClusterConfigurationService clusterConfigService = mock(ClusterConfigurationService.class);
--
To stop receiving notification emails like this one, please contact
sai_boorlagadda@apache.org.