mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 15:05:49 +00:00
Merge branch 'fixed_config' of github.com:liviu-lesan/planetmint into fixed_config
This commit is contained in:
commit
742db0f795
@ -4,18 +4,9 @@
|
|||||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from importlib import import_module
|
|
||||||
from itertools import repeat
|
|
||||||
|
|
||||||
import tarantool
|
import tarantool
|
||||||
from planetmint.config import Config
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -26,14 +17,16 @@ class TarantoolDB:
|
|||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
|
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
|
||||||
|
self._load_setup_files()
|
||||||
if reset_database:
|
if reset_database:
|
||||||
self._load_setup_files()
|
|
||||||
self.drop_database()
|
self.drop_database()
|
||||||
self.init_database()
|
self.init_database()
|
||||||
|
|
||||||
def _load_setup_files(self):
|
def _load_setup_files(self):
|
||||||
self.drop_commands = self.__read_commands(file_path="drop_db.txt")
|
init_path = Config().get()["database"]["init_config"]["absolute_path"]
|
||||||
self.init_commands = self.__read_commands(file_path="init_db.txt")
|
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):
|
def space(self, space_name: str):
|
||||||
return self.db_connect.space(space_name)
|
return self.db_connect.space(space_name)
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
box.cfg{listen = 3301}
|
|
||||||
|
|
||||||
abci_chains = box.schema.space.create('abci_chains',{engine = 'memtx' , is_sync = false})
|
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: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'}})
|
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('txid_search', {type = 'tree', unique=false, parts={'transaction_id'}})
|
||||||
keys:create_index('output_search', {type = 'tree', unique=false, parts={'output_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')
|
local console = require('console')
|
||||||
console.start()
|
console.start()
|
||||||
|
|||||||
1
planetmint/backend/tarantool/transaction/__init__.py
Normal file
1
planetmint/backend/tarantool/transaction/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from planetmint.backend.tarantool.transaction import tools
|
||||||
@ -1,13 +1,15 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
from planetmint.config import Config
|
||||||
|
|
||||||
|
|
||||||
def run(commands: list, config: dict):
|
def run(commands: list, config: dict):
|
||||||
sshProcess = subprocess.Popen(['%s %s' % (config["service"], config["host"])],
|
sshProcess = subprocess.Popen(
|
||||||
stdin=subprocess.PIPE,
|
['%s %s:%s@%s:%s' % (config["service"], config["login"], config["password"], config["host"], config["port"])],
|
||||||
stdout=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
universal_newlines=True,
|
stdout=subprocess.PIPE,
|
||||||
bufsize=0,
|
universal_newlines=True,
|
||||||
shell=True)
|
bufsize=0,
|
||||||
|
shell=True)
|
||||||
|
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
try:
|
try:
|
||||||
@ -18,3 +20,21 @@ def run(commands: list, config: dict):
|
|||||||
# TODO To add here Exception Handler for stdout
|
# TODO To add here Exception Handler for stdout
|
||||||
# for line in sshProcess.stdout:
|
# for line in sshProcess.stdout:
|
||||||
# print(line)
|
# 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)
|
||||||
|
|||||||
@ -48,13 +48,11 @@ class Config(metaclass=Singleton):
|
|||||||
'crlfile': None
|
'crlfile': None
|
||||||
}
|
}
|
||||||
self.__private_init_config = {
|
self.__private_init_config = {
|
||||||
"init_file": "init_db.txt",
|
"absolute_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/init_db.txt"
|
||||||
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.__private_drop_config = {
|
self.__private_drop_config = {
|
||||||
"drop_file": "drop_db.txt", # planetmint/backend/tarantool/init_db.txt
|
"absolute_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/drop_db.txt"
|
||||||
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
|
|
||||||
}
|
}
|
||||||
self.__private_database_tarantool = {
|
self.__private_database_tarantool = {
|
||||||
'backend': 'tarantool_db',
|
'backend': 'tarantool_db',
|
||||||
|
|||||||
3
setup.py
3
setup.py
@ -138,5 +138,6 @@ setup(
|
|||||||
'dev': dev_require + tests_require + docs_require,
|
'dev': dev_require + tests_require + docs_require,
|
||||||
'docs': docs_require,
|
'docs': docs_require,
|
||||||
},
|
},
|
||||||
package_data={'planetmint.common.schema': ['*.yaml']},
|
package_data={'planetmint.common.schema': ['*.yaml'],
|
||||||
|
'planetmint.backend.tarantool': ['*.txt']}
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user