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

mck pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 78deb3e  Implement Virtual Table exposing Cassandra relevant system 
properties.
78deb3e is described below

commit 78deb3e6df31e81f1da40a09d7c40f3d4557ff75
Author: Mick Semb Wever <m...@apache.org>
AuthorDate: Mon Mar 2 14:15:47 2020 +0100

    Implement Virtual Table exposing Cassandra relevant system properties.
    
     patch by Mick Semb Wever; reviewed by Chris Lohfink for CASSANDRA-15616
---
 .../db/virtual/SystemPropertiesTable.java          | 111 +++++++++++++++++++++
 .../cassandra/db/virtual/SystemViewsKeyspace.java  |   1 +
 .../db/virtual/SystemPropertiesTableTest.java      |  85 ++++++++++++++++
 3 files changed, 197 insertions(+)

diff --git 
a/src/java/org/apache/cassandra/db/virtual/SystemPropertiesTable.java 
b/src/java/org/apache/cassandra/db/virtual/SystemPropertiesTable.java
new file mode 100644
index 0000000..864b11b
--- /dev/null
+++ b/src/java/org/apache/cassandra/db/virtual/SystemPropertiesTable.java
@@ -0,0 +1,111 @@
+/*
+ * 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.cassandra.db.virtual;
+
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+
+import org.apache.cassandra.config.Config;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.marshal.*;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.schema.TableMetadata;
+
+final class SystemPropertiesTable extends AbstractVirtualTable
+{
+    private static final String NAME = "name";
+    private static final String VALUE = "value";
+
+    private static final Set<String> CASSANDRA_RELEVANT_PROPERTIES = 
Sets.newHashSet(
+            // base jvm properties
+            "java.home",
+            "java.io.tmpdir",
+            "java.library.path",
+            "java.security.egd",
+            "java.version",
+            "java.vm.name",
+            "line.separator",
+            "os.arch",
+            "os.name",
+            "user.home",
+            "sun.arch.data.model",
+            // jmx properties
+            "java.rmi.server.hostname",
+            "com.sun.management.jmxremote.authenticate",
+            "com.sun.management.jmxremote.rmi.port",
+            "com.sun.management.jmxremote.ssl",
+            "com.sun.management.jmxremote.ssl.need.client.auth",
+            "com.sun.management.jmxremote.access.file",
+            "com.sun.management.jmxremote.password.file",
+            "com.sun.management.jmxremote.port",
+            "com.sun.management.jmxremote.ssl.enabled.protocols",
+            "com.sun.management.jmxremote.ssl.enabled.cipher.suites",
+            "mx4jaddress",
+            "mx4jport",
+            // cassandra properties (without the "cassandra." prefix)
+            "cassandra-foreground",
+            "cassandra-pidfile",
+            "default.provide.overlapping.tombstones",
+            "org.apache.cassandra.disable_mbean_registration"
+            );
+
+    SystemPropertiesTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, "system_properties")
+                           .comment("Cassandra relevant system properties")
+                           .kind(TableMetadata.Kind.VIRTUAL)
+                           .partitioner(new 
LocalPartitioner(UTF8Type.instance))
+                           .addPartitionKeyColumn(NAME, UTF8Type.instance)
+                           .addRegularColumn(VALUE, UTF8Type.instance)
+                           .build());
+    }
+
+    public DataSet data()
+    {
+        SimpleDataSet result = new SimpleDataSet(metadata());
+
+        System.getProperties().stringPropertyNames()
+                .stream()
+                .filter(SystemPropertiesTable::isCassandraRelevant)
+                .forEach(name -> addRow(result, name, 
System.getProperty(name)));
+
+        return result;
+    }
+
+    @Override
+    public DataSet data(DecoratedKey partitionKey)
+    {
+        SimpleDataSet result = new SimpleDataSet(metadata());
+        String name = UTF8Type.instance.compose(partitionKey.getKey());
+        if (isCassandraRelevant(name))
+            addRow(result, name, System.getProperty(name));
+
+        return result;
+    }
+
+    static boolean isCassandraRelevant(String name)
+    {
+        return name.startsWith(Config.PROPERTY_PREFIX) || 
CASSANDRA_RELEVANT_PROPERTIES.contains(name);
+    }
+
+    private static void addRow(SimpleDataSet result, String name, String value)
+    {
+        result.row(name).column(VALUE, value);
+    }
+}
diff --git a/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java 
b/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java
index abcdf87..0805fcf 100644
--- a/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java
+++ b/src/java/org/apache/cassandra/db/virtual/SystemViewsKeyspace.java
@@ -31,6 +31,7 @@ public final class SystemViewsKeyspace extends VirtualKeyspace
                     .add(new CachesTable(NAME))
                     .add(new ClientsTable(NAME))
                     .add(new SettingsTable(NAME))
+                    .add(new SystemPropertiesTable(NAME))
                     .add(new SSTableTasksTable(NAME))
                     .add(new ThreadPoolsTable(NAME))
                     .add(new InternodeOutboundTable(NAME))
diff --git 
a/test/unit/org/apache/cassandra/db/virtual/SystemPropertiesTableTest.java 
b/test/unit/org/apache/cassandra/db/virtual/SystemPropertiesTableTest.java
new file mode 100644
index 0000000..ef952e8
--- /dev/null
+++ b/test/unit/org/apache/cassandra/db/virtual/SystemPropertiesTableTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.cassandra.db.virtual;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import org.apache.cassandra.cql3.CQLTester;
+
+public class SystemPropertiesTableTest extends CQLTester
+{
+    private static final String KS_NAME = "vts";
+
+    private SystemPropertiesTable table;
+
+    @BeforeClass
+    public static void setUpClass()
+    {
+        CQLTester.setUpClass();
+    }
+
+    @Before
+    public void config()
+    {
+        table = new SystemPropertiesTable(KS_NAME);
+        VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, 
ImmutableList.of(table)));
+    }
+
+    @Test
+    public void testSelectAll() throws Throwable
+    {
+        ResultSet result = executeNet("SELECT * FROM vts.system_properties");
+
+        for (Row r : result)
+            Assert.assertEquals(System.getProperty(r.getString("name")), 
r.getString("value"));
+    }
+
+    @Test
+    public void testSelectPartition() throws Throwable
+    {
+        List<String> properties = System.getProperties()
+                                        .stringPropertyNames()
+                                        .stream()
+                                        .filter(name -> 
SystemPropertiesTable.isCassandraRelevant(name))
+                                        .collect(Collectors.toList());
+
+        for (String property : properties)
+        {
+            String q = "SELECT * FROM vts.system_properties WHERE name = '" + 
property + '\'';
+            assertRowsNet(executeNet(q), new Object[] {property, 
System.getProperty(property)});
+        }
+    }
+
+    @Test
+    public void testSelectEmpty() throws Throwable
+    {
+        String q = "SELECT * FROM vts.system_properties WHERE name = 'EMPTY'";
+        assertRowsNet(executeNet(q));
+    }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to