Loading src/automation/service/AutomationService.py +2 −3 Original line number Diff line number Diff line Loading @@ -17,13 +17,12 @@ from common.Settings import get_service_port_grpc from common.proto.automation_pb2_grpc import add_AutomationServiceServicer_to_server from common.tools.service.GenericGrpcService import GenericGrpcService from automation.service.AutomationServiceServicerImpl import AutomationServiceServicerImpl from automation.service.NameMapping import NameMapping class AutomationService(GenericGrpcService): def __init__(self, name_mapping : NameMapping, cls_name: str = __name__) -> None: def __init__(self, cls_name: str = __name__) -> None: port = get_service_port_grpc(ServiceNameEnum.AUTOMATION) super().__init__(port, cls_name=cls_name) self.automation_servicer = AutomationServiceServicerImpl(name_mapping) self.automation_servicer = AutomationServiceServicerImpl() def install_servicers(self): add_AutomationServiceServicer_to_server(self.automation_servicer, self.server) src/automation/service/AutomationServiceServicerImpl.py +11 −6 Original line number Diff line number Diff line Loading @@ -13,27 +13,32 @@ # limitations under the License. import logging, os, grpc from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from common.method_wrappers.Decorator import MetricsPool from common.proto.automation_pb2_grpc import AutomationServiceServicer LOGGER = logging.getLogger(__name__) METRICS_POOL = MetricsPool('Automation', 'RPC') class AutomationServiceServicerImpl(AutomationServiceServicer): @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMCreate(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMCreate') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMUpdate(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMUpdate') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMDelete(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMDelete') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMGetById(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMGetById') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMGetByService(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMGetByService') src/automation/service/__main__.py +30 −6 Original line number Diff line number Diff line Loading @@ -12,15 +12,39 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging,sys import logging, signal, sys, threading from prometheus_client import start_http_server from common.Settings import get_log_level, get_metrics_port from .AutomationService import AutomationService LOGGER : logging.Logger = None LOG_LEVEL = get_log_level() logging.basicConfig(level=LOG_LEVEL, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s") LOGGER = logging.getLogger(__name__) terminate = threading.Event() def signal_handler(signal, frame): # pylint: disable=redefined-outer-name,unused-argument LOGGER.warning('Terminate signal received') terminate.set() def main(): global LOGGER # pylint: disable=global-statement LOGGER = logging.getLogger(__name__) LOGGER.info('Starting...') signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) # Start metrics server metrics_port = get_metrics_port() start_http_server(metrics_port) # Starting context service grpc_service = AutomationService() grpc_service.start() # Wait for Ctrl+C or termination signal while not terminate.wait(timeout=1.0): pass LOGGER.info('Starting Tests...') LOGGER.info('Terminating...') grpc_service.stop() LOGGER.info('Bye') return 0 Loading Loading
src/automation/service/AutomationService.py +2 −3 Original line number Diff line number Diff line Loading @@ -17,13 +17,12 @@ from common.Settings import get_service_port_grpc from common.proto.automation_pb2_grpc import add_AutomationServiceServicer_to_server from common.tools.service.GenericGrpcService import GenericGrpcService from automation.service.AutomationServiceServicerImpl import AutomationServiceServicerImpl from automation.service.NameMapping import NameMapping class AutomationService(GenericGrpcService): def __init__(self, name_mapping : NameMapping, cls_name: str = __name__) -> None: def __init__(self, cls_name: str = __name__) -> None: port = get_service_port_grpc(ServiceNameEnum.AUTOMATION) super().__init__(port, cls_name=cls_name) self.automation_servicer = AutomationServiceServicerImpl(name_mapping) self.automation_servicer = AutomationServiceServicerImpl() def install_servicers(self): add_AutomationServiceServicer_to_server(self.automation_servicer, self.server)
src/automation/service/AutomationServiceServicerImpl.py +11 −6 Original line number Diff line number Diff line Loading @@ -13,27 +13,32 @@ # limitations under the License. import logging, os, grpc from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from common.method_wrappers.Decorator import MetricsPool from common.proto.automation_pb2_grpc import AutomationServiceServicer LOGGER = logging.getLogger(__name__) METRICS_POOL = MetricsPool('Automation', 'RPC') class AutomationServiceServicerImpl(AutomationServiceServicer): @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMCreate(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMCreate') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMUpdate(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMUpdate') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMDelete(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMDelete') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMGetById(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMGetById') @safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) def ZSMGetByService(self) -> None: LOGGER.info('NOT IMPLEMENTED ZSMGetByService')
src/automation/service/__main__.py +30 −6 Original line number Diff line number Diff line Loading @@ -12,15 +12,39 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging,sys import logging, signal, sys, threading from prometheus_client import start_http_server from common.Settings import get_log_level, get_metrics_port from .AutomationService import AutomationService LOGGER : logging.Logger = None LOG_LEVEL = get_log_level() logging.basicConfig(level=LOG_LEVEL, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s") LOGGER = logging.getLogger(__name__) terminate = threading.Event() def signal_handler(signal, frame): # pylint: disable=redefined-outer-name,unused-argument LOGGER.warning('Terminate signal received') terminate.set() def main(): global LOGGER # pylint: disable=global-statement LOGGER = logging.getLogger(__name__) LOGGER.info('Starting...') signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) # Start metrics server metrics_port = get_metrics_port() start_http_server(metrics_port) # Starting context service grpc_service = AutomationService() grpc_service.start() # Wait for Ctrl+C or termination signal while not terminate.wait(timeout=1.0): pass LOGGER.info('Starting Tests...') LOGGER.info('Terminating...') grpc_service.stop() LOGGER.info('Bye') return 0 Loading