Permalink
Browse files

an app using the luwak external branch to expose the luwak API

  • Loading branch information...
0 parents commit dc778be126eaa96bd0b030332c26d2fed3d74c8f Bryan Fink committed Apr 5, 2012
@@ -0,0 +1,6 @@
+ebin/
+*~
+rel/luwak
+deps/
+erl_crash.dump
+
@@ -0,0 +1,41 @@
+Luwakapp is a demonstration of the
+[`external` luwak branch](https://github.com/beerriot/luwak/tree/external),
+which uses the
+[Riak Erlang client](https://github.com/basho/riak-erlang-client) to
+communicate with Riak over Protocol Buffers, instead of expecting code
+to run on a Riak node. The app exposes the same HTTP interface that
+Riak used to expose itself.
+
+## Prereqs
+
+You'll need [Riak](http://wiki.basho.com/Riak.html) and Erlang R14B
+installed. You'll also need [rebar](https://github.com/basho/rebar).
+
+## Setup & Run
+
+Clone this repo:
+
+ git clone git://github.com/beerriot/luwakapp
+
+Build the app:
+
+ cd luwakapp
+ rebar get-deps compile generate
+
+Edit your config. In `rel/luwak/etc/`, you'll find `sys.config`.
+Change the `riak_ip` and `riak_port` settings to point to one of your
+Riak nodes (default `127.0.0.1:8087`). Also change the `http` and/or
+`prefix` settings if you want the interface exposed somewhere other
+than `http://localhost:8080/luwak/`.
+
+Start the app:
+
+ rel/luwak/bin/luwak console
+
+(or use `start` instead of `console`, if you'd like it to run in the
+background).
+
+# Use
+
+Interacting with this app should be exactly as described on the
+[Luwak wiki page](http://wiki.basho.com/Luwak.html).
@@ -0,0 +1,19 @@
+{application, luwakapp,
+ [
+ {description, "Non-Erlang Luwak Interfaces"},
+ {vsn, "1"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ luwak,
+ webmachine
+ ]},
+ {mod, { luwakapp_app, []}},
+ {env, [
+ {riak_ip, "127.0.0.1"},
+ {riak_port, 8087},
+ {http, [ {"127.0.0.1", 8080} ]},
+ {prefix, "luwak"}
+ ]}
+ ]}.
@@ -0,0 +1,35 @@
+%% -------------------------------------------------------------------
+%%
+%% Copyright (c) 2011 Bryan Fink. All Rights Reserved.
+%%
+%% This file is provided 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.
+%%
+%% -------------------------------------------------------------------
+-module(luwakapp_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ luwakapp_sup:start_link().
+
+stop(_State) ->
+ ok.
@@ -0,0 +1,66 @@
+%% -------------------------------------------------------------------
+%%
+%% Copyright (c) 2011 Bryan Fink. All Rights Reserved.
+%%
+%% This file is provided 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.
+%%
+%% -------------------------------------------------------------------
+-module(luwakapp_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+
+%% ===================================================================
+%% API functions
+%% ===================================================================
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ===================================================================
+%% Supervisor callbacks
+%% ===================================================================
+
+init([]) ->
+ Webmachines = webmachines(),
+ {ok, { {one_for_one, 5, 10}, Webmachines} }.
+
+webmachines() ->
+ {ok, Prefix} = application:get_env(luwakapp, prefix),
+ {ok, RiakIP} = application:get_env(luwakapp, riak_ip),
+ {ok, RiakPort} = application:get_env(luwakapp, riak_port),
+ Opts = [{prefix, Prefix}, {ip, RiakIP}, {port, RiakPort}],
+ Routing = [{[Prefix], luwakapp_wm_file, Opts},
+ {[Prefix, key], luwakapp_wm_file, Opts}],
+
+ {ok, HTTP} = application:get_env(luwakapp, http),
+ [ webmachine(IP, Port, Routing) || {IP, Port} <- HTTP ].
+
+webmachine(IP, Port, Routing) ->
+ Config = [{ip, IP}, {port, Port}, {dispatch, Routing}],
+ {webmachine_name(IP, Port),
+ {webmachine_mochiweb, start, [Config]},
+ permanent, 5000, worker, [mochiweb_socket_server]}.
+
+webmachine_name(IP, Port) ->
+ list_to_atom(lists:flatten(["http", IP, ":", integer_to_list(Port)])).
Oops, something went wrong.

0 comments on commit dc778be

Please sign in to comment.