Merge branch 'main' into fixed_config

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2022-05-13 11:04:49 +02:00
commit f3a56db9e8
24 changed files with 279 additions and 126 deletions

View File

@ -26,6 +26,15 @@ env:
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
- python: 3.9
env:
- PLANETMINT_DATABASE_BACKEND=tarantool
- PLANETMINT_DATABASE_SSL=
- python: 3.9
env:
- PLANETMINT_DATABASE_BACKEND=tarantool
- PLANETMINT_DATABASE_SSL=
- PLANETMINT_CI_ABCI=enable
- python: 3.9 - python: 3.9
env: env:
- PLANETMINT_DATABASE_BACKEND=localmongodb - PLANETMINT_DATABASE_BACKEND=localmongodb
@ -34,7 +43,8 @@ matrix:
env: env:
- PLANETMINT_DATABASE_BACKEND=localmongodb - PLANETMINT_DATABASE_BACKEND=localmongodb
- PLANETMINT_DATABASE_SSL= - PLANETMINT_DATABASE_SSL=
- PLANETMINT_CI_ABCI=enable - PLANETMINT_CI_ABCI=enable
- python: 3.9 - python: 3.9
env: env:
- PLANETMINT_ACCEPTANCE_TEST=enable - PLANETMINT_ACCEPTANCE_TEST=enable

View File

@ -34,7 +34,7 @@ RUN mkdir -p /data/db /data/configdb \
# Planetmint enviroment variables # Planetmint enviroment variables
ENV PLANETMINT_DATABASE_PORT 27017 ENV PLANETMINT_DATABASE_PORT 27017
ENV PLANETMINT_DATABASE_BACKEND localmongodb ENV PLANETMINT_DATABASE_BACKEND tarantool
ENV PLANETMINT_SERVER_BIND 0.0.0.0:9984 ENV PLANETMINT_SERVER_BIND 0.0.0.0:9984
ENV PLANETMINT_WSSERVER_HOST 0.0.0.0 ENV PLANETMINT_WSSERVER_HOST 0.0.0.0
ENV PLANETMINT_WSSERVER_SCHEME ws ENV PLANETMINT_WSSERVER_SCHEME ws

View File

@ -55,6 +55,7 @@ services:
- "9984:9984" - "9984:9984"
- "9985:9985" - "9985:9985"
- "26658" - "26658"
- "2222:2222"
healthcheck: healthcheck:
test: ["CMD", "bash", "-c", "curl http://planetmint:9984 && curl http://tendermint:26657/abci_query"] test: ["CMD", "bash", "-c", "curl http://planetmint:9984 && curl http://tendermint:26657/abci_query"]
interval: 3s interval: 3s
@ -62,6 +63,7 @@ services:
retries: 3 retries: 3
command: '.ci/entrypoint.sh' command: '.ci/entrypoint.sh'
restart: always restart: always
tendermint: tendermint:
image: tendermint/tendermint:v0.31.5 image: tendermint/tendermint:v0.31.5
# volumes: # volumes:
@ -72,6 +74,7 @@ services:
- "26657:26657" - "26657:26657"
command: sh -c "tendermint init && tendermint node --consensus.create_empty_blocks=false --proxy_app=tcp://planetmint:26658" command: sh -c "tendermint init && tendermint node --consensus.create_empty_blocks=false --proxy_app=tcp://planetmint:26658"
restart: always restart: always
bdb: bdb:
image: busybox image: busybox
depends_on: depends_on:
@ -105,7 +108,7 @@ services:
context: . context: .
dockerfile: Dockerfile-dev dockerfile: Dockerfile-dev
args: args:
backend: localmongodb backend: tarantool
volumes: volumes:
- .:/usr/src/app/ - .:/usr/src/app/
command: make -C docs/root html command: make -C docs/root html

View File

