Commit 26a88ef4 authored by Luca Braun's avatar Luca Braun

implemented failed transaction handling

parent e76b8df3
...@@ -25,11 +25,17 @@ class Repository(MongoRepositoryBase): ...@@ -25,11 +25,17 @@ class Repository(MongoRepositoryBase):
collection.delete_many({}) collection.delete_many({})
def add_transaction(self, transaction: Transaction): def add_transaction(self, transaction: Transaction):
'''
Adds a transaction to mongodb repository.
@throws
KeyError - Duplicate transaction ID
'''
reference = self.get_transaction_with_id(transaction.id()) reference = self.get_transaction_with_id(transaction.id())
if reference == None: if reference == None:
super().insert_entry(self._transaction_collection, transaction.to_serializable_dict()) super().insert_entry(self._transaction_collection, transaction.to_serializable_dict())
else: else:
raise ValueError(f"ID {transaction['UniqueID']} already exists") raise KeyError(f"ID {transaction['UniqueID']} already exists")
def all_transactions_for_use_case(self, use_case: str) -> List[Transaction]: def all_transactions_for_use_case(self, use_case: str) -> List[Transaction]:
result = super().get_entries(self._transaction_collection, projection={'_id': False}, selection={"use_case": use_case}) result = super().get_entries(self._transaction_collection, projection={'_id': False}, selection={"use_case": use_case})
......
...@@ -140,7 +140,9 @@ class MessageHandler: ...@@ -140,7 +140,9 @@ class MessageHandler:
# check if there is a doctype in the message # check if there is a doctype in the message
if "docType" not in transaction_message.keys(): if "docType" not in transaction_message.keys():
LOGGER.error("Transaction has no docType, ignoring it.") LOGGER.error("Transaction has no docType, storing it under docType 'unknown'.")
transaction_message["docType"] = "unknown"
self._mongo_repo.add_failed_transaction(transaction_message)
return return
use_case = transaction_message["ApplicationType"] use_case = transaction_message["ApplicationType"]
...@@ -149,7 +151,7 @@ class MessageHandler: ...@@ -149,7 +151,7 @@ class MessageHandler:
try: try:
tables = self._rest_fetcher.fetch_schema_information(use_case) tables = self._rest_fetcher.fetch_schema_information(use_case)
except ValueError as e: except ValueError as e:
print(f"{e}") LOGGER.error(f"{e}\nStoring it as a failed transaction.")
self._mongo_repo.add_failed_transaction(transaction_message) self._mongo_repo.add_failed_transaction(transaction_message)
return return
...@@ -162,7 +164,8 @@ class MessageHandler: ...@@ -162,7 +164,8 @@ class MessageHandler:
# abort if table does not exist. # abort if table does not exist.
if target_table == None: if target_table == None:
LOGGER.error(f"There is no table '{docType}', ignoring the message.") LOGGER.error(f"There is no table '{docType}', storing it as a failed transaction.")
self._mongo_repo.add_failed_transaction(transaction_message)
return return
mappings = table["mappings"] mappings = table["mappings"]
...@@ -189,8 +192,11 @@ class MessageHandler: ...@@ -189,8 +192,11 @@ class MessageHandler:
try: try:
self._mongo_repo.add_transaction(transaction) self._mongo_repo.add_transaction(transaction)
except ValueError as e: except KeyError as e:
LOGGER.error(f"{e}, ignoring node") LOGGER.error(f"{e}")
self._mongo_repo.add_failed_transaction(transaction_message)
return
msg = { msg = {
"type": "new-trace", "type": "new-trace",
......
...@@ -18,7 +18,7 @@ class RestFetcher: ...@@ -18,7 +18,7 @@ class RestFetcher:
) )
if response.status_code != 200: if response.status_code != 200:
raise ValueError("Error while retrieving schema information") raise ValueError(f"Error while retrieving schema information.\tStatus-code:{response.status_code}")
tables = json.loads(response.text) tables = json.loads(response.text)
return tables return tables
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