You are viewing a plain text version of this content. The canonical link for it is here.
Posted to s4-commits@incubator.apache.org by mm...@apache.org on 2013/01/18 15:57:13 UTC

git commit: Improve application and platform configuration - added missing files

Updated Branches:
  refs/heads/S4-59 d3b7c30ab -> 2ecb531f7


Improve application and platform configuration
- added missing files


Project: http://git-wip-us.apache.org/repos/asf/incubator-s4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s4/commit/2ecb531f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s4/tree/2ecb531f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s4/diff/2ecb531f

Branch: refs/heads/S4-59
Commit: 2ecb531f7a641ec7751299a721cc1004720a4c5f
Parents: d3b7c30
Author: Matthieu Morel <mm...@apache.org>
Authored: Fri Jan 18 16:50:27 2013 +0100
Committer: Matthieu Morel <mm...@apache.org>
Committed: Fri Jan 18 16:56:17 2013 +0100

----------------------------------------------------------------------
 .../src/main/resources/default.s4.base.properties  |    4 +
 test-apps/custom-modules/README.txt                |    1 +
 test-apps/custom-modules/build.gradle              |  116 ++++++++++++
 .../src/main/java/org/apache/s4/TestListener.java  |  136 +++++++++++++++
 .../java/org/apache/s4/TestListenerModule.java     |   14 ++
 5 files changed, 271 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/2ecb531f/subprojects/s4-base/src/main/resources/default.s4.base.properties
