diff options
author | Gokul Singaraju <gs244f@att.com> | 2018-04-19 22:34:23 -0400 |
---|---|---|
committer | Gokul Singaraju <gs244f@att.com> | 2018-04-19 22:37:50 -0400 |
commit | 44089313231b33a65ed5058a5d1c6b1d0637aa38 (patch) | |
tree | daa5a26bc8ebe5f41cec2402f32d6043c9070872 | |
parent | 042bc21ea4af4c8e5ee4cbbb0e3d0c89a70b7b8e (diff) |
Add healthcheck api
Issue-ID: DCAEGEN2-456
Change-Id: I7455e357e5fb584f644768d33437ef43f53be6e5
Signed-Off-by: Gokul Singaraju <gs244f@att.com>
-rw-r--r-- | Dockerfile | 4 | ||||
-rwxr-xr-x | bin/check_health.py | 66 | ||||
-rwxr-xr-x | bin/run.py | 5 | ||||
-rw-r--r-- | coverage.xml | 4 | ||||
-rw-r--r-- | miss_htbt_service/htbtworker.py | 8 | ||||
-rw-r--r-- | requirements.txt | 6 | ||||
-rw-r--r-- | xunit-results.xml | 12 |
7 files changed, 90 insertions, 15 deletions
@@ -18,7 +18,9 @@ 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/site-packages +#ENV PYTHONPATH="/usr/local/lib/python3.6:/usr/local/lib/python3.6/site-packages:${PATH}" +#ENV PYTHONPATH="/usr/local/lib/python3.6/site-packages:/usr/local/lib/python3.6" +ENV PYTHONPATH=/usr/local/lib/python3.6/site-packages #CMD run.py #ENTRYPOINT ["/bin/python", "./bin/run.py"] #ENTRYPOINT ["/usr/bin/python","./bin/run.py" ] diff --git a/bin/check_health.py b/bin/check_health.py new file mode 100755 index 0000000..53e9da6 --- /dev/null +++ b/bin/check_health.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# ============LICENSE_START======================================================= +# Copyright (c) 2017-2018 AT&T Intellectual Property. 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +from http.server import HTTPServer, BaseHTTPRequestHandler +from urllib import parse + +#from BaseHTTPServer import BaseHTTPRequestHandler +#import urlparse +import json + +class GetHandler(BaseHTTPRequestHandler): + + def do_GET(self): + parsed_path = parse.urlparse(self.path) + message = '\n'.join([ + 'CLIENT VALUES:', + 'client_address=%s (%s)' % (self.client_address, self.address_string()), + 'command=%s' % self.command, + 'path=%s' % self.path, + 'real path=%s' % parsed_path.path, + 'query=%s' % parsed_path.query, + 'request_version=%s' % self.request_version, + '', + 'SERVER VALUES:', + 'server_version=%s' % self.server_version, + 'sys_version=%s' % self.sys_version, + 'protocol_version=%s' % self.protocol_version, + '', + ]) + self.send_response(200) + self.end_headers() + self.wfile.write(message) + return + + def do_POST(self): + content_len = int(self.headers.getheader('content-length')) + post_body = self.rfile.read(content_len) + self.send_response(200) + self.end_headers() + + data = json.loads(post_body) + + self.wfile.write(data['health']) + return + +if __name__ == '__main__': + from http.server import HTTPServer + #from BaseHTTPServer import HTTPServer + server = HTTPServer(("", 10000), GetHandler) + print('Starting server at http://localhost:10000') + server.serve_forever() @@ -21,6 +21,7 @@ # Author Gokul Singaraju gs244f@att.com # +import os import sys import yaml import multiprocessing @@ -45,6 +46,10 @@ if __name__ == '__main__': multiprocessing.log_to_stderr() logger = multiprocessing.get_logger() logger.setLevel(logging.INFO) + my_env = os.environ.copy() + my_env["PYTHONPATH"] = my_env["PYTHONPATH"]+"/usr/local/lib/python3.6:" + p = subprocess.Popen(['./bin/check_health.py'],stdout=subprocess.PIPE,env=my_env) + #print(p.communicate()) with open("./miss_htbt_service/config/config.yaml", 'r') as ymlfile: cfg = yaml.load(ymlfile) # Put some initial values into the queue diff --git a/coverage.xml b/coverage.xml index ad70a4c..548bbd7 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,9 +1,9 @@ <?xml version="1.0" ?> -<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.5926" lines-covered="96" lines-valid="162" timestamp="1522178057938" version="4.5.1"> +<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.5926" lines-covered="96" lines-valid="162" timestamp="1524188090312" version="4.5.1"> <!-- Generated by coverage.py: https://coverage.readthedocs.io --> <!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd --> <sources> - <source>/root/fresh/heartbeat</source> + <source>/root/nhtbt/heartbeat</source> </sources> <packages> <package branch-rate="0" complexity="0" line-rate="0.5926" name="miss_htbt_service"> diff --git a/miss_htbt_service/htbtworker.py b/miss_htbt_service/htbtworker.py index b81deae..11fa611 100644 --- a/miss_htbt_service/htbtworker.py +++ b/miss_htbt_service/htbtworker.py @@ -251,10 +251,10 @@ def main(args): global mr_url, pol_url, missing_htbt, intvl, intopic, outopic mr_url = get_collector_uri() pol_url = get_policy_uri() - missing_htbt = int(args[2]) - intvl = int(args[3]) - intopic = args[4] - outopic = args[5] + missing_htbt = int(args[1]) + intvl = int(args[2]) + intopic = args[3] + outopic = args[4] print ("Message router url %s " % mr_url) print ("Policy router url %s " % pol_url) print ("Interval %s " % intvl) diff --git a/requirements.txt b/requirements.txt index 9617d32..768a335 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,8 @@ -Flask==0.12.2 -connexion==1.1.12 +request==1.0.1 requests==2.18.2 six==1.10.0 PyYAML==3.12 +httplib2==0.9.2 HTTPretty==0.8.14 +pyOpenSSL==17.5.0 +Wheel==0.31.0 diff --git a/xunit-results.xml b/xunit-results.xml index ce0fd44..807f702 100644 --- a/xunit-results.xml +++ b/xunit-results.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="1" time="0.303"><testcase classname="tests.test_binding" file="tests/test_binding.py" line="50" name="test_resolve_all" time="0.025246858596801758"><system-out>http://mrrouter.att.com:3904/events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 +<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="1" time="0.325"><testcase classname="tests.test_binding" file="tests/test_binding.py" line="50" name="test_resolve_all" time="0.013495683670043945"><system-out>http://mrrouter.att.com:3904/events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 <Response [200]> {"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"SWMSVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vMrf","sourceName":"SWMSVM","nfNamingCode":"vMRF"}}} Send URL : http://mytest.onap.org:3904/events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 @@ -8,15 +8,15 @@ Policy url http://mytest.onap.org:3904 Interval 60.0 Input topic VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT Output topic OUTPUT_TOPIC_v1 -Checking... 2018-03-27 15:14:17.651127 +Checking... 2018-04-19 21:34:50.124093 Getting :http://mytest.onap.org:3904/events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 {"event": {"commonEventHeader": {"startEpochMicrosec": 1518616063564475, "sourceId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "eventId": "10048640", "reportingEntityId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "priority": "Normal", "version": 3, "reportingEntityName": "SWMSVM", "sequence": 10048640, "domain": "heartbeat", "lastEpochMicrosec": 1518616063564476, "eventName": "Heartbeat_vMrf", "sourceName": "SWMSVM", "nfNamingCode": "vMRF"}}} Line:{"event": {"commonEventHeader": {"startEpochMicrosec": 1518616063564475, "sourceId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "eventId": "10048640", "reportingEntityId": "587c14b3-72c0-4581-b5cb-6567310b9bb7", "priority": "Normal", "version": 3, "reportingEntityName": "SWMSVM", "sequence": 10048640, "domain": "heartbeat", "lastEpochMicrosec": 1518616063564476, "eventName": "Heartbeat_vMrf", "sourceName": "SWMSVM", "nfNamingCode": "vMRF"}}} Adding new source 587c14b3-72c0-4581-b5cb-6567310b9bb7 10048640 Returned 1 -</system-out><system-err>2018-03-27 15:14:17,645 | urllib3.connectionpool | connectionpool | _new_conn | 208 | DEBUG | Starting new HTTP connection (1): mrrouter.att.com -2018-03-27 15:14:17,648 | urllib3.connectionpool | connectionpool | _make_request | 396 | DEBUG | http://mrrouter.att.com:3904 "GET /events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 HTTP/1.1" 200 415 -2018-03-27 15:14:17,652 | urllib3.connectionpool | connectionpool | _new_conn | 208 | DEBUG | Starting new HTTP connection (1): mytest.onap.org -2018-03-27 15:14:17,662 | urllib3.connectionpool | connectionpool | _make_request | 396 | DEBUG | http://mytest.onap.org:3904 "GET /events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 HTTP/1.1" 200 442 +</system-out><system-err>2018-04-19 21:34:50,118 | urllib3.connectionpool | connectionpool | _new_conn | 208 | DEBUG | Starting new HTTP connection (1): mrrouter.att.com +2018-04-19 21:34:50,121 | urllib3.connectionpool | connectionpool | _make_request | 396 | DEBUG | http://mrrouter.att.com:3904 "GET /events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 HTTP/1.1" 200 415 +2018-04-19 21:34:50,125 | urllib3.connectionpool | connectionpool | _new_conn | 208 | DEBUG | Starting new HTTP connection (1): mytest.onap.org +2018-04-19 21:34:50,126 | urllib3.connectionpool | connectionpool | _make_request | 396 | DEBUG | http://mytest.onap.org:3904 "GET /events/VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT/DefaultGroup/1?timeout=15000 HTTP/1.1" 200 442 </system-err></testcase></testsuite>
\ No newline at end of file |