Skip to content

Commit

Permalink
Add the hello_world4 example to show how CloudI can be included with …
Browse files Browse the repository at this point in the history
…a relx release.
  • Loading branch information
okeuday committed Oct 1, 2013
1 parent 6f30afd commit 41693c1
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* `hello_world1` - Using CloudI configuration or the CloudI Service API
* `hello_world2` - Including CloudI in your Erlang OTP/reltool release
* `hello_world3` - Including CloudI as a rebar dependency
* `hello_world4` - Including CloudI as a relx release

15 changes: 15 additions & 0 deletions examples/hello_world4/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY : all clean release

CLOUDI_VERSION=1.2.5
CLOUDI_PATH=/usr/local/lib/cloudi-$(CLOUDI_VERSION)/lib/cloudi_core-$(CLOUDI_VERSION)

all: src/hello_world4.erl
erlc -pz $(CLOUDI_PATH) -pz $(CLOUDI_PATH)/ebin -o ebin src/hello_world4.erl

clean:
rm -f ebin/hello_world4.beam
rm -rf release

release: all reltool.config
../../src/lib/reltool_util/release

38 changes: 38 additions & 0 deletions examples/hello_world4/README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Hello World 4 Example

## PURPOSE

Provide the simplest example of an Erlang application running within the same
Erlang VM as CloudI, with a CloudI service (`hello_world4.erl`), using relx.
The example uses the same OTP release for both CloudI and the internal CloudI
service.

## DETAILS

The approach with the Hello World 4 Example is for CloudI to load the
`hello_world4` application after CloudI has started. The `hello_world4`
application can be specified within the cloudi.conf or provided
dynamically to the CloudI Service API, to start the CloudI service
(separate from the application's supervision hierarchy, if one is present).
Using this method of deployment (within the same OTP release) the
`hello_world4` application file can specify CloudI as a dependency by
listing the `cloudi_core` application as a dependency, unlike the
approach within the `hello_world1` example.

## USAGE

To use an Erlang/OTP application file for an internal service with the same
module name:

$ git clone https://github.com/erlware/relx
$ cd relx
$ make
$ cd ..
$ make
$ relx/relx
$ cd release
$ bin/cloudi start
$ curl http://localhost:6467/examples/hello_world4
Hello World!
$ bin/cloudi stop

24 changes: 24 additions & 0 deletions examples/hello_world4/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[{sasl, [
{sasl_error_logger, {file, "logs/sasl.log"}},
{error_logger_mf_dir, "logs"},
{error_logger_mf_maxbytes, 536870912}, % 512 MB
{error_logger_mf_maxfiles, 128},
{utc_log, true}
]},
{ec2nodefinder, [
{group, "PUT group-name here"},
{private_key, "PUT private-key-filepath here"},
{cert, "PUT cert-filepath here"},
{ping_timeout_sec, 60},
{ec2_home, "/usr"},
{ec2_home, "/usr/lib/jvm/java-6-openjdk-amd64/jre"}
]},
{nodefinder, [
{addr, {224,0,0,1}},
{port, 4475},
{multicast_ttl, 1}
]},
{cloudi_core, [
{configuration, "releases/1/cloudi.conf"}
]}].

31 changes: 31 additions & 0 deletions examples/hello_world4/cloudi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{acl, [
]}.
{services, [
{internal,
"/cloudi/api/",
cloudi_service_api_requests,
[],
none,
5000, 5000, 5000, undefined, undefined, 1, 5, 300,
[]},
{internal,
"/tests/http/",
cloudi_service_http_cowboy,
[{port, 6467}, {output, internal}],
immediate_closest,
5000, 5000, 5000, undefined, undefined, 1, 5, 300,
[{duo_mode, true}]},
{internal,
"/examples/",
hello_world4,
[],
none,
5000, 5000, 5000, undefined, undefined, 1, 5, 300,
[]}
]}.
{nodes, [
]}.
{logging, [
{file, "log/cloudi.log"}
]}.

13 changes: 13 additions & 0 deletions examples/hello_world4/ebin/hello_world4.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*-
% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et:

{application, hello_world4,
[{description, "Hello World Example Application"},
{vsn, "1.3.0"},
{modules, [
hello_world4]},
{registered, []},
{applications, [
cloudi_core,
stdlib,
kernel]}]}.
18 changes: 18 additions & 0 deletions examples/hello_world4/relx.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{lib_dirs,
[
"/usr/local/lib/cloudi-1.2.5/lib"
]}.
{release, {cloudi, "1"},
[hello_world4,
cloudi_core]}.

{extended_start_script, true}.

{output_dir, "release"}.

{overlay, [
{copy, "./app.config", "releases/{{rel_vsn}}/sys.config"},
{copy, "./vm.args", "releases/{{rel_vsn}}/vm.args"},
{copy, "./cloudi.conf", "releases/{{rel_vsn}}/cloudi.conf"}
]}.

30 changes: 30 additions & 0 deletions examples/hello_world4/src/hello_world4.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-module(hello_world4).
-behaviour(cloudi_service).

%% cloudi_service callbacks
-export([cloudi_service_init/3,
cloudi_service_handle_request/11,
cloudi_service_handle_info/3,
cloudi_service_terminate/2]).

-include_lib("cloudi_core/include/cloudi_logger.hrl").

-record(state,
{
}).

cloudi_service_init(_Args, _Prefix, Dispatcher) ->
cloudi_service:subscribe(Dispatcher, "hello_world4/get"),
{ok, #state{}}.

cloudi_service_handle_request(_Type, _Name, _Pattern, _RequestInfo, _Request,
_Timeout, _Priority, _TransId, _Pid,
#state{} = State, _Dispatcher) ->
{reply, <<"Hello World!">>, State}.

cloudi_service_handle_info(Request, State, _) ->
?LOG_WARN("Unknown info \"~p\"", [Request]),
{noreply, State}.

cloudi_service_terminate(_, #state{}) ->
ok.
22 changes: 22 additions & 0 deletions examples/hello_world4/vm.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

## Name of the node
-sname cloudi_hello_world4

## Cookie for distributed erlang
-setcookie cloudi_hello_world4

## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
##-heart

## Enable kernel poll and a few async threads
+K true
+A 5

## Increase number of Erlang processes
+P 65536

## Increase number of concurrent ports/sockets
-env ERL_MAX_PORTS 32768
#+Q 32768 # change for R17

2 changes: 2 additions & 0 deletions src/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Erlang application for each CloudI service to help isolate
CloudI service Erlang application dependencies
* Update all dependencies to have {registered, []}, to keep relx happy
* Add the hello_world4 example to show how CloudI can be included with
a relx release

2013-09-28 Michael Truog <mjtruog [at] gmail (dot) com>

Expand Down

0 comments on commit 41693c1

Please sign in to comment.