@ -99,8 +99,7 @@ $ bash stack.sh -h
ENV[TM_VERSION] ENV[TM_VERSION]
(Optional) Tendermint version to use for the setup. (default: 0.22.8) (Optional) Tendermint version to use for the setup. (default: 0.22.8)
ENV[MONGO_VERSION]
(Optional) MongoDB version to use with the setup. (default: 3.6)
ENV[AZURE_CLIENT_ID] ENV[AZURE_CLIENT_ID]
Only required when STACK_TYPE="cloud" and STACK_TYPE_PROVIDER="azure". Steps to generate: Only required when STACK_TYPE="cloud" and STACK_TYPE_PROVIDER="azure". Steps to generate:
@ -181,8 +180,6 @@ $ export STACK_BRANCH=master
#Optional, since 0.22.8 is the default tendermint version. #Optional, since 0.22.8 is the default tendermint version.
$ export TM_VERSION=0.22.8 $ export TM_VERSION=0.22.8
#Optional, since 3.6 is the default MongoDB version.
$ export MONGO_VERSION=3.6
$ bash stack.sh $ bash stack.sh
``` ```
@ -232,8 +229,7 @@ $ export STACK_BRANCH=master
#Optional, since 0.22.8 is the default tendermint version #Optional, since 0.22.8 is the default tendermint version
$ export TM_VERSION=0.22.8 $ export TM_VERSION=0.22.8
#Optional, since 3.6 is the default MongoDB version.
$ export MONGO_VERSION=3.6
$ bash stack.sh $ bash stack.sh
``` ```

View File

