You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2017/05/03 09:48:08 UTC

[5/5] deltaspike git commit: DELTASPIKE-1245 add ConfigEntry listing

DELTASPIKE-1245 add ConfigEntry listing


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/5c04cec3
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/5c04cec3
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/5c04cec3

Branch: refs/heads/master
Commit: 5c04cec3b4c381f78a5de9888ab81f7f0c701ed9
Parents: 0a033b2
Author: Mark Struberg <st...@apache.org>
Authored: Wed May 3 11:13:15 2017 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Wed May 3 11:13:15 2017 +0200

----------------------------------------------------------------------
 .../impl/config/ConfigurationExtension.java     |   6 +
 .../core/impl/config/DeltaSpikeConfigInfo.java  | 198 ++++++++++++++++++-
 .../impl/config/DeltaSpikeConfigInfoMBean.java  |  11 +-
 .../core/api/config/SecretTestConfigFilter.java |   2 +-
 .../test/core/impl/future/FutureableTest.java   |  18 +-
 .../core/impl/jmx/SimpleRegistrationTest.java   |   6 +-
 6 files changed, 222 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5c04cec3/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
index 1a14c18..d6e5223 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
@@ -33,6 +33,7 @@ import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.enterprise.inject.spi.ProcessBean;
+import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -127,6 +128,11 @@ public class ConfigurationExtension implements Extension, Deactivatable
                 ObjectName name = new ObjectName("deltaspike.config." + appName + ":type=DeltaSpikeConfig");
                 mBeanServer.registerMBean(cfgMBean, name);
             }
