<commit_before>Beehive Router
===

Getting started
===

To start the router:

    make && make boot
    ./scripts/start_beehive.sh

This will start the basic router with the default options. The default node type that gets started is the router type. You can start a node (see glossary below) with the following command. Node that the -s argument refers to a seed node. This is any node already in the mesh.

    ./scripts/start_beehive.sh -t node -n <EMAIL> -s <EMAIL>

There are many options to starting the router, for more information and options, type:

    ./scripts/start_beehive.sh -h

To start with a list of bees, use the -i option to point to a file that looks like:

    {"app1", "ec2-67-202-21-173.compute-1.amazonaws.com", 8080}.
    {"app2", "ec2-174-129-54-214.compute-1.amazonaws.com", 8080}.

To start it, run:

    ./scripts/start_beehive.sh -i /path/to/the/file/from/above

How it works
===
There are 4 mnesia tables setup by the beehive router:

<img src="https://github.com/auser/beehive/raw/master/lib/erlang/docs/tables.png" width="300" alt="table" />

The app table stores the applications associated with Beehive.

The bee table stores the bee data, and their state.

The user table stores information about the users associated with the system.

The user_app table stores the mappings between users and their apps

## Proxy

The proxy can be hot-loaded with new routes simply with a RESTful interface. The name (the routing key), the endpoint host and the port of the bee need to be included. For instance:

    curl -i -XPOST -d"{\"app_name\":\"test\", \"host\":\"google.com\", \"port\":\"80\"}" beehive.com:8080/bee/new

The parameters that must be included are the app_name (the routing key), the host and the port. You can check to make sure that they were added by visiting the page: http://beehive.com:8080/bee/all

These can also be added at the erlang command-line by:

    bee_srv:add_bee({"streaming",{127,0,0,1}, 5001}).
    % or
    bee_srv:add_bee([{app_name, "streaming"}, {host, "127.0.0.1"}, {port, 5001}]).

## Apps
Adding an application can also be added via the RESTful interface. For example:

    curl -i -XPOST -d"{\"name\":\"beehive\", \"host\":\"ec2-75-121-34-215-amazon.com\", \"port\":\"8080\"}" beehive.com:8080/app/new
    curl -i -XPOST -d"{\"name\":\"test\", \"host\":\"ec2-75-121-34-210-amazon.com\", \"port\":\"8081\"}" beehive.com:8080/app/new

Viewing the list of supported apps:

    curl -i beehive.com:8080/app

All operations can be handled in a RESTful interface.

For instance, to terminate and restart the application in the beehive, issue a request such as:

    curl -i -XPOST http://beehive.com:8080/apps/[app_name]/restart

## Nodes
Beehive is a distributed system. You can add multiple nodes in the router. The node_manager handles the node connections.

Viewing the nodes is as easy as a query as well:

    curl -i beehive.com:8080/nodes

To add a new node, as mentioned above, start a node with the seed value from the start script:
  <commit_msg>Added info about the storage nodes into the README<commit_after>Beehive Router
===

Getting started
===

To start the router:

    make && make boot
    ./scripts/start_beehive.sh

This will start the basic router with the default options. The default node type that gets started is the router type. You can start a node (see glossary below) with the following command. Node that the -s argument refers to a seed node. This is any node already in the mesh.

    ./scripts/start_beehive.sh -t node -n <EMAIL> -s <EMAIL>

You also need to start some storage backends to store the squashed bees. This is easy to do with the ./scripts/start_beehive.sh script:

    ./scripts/start_beehive.sh -t storage -s <EMAIL>

There are many options to starting the router, for more information and options, type:

    ./scripts/start_beehive.sh -h

To start with a list of bees, use the -i option to point to a file that looks like:

    {"app1", "ec2-67-202-21-173.compute-1.amazonaws.com", 8080}.
    {"app2", "ec2-174-129-54-214.compute-1.amazonaws.com", 8080}.

To start it, run:

    ./scripts/start_beehive.sh -i /path/to/the/file/from/above

How it works
===
There are 4 mnesia tables setup by the beehive router:

<img src="https://github.com/auser/beehive/raw/master/lib/erlang/docs/tables.png" width="300" alt="table" />

The app table stores the applications associated with Beehive.

The bee table stores the bee data, and their state.

The user table stores information about the users associated with the system.

The user_app table stores the mappings between users and their apps

## Proxy

The proxy can be hot-loaded with new routes simply with a RESTful interface. The name (the routing key), the endpoint host and the port of the bee need to be included. For instance:

    curl -i -XPOST -d"{\"app_name\":\"test\", \"host\":\"google.com\", \"port\":\"80\"}" beehive.com:8080/bee/new

The parameters that must be included are the app_name (the routing key), the host and the port. You can check to make sure that they were added by visiting the page: http://beehive.com:8080/bee/all

These can also be added at the erlang command-line by:

    bee_srv:add_bee({"streaming",{127,0,0,1}, 5001}).
    % or
    bee_srv:add_bee([{app_name, "streaming"}, {host, "127.0.0.1"}, {port, 5001}]).

## Apps
Adding an application can also be added via the RESTful interface. For example:

    curl -i -XPOST -d"{\"name\":\"beehive\", \"host\":\"ec2-75-121-34-215-amazon.com\", \"port\":\"8080\"}" beehive.com:8080/app/new
    curl -i -XPOST -d"{\"name\":\"test\", \"host\":\"ec2-75-121-34-210-amazon.com\", \"port\":\"8081\"}" beehive.com:8080/app/new

Viewing the list of supported apps:

    curl -i beehive.com:8080/app

All operations can be handled in a RESTful interface.

For instance, to terminate and restart the application in the beehive, issue a request such as:

    curl -i -XPOST http://beehive.com:8080/apps/[app_name]/restart

## Storage nodes
To store the distributable bees, you must start a storage backend. Beehive makes this easy again by using the start script:

    ./scripts/start_beehive.sh -t storage

Note, these storage backends must have git installed (currently the only supported scm) because they will clone the url repos (off-site for now) and squash the filesystem.

## Nodes
Beehive is a distributed system. You can add multiple nodes in the router. The node_manager handles the node connections.

Viewing the nodes is as easy as a query as well:

    curl -i beehive.com:8080/nodes

To add a new node, as mentioned above, start a node with the seed value from the start script:
  
{'fraction_non_alphanumeric': 0.1132388419782871, 'fraction_numerical': 0.035886610373944514, 'mean_word_length': 3.561898211829436, 'pattern_counts': {'":': 18, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6407301', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2062, 'n_words': 864}