Merge branch 'fixed_config' of github.com:liviu-lesan/planetmint into fixed_config

This commit is contained in:
Jürgen Eckel 2022-04-07 09:52:50 +02:00
commit 742db0f795
6 changed files with 36 additions and 40 deletions

View File

@ -4,18 +4,9 @@
# 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
from planetmint.config import Config
from planetmint.backend.exceptions import ConnectionError
# BACKENDS = { # This is path to MongoDBClass
# 'tarantool_db': 'planetmint.backend.connection_tarantool.TarantoolDB',
# 'localmongodb': 'planetmint.backend.localmongodb.connection.LocalMongoDBConnection'
# }
logger = logging.getLogger(__name__)
@ -26,14 +17,16 @@ class TarantoolDB:
self.host = host
self.port = port
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
if reset_database:
self._load_setup_files()
if reset_database:
self.drop_database()
self.init_database()
def _load_setup_files(self):
self.drop_commands = self.__read_commands(file_path="drop_db.txt")
self.init_commands = self.__read_commands(file_path="init_db.txt")
init_path = Config().get()["database"]["init_config"]["absolute_path"]
drop_path = Config().get()["database"]["drop_config"]["absolute_path"]
self.drop_commands = self.__read_commands(file_path=init_path)
self.init_commands = self.__read_commands(file_path=drop_path)
def space(self, space_name: str):
return self.db_connect.space(space_name)

View File

@ -1,5 +1,3 @@
box.cfg{listen = 3301}
abci_chains = box.schema.space.create('abci_chains',{engine = 'memtx' , is_sync = false})
abci_chains:format({{name='height' , type='integer'},{name='is_synched' , type='boolean'},{name='chain_id',type='string'}})
abci_chains:create_index('id_search' ,{type='hash', parts={'chain_id'}})
@ -67,20 +65,5 @@ keys:create_index('keys_search', {type = 'tree', unique=false, parts={'public_ke
keys:create_index('txid_search', {type = 'tree', unique=false, parts={'transaction_id'}})
keys:create_index('output_search', {type = 'tree', unique=false, parts={'output_id'}})
box.schema.user.create('planetmint', {if_not_exists=true, password = 'planet_user'})
box.schema.user.grant('planetmint', 'read, write', 'space', 'abci_chains')
box.schema.user.grant('planetmint', 'read, write', 'space', 'assets')
box.schema.user.grant('planetmint', 'read, write', 'space', 'blocks')
box.schema.user.grant('planetmint', 'read, write', 'space', 'blocks_tx')
box.schema.user.grant('planetmint', 'read, write', 'space', 'elections')
box.schema.user.grant('planetmint', 'read, write', 'space', 'meta_data')
box.schema.user.grant('planetmint', 'read, write', 'space', 'pre_commits')
box.schema.user.grant('planetmint', 'read, write', 'space', 'validators')
box.schema.user.grant('planetmint', 'read, write', 'space', 'transactions')
box.schema.user.grant('planetmint', 'read, write', 'space', 'inputs')
box.schema.user.grant('planetmint', 'read, write', 'space', 'outputs')
box.schema.user.grant('planetmint', 'read, write', 'space', 'keys')
local console = require('console')
console.start()

View File

@ -0,0 +1 @@
from planetmint.backend.tarantool.transaction import tools

View File

@ -1,8 +1,10 @@
import subprocess
from planetmint.config import Config
def run(commands: list, config: dict):
sshProcess = subprocess.Popen(['%s %s' % (config["service"], config["host"])],
sshProcess = subprocess.Popen(
['%s %s:%s@%s:%s' % (config["service"], config["login"], config["password"], config["host"], config["port"])],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True,
@ -18,3 +20,21 @@ def run(commands: list, config: dict):
# TODO To add here Exception Handler for stdout
# for line in sshProcess.stdout:
# print(line)
def __read_commands(file_path):
with open(file_path, "r") as cmd_file:
commands = [line.strip()+'\n' for line in cmd_file.readlines() if len(str(line)) > 1]
cmd_file.close()
return commands
def _load_setup_files():
drop_commands = __read_commands(file_path="drop_db.txt")
init_commands = __read_commands(file_path="init_db.txt")
return init_commands, drop_commands
init, drop = _load_setup_files()
db_config = Config().get()["database"]
run(commands=drop, config=db_config)

View File

@ -48,13 +48,11 @@ class Config(metaclass=Singleton):
'crlfile': None
}
self.__private_init_config = {
"init_file": "init_db.txt",
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
"absolute_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/init_db.txt"
}
self.__private_drop_config = {
"drop_file": "drop_db.txt", # planetmint/backend/tarantool/init_db.txt
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
"absolute_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/drop_db.txt"
}
self.__private_database_tarantool = {
'backend': 'tarantool_db',

View File

@ -138,5 +138,6 @@ setup(
'dev': dev_require + tests_require + docs_require,
'docs': docs_require,
},
package_data={'planetmint.common.schema': ['*.yaml']},
package_data={'planetmint.common.schema': ['*.yaml'],
'planetmint.backend.tarantool': ['*.txt']}
)