<commit_before># Orion Context Broker

This is the code repository for the Orion Context Broker, a C++ implementation of the NGSI9/10 REST API binding
developed as a part of the FI-WARE platform.

If this is your first contact with Orion Context Broker, it is highly recommended to have a look to the brief Quick Start guide:

https://wiki.fi-ware.org/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_Quick_Start_for_Programmers

You will find all the information on Orion Context Broker in its page in the FI-WARE Catalogue:

http://catalogue.fi-ware.eu/enablers/publishsubscribe-context-broker-orion-context-broker

Note that you don't need this repository code if you install the broker via its RPM package (check Orion Context
Broker installation and administration manual about installing via RPM).

## Installing and Using the broker

The administration and programming manuals for Orion Context Broker are found in the FI-WARE Catalogue page,
under the "Documentation" tab.

http://catalogue.fi-ware.eu/enablers/publishsubscribe-context-broker-orion-context-broker

## Building Orion Context Broker

Orion Context Broker reference distribution is CentOS 6.3. This doesn't mean that the broker cannot be
built in other distributions (actually, it can). This section also includes indications on how to build
in other distributions, just in the case it may help people that don't use CentOS. However, note that
the only "officially supported" procedure is the one for CentOS 6.3; the others are provided "as is"
and can get obsolete from time to time.

### CentOS 6.3 (official)

The Orion Context Broker uses the following libraries as build dependencies:

* boost: 1.41 (the one that comes in EPEL6 repository)
* libmicrohttpd: 0.9.22 (the one that comes in EPEL6 repository)
* libcurl: 7.19.7 (for proxyCoap)
* Mongo Driver: 2.2.3 (from source)
* gtest (only for `make unit_test` building target): 1.5 (from sources)
* gmock (only for `make unit_test` building target): 1.5 (from sources)
* cantcoap (for proxyCoap)

We assume that EPEL6 repository is configured in yum, given that many RPM packages are installed from there
(check the procedure at http://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F):

The basic procedure is as follows (assuming you don't run commands as root, we use sudo for those
commands that require root privilege):

* Install the needed building tools (compiler, etc.).

```
sudo yum install make cmake gcc-c++ scons
```

* Install the required libraries (except the mongo driver and gmock, described in following steps).

```
sudo yum install libmicrohttpd-devel boost-devel libcurl-devel
```

* Install the Mongo Driver from source (reference procedure http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-cpp-driver/):

```
wget http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-2.2.3.tgz
# Don't pay attention to the '-linux-x86_64' in the name: it is actually source code for any platform
tar xfvz mongodb-linux-x86_64-2.2.3.tgz
cd mongo-cxx-driver-v2.2
scons                                         # The build/libmongoclient.a library is generated as outcome
sudo scons install                            # This puts .h files in /usr/local/include and libmongoclient.a in /usr/local/lib
sudo chmod a+r -R /usr/local/include/mongo    # It seems that scons install breaks permissions
```

* Install Google Test/Mock from sources (there are RPM pacakges for this, but they don't seem to be working with the
  current CMakeLists.txt configuration)

```
wget http://googlemock.googlecode.com/files/gmock-1.5.0.tar.bz2
tar xfvj gmock-1.5.0.tar.bz2
cd gmock-1.5.0
./configure
make
sudo make install  # installation puts .h files in /usr/local/include and library in /usr/local/lib
sudo ldconfig      # just in case... it doesn't hurt :)
```

* Install cantcoap (with dependencies). Note that we are using a particular snapshoot of the code (corresponding arround July 21st, 2014) given that cantcoap repository doesn't provide any releasing mechanism.
```
sudo yum install clang CUnit-devel

git clone https://github.com/staropram/cantcoap
cd cantcoap
git checkout 749e22376664dd3adae17492090e58882d3b28a7
make
sudo cp cantcoap.h /usr/local/include
sudo cp dbg.h /usr/local/include
sudo cp nethelper.h /usr/local/include
sudo cp libcantcoap.a /usr/local/lib
```

* Get the code (alternatively you can download it using a zipped version or a different URL pattern):

```
sudo yum install git
git clone git@github.com:telefonicaid/fiware-orion.git
```

* Build the source:

```
cd fiware-orion
make
```

* (Optional but highly recommended) run unit test. Firstly, you have to install MongoDB (as the unit tests rely on mongod
  running in localhost).

```
sudo yum install mongodb-server
sudo yum  update pcre            # otherwise, mongod crashes in CentOS 6.3
sudo /etc/init.d/mongod start
sudo /etc/init.d/mongod status   # to check that mongod is actually running
make unit_test
```

* Install the binary. You can use INSTALL_DIR to set the installation prefix path (default is
/usr), thus the broker is installed in `$INSTALL_DIR/bin` directory.

```
sudo make install INSTALL_DIR=/usr
```

* Check that everything is ok, invoking the broker version message:

```
contextBroker --version
```

The Orion Context Broker comes with a suite of valgrind and end-to-end tests that you can also run,
following the following procedure (optional):

* Install the required tools:

```
sudo yum install python python-flask python-jinja2 curl libxml2 nc mongodb valgrind libxslt 
```

* Install COAP client (an example application included in the libcoap sources).
```
wget http://sourceforge.net/projects/libcoap/files/coap-18/libcoap-4.1.1.tar.gz/download
tar xvzf libcoap-4.1.1.tar.gz
cd libcoap-4.1.1
./configure
make
sudo cp examples/coap-client /usr/local/bin
```
<commit_msg>FIX typo in libcoap install procedure<commit_after># Orion Context Broker

This is the code repository for the Orion Context Broker, a C++ implementation of the NGSI9/10 REST API binding
developed as a part of the FI-WARE platform.

If this is your first contact with Orion Context Broker, it is highly recommended to have a look to the brief Quick Start guide:

https://wiki.fi-ware.org/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_Quick_Start_for_Programmers

You will find all the information on Orion Context Broker in its page in the FI-WARE Catalogue:

http://catalogue.fi-ware.eu/enablers/publishsubscribe-context-broker-orion-context-broker

Note that you don't need this repository code if you install the broker via its RPM package (check Orion Context
Broker installation and administration manual about installing via RPM).

