Skip to content

Commit

Permalink
Merge pull request hyperledger#1132 from ArtObr/indy_1947
Browse files Browse the repository at this point in the history
 INDY-1947: Action req_handler implementation
  • Loading branch information
ashcherbakov authored Jan 22, 2019
2 parents 3c2f623 + 69ad214 commit fef4180
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
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
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}}
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

This file was deleted.

0 comments on commit fef4180

Please sign in to comment.