curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [6/8] git commit: working on moving to Dropwizard's config and logging
Date Wed, 28 May 2014 17:33:56 GMT
working on moving to Dropwizard's config and logging


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/078d7bec
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/078d7bec
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/078d7bec

Branch: refs/heads/curator-rpc
Commit: 078d7becd84015f579cf4ac898c3de567e292efa
Parents: 59b78a9
Author: randgalt <randgalt@apache.org>
Authored: Wed May 28 10:53:49 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Wed May 28 10:53:54 2014 -0500

----------------------------------------------------------------------
 curator-x-rpc/pom.xml                           | 14 +++--
 .../curator/x/rpc/CuratorProjectionServer.java  | 10 ----
 .../rpc/configuration/ConfigurationBuilder.java | 60 ++++++++++++++++++++
 .../x/rpc/configuration/ConfigurationX.java     | 54 ++++++++++++++++++
 .../configuration/TestConfigurationBuilder.java | 46 +++++++++++++++
 .../test/resources/configuration/logging.json   | 19 +++++++
 .../test/resources/configuration/simple.json    |  7 +++
 pom.xml                                         | 14 +++--
 8 files changed, 206 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/curator-x-rpc/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rpc/pom.xml b/curator-x-rpc/pom.xml
index b0534c8..6aeaa94 100644
--- a/curator-x-rpc/pom.xml
+++ b/curator-x-rpc/pom.xml
@@ -33,16 +33,22 @@
         <dependency>
             <groupId>com.facebook.swift</groupId>
             <artifactId>swift-service</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.fasterxml.jackson.core</groupId>
+                    <artifactId>jackson-annotations</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
-            <groupId>io.airlift</groupId>
-            <artifactId>log-manager</artifactId>
+            <groupId>io.dropwizard</groupId>
+            <artifactId>dropwizard-configuration</artifactId>
         </dependency>
 
         <dependency>
-            <groupId>org.codehaus.jackson</groupId>
-            <artifactId>jackson-mapper-asl</artifactId>
+            <groupId>io.dropwizard</groupId>
+            <artifactId>dropwizard-logging</artifactId>
         </dependency>
 
         <dependency>

http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
index bf92cde..40e543f 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
@@ -28,8 +28,6 @@ import com.google.common.collect.Maps;
 import io.airlift.configuration.ConfigurationFactory;
 import io.airlift.configuration.ConfigurationLoader;
 import io.airlift.configuration.ConfigurationMetadata;
-import io.airlift.log.Logging;
-import io.airlift.log.LoggingConfiguration;
 import io.airlift.units.DataSize;
 import io.airlift.units.Duration;
 import org.apache.curator.x.rpc.configuration.Configuration;
@@ -79,7 +77,6 @@ public class CuratorProjectionServer
         }
 
         ConfigurationFactory configurationFactory = new ConfigurationFactory(options);
-        initLogging(configurationFactory);
 
         Configuration configuration = configurationFactory.build(Configuration.class);
 
@@ -98,12 +95,6 @@ public class CuratorProjectionServer
         Runtime.getRuntime().addShutdownHook(hook);
     }
 