## Installing and Using the broker

The administration and programming manuals for Orion Context Broker are found in the FI-WARE Catalogue page,
under the "Documentation" tab.

http://catalogue.fi-ware.eu/enablers/publishsubscribe-context-broker-orion-context-broker

## Building Orion Context Broker

Orion Context Broker reference distribution is CentOS 6.3. This doesn't mean that the broker cannot be
built in other distributions (actually, it can). This section also includes indications on how to build
in other distributions, just in the case it may help people that don't use CentOS. However, note that
the only "officially supported" procedure is the one for CentOS 6.3; the others are provided "as is"
and can get obsolete from time to time.

### CentOS 6.3 (official)

The Orion Context Broker uses the following libraries as build dependencies:

* boost: 1.41 (the one that comes in EPEL6 repository)
* libmicrohttpd: 0.9.22 (the one that comes in EPEL6 repository)
* libcurl: 7.19.7 (for proxyCoap)
* Mongo Driver: 2.2.3 (from source)
* gtest (only for `make unit_test` building target): 1.5 (from sources)
* gmock (only for `make unit_test` building target): 1.5 (from sources)
* cantcoap (for proxyCoap)

We assume that EPEL6 repository is configured in yum, given that many RPM packages are installed from there
(check the procedure at http://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F):

The basic procedure is as follows (assuming you don't run commands as root, we use sudo for those
commands that require root privilege):

* Install the needed building tools (compiler, etc.).

```
sudo yum install make cmake gcc-c++ scons
```

* Install the required libraries (except the mongo driver and gmock, described in following steps).

```
sudo yum install libmicrohttpd-devel boost-devel libcurl-devel
```

* Install the Mongo Driver from source (reference procedure http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-cpp-driver/):

```
wget http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-2.2.3.tgz
# Don't pay attention to the '-linux-x86_64' in the name: it is actually source code for any platform
tar xfvz mongodb-linux-x86_64-2.2.3.tgz
cd mongo-cxx-driver-v2.2
scons                                         # The build/libmongoclient.a library is generated as outcome
sudo scons install                            # This puts .h files in /usr/local/include and libmongoclient.a in /usr/local/lib
sudo chmod a+r -R /usr/local/include/mongo    # It seems that scons install breaks permissions
```

* Install Google Test/Mock from sources (there are RPM pacakges for this, but they don't seem to be working with the
  current CMakeLists.txt configuration)

```
wget http://googlemock.googlecode.com/files/gmock-1.5.0.tar.bz2
tar xfvj gmock-1.5.0.tar.bz2
cd gmock-1.5.0
./configure
make
sudo make install  # installation puts .h files in /usr/local/include and library in /usr/local/lib
sudo ldconfig      # just in case... it doesn't hurt :)
```

* Install cantcoap (with dependencies). Note that we are using a particular snapshoot of the code (corresponding arround July 21st, 2014) given that cantcoap repository doesn't provide any releasing mechanism.
```
sudo yum install clang CUnit-devel

git clone https://github.com/staropram/cantcoap
cd cantcoap
git checkout 749e22376664dd3adae17492090e58882d3b28a7
make
sudo cp cantcoap.h /usr/local/include
sudo cp dbg.h /usr/local/include
sudo cp nethelper.h /usr/local/include
sudo cp libcantcoap.a /usr/local/lib
```

* Get the code (alternatively you can download it using a zipped version or a different URL pattern):

```
sudo yum install git
git clone <EMAIL>:telefonicaid/fiware-orion.git
```

* Build the source:

```
cd fiware-orion
make
```

* (Optional but highly recommended) run unit test. Firstly, you have to install MongoDB (as the unit tests rely on mongod
  running in localhost).

```
sudo yum install mongodb-server
sudo yum  update pcre            # otherwise, mongod crashes in CentOS 6.3
sudo /etc/init.d/mongod start
sudo /etc/init.d/mongod status   # to check that mongod is actually running
make unit_test
```

* Install the binary. You can use INSTALL_DIR to set the installation prefix path (default is
/usr), thus the broker is installed in `$INSTALL_DIR/bin` directory.

```
sudo make install INSTALL_DIR=/usr
```

* Check that everything is ok, invoking the broker version message:

```
contextBroker --version
```

The Orion Context Broker comes with a suite of valgrind and end-to-end tests that you can also run,
following the following procedure (optional):

* Install the required tools:

```
sudo yum install python python-flask python-jinja2 curl libxml2 nc mongodb valgrind libxslt 
```

* Install COAP client (an example application included in the libcoap sources).
```
wget http://sourceforge.net/projects/libcoap/files/coap-18/libcoap-4.1.1.tar.gz/download
mv download libcoap-4.1.1.tar.gz
tar xvzf libcoap-4.1.1.tar.gz
cd libcoap-4.1.1
./configure
make
sudo cp examples/coap-client /usr/local/bin
```

{'fraction_non_alphanumeric': 0.08175940105496002, 'fraction_numerical': 0.019312574442742897, 'mean_word_length': 4.117544623421854, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6970720', 'n_tokens_mistral': 3809, 'n_tokens_neox': 3508, 'n_words': 1440}