@ -11,16 +11,16 @@ The following doc describes how to run a local node for developing Planetmint Te
There are two crucial dependencies required to start a local node: There are two crucial dependencies required to start a local node:
- MongoDB - Tarantool
- Tendermint - Tendermint
and of course you also need to install Planetmint Sever from the local code you just developed. and of course you also need to install Planetmint Sever from the local code you just developed.
## Install and Run MongoDB ## Install and Run Tarantool
MongoDB can be easily installed, just refer to their [installation documentation](https://docs.mongodb.com/manual/installation/) for your distro. Tarantool can be easily installed, just refer to their [installation documentation](https://www.tarantool.io/en/download/os-installation/ubuntu/) for your distro.
We know MongoDB 3.4 and 3.6 work with Planetmint. We know Tarantool 2.8 work with Planetmint.
After the installation of MongoDB is complete, run MongoDB using `sudo mongod` After the installation of Tarantool is complete, run Tarantool using `tarantool` and to create a listener `box.cfg{listen=3301}` in cli of Tarantool.
## Install and Run Tendermint ## Install and Run Tendermint
@ -125,7 +125,7 @@ To execute tests when developing a feature or fixing a bug one could use the fol
$ pytest -v $ pytest -v
``` ```
NOTE: MongoDB and Tendermint should be running as discussed above. NOTE: Tarantool and Tendermint should be running as discussed above.
One could mark a specific test and execute the same by appending `-m my_mark` to the above command. One could mark a specific test and execute the same by appending `-m my_mark` to the above command.

View File

@ -39,7 +39,7 @@ $ docker-compose up -d bdb
The above command will launch all 3 main required services/processes: The above command will launch all 3 main required services/processes:
* ``mongodb`` * ``tarantool``
* ``tendermint`` * ``tendermint``
* ``planetmint`` * ``planetmint``
@ -55,7 +55,7 @@ To follow the logs of the ``planetmint`` service:
$ docker-compose logs -f planetmint $ docker-compose logs -f planetmint
``` ```
To follow the logs of the ``mongodb`` service:
```bash ```bash
$ docker-compose logs -f mdb $ docker-compose logs -f mdb

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@ -9,7 +9,7 @@ Code is Apache-2.0 and docs are CC-BY-4.0
Each Planetmint node runs: Each Planetmint node runs:
- MongoDB - Tarantool
- Planetmint Server - Planetmint Server
- Tendermint - Tendermint
@ -17,11 +17,6 @@ When running a Planetmint node for long periods
of time, we need to consider doing log rotation, i.e. we do not want the logs taking of time, we need to consider doing log rotation, i.e. we do not want the logs taking
up large amounts of storage and making the node unresponsive or getting it into a bad state. up large amounts of storage and making the node unresponsive or getting it into a bad state.
## MongoDB Logging and Log Rotation
See the MongoDB docs about
[logging](https://docs.mongodb.com/v3.6/administration/monitoring/#monitoring-standard-loggging)
and [log rotation](https://docs.mongodb.com/v3.6/tutorial/rotate-log-files/).
## Planetmint Server Logging and Log Rotation ## Planetmint Server Logging and Log Rotation

View File

@ -155,13 +155,12 @@ recheck = false
Note: The list of `persistent_peers` doesn't have to include all nodes Note: The list of `persistent_peers` doesn't have to include all nodes
in the network. in the network.
## Member: Start MongoDB ## Member: Start Tarantool
If you installed MongoDB using `sudo apt install mongodb`, then MongoDB should already be running in the background. You can check using `systemctl status mongodb`. You install Tarantool as described [here](https://www.tarantool.io/ru/download/os-installation/ubuntu/).
If MongoDB isn't running, then you can start it using the command `mongod`, but that will run it in the foreground. If you want to run it in the background (so it will continue running after you logout), you can use `mongod --fork --logpath /var/log/mongodb.log`. (You might have to create the `/var/log` directory if it doesn't already exist.) You can start it using the command `tarantool`.To run it in the background (so it will continue running after you logout), you can have to create a listener `box.cfg{listen=3301}`.
If you installed MongoDB using `sudo apt install mongodb`, then a MongoDB startup script should already be installed (so MongoDB will start automatically when the machine is restarted). Otherwise, you should install a startup script for MongoDB.
## Member: Start Planetmint and Tendermint Using Monit ## Member: Start Planetmint and Tendermint Using Monit

View File

@ -4,4 +4,4 @@ You can find one of the installation methods with Ansible on GitHub at:
[Ansible script](https://github.com/planetmint/planetmint-node-ansible) [Ansible script](https://github.com/planetmint/planetmint-node-ansible)
It allows to install Planetmint, MongoDB, Tendermint, and python, and then connect nodes into a network. Current tested machine is Ubuntu 18.04. It allows to install Planetmint, Tarantool, Tendermint, and python, and then connect nodes into a network. Current tested machine is Ubuntu 18.04.

View File

@ -15,7 +15,7 @@ Docker image and a
This image contains all the services required for a Planetmint node i.e. This image contains all the services required for a Planetmint node i.e.
- Planetmint Server - Planetmint Server
- MongoDB - Tarantool
- Tendermint - Tendermint
**Note:** **NOT for Production Use:** *This is an single node opinionated image not well suited for a network deployment.* **Note:** **NOT for Production Use:** *This is an single node opinionated image not well suited for a network deployment.*
@ -42,8 +42,6 @@ $ docker run \
--publish 9985:9985 \ --publish 9985:9985 \
--publish 27017:27017 \ --publish 27017:27017 \
--publish 26657:26657 \ --publish 26657:26657 \
--volume $HOME/planetmint_docker/mongodb/data/db:/data/db \
--volume $HOME/planetmint_docker/mongodb/data/configdb:/data/configdb \
--volume $HOME/planetmint_docker/tendermint:/tendermint \ --volume $HOME/planetmint_docker/tendermint:/tendermint \
planetmint/planetmint:all-in-one planetmint/planetmint:all-in-one
``` ```
@ -55,10 +53,7 @@ Let's analyze that command:
* `publish 9984:9984` map the host port `9984` to the container port `9984` * `publish 9984:9984` map the host port `9984` to the container port `9984`
(the Planetmint API server) (the Planetmint API server)
* `9985` Planetmint Websocket server * `9985` Planetmint Websocket server
* `27017` Default port for MongoDB
* `26657` Tendermint RPC server * `26657` Tendermint RPC server
* `--volume "$HOME/planetmint_docker/mongodb:/data"` map the host directory
`$HOME/planetmint_docker/mongodb` to the container directory `/data`;
this allows us to have the data persisted on the host machine, this allows us to have the data persisted on the host machine,
you can read more in the [official Docker you can read more in the [official Docker
documentation](https://docs.docker.com/engine/tutorials/dockervolumes) documentation](https://docs.docker.com/engine/tutorials/dockervolumes)

View File

@ -22,28 +22,24 @@ The value of each setting is determined according to the following rules:
* Otherwise, use the default value * Otherwise, use the default value
The local config file is `$HOME/.planetmint` by default (a file which might not even exist), but you can tell Planetmint to use a different file by using the `-c` command-line option, e.g. `planetmint -c path/to/config_file.json start` The local config file is `$HOME/.planetmint` by default (a file which might not even exist), but you can tell Planetmint to use a different file by using the `-c` command-line option, e.g. `planetmint -c path/to/config_file.json start`
or using the `PLANETMINT_CONFIG_PATH` environment variable, e.g. `BIGHAINDB_CONFIG_PATH=.my_planetmint_config planetmint start`. or using the `PLANETMINT_CONFIG_PATH` environment variable, e.g. `PLANETMINT_CONFIG_PATH=.my_planetmint_config planetmint start`.
Note that the `-c` command line option will always take precedence if both the `PLANETMINT_CONFIG_PATH` and the `-c` command line option are used. Note that the `-c` command line option will always take precedence if both the `PLANETMINT_CONFIG_PATH` and the `-c` command line option are used.
You can read the current default values in the file [planetmint/\_\_init\_\_.py](https://github.com/planetmint/planetmint/blob/master/planetmint/__init__.py). (The link is to the latest version.) You can read the current default values in the file [planetmint/\_\_init\_\_.py](https://github.com/planetmint/planetmint/blob/master/planetmint/__init__.py). (The link is to the latest version.)
Running `planetmint -y configure localmongodb` will generate a local config file in `$HOME/.planetmint` with all the default values.
## database.* ## database.*
The settings with names of the form `database.*` are for the backend database The settings with names of the form `database.*` are for the backend database
(currently only MongoDB). They are: (currently only Tarantool). They are:
* `database.backend` can only be `localmongodb`, currently. * `database.backend` can only be `localtarantool`, currently.
* `database.host` is the hostname (FQDN) of the backend database. * `database.host` is the hostname (FQDN) of the backend database.
* `database.port` is self-explanatory. * `database.port` is self-explanatory.
* `database.name` is a user-chosen name for the database inside MongoDB, e.g. `planetmint`. * `database.user` is a user-chosen name for the database inside Tarantool, e.g. `planetmint`.
* `database.connection_timeout` is the maximum number of milliseconds that Planetmint will wait before giving up on one attempt to connect to the backend database. * `database.pass` is the password of the user for connection to tarantool listener.
* `database.max_tries` is the maximum number of times that Planetmint will try to establish a connection with the backend database. If 0, then it will try forever.
* `database.replicaset` is the name of the MongoDB replica set. The default value is `null` because in Planetmint 2.0+, each Planetmint node has its own independent MongoDB database and no replica set is necessary. Replica set must already exist if this option is configured, Planetmint will not create it.
* `database.ssl` must be `true` or `false`. It tells Planetmint Server whether it should connect to MongoDB using TLS/SSL or not. The default value is `false`.
There are three ways for Planetmint Server to authenticate itself with MongoDB (or a specific MongoDB database): no authentication, username/password, and x.509 certificate authentication. There are two ways for Planetmint Server to authenticate itself with Tarantool (or a specific Tarantool service): no authentication, username/password.
**No Authentication** **No Authentication**
@ -51,58 +47,18 @@ If you use all the default Planetmint configuration settings, then no authentica
**Username/Password Authentication** **Username/Password Authentication**
To use username/password authentication, a MongoDB instance must already be running somewhere (maybe in another machine), it must already have a database for use by Planetmint (usually named `planetmint`, which is the default `database.name`), and that database must already have a "readWrite" user with associated username and password. To create such a user, login to your MongoDB instance as Admin and run the following commands: To use username/password authentication, a Tarantool instance must already be running somewhere (maybe in another machine), it must already have a spaces for use by Planetmint, and that database must already have a "readWrite" user with associated username and password.
```text
use <database.name>
db.createUser({user: "<database.login>", pwd: "<database.password>", roles: [{role: "readWrite", db: "<database.name>"}]})
```
* `database.login` is the user's username.
* `database.password` is the user's password, given in plaintext.
* `database.ca_cert`, `database.certfile`, `database.keyfile`, `database.crlfile`, and `database.keyfile_passphrase` are not used so they can have their default values.
**x.509 Certificate Authentication**
To use x.509 certificate authentication, a MongoDB instance must be running somewhere (maybe in another machine), it must already have a database for use by Planetmint (usually named `planetmint`, which is the default `database.name`), and that database must be set up to use x.509 authentication. See the MongoDB docs about how to do that.
* `database.login` is the user's username.
* `database.password` isn't used so the default value (`null`) is fine.
* `database.ca_cert`, `database.certfile`, `database.keyfile` and `database.crlfile` are the paths to the CA, signed certificate, private key and certificate revocation list files respectively.
* `database.keyfile_passphrase` is the private key decryption passphrase, specified in plaintext.
**Example using environment variables**
```text
export PLANETMINT_DATABASE_BACKEND=localmongodb
export PLANETMINT_DATABASE_HOST=localhost
export PLANETMINT_DATABASE_PORT=27017
export PLANETMINT_DATABASE_NAME=database8
export PLANETMINT_DATABASE_CONNECTION_TIMEOUT=5000
export PLANETMINT_DATABASE_MAX_TRIES=3
```
**Default values** **Default values**
If (no environment variables were set and there's no local config file), or you used `planetmint -y configure localmongodb` to create a default local config file for a `localmongodb` backend, then the defaults will be:
```js ```js
"database": { "database": {
"backend": "localmongodb", "backend": "tarantool",
"host": "localhost", "host": "localhost",
"port": 27017, "port": 3301,
"name": "planetmint", "username": null,
"connection_timeout": 5000,
"max_tries": 3,
"replicaset": null,
"login": null,
"password": null "password": null
"ssl": false,
"ca_cert": null,
"certfile": null,
"keyfile": null,
"crlfile": null,
"keyfile_passphrase": null,
} }
``` ```

View File

@ -25,18 +25,18 @@ Show the version number. `planetmint -v` does the same thing.
Generate a local configuration file (which can be used to set some or all [Planetmint node configuration settings](configuration)). It will ask you for the values of some configuration settings. Generate a local configuration file (which can be used to set some or all [Planetmint node configuration settings](configuration)). It will ask you for the values of some configuration settings.
If you press Enter for a value, it will use the default value. If you press Enter for a value, it will use the default value.
At this point, only one database backend is supported: `localmongodb`. At this point, only one database backend is supported: `tarantool`.
If you use the `-c` command-line option, it will generate the file at the specified path: If you use the `-c` command-line option, it will generate the file at the specified path:
```text ```text
planetmint -c path/to/new_config.json configure localmongodb planetmint -c path/to/new_config.json configure tarantool
``` ```
If you don't use the `-c` command-line option, the file will be written to `$HOME/.planetmint` (the default location where Planetmint looks for a config file, if one isn't specified). If you don't use the `-c` command-line option, the file will be written to `$HOME/.planetmint` (the default location where Planetmint looks for a config file, if one isn't specified).
If you use the `-y` command-line option, then there won't be any interactive prompts: it will use the default values for all the configuration settings. If you use the `-y` command-line option, then there won't be any interactive prompts: it will use the default values for all the configuration settings.
```text ```text
planetmint -y configure localmongodb planetmint -y configure tarantool
``` ```
@ -47,13 +47,13 @@ Show the values of the [Planetmint node configuration settings](configuration).
## planetmint init ## planetmint init
Create a backend database (local MongoDB), all database tables/collections, Create a backend database (local tarantool), all database tables/collections,
various backend database indexes, and the genesis block. various backend database indexes, and the genesis block.
## planetmint drop ## planetmint drop
Drop (erase) the backend database (the local MongoDB database used by this node). Drop (erase) the backend database (the local tarantool database used by this node).
You will be prompted to make sure. You will be prompted to make sure.
If you want to force-drop the database (i.e. skipping the yes/no prompt), then use `planetmint -y drop` If you want to force-drop the database (i.e. skipping the yes/no prompt), then use `planetmint -y drop`
@ -148,7 +148,7 @@ $ planetmint election new migration --private-key /home/user/.tendermint/config/
``` ```
Concluded chain migration elections halt block production at whichever block height they are approved. Concluded chain migration elections halt block production at whichever block height they are approved.
Afterwards, validators are supposed to upgrade Tendermint, set new `chain_id`, `app_hash`, and `validators` (to learn these values, use the [election show](#election-show) command) in `genesis.json`, make and save a MongoDB dump, and restart the system. Afterwards, validators are supposed to upgrade Tendermint, set new `chain_id`, `app_hash`, and `validators` (to learn these values, use the [election show](#election-show) command) in `genesis.json`, make and save a tarantool dump, and restart the system.
For more details about how chain migrations work, refer to [Type 3 scenarios in BEP-42](https://github.com/planetmint/BEPs/tree/master/42). For more details about how chain migrations work, refer to [Type 3 scenarios in BEP-42](https://github.com/planetmint/BEPs/tree/master/42).

View File

@ -10,17 +10,15 @@ Code is Apache-2.0 and docs are CC-BY-4.0
A production Planetmint node must include: A production Planetmint node must include:
* Planetmint Server * Planetmint Server
* MongoDB Server 3.4+ (mongod) * Tarantool
* Tendermint * Tendermint
* Storage for MongoDB and Tendermint * Storage for MongoDB and Tendermint
It could also include several other components, including: It could also include several other components, including:
* NGINX or similar, to provide authentication, rate limiting, etc. * NGINX or similar, to provide authentication, rate limiting, etc.
* An NTP daemon running on all machines running Planetmint Server or mongod, and possibly other machines * An NTP daemon running on all machines running Planetmint Server or tarantool, and possibly other machines
* Probably _not_ MongoDB Automation Agent. It's for automating the deployment of an entire MongoDB cluster.
* MongoDB Monitoring Agent
* MongoDB Backup Agent
* Log aggregation software * Log aggregation software
* Monitoring software * Monitoring software
* Maybe more * Maybe more

View File

@ -7,7 +7,7 @@ Code is Apache-2.0 and docs are CC-BY-4.0
# Production Node Requirements # Production Node Requirements
**This page is about the requirements of Planetmint Server.** You can find the requirements of MongoDB, Tendermint and other [production node components](node-components) in the documentation for that software. **This page is about the requirements of Planetmint Server.** You can find the requirements of Tarantool, Tendermint and other [production node components](node-components) in the documentation for that software.
## OS Requirements ## OS Requirements

View File

@ -14,5 +14,5 @@ Here are some references about how to secure an Ubuntu 18.04 server:
Also, here are some recommendations a node operator can follow to enhance the privacy of the data coming to, stored on, and leaving their node: Also, here are some recommendations a node operator can follow to enhance the privacy of the data coming to, stored on, and leaving their node:
- Ensure that all data stored on a node is encrypted at rest, e.g. using full disk encryption. This can be provided as a service by the operating system, transparently to Planetmint, MongoDB and Tendermint. - Ensure that all data stored on a node is encrypted at rest, e.g. using full disk encryption. This can be provided as a service by the operating system, transparently to Planetmint, Tarantool and Tendermint.
- Ensure that all data is encrypted in transit, i.e. enforce using HTTPS for the HTTP API and the Websocket API. This can be done using NGINX or similar, as we do with the IPDB Testnet. - Ensure that all data is encrypted in transit, i.e. enforce using HTTPS for the HTTP API and the Websocket API. This can be done using NGINX or similar, as we do with the IPDB Testnet.

View File

@ -5,11 +5,11 @@ SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
Code is Apache-2.0 and docs are CC-BY-4.0 Code is Apache-2.0 and docs are CC-BY-4.0
---> --->
# Set Up Planetmint, MongoDB and Tendermint # Set Up Planetmint, Tarantool and Tendermint
We now install and configure software that must run We now install and configure software that must run
in every Planetmint node: Planetmint Server, in every Planetmint node: Planetmint Server,
MongoDB and Tendermint. Tarantool and Tendermint.
## Install Planetmint Server ## Install Planetmint Server
@ -69,25 +69,18 @@ under `"wsserver"`:
where `bnode.example.com` should be replaced by your node's actual subdomain. where `bnode.example.com` should be replaced by your node's actual subdomain.
## Install (and Start) MongoDB ## Install (and Start) Tarantool
Install a recent version of MongoDB. Install a recent version of Tarantool.
Planetmint Server requires version 3.4 or newer. Planetmint Server requires version 3.4 or newer.
``` ```
sudo apt install mongodb curl -L https://tarantool.io/DDJLJzv/release/2.8/installer.sh | bash
sudo apt-get -y install tarantool
``` ```
If you install MongoDB using the above command (which installs the `mongodb` package),
it also configures MongoDB, starts MongoDB (in the background),
and installs a MongoDB startup script
(so that MongoDB will be started automatically when the machine is restarted).
Note: The `mongodb` package is _not_ the official MongoDB package
from MongoDB the company. If you want to install the official MongoDB package,
please see
[the MongoDB documentation](https://docs.mongodb.com/manual/installation/).
Note that installing the official package _doesn't_ also start MongoDB.
## Install Tendermint ## Install Tendermint

View File

@ -2,7 +2,7 @@
## General Tips ## General Tips
- Check the Planetmint, Tendermint and MongoDB logs. - Check the Planetmint, Tendermint and Tarantool logs.
For help with that, see the page about [Logging and Log Rotation](../appendices/log-rotation). For help with that, see the page about [Logging and Log Rotation](../appendices/log-rotation).
- Try Googling the error message. - Try Googling the error message.
@ -36,7 +36,7 @@ addr_book_strict = false
If you want to refresh your node back to a fresh empty state, then your best bet is to terminate it and deploy a new machine, but if that's not an option, then you can: If you want to refresh your node back to a fresh empty state, then your best bet is to terminate it and deploy a new machine, but if that's not an option, then you can:
* drop the `planetmint` database in MongoDB using `planetmint drop` (but that only works if MongoDB is running) * drop the `planetmint` database in tarantool using `planetmint drop` (but that only works if tarantool is running)
* reset Tendermint using `tendermint unsafe_reset_all` * reset Tendermint using `tendermint unsafe_reset_all`
* delete the directory `$HOME/.tendermint` * delete the directory `$HOME/.tendermint`

View File

@ -0,0 +1,176 @@
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
import logging
from importlib import import_module
from itertools import repeat
import tarantool
import planetmint
import os
from planetmint.backend.exceptions import ConnectionError
from planetmint.backend.utils import get_planetmint_config_value, get_planetmint_config_value_or_key_error
from planetmint.common.exceptions import ConfigurationError
BACKENDS = { # This is path to MongoDBClass
'tarantool': 'planetmint.backend.connection_tarantool.TarantoolDB',
}
logger = logging.getLogger(__name__)
class TarantoolDB:
init_config = {
"init_file": "init_db.txt",
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
}
drop_config = {
"drop_file": "drop_db.txt", # planetmint/backend/tarantool/init_db.txt
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
}
def __init__(self, host: str, port: int, user: str, password: str, reset_database: bool = False):
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
if reset_database:
self.drop_database()
self.init_database()
def get_connection(self, space_name: str = None):
return self.db_connect if space_name is None else self.db_connect.space(space_name)
def __read_commands(self, file_path):
with open(file_path, "r") as cmd_file:
commands = [line.strip() for line in cmd_file.readlines() if len(str(line)) > 1]
cmd_file.close()
return commands
def drop_database(self):
from planetmint.backend.tarantool.utils import run
# config = get_planetmint_config_value_or_key_error("ctl_config")
# drop_config = config["drop_config"]
f_path = "%s%s" % (self.drop_config["relative_path"], self.drop_config["drop_file"])
commands = self.__read_commands(file_path=f_path)
run(commands=commands, config=config)
def init_database(self):
from planetmint.backend.tarantool.utils import run
# config = get_planetmint_config_value_or_key_error("ctl_config")
# init_config = config["init_config"]
f_path = "%s%s" % (self.init_config["relative_path"], self.init_config["init_file"])
commands = self.__read_commands(file_path=f_path)
run(commands=commands, config=config)
def connect(host: str = None, port: int = None, username: str = None, password: str = None,
backend: str = None, reset_database: bool = False, name=None, max_tries=None,
connection_timeout=None, replicaset=None, ssl=None, login: str = None, ctl_config=None,
ca_cert=None, certfile=None, keyfile=None, keyfile_passphrase=None, reconnect_delay=None,
crlfile=None, connect_now=True, encoding=None):
backend = backend or get_planetmint_config_value_or_key_error('backend') # TODO Rewrite Configs
host = host or get_planetmint_config_value_or_key_error('host')
port = port or get_planetmint_config_value_or_key_error('port')
username = username or login or get_planetmint_config_value('login')
password = password or get_planetmint_config_value('password')
try: # Here we get class using getattr function
module_name, _, class_name = BACKENDS[backend].rpartition('.')
Class = getattr(import_module(module_name), class_name)
except KeyError:
raise ConfigurationError('Backend `{}` is not supported. '
'Planetmint currently supports {}'.format(backend, BACKENDS.keys()))
except (ImportError, AttributeError) as exc:
raise ConfigurationError('Error loading backend `{}`'.format(backend)) from exc
print(host)
print(port)
print(username)
logger.debug('Connection: {}'.format(Class))
return Class(host=host, port=port, user=username, password=password, reset_database=reset_database)
class Connection:
"""Connection class interface.
All backend implementations should provide a connection class that inherits
from and implements this class.
"""
def __init__(self, host=None, port=None, connection_timeout=None, max_tries=None,
**kwargs):
"""Create a new :class:`~.Connection` instance.
Args:
host (str): the host to connect to.
port (int): the port to connect to.
dbname (str): the name of the database to use.
connection_timeout (int, optional): the milliseconds to wait
until timing out the database connection attempt.
Defaults to 5000ms.
max_tries (int, optional): how many tries before giving up,
if 0 then try forever. Defaults to 3.
**kwargs: arbitrary keyword arguments provided by the
configuration's ``database`` settings
"""
dbconf = planetmint.config['database']
self.host = host or dbconf['host']
self.port = port or dbconf['port']
self.connection_timeout = connection_timeout if connection_timeout is not None \
else dbconf['connection_timeout']
self.max_tries = max_tries if max_tries is not None else dbconf['max_tries']
self.max_tries_counter = range(self.max_tries) if self.max_tries != 0 else repeat(0)
self._conn = None
@property
def conn(self):
pass
if self._conn is None:
self.connect()
return self._conn
def run(self, query):
pass
"""Run a query.
Args:
query: the query to run
Raises:
:exc:`~DuplicateKeyError`: If the query fails because of a
duplicate key constraint.
:exc:`~OperationFailure`: If the query fails for any other
reason.
:exc:`~ConnectionError`: If the connection to the database
fails.
"""
raise NotImplementedError()
def connect(self):
pass
"""Try to connect to the database.
Raises:
:exc:`~ConnectionError`: If the connection to the database
fails.
"""
attempt = 0
for i in self.max_tries_counter:
attempt += 1
try:
self._conn = self._connect()
except ConnectionError as exc:
logger.warning('Attempt %s/%s. Connection to %s:%s failed after %sms.',
attempt, self.max_tries if self.max_tries != 0 else '',
self.host, self.port, self.connection_timeout)
if attempt == self.max_tries:
logger.critical('Cannot connect to the Database. Giving up.')
raise ConnectionError() from exc
else:
break

View File

@ -0,0 +1,31 @@
# How to start using planetmint with tarantool
First of all you have do download [Tarantool](https://www.tarantool.io/en/download/os-installation/ubuntu/).
## How to connect tarantool to planetmint
After a successful instalation you should be able to run from you terminal command ```tarantool```. In the cli of tarantool you need initializa a listening following the example :
```
box.cfg{listen=3301}
```
[^1].
Afterwards quit cli of tarantool and scan by port if to be sure that service was created by tarantool.
### How to init spaces and indexes of tarantool[^2].
For this step you need to go in the root folder of planetmint and run from your virtual enviroment:
```
python planetmint init localhost 3301 admin pass
```
### In case you want to reset tarantool you can run command above and adding at the end True.
[^1]: This is example of the port address that can be used.
[^2]: Not yet working

View File

@ -323,9 +323,9 @@ def create_parser():
help='Prepare the config file.') help='Prepare the config file.')
config_parser.add_argument('backend', config_parser.add_argument('backend',
choices=['tarantool_db'], choices=['tarantool', 'localmongodb'],
default='tarantool_db', default='tarantool',
const='tarantool_db', const='tarantool',
nargs='?', nargs='?',
help='The backend to use. It can only be ' help='The backend to use. It can only be '
'"tarantool_db", currently.') '"tarantool_db", currently.')

View File

@ -84,7 +84,7 @@ install_requires = [
'gunicorn==20.1.0', 'gunicorn==20.1.0',
'jsonschema==3.2.0', 'jsonschema==3.2.0',
'logstats==0.3.0', 'logstats==0.3.0',
'packaging>=20.9', 'packaging>=20.9',
# TODO Consider not installing the db drivers, or putting them in extras. # TODO Consider not installing the db drivers, or putting them in extras.
'pymongo==3.11.4', 'pymongo==3.11.4',
'tarantool==0.7.1', 'tarantool==0.7.1',
@ -92,9 +92,10 @@ install_requires = [
'pyyaml==5.4.1', 'pyyaml==5.4.1',
'requests==2.25.1', 'requests==2.25.1',
'setproctitle==1.2.2', 'setproctitle==1.2.2',
'ptvsd'
] ]
if sys.version_info < (3, 6): if sys.version_info < (3, 9):
install_requires.append('pysha3~=1.0.2') install_requires.append('pysha3~=1.0.2')
setup( setup(

View File

@ -52,7 +52,7 @@ def pytest_addoption(parser):
parser.addoption( parser.addoption(
'--database-backend', '--database-backend',
action='store', action='store',
default=os.environ.get('PLANETMINT_DATABASE_BACKEND', 'tarantool_db'), default=os.environ.get('PLANETMINT_DATABASE_BACKEND', 'tarantool'),
help='Defines the backend to use (available: {})'.format(backends), help='Defines the backend to use (available: {})'.format(backends),
) )
@ -99,7 +99,7 @@ def _configure_planetmint(request):
test_db_name = '{}_{}'.format(TEST_DB_NAME, xdist_suffix) test_db_name = '{}_{}'.format(TEST_DB_NAME, xdist_suffix)
# backend = request.config.getoption('--database-backend') # backend = request.config.getoption('--database-backend')
backend = "tarantool_db" backend = "tarantool"
config = { config = {
'database': Config().get_db_map(backend), 'database': Config().get_db_map(backend),

View File

@ -127,7 +127,7 @@ def test_env_config(monkeypatch):
assert result == expected assert result == expected
@pytest.mark.skip
def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request): # TODO Disabled until we create a better config format def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request): # TODO Disabled until we create a better config format
return return
# constants # constants