forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hyperledger#1132 from ArtObr/indy_1947
INDY-1947: Action req_handler implementation
- Loading branch information
Showing
4 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
43 changes: 42 additions & 1 deletion
43
indy_node/server/request_handlers/action_req_handlers/pool_restart_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,46 @@ | ||
from indy_common.authorize.auth_actions import AuthActionAdd | ||
from indy_common.authorize.auth_request_validator import WriteRequestValidator | ||
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, ACTION | ||
|
||
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, | ||
write_req_validator: WriteRequestValidator, | ||
restarter: Restarter): | ||
super().__init__(database_manager, POOL_RESTART, None) | ||
self.write_req_validator = write_req_validator | ||
self.restarter = restarter | ||
|
||
def static_validation(self, request: Request): | ||
self._validate_request_type(request) | ||
|
||
def dynamic_validation(self, request: Request): | ||
self._validate_request_type(request) | ||
action = request.operation.get(ACTION) | ||
self.write_req_validator.validate(request, | ||
[AuthActionAdd(txn_type=POOL_RESTART, | ||
field=ACTION, | ||
value=action)]) | ||
|
||
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)) | ||
self.restarter.handleRestartRequest(request) | ||
result = generate_action_result(request) | ||
logger.debug("Transaction {} with type {} finished" | ||
.format(req_id, request.txn_type)) | ||
return result |
8 changes: 8 additions & 0 deletions
8
indy_node/server/request_handlers/action_req_handlers/utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} |
44 changes: 43 additions & 1 deletion
44
indy_node/server/request_handlers/action_req_handlers/validator_info_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
5 changes: 0 additions & 5 deletions
5
indy_node/server/request_handlers/config_req_handlers/node_upgrade_handler.py
This file was deleted.
Oops, something went wrong.