Commit fca98b09 authored by alelercher's avatar alelercher

Merge branch 'trace-input-handling' into 'master'

Trace input handling

Additional docu and first tests

See merge request !2
parents d7d2b38b 9ac8ef4c
# SMART tool
We propose a framework underlying decentralized social media called SMART, capable of finding relevant interest communities without violating users’ privacy and anonymity. Its objective is to improve trust and eliminate malicious actors in participatory exchanges and collaborative decision making.
## Microservice architecture
![SMART architecture image](smart-architecture.png)
\ No newline at end of file
## Project structure
The five folders *data-hub*, *message-broker*, *rest-gateway*, *transaction-hub-in* and *transaction-hub-out* contain the microservices for the five architecture layers respectively.
The *modules* folder contains various Python modules used by multiple microservices to improve code-reuse. When building the Docker images this folder is copied into the app path.
The *tools* folder contains supportive scripts used during development and must not be used by any microservice.
The scripts *build.py* and *deploy.py* are used to create Docker images and deploy these images in Kubernetes respectively.
The *images* folder holds the images used in this document.
## Overall microservice architecture
![SMART architecture image](images/smart-architecture.png)
# Semantic Linking Microservice
The semantic linking microservice helps to explicitly state implicit connections between users by analyzing extensive and repeated interactions. The explicit information about links will then be the basis for all further reasoning, classification and intelligence.
This microservice receives a message from the trace retrieval microservice when new traces are available. It then loads all traces by calling the trace retrieval's REST interface and processes these.
## Technologies
- Python 3.x
- Python module Flask
- Python module Connexion with Swagger
(Check Dockerfile for used Python modules)
- Docker
- Kubernetes
\ No newline at end of file
# SMART RESTful API Gateway
The RESTful API Gateway is used as the central access point. It works as a abstraction layer to the individual microservices of SMART.
The RESTful API gateway is used as the central access point. It works as a abstraction layer to the individual microservices of SMART.
## Blockchain transactions
Blockchain transactions posted to this gateway are checked for schema validity and forwarded to the trace retrieval microservice via messaging.
## Technologies
- Python 3.x
......
# add modules folder to interpreter path
import sys
import os
modules_paths = ['../app/', '../../modules/']
for path in modules_paths:
if os.path.exists(path):
sys.path.insert(1, path)
import unittest
import manage_sys_paths
import rest.blockchain_trace as blockchain_trace
class Test_BlockchainTrace(unittest.TestCase):
def _get_valid_input(self):
return {
"ApplicationType": "string",
"Metadata": {},
"ResourceIds": "string",
"ResourceMd5": "string",
"ResourceState": "string",
"Timestamp": "2019-08-27T14:00:48.587Z",
"TransactionFrom": "string",
"TransactionFromLatLng": "string",
"TransactionId": "string",
"TransactionTo": "string",
"TransactionToLatLng": "string",
"TransferredAsset": "string"
}
def test_isBlockchainTraceValid_validInputAndTypes(self):
input = self._get_valid_input()
self.assertTrue(blockchain_trace.isBlockchainTraceValid(input), "Trace should be valid")
def test_isBlockchainTraceValid_invalidMetadataInputType(self):
input = self._get_valid_input()
input["Metadata"] = "string"
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Metadata type should be invalid")
def test_isBlockchainTraceValid_invalidTransactionFromLatLngInputType(self):
input = self._get_valid_input()
input["TransactionFromLatLng"] = ["55.1", "44.1"]
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "TransactionFromLatLng type should be invalid")
def test_isBlockchainTraceValid_emptyInput(self):
input = {}
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Empty input should not be accepted")
def test_isBlockchainTraceValid_missingKeys(self):
input = {
"ApplicationType": "string",
"Metadata": {},
"ResourceIds": "string",
"ResourceMd5": "string",
"ResourceState": "string",
"TransactionFrom": "string",
"TransactionFromLatLng": "string",
"TransactionId": "string",
"TransactionTo": "string",
"TransactionToLatLng": "string",
"TransferredAsset": "string"
}
self.assertFalse(blockchain_trace.isBlockchainTraceValid(input), "Input should not be accepted because timestamp is missing")
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
# Trace Retrieval Microservice
The trace retrieval microservice is used as an interface to the blockchain component (TIC). It receives and preprocesses all available traces.
The RESTful API gateway sends traces as messages to the trace retrieval microservice. These traces are then stored in a MongoDB document database and the semantic linking microservice is notified. This microservice provides access to all stored traces via REST.
## Technologies
- Python 3.x
(Check Dockerfile for used Python modules)
- MongoDB
- Docker
- Kubernetes
\ No newline at end of file
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