diff options
author | SrikanthNaidu <sn8492@att.com> | 2018-12-10 21:46:40 +0530 |
---|---|---|
committer | SrikanthNaidu <sn8492@att.com> | 2018-12-12 18:45:52 +0530 |
commit | 20110ffeb5071193e7b437e797636d9d6318dcd4 (patch) | |
tree | ebd4e64715f4cafc7261b2eff9990e4faa53d050 /miss_htbt_service/cbs_polling.py | |
parent | 5712f01385eaa05178279aa7e730b3bdde3d1b80 (diff) |
Heartbeat Microservice Support
Heartbeat service monitors missing HB notification
Issue-ID: DCAEGEN2-267
Change-Id: I21f36056e9509a167bff476231a6bbd661aca1b9
Signed-off-by: SrikanthNaidu <sn8492@att.com>
Diffstat (limited to 'miss_htbt_service/cbs_polling.py')
-rw-r--r-- | miss_htbt_service/cbs_polling.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/miss_htbt_service/cbs_polling.py b/miss_htbt_service/cbs_polling.py new file mode 100644 index 0000000..4212ab7 --- /dev/null +++ b/miss_htbt_service/cbs_polling.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +# Copyright 2018 AT&T Intellectual Property, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Author Prakash Hosangady(ph553f@att.com) +# CBS Polling +# Set the hb_common table with state="RECONFIGURATION" periodically +# to get the new configuration downloaded + +import requests +import sched, datetime, time +import string +import sys +import os +import socket +import htbtworker as pm +import misshtbtd as db +import logging +import get_logger +_logger = get_logger.get_logger(__name__) + + +def pollCBS(current_pid): + + ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval = db.read_hb_properties() + hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(user_name,password,ip_address,port_num,db_name) + msg="CBSP:Main process ID in hb_common is %d",hbc_pid + _logger.info(msg) + msg="CBSP:My parent process ID is %d",current_pid + _logger.info(msg) + msg="CBSP:CBS Polling interval is %d", cbs_polling_interval + _logger.info(msg) + time.sleep(cbs_polling_interval) + hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(user_name,password,ip_address,port_num,db_name) + #connection_db = pm.postgres_db_open(user_name,password,ip_address,port_num,db_name) + #cur = connection_db.cursor() + source_name = socket.gethostname() + source_name = source_name + "-" + str(os.getenv('SERVICE_NAME')) + result= True + if(int(current_pid)==int(hbc_pid) and source_name==hbc_srcName and hbc_state == "RUNNING"): + _logger.info("CBSP:ACTIVE Instance:Change the state to RECONFIGURATION") + state = "RECONFIGURATION" + update_flg = 1 + db.create_update_hb_common(update_flg, hbc_pid, state, user_name,password,ip_address,port_num,db_name) + else: + _logger.info("CBSP:Inactive instance or hb_common state is not RUNNING") + return result +if __name__ == "__main__": + current_pid = sys.argv[1] + while(True): + pollCBS(current_pid) |