Commit bf2c831c authored by Alexander Lercher's avatar Alexander Lercher

Workaround for trace access

parent ee789e29
import pymongo
import network_constants as netconst
class MongoRepository:
# TODO extract to docker env var
_username = 'root'
_password = 'root'
_collection: pymongo.collection.Collection = None
_mongo_client: pymongo.MongoClient = None
def __init__(self, username=_username, password=_password):
self._mongo_client = pymongo.MongoClient(f"mongodb://{username}:{password}@{netconst.MONGO_DB_HOSTNAME}:{netconst.MONGO_DB_PORT}/")
database = self._mongo_client['traceRetrievalDB']
self._collection = database['traces']
def insert_trace(self, content: dict):
self._collection.insert_one(content)
def get_traces(self, selection: dict = {}, projection: dict = {'_': 0}) -> pymongo.cursor.Cursor:
return self._collection.find(selection, projection)
def close_connection(self):
self._mongo_client.close()
self._collection = None
self._mongo_client = None
import json
import requests
import network_constants as netconst
from db.MongoRepository import MongoRepository
from intelligence_zahra.Processor import Processor
import logging
......@@ -32,6 +33,14 @@ class MessageHandler:
LOGGER.info("Message Type could not be processed")
def handle_new_traces_available(self):
# TODO remove workaround
repo = MongoRepository()
traces = list(repo.get_traces(projection={'_id':0}))
self._processor.process(traces)
repo.close_connection()
return
# get traces
url = f'http://{netconst.TRACE_RETRIEVAL_HOSTNAME}:{netconst.TRACE_RETRIEVAL_REST_PORT}/api/trace'
response = requests.get(url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment