Metadata-Version: 2.2
Name: dp-cubed
Version: 0.9.1
Summary: Dynamic Profile Processing Platform
Author: Vaclav Bartos
Author-email: bartos@cesnet.cz
License: COPYRIGHT AND PERMISSION NOTICE
        
        Copyright (C) 2020-2023 CESNET, z.s.p.o.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
          1. Redistributions of source code must retain the above copyright
             notice, this list of conditions and the following disclaimer.
          2. Redistributions in binary form must reproduce the above copyright
             notice, this list of conditions and the following disclaimer in
             the documentation and/or other materials provided with the distribution.
          3. Neither the name of the Company nor the names of its contributors may
             be used to endorse or promote products derived from this software
             without specific prior written permission.
        
        This software is provided "as is", and any express or implied warranties,
        including, but not limited to, the implied warranties of merchantability
        and fitness for a particular purpose are disclaimed. In no event shall the
        company or contributors be liable for any direct, indirect, incidental,
        special, exemplary, or consequential damages (including, but not limited to,
        procurement of substitute goods or services; loss of use, data, or profits;
        or business interruption) however caused and on any theory of liability,
        whether in contract, strict liability, or tort (including negligence or
        otherwise) arising in any way out of the use of this software, even if
        advised of the possibility of such damage.
        
Project-URL: Homepage, https://github.com/CESNET/dp3
Project-URL: Repository, https://github.com/CESNET/dp3
Project-URL: Documentation, https://cesnet.github.io/dp3
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
Classifier: Framework :: Pydantic :: 1
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Intended Audience :: Developers
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: AMQPStorm~=2.7.2
Requires-Dist: apscheduler~=3.10.0
Requires-Dist: event-count-logger>=1.1
Requires-Dist: fastapi>=0.109.1
Requires-Dist: pydantic>=2.4.0
Requires-Dist: pymongo~=4.6.3
Requires-Dist: python-dateutil~=2.8
Requires-Dist: pyyaml~=6.0
Requires-Dist: requests~=2.32.0
Requires-Dist: uvicorn>=0.22.0
Provides-Extra: dev
Requires-Dist: mkdocs>=1.0.3; extra == "dev"
Requires-Dist: mkdocs-gen-files>=0.4; extra == "dev"
Requires-Dist: mkdocs-literate-nav>=0.6; extra == "dev"
Requires-Dist: mkdocs-material>=9.0; extra == "dev"
Requires-Dist: mkdocs-section-index>=0.3; extra == "dev"
Requires-Dist: mkdocstrings>=0.19; extra == "dev"
Requires-Dist: mkdocstrings-python>=0.8; extra == "dev"
Requires-Dist: pre-commit~=3.0; extra == "dev"
Provides-Extra: deploy
Requires-Dist: gunicorn>=20.1; extra == "deploy"
Provides-Extra: scripts
Requires-Dist: numpy>=1.23.0; extra == "scripts"
Requires-Dist: pandas~=1.4.3; extra == "scripts"

# Dynamic Profile Processing Platform (DP³)

<p align="center">
  <a href="https://cesnet.github.io/dp3/"><img src="https://cesnet.github.io/dp3/img/dp3-logo-min.svg" alt="DP3"></a>
</p>
<p align="center">
  <a href="https://pypi.org/project/dp-cubed/"><img src="https://badge.fury.io/py/dp-cubed.svg" alt="PyPI version" height="20"></a>
</p>

DP³ is a platform helps to keep a database of information (attributes) about individual
entities (designed for IP addresses and other network identifiers, but may be anything),
when the data constantly changes in time.

