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

implemented failed transaction handling

parent e76b8df3
......@@ -25,11 +25,17 @@ class Repository(MongoRepositoryBase):
collection.delete_many({})
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())
if reference == None:
super().insert_entry(self._transaction_collection, transaction.to_serializable_dict())
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]:
result = super().get_entries(self._transaction_collection, projection={'_id': False}, selection={"use_case": use_case})
......
......@@ -140,7 +140,9 @@ class MessageHandler:
# check if there is a doctype in the message
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
use_case = transaction_message["ApplicationType"]
......@@ -149,7 +151,7 @@ class MessageHandler:
try:
tables = self._rest_fetcher.fetch_schema_information(use_case)
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)
return
......@@ -162,7 +164,8 @@ class MessageHandler:
# abort if table does not exist.
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
mappings = table["mappings"]
......@@ -189,8 +192,11 @@ class MessageHandler:
try:
self._mongo_repo.add_transaction(transaction)
except ValueError as e:
LOGGER.error(f"{e}, ignoring node")
except KeyError as e:
LOGGER.error(f"{e}")
self._mongo_repo.add_failed_transaction(transaction_message)
return
msg = {
"type": "new-trace",
......
......@@ -18,7 +18,7 @@ class RestFetcher:
)
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)
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