Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 046fc42c37ff8f520ef0e79a732e2d428d62baaf @jbrisbin committed Mar 29, 2012
@@ -0,0 +1,6 @@
+.DS_Store
+data
+deps
+ebin
+*.dump
+log
@@ -0,0 +1,33 @@
+PACKAGE=cowboy-riak_core-vnode-dispatcher
+DIST_DIR=dist
+EBIN_DIR=ebin
+INCLUDE_DIRS=include
+DEPS_DIR=deps
+DEPS ?= cowboy sockjs basho_stats lager mochiweb poolboy protobuffs riak_core riak_sysmon webmachine
+DEPS_EZ=$(foreach DEP, $(DEPS), $(DEPS_DIR)/$(DEP).ez)
+RABBITMQ_HOME ?= .
+
+all: compile
+
+clean:
+ rm -rf $(DIST_DIR)
+ rm -rf $(EBIN_DIR)
+
+distclean: clean
+ rm -rf $(DEPS_DIR)
+
+package: compile $(DEPS_EZ)
+ rm -f $(DIST_DIR)/$(PACKAGE).ez
+ mkdir -p $(DIST_DIR)/$(PACKAGE)
+ cp -r $(EBIN_DIR) $(DIST_DIR)/$(PACKAGE)
+ $(foreach EXTRA_DIR, $(INCLUDE_DIRS), cp -r $(EXTRA_DIR) $(DIST_DIR)/$(PACKAGE);)
+ (cd $(DIST_DIR); zip -r $(PACKAGE).ez $(PACKAGE))
+
+$(DEPS_DIR):
+ ./rebar get-deps
+
+$(DEPS_EZ):
+ cd $(DEPS_DIR); $(foreach DEP, $(DEPS), zip -r $(DEP).ez $(DEP);)
+
+compile: $(DEPS_DIR)
+ ./rebar compile
@@ -0,0 +1,114 @@
+%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ft=erlang ts=4 sw=4 et
+[
+ {hello_world, [
+ {web_port, 3000},
+ {master_node, 'helloworld1@localhost'}
+ ]},
+
+ %% Riak Core config
+ {riak_core, [
+ %% Default location of ringstate
+ {ring_state_dir, "./data/ring1"},
+
+ %% http is a list of IP addresses and TCP ports that the Riak
+ %% HTTP interface will bind.
+ %{http, [ {"127.0.0.1", 8098 } ]},
+
+ %% https is a list of IP addresses and TCP ports that the Riak
+ %% HTTPS interface will bind.
+ %{https, [{ "127.0.0.1", 8098 }]},
+
+ %% Default cert and key locations for https can be overridden
+ %% with the ssl config variable, for example:
+ %{ssl, [
+ % {certfile, "./etc/cert.pem"},
+ % {keyfile, "./etc/key.pem"}
+ % ]},
+
+ %% riak_handoff_port is the TCP port that Riak uses for
+ %% intra-cluster data handoff.
+ {handoff_port, 8099 },
+
+ %% To encrypt riak_core intra-cluster data handoff traffic,
+ %% uncomment the following line and edit its path to an
+ %% appropriate certfile and keyfile. (This example uses a
+ %% single file with both items concatenated together.)
+ %{handoff_ssl_options, [{certfile, "/tmp/erlserver.pem"}]},
+
+ %% Platform-specific installation paths (substituted by rebar)
+ {platform_bin_dir, "./bin"},
+ {platform_data_dir, "./data"},
+ {platform_etc_dir, "./etc"},
+ {platform_lib_dir, "./lib"},
+ {platform_log_dir, "./log"}
+ ]},
+
+ %% Lager Config
+ {lager, [
+ %% What handlers to install with what arguments
+ %% The defaults for the logfiles are to rotate the files when
+ %% they reach 10Mb or at midnight, whichever comes first, and keep
+ %% the last 5 rotations. See the lager README for a description of
+ %% the time rotation format:
+ %% https://github.com/basho/lager/blob/master/README.org
+ %%
+ %% If you wish to disable rotation, you can either set the size to 0
+ %% and the rotation time to "", or instead specify a 2-tuple that only
+ %% consists of {Logfile, Level}.
+ {handlers, [
+ {lager_console_backend, info},
+ {lager_file_backend, [
+ {"./log/error.log", error, 10485760, "$D0", 5},
+ {"./log/console.log", info, 10485760, "$D0", 5}
+ ]}
+ ]},
+
+ %% Whether to write a crash log, and where.
+ %% Commented/omitted/undefined means no crash logger.
+ {crash_log, "./log/crash.log"},
+
+ %% Maximum size in bytes of events in the crash log - defaults to 65536
+ {crash_log_msg_size, 65536},
+
+ %% Maximum size of the crash log in bytes, before its rotated, set
+ %% to 0 to disable rotation - default is 0
+ {crash_log_size, 10485760},
+
+ %% What time to rotate the crash log - default is no time
+ %% rotation. See the lager README for a description of this format:
+ %% https://github.com/basho/lager/blob/master/README.org
+ {crash_log_date, "$D0"},
+
+ %% Number of rotated crash logs to keep, 0 means keep only the
+ %% current one - default is 0
+ {crash_log_count, 5},
+
+ %% Whether to redirect error_logger messages into lager - defaults to true
+ {error_logger_redirect, true}
+ ]},
+
+ %% riak_sysmon config
+ {riak_sysmon, [
+ %% To disable forwarding events of a particular type, use a
+ %% limit of 0.
+ {process_limit, 30},
+ {port_limit, 2},
+
+ %% Finding reasonable limits for a given workload is a matter
+ %% of experimentation.
+ {gc_ms_limit, 100},
+ {heap_word_limit, 40111000},
+
+ %% Configure the following items to 'false' to disable logging
+ %% of that event type.
+ {busy_port, true},
+ {busy_dist_port, true}
+ ]},
+
+ %% SASL config
+ {sasl, [
+ {sasl_error_logger, false}
+ ]}
+
+].
@@ -0,0 +1,7 @@
+-ifndef(MISULTIN_RIAK_CORE_VNODE_DISPATCHER).
+-define(MISULTIN_RIAK_CORE_VNODE_DISPATCHER, ok).
+
+-define(VNODE_MASTER(Name, VNode), {Name, {riak_core_vnode_master, start_link, [VNode]}, permanent, 5000, worker, [riak_core_vnode_master]}).
+-define(GEN_SERVER(Name, Worker), {Name, {Worker, start_link, []}, permanent, 5000, worker, [Worker]}).
+
+-endif.
@@ -0,0 +1,2 @@
+#!/bin/bash
+erl +K true +A 5 -pa ebin -pa deps/*/ebin -config hello_world1 -s hello_world -sname helloworld1@localhost

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,22 @@
+<!doctype html>
+<html>
+ <head>
+ <title>riak_core / cowboy Integeration Test</title>
+ <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
+ <script src="http://cdn.sockjs.org/sockjs-0.2.min.js"></script>
+ <script>
+ var ws = new SockJS("/data");
+ ws.onmessage = function(msg) {
+ console.log("from server: ", msg.data);
+ $("#content").html(msg.data);
+ }
+ ws.onopen = function() {
+ console.log("sending data to client...");
+ ws.send("data from client");
+ }
+ </script>
+ </head>
+ <body>
+ <div id="content"></div>
+ </body>
+</html>
BIN rebar
Binary file not shown.
@@ -0,0 +1,12 @@
+{erl_opts, [
+ debug_info,
+ {parse_transform, lager_transform}
+ %fail_on_warning
+]}.
+
+{deps, [
+ {cowboy, ".*", {git, "https://github.com/extend/cowboy.git", "HEAD"}},
+ {mimetypes, ".*", {git, "https://github.com/spawngrid/mimetypes.git", "HEAD"}},
+ {sockjs, ".*", {git, "https://github.com/sockjs/sockjs-erlang.git", "HEAD"}},
+ {riak_core, ".*", {git, "https://github.com/basho/riak_core.git", {tag, "1.1.1"}}}
+]}.
@@ -0,0 +1,13 @@
+{application, hello_world, [
+ {description, "Hello World! Test App"},
+ {vsn, "1.0"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ cowboy,
+ riak_core
+ ]},
+ {mod, { hello_world_app, []}},
+ {env, []}
+]}.
@@ -0,0 +1,21 @@
+-module(hello_world).
+
+-export([
+ start/0,
+ stop/0
+]).
+
+start() ->
+ application:start(crypto),
+ application:start(sasl),
+ application:start(lager),
+ application:start(webmachine),
+ application:start(os_mon),
+ application:start(riak_sysmon),
+ application:start(riak_core),
+ application:start(sockjs),
+ application:start(cowboy),
+ application:start(hello_world).
+
+stop() ->
+ ok.
@@ -0,0 +1,20 @@
+-module(hello_world_app).
+-behaviour(application).
+
+-export([
+ start/2,
+ stop/1
+]).
+
+start(_StartType, _StartArgs) ->
+ case hello_world_sup:start_link() of
+ {ok, Pid} ->
+ ok = riak_core:register([{vnode_module, hello_world_vnode}]),
+ ok = riak_core_node_watcher:service_up(hello_world, self()),
+
+ {ok, Pid};
+ Else -> Else
+ end.
+
+stop(_State) ->
+ ok.
@@ -0,0 +1,20 @@
+-module(hello_world_sup).
+-behaviour(supervisor).
+
+-include("hello_world_vnode_dispatcher.hrl").
+
+-export([
+ start_link/0,
+ init/1
+]).
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init(_Args) ->
+ Workers = [
+ ?GEN_SERVER(hello_world_vnode_dispatcher_master, hello_world_vnode_dispatcher),
+ ?VNODE_MASTER(hello_world_vnode_master, hello_world_vnode)
+ ],
+
+ {ok, {{one_for_one, 10, 10}, Workers}}.
@@ -0,0 +1,77 @@
+-module(hello_world_vnode).
+-behaviour(riak_core_vnode).
+
+-include_lib("riak_core/include/riak_core_vnode.hrl").
+
+-export([
+ delete/1,
+ encode_handoff_item/2,
+ handle_command/3,
+ handle_coverage/4,
+ handle_exit/3,
+ handle_handoff_command/3,
+ handle_handoff_data/2,
+ handoff_cancelled/1,
+ handoff_finished/2,
+ handoff_starting/2,
+ init/1,
+ is_empty/1,
+ start_vnode/1,
+ terminate/2
+]).
+
+-record(state, {
+ partition :: partition()
+}).
+
+start_vnode(I) ->
+ riak_core_vnode_master:get_vnode_pid(I, ?MODULE).
+
+init([Partition]) ->
+ lager:debug("started ~p at partition ~p", [?MODULE, Partition]),
+ {ok, #state { partition = Partition }}.
+
+handle_command({sockjs, Data, Conn}, _Sender, State) ->
+ lager:info("Got data from client: ~p", [Data]),
+ Conn:send(<<"Hello World!">>),
+ {noreply, State};
+
+handle_command(Msg, _Sender, State) ->
+ lager:warning("unhandled command: ~p~n", [Msg]),
+ {noreply, State}.
+
+handle_coverage(Request, KeySpaces, Sender, State) ->
+ lager:debug("handle_coverage: ~p ~p ~p ~p~n", [Request, KeySpaces, Sender, State]),
+ {continue, State}.
+
+handle_exit(Pid, Reason, State) ->
+ lager:debug("handle exit: ~p ~p~n", [Pid, Reason]),
+ {stop, Reason, State}.
+
+handle_handoff_command(Message, Sender, State) ->
+ lager:debug("handle handoff: ~p ~p~n", [Message, Sender]),
+ {forward, State}.
+
+handoff_starting(_TargetNode, State) ->
+ {true, State}.
+
+handoff_cancelled(State) ->
+ {ok, State}.
+
+handoff_finished(_TargetNode, State) ->
+ {ok, State}.
+
+handle_handoff_data(_Data, State) ->
+ {reply, ok, State}.
+
+encode_handoff_item(_ObjectName, _ObjectValue) ->
+ <<>>.
+
+is_empty(State) ->
+ {true, State}.
+
+delete(State) ->
+ {ok, State}.
+
+terminate(_Reason, _State) ->
+ ok.
Oops, something went wrong.

0 comments on commit 046fc42

Please sign in to comment.