You can read more about how it works in the [documentation](https://cesnet.github.io/dp3/architecture/).

This is a basis of CESNET's "Asset Discovery Classification and Tagging" (ADiCT) project,
focused on discovery and classification of network devices,
but the platform itself is general and should be usable for any kind of data.

DP³ doesn't do much by itself, it must be supplemented by application-specific modules providing
and processing data.

## Repository structure

* `dp3` - Python package containing code of the processing core and the API
* `config` - default/example configuration
* `install` - deployment configuration

See the [documentation](https://cesnet.github.io/dp3/) for more details.

## Installation

See the [docs](https://cesnet.github.io/dp3/install/) for more details.

### Installing for application development

Pre-requisites: Python 3.9 or higher, `pip` (with `virtualenv` installed), `git`, `Docker` and `Docker Compose`.

Create a virtualenv and install the DP³ platform using:

```shell
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install git+https://github.com/CESNET/dp3.git#egg=dp-cubed
```

#### Creating a DP³ application

DP³ comes with a `dp3` utility, which is used to create a new DP³ application and run it.
To create a new DP³ application we use the `setup` command. Run:

```shell
dp3 setup <application_directory> <your_application_name> 
```

So for example, to create an application called `my_app` in the current directory, run:

```shell
dp3 setup . my_app
```

Which produces a template DP3 application directory structure.

#### Running the Application

To run the application, we first need to setup the other services the platform depends on,
such as the MongoDB database, the RabbitMQ message distribution and the Redis database.
This can be done using the supplied `docker-compose.yml` file. Simply run:

```shell
docker compose up -d --build
```
There are two main ways to run the application itself. First is a little more hand-on, 
and allows easier debugging. 
There are two main kinds of processes in the application: the API and the worker processes.

To run the API, simply run:

```shell
APP_NAME=my_app CONF_DIR=config dp3 api
```

The starting configuration sets only a single worker process, which you can run using:

```shell
dp3 worker my_app config 0     
```

The second way is to use the `docker-compose.app.yml` file, which runs the API and the worker processes
in separate containers. To run the API, simply run:

```shell
docker compose -f docker-compose.app.yml up -d --build
```

Either way, to test that everything is running properly, you can run:
```shell
curl -X 'GET' 'http://localhost:5000/' \
     -H 'Accept: application/json' 
```

Which should return a JSON response with the following content:
```json
{
   "detail": "It works!"
}
```

Final note, to simplify the experience of adjusting the app configuration, 
especially that of the DB entities, we provide the `dp3 check` command.
The command simply loads the configuration and checks that it is valid, but if not,
it tries really hard to pinpoint where exactly you went wrong. This can be used as follows:

```shell
dp3 check <config_directory>
```

You are now ready to start developing your application!

## Installing for platform development

Pre-requisites: Python 3.9 or higher, `pip` (with `virtualenv` installed), `git`, `Docker` and `Docker Compose`.

Pull the repository and install using:

```shell
git clone --branch master git@github.com:CESNET/dp3.git dp3 
cd dp3
python3 -m venv venv
source venv/bin/activate  
python -m pip install --upgrade pip  
pip install --editable ".[dev]" 
pre-commit install
```

### Running the dependencies and the platform

The DP³ platform is now installed and ready for development.
To run it, we first need to setup the other services the platform depends on,
such as the MongoDB database, the RabbitMQ message distribution and the Redis database.
This can be done using the supplied `docker-compose.yml` file. Simply run:

```shell
docker compose up -d --build
```

After the first `compose up` command, the images for RabbitMQ, MongoDB and Redis will be downloaded,
their images will be built according to the configuration and all three services will be started.
On subsequent runs, Docker will use the cache, so if the configuration does not change, the download
and build steps will not be repeated.

The configuration is taken implicitly from the `docker-compose.yml` file in the current directory.
The `docker-compose.yml` configuration contains the configuration for the services,
as well as a testing setup of the DP³ platform itself. 
The full configuration is in `tests/test_config`.
The setup includes one worker process and one API process to handle requests. 
The API process is exposed on port 5000, so you can send requests to it using `curl` or from your browser:

```shell
curl -X 'GET' 'http://localhost:5000/' \
     -H 'Accept: application/json' 
```
```shell
curl -X 'POST' 'http://localhost:5000/datapoints' \
     -H 'Content-Type: application/json' \
     --data '[{"type": "test_entity_type", "id": "abc", "attr": "test_attr_int", "v": 123, "t1": "2023-07-01T12:00:00", "t2": "2023-07-01T13:00:00"}]'
```

### Testing

With the testing platform setup running, we can now run tests. 
Tests are run using the `unittest` framework and can be run using:

```shell
python -m unittest discover \
       -s tests/test_common \
       -v
CONF_DIR=tests/test_config \
python -m unittest discover \
       -s tests/test_api \
       -v
```