+            catch (InstanceAlreadyExistsException iae)
+            {
+                // all fine, the CfgBean got already registered.
+                // Most probably by the ServletConfigListener
+            }
             catch (Exception e)
             {
                 throw new RuntimeException(e);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5c04cec3/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfo.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfo.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfo.java
index 87f4b52..286806b 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfo.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfo.java
@@ -18,11 +18,21 @@
  */
 package org.apache.deltaspike.core.impl.config;
 
-import org.apache.deltaspike.core.api.config.ConfigResolver;
-import org.apache.deltaspike.core.spi.config.ConfigSource;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+
+import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.core.spi.config.ConfigSource;
 
 /**
  * JMX MBean for DeltaSpike
@@ -37,22 +47,138 @@ public class DeltaSpikeConfigInfo implements DeltaSpikeConfigInfoMBean
     }
 
     @Override
-    public List<String> getConfigSources()
+    public String[] getConfigSourcesAsString()
     {
         ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
         try
         {
             Thread.currentThread().setContextClassLoader(appConfigClassLoader);
+
+            ConfigSource[] configSources = ConfigResolver.getConfigSources();
             List<String> configSourceInfo = new ArrayList<String>();
+            for (ConfigSource configSource : configSources)
+            {
+                configSourceInfo.add(Integer.toString(configSource.getOrdinal())
+                    + " - " + configSource.getConfigName());
+            }
+
+            return configSourceInfo.toArray(new String[configSourceInfo.size()]);
+        }
+        finally
+        {
+            // set back the original TCCL
+            Thread.currentThread().setContextClassLoader(originalCl);
+        }
+
+    }
+
+    @Override
+    public String[] getConfigEntriesAsString()
+    {
+        ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader(appConfigClassLoader);
+
+            List<ConfigEntry> configEntries = calculateConfigEntries();
+
+            String[] configArray = new String[configEntries.size()];
+
+            for (int i = 0 ; i < configEntries.size(); i++)
+            {
+                ConfigEntry configEntry = configEntries.get(i);
+                configArray[i] = configEntry.getKey() + " = " + configEntry.getValue()
+                    + " - picked up from: " + configEntry.getFromConfigSource();
+            }
+
+            return configArray;
+
+        }
+        finally
+        {
+            // set back the original TCCL
+            Thread.currentThread().setContextClassLoader(originalCl);
+        }
+    }
+
+    @Override
+    public TabularData getConfigEntries()
+    {
+        ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader(appConfigClassLoader);
+
+            List<ConfigEntry> configEntries = calculateConfigEntries();
+
+            String[] configArray = new String[configEntries.size()];
+
+            for (int i = 0 ; i < configEntries.size(); i++)
+            {
+                ConfigEntry configEntry = configEntries.get(i);
+                configArray[i] = configEntry.getKey() + " = " + configEntry.getValue()
+                    + " - picked up from: " + configEntry.getFromConfigSource();
+            }
+
+            String typeName = "ConfigEntries";
+            OpenType<?>[] types = new OpenType<?>[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING};
+            String[] keys = new String[]{"Key", "Value", "fromConfigSource"};
+
+            CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
+            TabularType type = new TabularType(typeName, typeName, ct, keys);
+            TabularDataSupport configEntryInfo = new TabularDataSupport(type);
+
+            ConfigSource[] configSources = ConfigResolver.getConfigSources();
+            for (ConfigEntry configEntry : configEntries)
+            {
+                configEntryInfo.put(
+                    new CompositeDataSupport(ct, keys,
+                        new Object[]{configEntry.getKey(), configEntry.getValue(), configEntry.getFromConfigSource()}));
+            }
+
+            return configEntryInfo;
+        }
+        catch (OpenDataException e)
+        {
+            throw new RuntimeException(e);
+        }
+        finally
+        {
+            // set back the original TCCL
+            Thread.currentThread().setContextClassLoader(originalCl);
+        }
+    }
+
+    @Override
+    public TabularData getConfigSources()
+    {
+        ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader(appConfigClassLoader);
+
+            String typeName = "ConfigSources";
+            OpenType<?>[] types = new OpenType<?>[]{SimpleType.INTEGER, SimpleType.STRING};
+            String[] keys = new String[]{"Ordinal", "ConfigSource"};
+
+            CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
+            TabularType type = new TabularType(typeName, typeName, ct, keys);
+            TabularDataSupport configSourceInfo = new TabularDataSupport(type);
+
             ConfigSource[] configSources = ConfigResolver.getConfigSources();
             for (ConfigSource configSource : configSources)
             {
-                configSourceInfo.add(Integer.toString(configSource.getOrdinal()) +
-                        " - " + configSource.getConfigName());
+                configSourceInfo.put(
+                    new CompositeDataSupport(ct, keys,
+                            new Object[]{configSource.getOrdinal(), configSource.getConfigName()}));
             }
 
             return configSourceInfo;
         }
+        catch (OpenDataException e)
+        {
+            throw new RuntimeException(e);
+        }
         finally
         {
             // set back the original TCCL
@@ -60,5 +186,67 @@ public class DeltaSpikeConfigInfo implements DeltaSpikeConfigInfoMBean
         }
     }
 
+    private List<ConfigEntry> calculateConfigEntries()
+    {
+        Map<String, String> allProperties = ConfigResolver.getAllProperties();
+        List<ConfigEntry> configEntries = new ArrayList<ConfigEntry>(allProperties.size());
+        ConfigSource[] configSources = ConfigResolver.getConfigSources();
+
+        for (Map.Entry<String, String> configEntry : allProperties.entrySet())
+        {
+            String key = configEntry.getKey();
+            String value = ConfigResolver.filterConfigValueForLog(key,
+                                    ConfigResolver.getProjectStageAwarePropertyValue(key));
+
+            String fromConfigSource = getFromConfigSource(configSources, key);
+            configEntries.add(new ConfigEntry(key, value, fromConfigSource));
+        }
+
+        return configEntries;
+    }
+
+    private String getFromConfigSource(ConfigSource[] configSources, String key)
+    {
+        for (ConfigSource configSource : configSources)
+        {
+            if (configSource.getPropertyValue(key) != null)
+            {
+                return configSource.getConfigName();
+            }
+        }
+
+        return null;
+    }
+
+
+
+    private class ConfigEntry
+    {
+        private final String key;
+        private final String value;
+        private final String fromConfigSource;
+
+        public ConfigEntry(String key, String value, String fromConfigSource)
+        {
+            this.key = key;
+            this.value = value;
+            this.fromConfigSource = fromConfigSource;
+        }
+
+        public String getKey()
+        {
+            return key;
+        }
+
+        public String getValue()
+        {
+            return value;
+        }
+
+        public String getFromConfigSource()
+        {
+            return fromConfigSource;
+        }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5c04cec3/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfoMBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfoMBean.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfoMBean.java
index 01335b8..d2d154f 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfoMBean.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/DeltaSpikeConfigInfoMBean.java
@@ -18,9 +18,16 @@
  */
 package org.apache.deltaspike.core.impl.config;
 
-import java.util.List;
+import javax.management.openmbean.TabularData;
 
 public interface DeltaSpikeConfigInfoMBean
 {
-    List<String> getConfigSources();
+    String[] getConfigSourcesAsString();
+
+    TabularData getConfigSources();
+
+    String[] getConfigEntriesAsString();
+
+    TabularData getConfigEntries();
+
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5c04cec3/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java
index da5c779..6d1e272 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/SecretTestConfigFilter.java
@@ -42,6 +42,6 @@ public class SecretTestConfigFilter implements ConfigFilter
         {
             return "**********";
         }
-        return null;
+        return value;
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5c04cec3/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/FutureableTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/FutureableTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/FutureableTest.java
index b3a006a..bbf2542 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/FutureableTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/future/FutureableTest.java
@@ -67,15 +67,15 @@ public class FutureableTest {
     @Test
     public void voidTest()
     {
-    	CountDownLatch latch = new CountDownLatch(1);
-    	service.thatSLong(1000, latch);
-    	try
-    	{
-    		if (!latch.await(2000, TimeUnit.MILLISECONDS)) {
-    			fail("Asynchronous call should have terminated");
-    		}
-    	}
-    	catch (final InterruptedException e)
+        CountDownLatch latch = new CountDownLatch(1);
+        service.thatSLong(1000, latch);
+        try
+        {
+            if (!latch.await(2000, TimeUnit.MILLISECONDS)) {
+                fail("Asynchronous call should have terminated");
+            }
+        }
+        catch (final InterruptedException e)
         {
             Thread.interrupted();
             fail();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5c04cec3/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/jmx/SimpleRegistrationTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/jmx/SimpleRegistrationTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/jmx/SimpleRegistrationTest.java
index 512d24c..c287192 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/jmx/SimpleRegistrationTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/jmx/SimpleRegistrationTest.java
@@ -22,6 +22,7 @@ import org.junit.Test;
 
 import javax.inject.Inject;
 import javax.management.Attribute;
+import javax.management.MBeanOperationInfo;
 import javax.management.MBeanParameterInfo;
 import javax.management.MBeanServer;
 import javax.management.Notification;
@@ -71,8 +72,9 @@ public abstract class SimpleRegistrationTest {
         myMBean.broadcast();
         assertEquals(1, notifications.size());
         assertEquals(10L, notifications.iterator().next().getSequenceNumber());
-        
-        MBeanParameterInfo parameterInfo = server.getMBeanInfo(on).getOperations()[0].getSignature()[0];
+
+        MBeanOperationInfo[] operations = server.getMBeanInfo(on).getOperations();
+        MBeanParameterInfo parameterInfo = operations[0].getSignature()[0];
         assertEquals("multiplier", parameterInfo.getName());
         assertEquals("the multiplier", parameterInfo.getDescription());