-    private static void initLogging(ConfigurationFactory configurationFactory) throws IOException
-    {
-        LoggingConfiguration loggingConfiguration = configurationFactory.build(LoggingConfiguration.class);
-        Logging.initialize().configure(loggingConfiguration);
-    }
-
     public CuratorProjectionServer(Configuration configuration)
     {
         this.configuration = configuration;
@@ -149,7 +140,6 @@ public class CuratorProjectionServer
         Map<String, String> valuesMap = Maps.newTreeMap();
 
         buildMetaData(valuesMap, ConfigurationMetadata.getConfigurationMetadata(Configuration.class));
-        buildMetaData(valuesMap, ConfigurationMetadata.getConfigurationMetadata(LoggingConfiguration.class));
 
         System.out.println("Values:");
         for ( String s : valuesMap.values() )

http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
new file mode 100644
index 0000000..f8f5760
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
@@ -0,0 +1,60 @@
+package org.apache.curator.x.rpc.configuration;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
+import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver;
+import io.dropwizard.configuration.ConfigurationException;
+import io.dropwizard.configuration.ConfigurationFactory;
+import io.dropwizard.configuration.ConfigurationFactoryFactory;
+import io.dropwizard.configuration.ConfigurationSourceProvider;
+import io.dropwizard.configuration.DefaultConfigurationFactoryFactory;
+import io.dropwizard.jackson.AnnotationSensitivePropertyNamingStrategy;
+import io.dropwizard.jackson.LogbackModule;
+import io.dropwizard.logging.ConsoleAppenderFactory;
+import io.dropwizard.logging.FileAppenderFactory;
+import io.dropwizard.logging.LoggingFactory;
+import io.dropwizard.logging.SyslogAppenderFactory;
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+class ConfigurationBuilder
+{
+    private final String configurationSource;
+
+    static
+    {
+        LoggingFactory.bootstrap();
+    }
+
+    ConfigurationBuilder(String configurationSource)
+    {
+        this.configurationSource = configurationSource;
+    }
+
+    ConfigurationX build() throws IOException, ConfigurationException
+    {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.registerModule(new LogbackModule());
+        mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
+        SubtypeResolver subtypeResolver = new StdSubtypeResolver();
+        subtypeResolver.registerSubtypes(ConsoleAppenderFactory.class, FileAppenderFactory.class,
SyslogAppenderFactory.class);
+        mapper.setSubtypeResolver(subtypeResolver);
+
+        ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
+        ConfigurationFactoryFactory<ConfigurationX> factoryFactory = new DefaultConfigurationFactoryFactory<ConfigurationX>();
+        ConfigurationFactory<ConfigurationX> configurationFactory = factoryFactory.create(ConfigurationX.class,
validatorFactory.getValidator(), mapper, "curator");
+        ConfigurationSourceProvider provider = new ConfigurationSourceProvider()
+        {
+            @Override
+            public InputStream open(String path) throws IOException
+            {
+                return new ByteArrayInputStream(configurationSource.getBytes(Charset.defaultCharset()));
+            }
+        };
+        return configurationFactory.build(provider, "");
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
new file mode 100644
index 0000000..e9be8e1
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
@@ -0,0 +1,54 @@
+package org.apache.curator.x.rpc.configuration;
+
+import com.facebook.swift.service.ThriftServerConfig;
+import io.airlift.units.Duration;
+import io.dropwizard.logging.LoggingFactory;
+import java.util.concurrent.TimeUnit;
+
+public class ConfigurationX
+{
+    private ThriftServerConfig thrift = new ThriftServerConfig();
+    private LoggingFactory logging = new LoggingFactory();
+    private Duration projectionExpiration = new Duration(3, TimeUnit.MINUTES);
+    private Duration pingTime = new Duration(5, TimeUnit.SECONDS);
+
+    public LoggingFactory getLogging()
+    {
+        return logging;
+    }
+
+    public void setLogging(LoggingFactory logging)
+    {
+        this.logging = logging;
+    }
+
+    public ThriftServerConfig getThrift()
+    {
+        return thrift;
+    }
+
+    public void setThrift(ThriftServerConfig thrift)
+    {
+        this.thrift = thrift;
+    }
+
+    public Duration getProjectionExpiration()
+    {
+        return projectionExpiration;
+    }
+
+    public void setProjectionExpiration(Duration projectionExpiration)
+    {
+        this.projectionExpiration = projectionExpiration;
+    }
+
+    public Duration getPingTime()
+    {
+        return pingTime;
+    }
+
+    public void setPingTime(Duration pingTime)
+    {
+        this.pingTime = pingTime;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
b/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
new file mode 100644
index 0000000..caf5af3
--- /dev/null
+++ b/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
@@ -0,0 +1,46 @@
+package org.apache.curator.x.rpc.configuration;
+
+import ch.qos.logback.classic.Level;
+import com.google.common.collect.Sets;
+import com.google.common.io.Resources;
+import io.airlift.units.Duration;
+import io.dropwizard.logging.AppenderFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+public class TestConfigurationBuilder
+{
+    @Test
+    public void testSimple() throws Exception
+    {
+        ConfigurationX configuration = loadTestConfiguration("configuration/simple.json");
+        Assert.assertEquals(configuration.getThrift().getPort(), 1234);
+        Assert.assertEquals(configuration.getPingTime(), new Duration(10, TimeUnit.SECONDS));
+    }
+
+    @Test
+    public void testLogging() throws Exception
+    {
+        ConfigurationX configuration = loadTestConfiguration("configuration/logging.json");
+        Assert.assertEquals(configuration.getLogging().getLevel(), Level.INFO);
+        Assert.assertEquals(configuration.getLogging().getAppenders().size(), 2);
+
+        Set<String> types = Sets.newHashSet();
+        for ( AppenderFactory appenderFactory : configuration.getLogging().getAppenders()
)
+        {
+            types.add(appenderFactory.getClass().getSimpleName());
+        }
+        Assert.assertEquals(types, Sets.newHashSet("FileAppenderFactory", "ConsoleAppenderFactory"));
+    }
+
+    private ConfigurationX loadTestConfiguration(String name) throws Exception
+    {
+        URL resource = Resources.getResource(name);
+        String source = Resources.toString(resource, Charset.defaultCharset());
+        return new ConfigurationBuilder(source).build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/curator-x-rpc/src/test/resources/configuration/logging.json
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/resources/configuration/logging.json b/curator-x-rpc/src/test/resources/configuration/logging.json
new file mode 100644
index 0000000..970ef20
--- /dev/null
+++ b/curator-x-rpc/src/test/resources/configuration/logging.json
@@ -0,0 +1,19 @@
+{
+    "logging": {
+        "level": "INFO",
+
+        "appenders": [
+            {
+                "type": "file",
+                "currentLogFilename": "logs/foo.log",
+                "archivedLogFilenamePattern": "logs/foo-%d.log.gz",
+                "archivedFileCount": 10,
+                "timeZone": "UTC"
+            },
+
+            {
+                "type": "console"
+            }
+        ]
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/curator-x-rpc/src/test/resources/configuration/simple.json
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/resources/configuration/simple.json b/curator-x-rpc/src/test/resources/configuration/simple.json
new file mode 100644
index 0000000..ccb2925
--- /dev/null
+++ b/curator-x-rpc/src/test/resources/configuration/simple.json
@@ -0,0 +1,7 @@
+{
+    "thrift": {
+        "port": 1234
+    },
+
+    "pingTime": "10s"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/curator/blob/078d7bec/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c028839..137155b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,7 +85,7 @@
         <guava-version>16.0.1</guava-version>
         <testng-version>6.8.8</testng-version>
         <swift-version>0.12.0</swift-version>
-        <airlift-version>0.88</airlift-version>
+        <dropwizard-version>0.7.0</dropwizard-version>
 
         <!-- OSGi Properties -->
         <osgi.export.package />
@@ -433,9 +433,15 @@
             </dependency>
 
             <dependency>
-                <groupId>io.airlift</groupId>
-                <artifactId>log-manager</artifactId>
-                <version>${airlift-version}</version>
+                <groupId>io.dropwizard</groupId>
+                <artifactId>dropwizard-configuration</artifactId>
+                <version>${dropwizard-version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>io.dropwizard</groupId>
+                <artifactId>dropwizard-logging</artifactId>
+                <version>${dropwizard-version}</version>
             </dependency>
         </dependencies>
     </dependencyManagement>


Mime
View raw message