1 # -*- coding: utf-8 -*-
3 # This file is part of OSM Monitoring module
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
23 def wait_till_core_services_are_ready(config
, process_name
="osm-mon", commondb_wait_time
=5, kafka_wait_time
=5):
25 logging
.debug("wait_till_services_are_ready()")
28 logging
.info("Config information is not available")
31 # Check if common-db is ready
33 commondb_url
= config
.conf
["database"].get("uri")
35 commondb
= pymongo
.MongoClient(commondb_url
)
36 commondb
.server_info()
39 logging
.info("{} process is waiting for commondb to come up...".format(process_name
))
40 time
.sleep(commondb_wait_time
)
42 # Check if kafka is ready
45 # Logic to check kafka is ready
46 with socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
) as s
:
47 if s
.connect_ex(("kafka", int(config
.conf
["message"].get("port")))) == 0:
52 logging
.info("{} process is waiting for kafka to come up...".format(process_name
))
53 time
.sleep(kafka_wait_time
)