diff --git a/indy_node/server/request_handlers/action_req_handlers/pool_restart_handler.py b/indy_node/server/request_handlers/action_req_handlers/pool_restart_handler.py index aaaa20b69..e1693dff9 100644 --- a/indy_node/server/request_handlers/action_req_handlers/pool_restart_handler.py +++ b/indy_node/server/request_handlers/action_req_handlers/pool_restart_handler.py @@ -1,5 +1,38 @@ +from indy_node.server.request_handlers.action_req_handlers.utils import generate_action_result +from indy_node.server.restarter import Restarter + +from indy_common.constants import POOL_RESTART + +from plenum.common.request import Request +from plenum.common.txn_util import get_request_data +from plenum.server.database_manager import DatabaseManager from plenum.server.request_handlers.handler_interfaces.action_request_handler import ActionRequestHandler +from stp_core.common.log import getlogger + +logger = getlogger() class PoolRestartHandler(ActionRequestHandler): - pass + + def __init__(self, database_manager: DatabaseManager, + restarter: Restarter): + super().__init__(database_manager, POOL_RESTART, None) + self.restarter = restarter + + def static_validation(self, request: Request): + pass + + def dynamic_validation(self, request: Request): + self._validate_request_type(request) + identifier, req_id, operation = get_request_data(request) + + logger.debug("Transaction {} with type {} started" + .format(req_id, request.txn_type)) + self.restarter.handleRestartRequest(request) + result = generate_action_result(request) + logger.debug("Transaction {} with type {} finished" + .format(req_id, request.txn_type)) + return result + + def process_action(self, request: Request): + self._validate_request_type(request) diff --git a/indy_node/server/request_handlers/action_req_handlers/utils.py b/indy_node/server/request_handlers/action_req_handlers/utils.py new file mode 100644 index 000000000..b8e03c0db --- /dev/null +++ b/indy_node/server/request_handlers/action_req_handlers/utils.py @@ -0,0 +1,8 @@ +from plenum.common.request import Request +from plenum.common.types import f + + +def generate_action_result(request: Request): + return {**request.operation, **{ + f.IDENTIFIER.nm: request.identifier, + f.REQ_ID.nm: request.reqId}} diff --git a/indy_node/server/request_handlers/action_req_handlers/validator_info_handler.py b/indy_node/server/request_handlers/action_req_handlers/validator_info_handler.py index 9c899ba84..04854890a 100644 --- a/indy_node/server/request_handlers/action_req_handlers/validator_info_handler.py +++ b/indy_node/server/request_handlers/action_req_handlers/validator_info_handler.py @@ -1,5 +1,47 @@ +from indy_common.authorize.auth_actions import AuthActionAdd +from indy_common.authorize.auth_request_validator import WriteRequestValidator +from indy_common.constants import VALIDATOR_INFO +from indy_node.server.request_handlers.action_req_handlers.utils import generate_action_result +from plenum.common.constants import DATA +from plenum.common.request import Request +from plenum.common.txn_util import get_request_data +from plenum.server.database_manager import DatabaseManager + from plenum.server.request_handlers.handler_interfaces.action_request_handler import ActionRequestHandler +from stp_core.common.log import getlogger + +logger = getlogger() class ValidatorInfoHandler(ActionRequestHandler): - pass + def __init__(self, database_manager: DatabaseManager, + write_req_validator: WriteRequestValidator, + info_tool): + super().__init__(database_manager, VALIDATOR_INFO, None) + self.write_req_validator = write_req_validator + self.info_tool = info_tool + + def static_validation(self, request: Request): + pass + + def dynamic_validation(self, request: Request): + self._validate_request_type(request) + self.write_req_validator.validate(request, + [AuthActionAdd(txn_type=VALIDATOR_INFO, + field='*', + value='*')]) + + def process_action(self, request: Request): + self._validate_request_type(request) + identifier, req_id, operation = get_request_data(request) + logger.debug("Transaction {} with type {} started" + .format(req_id, request.txn_type)) + result = generate_action_result(request) + result[DATA] = self.info_tool.info + result[DATA].update(self.info_tool.memory_profiler) + result[DATA].update(self.info_tool._generate_software_info()) + result[DATA].update(self.info_tool.extractions) + result[DATA].update(self.info_tool.node_disk_size) + logger.debug("Transaction {} with type {} finished" + .format(req_id, request.txn_type)) + return result