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/03/22 16:31:47 UTC
[geode] branch develop updated: GEODE-4386: Add gfsh command to
describe jndi-binding (#1653)
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 d23c6d1 GEODE-4386: Add gfsh command to describe jndi-binding (#1653)
d23c6d1 is described below
commit d23c6d1c40a3998ebbd36a2a55edf2820493f33d
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Thu Mar 22 09:31:44 2018 -0700
GEODE-4386: Add gfsh command to describe jndi-binding (#1653)
---
.../cache/configuration/JndiBindingsType.java | 12 +-
.../cli/commands/DescribeJndiBindingCommand.java | 102 +++++++++++++++
.../sanctioned-geode-core-serializables.txt | 1 +
.../internal/cli/GfshParserAutoCompletionTest.java | 8 +-
.../DescribeJndiBindingCommandDUnitTest.java | 140 +++++++++++++++++++++
.../ManagedConnectionFactoryForTesting.java | 58 +++++++++
6 files changed, 316 insertions(+), 5 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/cache/configuration/JndiBindingsType.java b/geode-core/src/main/java/org/apache/geode/cache/configuration/JndiBindingsType.java
index 8c65c28..e677d57 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/configuration/JndiBindingsType.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/configuration/JndiBindingsType.java
@@ -659,7 +659,7 @@ public class JndiBindingsType {
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "",
propOrder = {"configPropertyName", "configPropertyType", "configPropertyValue"})
- public static class ConfigProperty {
+ public static class ConfigProperty implements CacheElement {
@XmlElement(name = "config-property-name", namespace = "http://geode.apache.org/schema/cache",
required = true)
@@ -680,6 +680,16 @@ public class JndiBindingsType {
}
/**
+ * Get the id of the element. The id is the same as the name.
+ *
+ * @return the id of the element
+ */
+ @Override
+ public String getId() {
+ return getName();
+ }
+
+ /**
* Gets the value of the configPropertyName property.
*
* @return
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
new file mode 100644
index 0000000..b7d860f
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
@@ -0,0 +1,102 @@
+/*
+ * 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.management.internal.cli.commands;
+
+import java.util.List;
+
+import org.apache.logging.log4j.Logger;
+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.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.Result;
+import org.apache.geode.management.internal.cli.functions.ListJndiBindingFunction;
+import org.apache.geode.management.internal.cli.result.ResultBuilder;
+import org.apache.geode.management.internal.cli.result.TabularResultData;
+import org.apache.geode.management.internal.security.ResourceOperation;
+import org.apache.geode.security.ResourcePermission;
+
+public class DescribeJndiBindingCommand extends GfshCommand {
+ private static final Logger logger = LogService.getLogger();
+
+ private 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.";
+ private static final Function LIST_BINDING_FUNCTION = new ListJndiBindingFunction();
+
+ @CliCommand(value = DESCRIBE_JNDI_BINDING, help = DESCRIBE_JNDIBINDING__HELP)
+ @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
+ operation = ResourcePermission.Operation.READ)
+ public Result describeJndiBinding(@CliOption(key = "name", mandatory = true,
+ help = "Name of the binding to describe") String bindingName) {
+ Result result = null;
+ TabularResultData tabularData = ResultBuilder.createTabularResultData();
+
+ InternalClusterConfigurationService ccService = getSharedConfiguration();
+ if (ccService != null) {
+ CacheConfig cacheConfig = ccService.getCacheConfig("cluster");
+ List<JndiBindingsType.JndiBinding> jndiBindings = cacheConfig.getJndiBindings();
+ for (JndiBindingsType.JndiBinding binding : jndiBindings) {
+ if (binding.getJndiName().equals(bindingName)
+ || binding.getJndiName().equals("java:" + bindingName)) {
+ addTableRow(tabularData, "type", binding.getType());
+ addTableRow(tabularData, "jndi-name", binding.getJndiName());
+ addTableRow(tabularData, "jdbc-driver-class", binding.getJdbcDriverClass());
+ addTableRow(tabularData, "user-name", binding.getUserName());
+ addTableRow(tabularData, "connection-url", binding.getConnectionUrl());
+
+ if (!"SimpleDataSource".equals(binding.getType())) {
+ if ("ManagedDataSource".equals(binding.getType())) {
+ addTableRow(tabularData, "managed-conn-factory-class",
+ binding.getManagedConnFactoryClass());
+ } else if ("PooledDataSource".equals(binding.getType())) {
+ addTableRow(tabularData, "conn-pooled-datasource-class",
+ binding.getConnPooledDatasourceClass());
+ } else if ("XAPooledDataSource".equals(binding.getType())) {
+ addTableRow(tabularData, "xa-datasource-class", binding.getXaDatasourceClass());
+ }
+
+ addTableRow(tabularData, "init-pool-size", binding.getInitPoolSize());
+ addTableRow(tabularData, "max-pool-size", binding.getMaxPoolSize());
+ addTableRow(tabularData, "idle-timeout-seconds", binding.getIdleTimeoutSeconds());
+ addTableRow(tabularData, "blocking-timeout-seconds",
+ binding.getBlockingTimeoutSeconds());
+ addTableRow(tabularData, "login-timeout-seconds", binding.getLoginTimeoutSeconds());
+ }
+
+ for (JndiBindingsType.JndiBinding.ConfigProperty confProp : binding.getConfigProperty()) {
+ addTableRow(tabularData, confProp.getName(), confProp.getValue());
+ }
+
+ break;
+ }
+ }
+ }
+
+ result = ResultBuilder.buildResult(tabularData);
+
+ return result;
+ }
+
+ private void addTableRow(TabularResultData table, String property, String value) {
+ table.accumulate("Property", property);
+ table.accumulate("Value", value != null ? value : "");
+ }
+}
diff --git a/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt b/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt
index 52c3d49..d296f77 100644
--- a/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt
+++ b/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt
@@ -123,6 +123,7 @@ org/apache/geode/cache/client/internal/pooling/ConnectionDestroyedException,true
org/apache/geode/cache/configuration/EnumActionDestroyOverflow,false,value:java/lang/String
org/apache/geode/cache/configuration/EnumReadableWritable,false,value:java/lang/String
org/apache/geode/cache/configuration/JndiBindingsType$JndiBinding,false,blockingTimeoutSeconds:java/lang/String,configProperty:java/util/List,connPooledDatasourceClass:java/lang/String,connectionUrl:java/lang/String,idleTimeoutSeconds:java/lang/String,initPoolSize:java/lang/String,jdbcDriverClass:java/lang/String,jndiName:java/lang/String,loginTimeoutSeconds:java/lang/String,managedConnFactoryClass:java/lang/String,maxPoolSize:java/lang/String,password:java/lang/String,transactionType:ja [...]
+org/apache/geode/cache/configuration/JndiBindingsType$JndiBinding$ConfigProperty,false,configPropertyName:java/lang/String,configPropertyType:java/lang/String,configPropertyValue:java/lang/String
org/apache/geode/cache/configuration/RegionAttributesDataPolicy,false,value:java/lang/String
org/apache/geode/cache/configuration/RegionAttributesIndexUpdateType,false,value:java/lang/String
org/apache/geode/cache/configuration/RegionAttributesMirrorType,false,value:java/lang/String
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
index 1462ac2..ec7ea8c 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
@@ -36,18 +36,18 @@ public class GfshParserAutoCompletionTest {
private GfshParserRule.CommandCandidate candidate;
@Test
- public void testCompletionDescibe() throws Exception {
+ public void testCompletionDescribe() throws Exception {
buffer = "describe";
candidate = parser.complete(buffer);
- assertThat(candidate.size()).isEqualTo(7);
+ assertThat(candidate.size()).isEqualTo(8);
assertThat(candidate.getFirstCandidate()).isEqualTo("describe client");
}
@Test
- public void testCompletionDescibeWithSpace() throws Exception {
+ public void testCompletionDescribeWithSpace() throws Exception {
buffer = "describe ";
candidate = parser.complete(buffer);
- assertThat(candidate.size()).isEqualTo(7);
+ assertThat(candidate.size()).isEqualTo(8);
assertThat(candidate.getFirstCandidate()).isEqualTo("describe client");
}
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
new file mode 100644
index 0000000..b15b08e
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandDUnitTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.management.internal.cli.commands;
+
+import java.util.Properties;
+
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+@Category(DistributedTest.class)
+public class DescribeJndiBindingCommandDUnitTest {
+
+ private static MemberVM locator, server;
+
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule();
+
+ @ClassRule
+ public static GfshCommandRule gfsh = new GfshCommandRule();
+
+ @BeforeClass
+ public static void before() throws Exception {
+ Properties props = new Properties();
+ // props.setProperty(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
+ // ListJndiBindingFunction.class.getName());
+
+ locator = cluster.startLocatorVM(0);
+ server = cluster.startServerVM(1, props, locator.getPort());
+
+ gfsh.connectAndVerify(locator);
+ }
+
+ @Test
+ public void describeJndiBindingForSimpleDataSource() {
+ gfsh.executeAndAssertThat(
+ "create jndi-binding --name=jndi-simple --type=SIMPLE --jdbc-driver-class=org.apache.derby.jdbc.EmbeddedDriver --connection-url=\"jdbc:derby:newDB;create=true\" --username=joe --datasource-config-properties={'name':'prop1','value':'value1'}")
+ .statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1");
+
+ gfsh.executeAndAssertThat("describe jndi-binding --name=jndi-simple").statusIsSuccess()
+ .tableHasRowWithValues("Property", "Value", "jndi-name", "jndi-simple")
+ .tableHasRowWithValues("Property", "Value", "type", "SimpleDataSource")
+ .tableHasRowWithValues("Property", "Value", "jdbc-driver-class",
+ "org.apache.derby.jdbc.EmbeddedDriver")
+ .tableHasRowWithValues("Property", "Value", "user-name", "joe").tableHasRowWithValues(
+ "Property", "Value", "connection-url", "jdbc:derby:newDB;create=true");
+ }
+
+ @Test
+ public void describeJndiBindingForManagedDataSource() {
+ gfsh.executeAndAssertThat(
+ "create jndi-binding --name=jndi-managed --type=MANAGED --jdbc-driver-class=org.apache.derby.jdbc.EmbeddedDriver --connection-url=\"jdbc:derby:newDB;create=true\" --init-pool-size=1 --max-pool-size=10 --idle-timeout-seconds=2 --blocking-timeout-seconds=11 --login-timeout-seconds=7 --datasource-config-properties={'name':'prop1','value':'value1','type':'java.lang.String'} --managed-conn-factory-class="
+ + ManagedConnectionFactoryForTesting.class.getName())
+ .statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1");
+
+ gfsh.executeAndAssertThat("describe jndi-binding --name=jndi-managed").statusIsSuccess()
+ .tableHasRowWithValues("Property", "Value", "jndi-name", "jndi-managed")
+ .tableHasRowWithValues("Property", "Value", "type", "ManagedDataSource")
+ .tableHasRowWithValues("Property", "Value", "jdbc-driver-class",
+ "org.apache.derby.jdbc.EmbeddedDriver")
+ .tableHasRowWithValues("Property", "Value", "user-name", "")
+ .tableHasRowWithValues("Property", "Value", "connection-url",
+ "jdbc:derby:newDB;create=true")
+ .tableHasRowWithValues("Property", "Value", "managed-conn-factory-class",
+ ManagedConnectionFactoryForTesting.class.getName())
+ .tableHasRowWithValues("Property", "Value", "init-pool-size", "1")
+ .tableHasRowWithValues("Property", "Value", "max-pool-size", "10")
+ .tableHasRowWithValues("Property", "Value", "idle-timeout-seconds", "2")
+ .tableHasRowWithValues("Property", "Value", "blocking-timeout-seconds", "11")
+ .tableHasRowWithValues("Property", "Value", "login-timeout-seconds", "7")
+ .tableHasRowWithValues("Property", "Value", "prop1", "value1");
+ }
+
+ @Test
+ public void describeJndiBindingForPooledDataSource() {
+ gfsh.executeAndAssertThat(
+ "create jndi-binding --name=jndi-pooled --type=POOLED --jdbc-driver-class=org.apache.derby.jdbc.EmbeddedDriver --connection-url=\"jdbc:derby:newDB;create=true\" --conn-pooled-datasource-class=org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource --init-pool-size=1 --max-pool-size=10 --idle-timeout-seconds=2 --blocking-timeout-seconds=11 --login-timeout-seconds=7 --datasource-config-properties={'name':'prop1','value':'value1','type':'java.lang.String'}")
+ .statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1");
+
+ gfsh.executeAndAssertThat("describe jndi-binding --name=jndi-pooled").statusIsSuccess()
+ .tableHasRowWithValues("Property", "Value", "jndi-name", "jndi-pooled")
+ .tableHasRowWithValues("Property", "Value", "type", "PooledDataSource")
+ .tableHasRowWithValues("Property", "Value", "jdbc-driver-class",
+ "org.apache.derby.jdbc.EmbeddedDriver")
+ .tableHasRowWithValues("Property", "Value", "user-name", "")
+ .tableHasRowWithValues("Property", "Value", "connection-url",
+ "jdbc:derby:newDB;create=true")
+ .tableHasRowWithValues("Property", "Value", "conn-pooled-datasource-class",
+ "org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource")
+ .tableHasRowWithValues("Property", "Value", "init-pool-size", "1")
+ .tableHasRowWithValues("Property", "Value", "max-pool-size", "10")
+ .tableHasRowWithValues("Property", "Value", "idle-timeout-seconds", "2")
+ .tableHasRowWithValues("Property", "Value", "blocking-timeout-seconds", "11")
+ .tableHasRowWithValues("Property", "Value", "login-timeout-seconds", "7")
+ .tableHasRowWithValues("Property", "Value", "prop1", "value1");
+ }
+
+ @Test
+ public void describeJndiBindingForXAPooledDataSource() {
+ gfsh.executeAndAssertThat(
+ "create jndi-binding --name=jndi-xapooled --type=XAPOOLED --jdbc-driver-class=org.apache.derby.jdbc.EmbeddedDriver --connection-url=\"jdbc:derby:newDB;create=true\" --xa-datasource-class=org.apache.derby.jdbc.EmbeddedXADataSource --init-pool-size=1 --max-pool-size=10 --idle-timeout-seconds=2 --blocking-timeout-seconds=11 --login-timeout-seconds=7 --datasource-config-properties={'name':'prop1','value':'value1','type':'java.lang.String'}")
+ .statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1");
+
+ gfsh.executeAndAssertThat("describe jndi-binding --name=jndi-xapooled").statusIsSuccess()
+ .tableHasRowWithValues("Property", "Value", "jndi-name", "jndi-xapooled")
+ .tableHasRowWithValues("Property", "Value", "type", "XAPooledDataSource")
+ .tableHasRowWithValues("Property", "Value", "jdbc-driver-class",
+ "org.apache.derby.jdbc.EmbeddedDriver")
+ .tableHasRowWithValues("Property", "Value", "user-name", "")
+ .tableHasRowWithValues("Property", "Value", "connection-url",
+ "jdbc:derby:newDB;create=true")
+ .tableHasRowWithValues("Property", "Value", "xa-datasource-class",
+ "org.apache.derby.jdbc.EmbeddedXADataSource")
+ .tableHasRowWithValues("Property", "Value", "init-pool-size", "1")
+ .tableHasRowWithValues("Property", "Value", "max-pool-size", "10")
+ .tableHasRowWithValues("Property", "Value", "idle-timeout-seconds", "2")
+ .tableHasRowWithValues("Property", "Value", "blocking-timeout-seconds", "11")
+ .tableHasRowWithValues("Property", "Value", "login-timeout-seconds", "7")
+ .tableHasRowWithValues("Property", "Value", "prop1", "value1");
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ManagedConnectionFactoryForTesting.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ManagedConnectionFactoryForTesting.java
new file mode 100644
index 0000000..916b3da
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ManagedConnectionFactoryForTesting.java
@@ -0,0 +1,58 @@
+/*
+ * 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.management.internal.cli.commands;
+
+import java.io.PrintWriter;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+public class ManagedConnectionFactoryForTesting implements ManagedConnectionFactory {
+ @Override
+ public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {
+ return null;
+ }
+
+ @Override
+ public Object createConnectionFactory() throws ResourceException {
+ return null;
+ }
+
+ @Override
+ public ManagedConnection createManagedConnection(Subject subject,
+ ConnectionRequestInfo cxRequestInfo) throws ResourceException {
+ return null;
+ }
+
+ @Override
+ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject,
+ ConnectionRequestInfo cxRequestInfo) throws ResourceException {
+ return null;
+ }
+
+ @Override
+ public void setLogWriter(PrintWriter out) throws ResourceException {}
+
+ @Override
+ public PrintWriter getLogWriter() throws ResourceException {
+ return null;
+ }
+}
--
To stop receiving notification emails like this one, please contact
jensdeppe@apache.org.