aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Dockerfile8
-rwxr-xr-xbin/run.py23
-rw-r--r--env.list4
-rw-r--r--miss_htbt_service/htbtworker.py42
-rwxr-xr-xrun1
-rw-r--r--tests/test_binding.py2
6 files changed, 53 insertions, 27 deletions
diff --git a/Dockerfile b/Dockerfile
index c96c4db..50e66dd 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,10 +12,10 @@ RUN pip install -r requirements.txt
RUN pip install -e .
RUN mkdir /tmp/config
-RUN echo 1.2.3.4 > /tmp/config/coll_ip.txt
-RUN echo 1234 > /tmp/config/coll_port.txt
-RUN echo 4.5.6.7 > /tmp/config/pol_ip.txt
-RUN echo 4567 > /tmp/config/pol_port.txt
+#RUN echo 1.2.3.4 > /tmp/config/coll_ip.txt
+#RUN echo 1234 > /tmp/config/coll_port.txt
+#RUN echo 4.5.6.7 > /tmp/config/pol_ip.txt
+#RUN echo 4567 > /tmp/config/pol_port.txt
EXPOSE 10000
#ENV PYTHONPATH="/usr/local/lib/python3.6:/usr/local/lib/python3.6/site-packages:${PATH}"
diff --git a/bin/run.py b/bin/run.py
index 95cb4d9..311b44c 100755
--- a/bin/run.py
+++ b/bin/run.py
@@ -29,10 +29,15 @@ import logging
import subprocess
from miss_htbt_service import get_logger
+mr_url = 'http://mrrouter.onap.org:3904'
+pol_url = 'http://mrrouter.onap.org:3904'
+intopic = 'VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT'
+outopic = 'POLICY-HILOTCA-EVENT-OUTPUT'
+
#Checks heartbeat by calling worker thread
-def checkhtbt(mr_url, misshtbt,intvl,intopic,outtopic):
- print('Doing some work',mr_url, misshtbt,intvl,intopic,outtopic)
- subprocess.call(["/usr/bin/python","./miss_htbt_service/htbtworker.py" , mr_url , str(misshtbt) , str(intvl) , intopic , outtopic])
+def checkhtbt(mr_url, intopic, pol_url, outopic, misshtbt,intvl):
+ print('Doing some work',mr_url, misshtbt,intvl,intopic,outopic)
+ subprocess.call(["/usr/bin/python","./miss_htbt_service/htbtworker.py" , mr_url , intopic, pol_url, outopic, str(misshtbt) , str(intvl) ])
sys.stdout.flush()
return
@@ -43,6 +48,15 @@ _logger = get_logger(__name__)
if __name__ == '__main__':
try:
print("Heartbeat Microservice ...")
+ if "INURL" in os.environ.keys():
+ mr_url = os.environ['INURL']
+ if "INTOPIC" in os.environ.keys():
+ intopic = os.environ['INTOPIC']
+ if "OUTURL" in os.environ.keys():
+ pol_url = os.environ['OUTURL']
+ if "OUTOPIC" in os.environ.keys():
+ outopic = os.environ['OUTOPIC']
+ print(outopic)
multiprocessing.log_to_stderr()
logger = multiprocessing.get_logger()
logger.setLevel(logging.INFO)
@@ -64,7 +78,8 @@ if __name__ == '__main__':
#print(cfg['vnfs'][vnf][1])
#print(cfg['vnfs'][vnf][2])
#Start Heartbeat monitoring process worker thread on VNFs configured
- p = multiprocessing.Process(target=checkhtbt, args=(cfg['global']['message_router_url'],cfg['vnfs'][vnf][0],cfg['vnfs'][vnf][1],cfg['vnfs'][vnf][2],cfg['vnfs'][vnf][3]))
+ logger.info("Starting threads...")
+ p = multiprocessing.Process(target=checkhtbt, args=( mr_url, intopic, pol_url, outopic, cfg['vnfs'][vnf][0],cfg['vnfs'][vnf][1]))
jobs.append(p)
p.start()
for j in jobs:
diff --git a/env.list b/env.list
new file mode 100644
index 0000000..90035b9
--- /dev/null
+++ b/env.list
@@ -0,0 +1,4 @@
+INURL=http://mrrouteri.onap.org:3904
+INTOPIC=VESCOLL-VNFNJ-1SECHEARTBEAT-OUTPUT
+OUTURL=http://mrroutero.onap.org:3904
+OUTOPIC=POLICY-HILOTCA-2EVENT-OUTPUT
diff --git a/miss_htbt_service/htbtworker.py b/miss_htbt_service/htbtworker.py
index 11fa611..3bad8c9 100644
--- a/miss_htbt_service/htbtworker.py
+++ b/miss_htbt_service/htbtworker.py
@@ -49,10 +49,10 @@ class PeriodicScheduler(object):
self.scheduler = sched.scheduler(time.time, time.sleep)
def setup(self, interval, action, actionargs=()):
+ #print("Args are :", locals())
action(*actionargs)
- self.scheduler.enter(interval, 1, self.setup,
- (interval, action, actionargs))
- def run(self):
+ self.scheduler.enter(interval, 1, self.setup,(interval, action, actionargs))
+ def run(self):
self.scheduler.run()
def stop(self):
@@ -101,13 +101,15 @@ def get_policy_uri():
# Process the heartbeat event on input topic
def periodic_event():
- global periodic_scheduler
- global mr_url, pol_url, missing_htbt, intvl, intopic, outopic
- ret = 0
- print("Checking..." , datetime.datetime.now())
- #Read heartbeat
- get_url = mr_url+'/events/'+intopic+'/DefaultGroup/1?timeout=15000'
- print("Getting :"+get_url)
+ global periodic_scheduler
+ global mr_url, pol_url, missing_htbt, intvl, intopic, outopic
+ ret = 0
+ #print("Args are :", locals())
+ print("Checking..." , datetime.datetime.now())
+ #Read heartbeat
+ get_url = mr_url+'/events/'+intopic+'/DefaultGroup/1?timeout=15000'
+ print("Getting :"+get_url)
+ try:
res = requests.get(get_url)
#print(res)
#print(res.headers)
@@ -227,7 +229,9 @@ def periodic_event():
del heartstate[chkey]
del hearttrack[chkey]
del heartflag[chkey]
- return ret
+ except requests.exceptions.ConnectionError:
+ print("Connection refused ..")
+ return ret
#test setup for coverage
def test_setup(args):
@@ -249,19 +253,21 @@ def test_setup(args):
def main(args):
global periodic_scheduler
global mr_url, pol_url, missing_htbt, intvl, intopic, outopic
- mr_url = get_collector_uri()
- pol_url = get_policy_uri()
- missing_htbt = int(args[1])
- intvl = int(args[2])
- intopic = args[3]
- outopic = args[4]
+ #mr_url = get_collector_uri()
+ #pol_url = get_policy_uri()
+ mr_url = args[0]
+ intopic = args[1]
+ pol_url = args[2]
+ outopic = args[3]
+ missing_htbt = int(args[4])
+ intvl = int(args[5])
print ("Message router url %s " % mr_url)
print ("Policy router url %s " % pol_url)
print ("Interval %s " % intvl)
#intvl = 60 # every second
#Start periodic scheduler runs every interval
periodic_scheduler = PeriodicScheduler()
- periodic_scheduler.setup(intvl, periodic_event) # it executes the event just once
+ periodic_scheduler.setup(intvl, periodic_event,) # it executes the event just once
periodic_scheduler.run() # it starts the scheduler
if __name__ == "__main__":
diff --git a/run b/run
new file mode 100755
index 0000000..ced043e
--- /dev/null
+++ b/run
@@ -0,0 +1 @@
+docker run --env-file ./env.list <dockerid>
diff --git a/tests/test_binding.py b/tests/test_binding.py
index 2e16f13..f0faac0 100644
--- a/tests/test_binding.py
+++ b/tests/test_binding.py
@@ -46,7 +46,7 @@ def package_contents(package_name):
#mr_url = 'http://127.0.0.1:3904'
mr_url = 'http://mrrouter.att.com:3904'
intopic = 'VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT'
-outopic = 'OUTPUT_TOPIC_v1'
+outopic = 'POLICY-HILOTCA-EVENT-OUTPUT'
@httpretty.activate
def test_resolve_all(monkeypatch):