Skip to content
Snippets Groups Projects
Commit a0adf03e authored by Konstantinos Poulakakis's avatar Konstantinos Poulakakis
Browse files

Some changes for starting the app.

parent 9ad5a7ee
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!238Automation component skeleton
...@@ -17,13 +17,12 @@ from common.Settings import get_service_port_grpc ...@@ -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.proto.automation_pb2_grpc import add_AutomationServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService from common.tools.service.GenericGrpcService import GenericGrpcService
from automation.service.AutomationServiceServicerImpl import AutomationServiceServicerImpl from automation.service.AutomationServiceServicerImpl import AutomationServiceServicerImpl
from automation.service.NameMapping import NameMapping
class AutomationService(GenericGrpcService): 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) port = get_service_port_grpc(ServiceNameEnum.AUTOMATION)
super().__init__(port, cls_name=cls_name) super().__init__(port, cls_name=cls_name)
self.automation_servicer = AutomationServiceServicerImpl(name_mapping) self.automation_servicer = AutomationServiceServicerImpl()
def install_servicers(self): def install_servicers(self):
add_AutomationServiceServicer_to_server(self.automation_servicer, self.server) add_AutomationServiceServicer_to_server(self.automation_servicer, self.server)
...@@ -13,27 +13,32 @@ ...@@ -13,27 +13,32 @@
# limitations under the License. # limitations under the License.
import logging, os, grpc 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 from common.proto.automation_pb2_grpc import AutomationServiceServicer
LOGGER = logging.getLogger(__name__)
METRICS_POOL = MetricsPool('Automation', 'RPC')
class AutomationServiceServicerImpl(AutomationServiceServicer): class AutomationServiceServicerImpl(AutomationServiceServicer):
@safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER)
def ZSMCreate(self) -> None: def ZSMCreate(self) -> None:
LOGGER.info('NOT IMPLEMENTED ZSMCreate') LOGGER.info('NOT IMPLEMENTED ZSMCreate')
@safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER)
def ZSMUpdate(self) -> None: def ZSMUpdate(self) -> None:
LOGGER.info('NOT IMPLEMENTED ZSMUpdate') LOGGER.info('NOT IMPLEMENTED ZSMUpdate')
@safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER)
def ZSMDelete(self) -> None: def ZSMDelete(self) -> None:
LOGGER.info('NOT IMPLEMENTED ZSMDelete') LOGGER.info('NOT IMPLEMENTED ZSMDelete')
@safe_and_metered_rpc_method(LOGGER) @safe_and_metered_rpc_method(METRICS_POOL,LOGGER)
def ZSMGetById(self) -> None: def ZSMGetById(self) -> None:
LOGGER.info('NOT IMPLEMENTED ZSMGetById') LOGGER.info('NOT IMPLEMENTED ZSMGetById')
@safe_and_metered_rpc_method(LOGGER)
@safe_and_metered_rpc_method(METRICS_POOL,LOGGER)
def ZSMGetByService(self) -> None: def ZSMGetByService(self) -> None:
LOGGER.info('NOT IMPLEMENTED ZSMGetByService') LOGGER.info('NOT IMPLEMENTED ZSMGetByService')
...@@ -12,15 +12,39 @@ ...@@ -12,15 +12,39 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # 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(): def main():
global LOGGER # pylint: disable=global-statement LOGGER.info('Starting...')
LOGGER = logging.getLogger(__name__) 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') LOGGER.info('Bye')
return 0 return 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment