aboutsummaryrefslogtreecommitdiffstats
path: root/src/python
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2021-03-29 11:49:13 +0200
committerZebek Bogumil <bogumil.zebek@nokia.com>2021-03-29 11:49:13 +0200
commit172e5045cead09db8af3715b62b5b87c919f7f8d (patch)
treec9862dbf86b82ccc4282b0e7cf6c77b7b2a8b104 /src/python
parent18c0838e23209d58881dc59a4ae24a2111883ac2 (diff)
Add readiness endpoint
Signed-off-by: Bogumil Zebek <bogumil.zebek@nokia.com> Issue-ID: INT-1869 Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com> Change-Id: I70323ddad5dcf4589789963afb1bb6831522a9a1
Diffstat (limited to 'src/python')
-rw-r--r--src/python/netconf_rest_application.py6
-rw-r--r--src/python/netconf_server/netconf_app_configuration.py4
-rw-r--r--src/python/netconf_server/netconf_rest_server.py33
3 files changed, 34 insertions, 9 deletions
diff --git a/src/python/netconf_rest_application.py b/src/python/netconf_rest_application.py
index 0d255bc..0a040c9 100644
--- a/src/python/netconf_rest_application.py
+++ b/src/python/netconf_rest_application.py
@@ -33,9 +33,9 @@ logging.basicConfig(
logger = logging.getLogger("netconf_rest_application")
-def start_rest_server(session, connection, server_rest: NetconfRestServer):
+def start_rest_server(session, connection, server_rest: NetconfRestServer, netconf_app_configuration: NetconfAppConfiguration):
sysrepo_cfg_manager = create_conf_manager(session, connection)
- server_rest.start(sysrepo_cfg_manager)
+ server_rest.start(sysrepo_cfg_manager, netconf_app_configuration)
def create_rest_server() -> NetconfRestServer:
@@ -52,6 +52,6 @@ if __name__ == "__main__":
if app_configuration:
logger.info("Netconf rest application configuration: {}".format(app_configuration))
rest_server = create_rest_server()
- SysrepoClient().run_in_session(start_rest_server, rest_server)
+ SysrepoClient().run_in_session(start_rest_server, rest_server, app_configuration)
else:
logger.error(error)
diff --git a/src/python/netconf_server/netconf_app_configuration.py b/src/python/netconf_server/netconf_app_configuration.py
index 190e113..0e25a41 100644
--- a/src/python/netconf_server/netconf_app_configuration.py
+++ b/src/python/netconf_server/netconf_app_configuration.py
@@ -27,11 +27,11 @@ class NetconfAppConfiguration(object):
kafka_port = args[3]
kafka_topic = args[4]
- return NetconfAppConfiguration(configuration_file, kafka_host_name, kafka_port, kafka_topic), None
+ return NetconfAppConfiguration(configuration_file, kafka_host_name, int(kafka_port), kafka_topic), None
else:
return None, "Invalid number of arguments. Please provide all required arguments."
- def __init__(self, module_configuration_file_path: str, kafka_host_name: str, kafka_port: str, kafka_topic: str):
+ def __init__(self, module_configuration_file_path: str, kafka_host_name: str, kafka_port: int, kafka_topic: str):
self.module_configuration_file_path = module_configuration_file_path
self.kafka_host_name = kafka_host_name
self.kafka_port = kafka_port
diff --git a/src/python/netconf_server/netconf_rest_server.py b/src/python/netconf_server/netconf_rest_server.py
index dce4f82..e90c104 100644
--- a/src/python/netconf_server/netconf_rest_server.py
+++ b/src/python/netconf_server/netconf_rest_server.py
@@ -18,8 +18,10 @@
# ============LICENSE_END=========================================================
###
-import logging as sys_logging
from flask import Flask, logging, make_response, Response, request
+
+from netconf_server.netconf_app_configuration import NetconfAppConfiguration
+from netconf_server.netconf_kafka_client import NetconfKafkaClient
from netconf_server.sysrepo_configuration.sysrepo_configuration_manager import SysrepoConfigurationManager
@@ -27,13 +29,17 @@ class NetconfRestServer:
_rest_server: Flask = Flask("server")
logger = logging.create_logger(_rest_server)
_configuration_manager: SysrepoConfigurationManager
+ _app_configuration: NetconfAppConfiguration
def __init__(self, host='0.0.0.0', port=6555):
self._host = host
self._port = port
- def start(self, configuration_manager: SysrepoConfigurationManager):
+ def start(self,
+ configuration_manager: SysrepoConfigurationManager,
+ netconf_app_configuration: NetconfAppConfiguration):
NetconfRestServer._configuration_manager = configuration_manager
+ NetconfRestServer._app_configuration = netconf_app_configuration
Flask.run(
NetconfRestServer._rest_server,
host=self._host,
@@ -42,12 +48,31 @@ class NetconfRestServer:
@staticmethod
@_rest_server.route("/healthcheck")
- def __health_check():
+ def _health_check():
return "UP"
@staticmethod
+ @_rest_server.route("/readiness")
+ def _readiness_check():
+ try:
+ NetconfRestServer.__try_connect_to_kafka()
+ return Response('Ready', status=200)
+ except Exception as e:
+ NetconfRestServer.logger.error("Unable to create a Kafka client", e)
+ return Response('Not Ready', status=503)
+
+ # if Kafka is up & running and hostname with port is proper, then client will be created; otherwise
+ # an error will be reported
+ @staticmethod
+ def __try_connect_to_kafka():
+ NetconfKafkaClient.create(
+ host=NetconfRestServer._app_configuration.kafka_host_name,
+ port=NetconfRestServer._app_configuration.kafka_port
+ )
+
+ @staticmethod
@_rest_server.route("/change_config/<path:module_name>", methods=['POST'])
- def __change_config(module_name):
+ def _change_config(module_name):
config_data = request.data.decode("utf-8")
NetconfRestServer._configuration_manager.change_configuration(config_data, module_name)
return NetconfRestServer.__create_http_response(202, "Accepted")