aboutsummaryrefslogtreecommitdiffstats
path: root/sanitycheck/dmaap-simulator
diff options
context:
space:
mode:
Diffstat (limited to 'sanitycheck/dmaap-simulator')
-rw-r--r--sanitycheck/dmaap-simulator/Dockerfile7
-rw-r--r--sanitycheck/dmaap-simulator/Makefile23
-rw-r--r--sanitycheck/dmaap-simulator/README.md23
-rw-r--r--sanitycheck/dmaap-simulator/requirements.txt6
-rw-r--r--sanitycheck/dmaap-simulator/simulator.py47
5 files changed, 106 insertions, 0 deletions
diff --git a/sanitycheck/dmaap-simulator/Dockerfile b/sanitycheck/dmaap-simulator/Dockerfile
new file mode 100644
index 0000000..f84cac2
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/Dockerfile
@@ -0,0 +1,7 @@
+FROM python:3
+WORKDIR /application
+COPY ./simulator.py ./
+COPY ./requirements.txt ./
+RUN pip install -r ./requirements.txt
+ENV FLASK_APP=./simulator.py
+CMD ["python", "./simulator.py"]
diff --git a/sanitycheck/dmaap-simulator/Makefile b/sanitycheck/dmaap-simulator/Makefile
new file mode 100644
index 0000000..af8f162
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/Makefile
@@ -0,0 +1,23 @@
+all: build
+
+.PHONY: build
+
+build:
+ @echo "##### Build dmaap simulator image #####"
+ docker build . -t dmaap-simulator
+ @echo "##### DONE #####"
+
+start:
+ @echo "##### Start dmaap simulator #####"
+ docker run -d -p 3904:3904 --name dmaap-simulator dmaap-simulator
+ @echo "##### DONE #####"
+
+stop:
+ @echo "##### Stop dmaap simulator #####"
+ docker rm -f dmaap-simulator
+ @echo "##### DONE #####"
+
+get-data:
+ @echo "##### Get data fetched by dmaap-simulator #####\n"
+ curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:3904/events
+ @echo "\n\n##### DONE #####"
diff --git a/sanitycheck/dmaap-simulator/README.md b/sanitycheck/dmaap-simulator/README.md
new file mode 100644
index 0000000..c06afdf
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/README.md
@@ -0,0 +1,23 @@
+DMaaP simulator
+---------------
+
+
+### Build an image
+```
+make build
+```
+
+### Start
+```
+make start
+```
+
+### Stop
+```
+make stop
+```
+
+### Get fetched events
+```
+make get-data
+```
diff --git a/sanitycheck/dmaap-simulator/requirements.txt b/sanitycheck/dmaap-simulator/requirements.txt
new file mode 100644
index 0000000..a6d2d3a
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/requirements.txt
@@ -0,0 +1,6 @@
+Click==7.0
+Flask==1.1.1
+itsdangerous==1.1.0
+Jinja2==2.10.3
+MarkupSafe==1.1.1
+Werkzeug==0.16.0
diff --git a/sanitycheck/dmaap-simulator/simulator.py b/sanitycheck/dmaap-simulator/simulator.py
new file mode 100644
index 0000000..3437442
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/simulator.py
@@ -0,0 +1,47 @@
+import json
+import logging as sys_logging
+
+from flask import Flask, request, logging
+app = Flask(__name__)
+
+sys_logging.basicConfig(level=sys_logging.DEBUG)
+logger = logging.create_logger(app)
+events = []
+
+@app.route("/events/unauthenticated.VES_NOTIFICATION_OUTPUT", methods=['POST'])
+def event_ves_notification_output():
+ return handle_new_event(request)
+
+@app.route("/events/unauthenticated.SEC_FAULT_OUTPUT", methods=['POST'])
+def event_sec_fault_output():
+ return handle_new_event(request)
+
+def handle_new_event(http_request):
+ receive_events = decode_request_data(http_request.data)
+ for event in receive_events:
+ events.append(json.loads(event))
+ return {}, 200
+
+@app.route("/events", methods=['GET'])
+def get_events():
+ return json.dumps(events), 200
+
+def decode_request_data(request_data):
+ data = request_data.decode("utf-8")
+ receive_events = data.split("\n")
+ receive_events = receive_events[:-1]
+ logger.info("received events: " + str(receive_events))
+ correct_events = []
+ for event in receive_events:
+ logger.info("received event: " + str(event))
+ correct_events.append(get_correct_json(event))
+ return correct_events
+
+def get_correct_json(incorrect_json):
+ json_start_position = incorrect_json.find("{")
+ correct_json = incorrect_json[json_start_position:]
+ correct_json = correct_json.replace("\r", "").replace("\t", "").replace(" ", "")
+ return correct_json
+
+if __name__ == "__main__":
+ app.run(host='0.0.0.0', port=3904)