----------------------------------------------------------------------
diff --git a/subprojects/s4-base/src/main/resources/default.s4.base.properties b/subprojects/s4-base/src/main/resources/default.s4.base.properties
new file mode 100644
index 0000000..8acb17c
--- /dev/null
+++ b/subprojects/s4-base/src/main/resources/default.s4.base.properties
@@ -0,0 +1,4 @@
+# default properties for bootstraping a node
+s4.cluster.zk_address = localhost:2181
+s4.cluster.zk_session_timeout = 10000
+s4.cluster.zk_connection_timeout = 10000
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/2ecb531f/test-apps/custom-modules/README.txt
----------------------------------------------------------------------
diff --git a/test-apps/custom-modules/README.txt b/test-apps/custom-modules/README.txt
new file mode 100644
index 0000000..daa9e06
--- /dev/null
+++ b/test-apps/custom-modules/README.txt
@@ -0,0 +1 @@
+This project contains some custom modules used for testing independently from the project's classpath
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/2ecb531f/test-apps/custom-modules/build.gradle
----------------------------------------------------------------------
diff --git a/test-apps/custom-modules/build.gradle b/test-apps/custom-modules/build.gradle
new file mode 100644
index 0000000..e93c141
--- /dev/null
+++ b/test-apps/custom-modules/build.gradle
@@ -0,0 +1,116 @@
+/**
+ * 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.
+ */
+
+
+/**
+* Apache S4 Application Build File
+*
+* Use this script to buils and package S4 apps.
+*
+* Run 'gradle install' on the s4 project to publish to your local maven repo.
+*
+* TODO: This should probably be distributed as an s4 plugin for Gradle.
+* TODO: There seem to be to be similarities with the war and jetty plugins. (war -> s4r, jetty -> s4Run).
+* We should make it easy to test the app from this script by a running a test task that starts and stops
+* an s4 server. See: http://www.gradle.org/releases/1.0-milestone-3/docs/userguide/userguide_single.html#war_plugin
+*
+* This is an interesting discussion:
+* http://gradle.1045684.n5.nabble.com/Exclude-properties-file-from-war-td3365147.html
+*
+*/
+
+/* Set the destination where we want to install the apps. */
+//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
+
+project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
+
+project.ext["s4Version"] = '0.5.0-incubating'
+description = 'Apache S4 App'
+//defaultTasks 'installS4R'
+project.ext["archivesBaseName"] = "$project.name"
+project.ext["distRootFolder"] = "$archivesBaseName-${-> version}"
+
+
+// Append the suffix 'SNAPSHOT' when the build is not for release.
+//version = new Version(major: 0, minor: 0, bugfix: 0, isRelease: false)
+group = 'org.apache.s4'
+
+apply plugin: 'java'
+apply plugin: 'eclipse'
+apply plugin: 'idea'
+
+/* Set Java version. */
+sourceCompatibility = 1.6
+targetCompatibility = 1.6
+
+    repositories {
+        mavenLocal()
+        mavenCentral()
+        maven { url 'http://google-gson.googlecode.com/svn/mavenrepo' }
+        maven { url 'https://repo.springsource.org/libs-release' }
+        maven { url 'http://repo.gradle.org/gradle/libs-releases-local' }
+
+        /* Add lib dir as a repo. Some jar files that are not available
+         in a public repo are distributed in the lib dir. */
+        flatDir name: 'libDir', dirs: "$rootDir/lib"
+    }
+
+/* All project libraries must be defined here. */
+project.ext["libraries"] = [
+
+           s4_base:            'org.apache.s4:s4-base:0.5.0-incubating',
+           s4_comm:            'org.apache.s4:s4-comm:0.5.0-incubating',
+       ]
+
+
+dependencies {
+
+   compile (libraries.s4_base)
+   compile (libraries.s4_comm)
+
+
+
+}
+
+/* Set the manifest attributes for the S4 archive here.
+*  TODO: separate custom properties from std ones and set custom properties at the top of the build script.
+*/
+manifest.mainAttributes(
+       provider: 'gradle',
+       'Implementation-Url': 'http://incubator.apache.org/projects/s4.html',
+       'Implementation-Version': version,
+       'Implementation-Vendor': 'Apache S4',
+       'Implementation-Vendor-Id': 'custom modules',
+       'S4-Version': s4Version
+       )
+
+project.ext["appDependencies"] = ( configurations.compile )
+
+// external dependencies will be available in the /lib directory of the s4r
+task copyDependenciesToLib(type: Copy) {
+    into project.libsDir.path+"/lib"
+    from configurations.runtime
+}
+
+// app jar will be available from the /app directory of the s4r
+task buildProjectJar() {
+	dependsOn jar {
+		destinationDir file(project.libsDir.path + "/app")
+		from sourceSets.main.output
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/2ecb531f/test-apps/custom-modules/src/main/java/org/apache/s4/TestListener.java
----------------------------------------------------------------------
diff --git a/test-apps/custom-modules/src/main/java/org/apache/s4/TestListener.java b/test-apps/custom-modules/src/main/java/org/apache/s4/TestListener.java
new file mode 100644
index 0000000..3451a28
--- /dev/null
+++ b/test-apps/custom-modules/src/main/java/org/apache/s4/TestListener.java
@@ -0,0 +1,136 @@
+package org.apache.s4;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.s4.base.Event;
+import org.apache.s4.base.EventMessage;
+import org.apache.s4.base.Listener;
+import org.apache.s4.base.SerializerDeserializer;
+import org.apache.s4.comm.topology.Assignment;
+import org.apache.s4.comm.topology.ClusterNode;
+import org.apache.s4.comm.topology.ZkClient;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.ExceptionEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+public class TestListener implements Listener {
+
+    private static Logger logger = LoggerFactory.getLogger(TestListener.class);
+
+    private ServerBootstrap bootstrap;
+    private final ChannelGroup channels = new DefaultChannelGroup();
+    private ZkClient zkClient;
+    private SerializerDeserializer serDeser;
+
+    @Inject
+    public TestListener(Assignment assignment, @Named("s4.comm.timeout") int timeout, SerializerDeserializer serDeser) {
+        // wait for an assignment
+        ClusterNode node = assignment.assignClusterNode();
+        this.serDeser = serDeser;
+
+        ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
+                Executors.newCachedThreadPool());
+
+        bootstrap = new ServerBootstrap(factory);
+
+        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
+            @Override
+            public ChannelPipeline getPipeline() {
+                ChannelPipeline p = Channels.pipeline();
+                p.addLast("1", new LengthFieldBasedFrameDecoder(999999, 0, 4, 0, 4));
+                p.addLast("2", new MyChannelHandler());
+
+                return p;
+            }
+        });
+
+        bootstrap.setOption("child.tcpNoDelay", true);
+        bootstrap.setOption("child.keepAlive", true);
+        bootstrap.setOption("child.reuseAddress", true);
+        bootstrap.setOption("child.connectTimeoutMillis", timeout);
+        bootstrap.setOption("readWriteFair", true);
+
+        Channel c = bootstrap.bind(new InetSocketAddress(node.getPort()));
+        channels.add(c);
+
+        zkClient = new ZkClient("localhost:2181");
+    }
+
+    @Override
+    public byte[] recv() {
+        while (true) {
+            try {
+                Thread.sleep(100000);
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @Override
+    public void close() {
+        try {
+            channels.close().await();
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+        bootstrap.releaseExternalResources();
+
+    }
+
+    @Override
+    public int getPartitionId() {
+        throw new NotImplementedException();
+    }
+
+    public class MyChannelHandler extends SimpleChannelHandler {
+        @Override
+        public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
+            channels.add(e.getChannel());
+            ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
+            Event event = (Event) serDeser.deserialize(((EventMessage) serDeser.deserialize(buffer.array()))
+                    .getSerializedEvent());
+
+            zkClient.createEphemeralSequential("/test/data", event.get("message", long.class));
+
+        }
+
+        @Override
+        public void exceptionCaught(ChannelHandlerContext context, ExceptionEvent event) {
+            logger.error("Error", event.getCause());
+            Channel c = context.getChannel();
+            c.close().addListener(new ChannelFutureListener() {
+                @Override
+                public void operationComplete(ChannelFuture future) throws Exception {
+                    if (future.isSuccess())
+                        channels.remove(future.getChannel());
+                    else
+                        logger.error("FAILED to close channel");
+                }
+            });
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/2ecb531f/test-apps/custom-modules/src/main/java/org/apache/s4/TestListenerModule.java
----------------------------------------------------------------------
diff --git a/test-apps/custom-modules/src/main/java/org/apache/s4/TestListenerModule.java b/test-apps/custom-modules/src/main/java/org/apache/s4/TestListenerModule.java
new file mode 100644
index 0000000..c58264f
--- /dev/null
+++ b/test-apps/custom-modules/src/main/java/org/apache/s4/TestListenerModule.java
@@ -0,0 +1,14 @@
+package org.apache.s4;
+
+import org.apache.s4.base.Listener;
+
+import com.google.inject.AbstractModule;
+
+public class TestListenerModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(Listener.class).to(TestListener.class);
+    }
+
+}