summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2021-04-09 12:55:29 +0200
committerZebek Bogumil <bogumil.zebek@nokia.com>2021-04-09 12:55:29 +0200
commit84730e0091265d49b71f861f5744ade72bb6c3e9 (patch)
treecd82ae332b34d065260ab584da13e1b2ce363623 /src
parentc0d47aca4a13b239e51772fa366fa780ec7812da (diff)
Fix readiness endpoint
Issue-ID: INT-1869 Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com> Change-Id: I7849c8acd59e40cf10e65bfefd519a75712f4a80
Diffstat (limited to 'src')
-rw-r--r--src/python/netconf_rest_application.py7
-rw-r--r--src/python/netconf_server/netconf_rest_server.py30
2 files changed, 21 insertions, 16 deletions
diff --git a/src/python/netconf_rest_application.py b/src/python/netconf_rest_application.py
index b13a084..8376fd8 100644
--- a/src/python/netconf_rest_application.py
+++ b/src/python/netconf_rest_application.py
@@ -21,7 +21,6 @@ import sys
import logging
from netconf_server.netconf_app_configuration import NetconfAppConfiguration
-from netconf_server.netconf_kafka_client import provide_configured_kafka_client
from netconf_server.netconf_rest_server import NetconfRestServer
from netconf_server.sysrepo_configuration.sysrepo_configuration_manager import SysrepoConfigurationManager
@@ -36,11 +35,7 @@ logger = logging.getLogger("netconf_rest_application")
def start_rest_server(session, connection, server_rest: NetconfRestServer, netconf_app_configuration: NetconfAppConfiguration):
sysrepo_cfg_manager = create_conf_manager(session, connection)
- kafka_client = provide_configured_kafka_client(
- netconf_app_configuration.kafka_host_name,
- netconf_app_configuration.kafka_port
- )
- server_rest.start(sysrepo_cfg_manager, kafka_client, netconf_app_configuration.kafka_topic)
+ server_rest.start(sysrepo_cfg_manager, netconf_app_configuration)
def create_rest_server() -> NetconfRestServer:
diff --git a/src/python/netconf_server/netconf_rest_server.py b/src/python/netconf_server/netconf_rest_server.py
index edaa6e8..5dbe6cd 100644
--- a/src/python/netconf_server/netconf_rest_server.py
+++ b/src/python/netconf_server/netconf_rest_server.py
@@ -20,7 +20,8 @@
from flask import Flask, logging, make_response, Response, request, jsonify
-from netconf_server.netconf_kafka_client import NetconfKafkaClient
+from netconf_server.netconf_app_configuration import NetconfAppConfiguration
+from netconf_server.netconf_kafka_client import provide_configured_kafka_client
from netconf_server.sysrepo_configuration.sysrepo_configuration_manager import SysrepoConfigurationManager
@@ -28,8 +29,7 @@ class NetconfRestServer:
_rest_server: Flask = Flask("server")
logger = logging.create_logger(_rest_server)
_configuration_manager: SysrepoConfigurationManager
- _kafka_topic: str
- _kafka_client: NetconfKafkaClient
+ _app_configuration: NetconfAppConfiguration
def __init__(self, host='0.0.0.0', port=6555):
self._host = host
@@ -37,11 +37,9 @@ class NetconfRestServer:
def start(self,
configuration_manager: SysrepoConfigurationManager,
- kafka_client: NetconfKafkaClient,
- kafka_topic: str):
+ netconf_app_configuration: NetconfAppConfiguration):
NetconfRestServer._configuration_manager = configuration_manager
- NetconfRestServer._kafka_client = kafka_client
- NetconfRestServer._kafka_topic = kafka_topic
+ NetconfRestServer._app_configuration = netconf_app_configuration
Flask.run(
NetconfRestServer._rest_server,
host=self._host,
@@ -56,11 +54,22 @@ class NetconfRestServer:
@staticmethod
@_rest_server.route("/readiness")
def _readiness_check():
- if NetconfRestServer._kafka_client:
+ try:
+ NetconfRestServer.__try_connect_to_kafka()
return Response('Ready', status=200)
- else:
+ 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():
+ return provide_configured_kafka_client(
+ NetconfRestServer._app_configuration.kafka_host_name,
+ NetconfRestServer._app_configuration.kafka_port
+ )
+
@staticmethod
@_rest_server.route("/change_config/<path:module_name>", methods=['POST'])
def _change_config(module_name):
@@ -71,7 +80,8 @@ class NetconfRestServer:
@staticmethod
@_rest_server.route("/change_history")
def _change_history():
- history = NetconfRestServer._kafka_client.get_all_messages_from(NetconfRestServer._kafka_topic)
+ history = NetconfRestServer.__try_connect_to_kafka()\
+ .get_all_messages_from(NetconfRestServer._app_configuration.kafka_topic)
return jsonify(history), 200
@staticmethod