Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
ffb7622f
Commit
ffb7622f
authored
Aug 19, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trace Retrieval: Receives traces as message; saves to MongoDB
parent
447c76aa
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
5 deletions
+48
-5
blockchain_trace.py
...b-in/trace-retrieval-microservice/app/blockchain_trace.py
+1
-2
MongoRepository.py
...in/trace-retrieval-microservice/app/db/MongoRepository.py
+21
-0
main.py
transaction-hub-in/trace-retrieval-microservice/app/main.py
+4
-3
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+22
-0
No files found.
transaction-hub-in/trace-retrieval-microservice/app/blockchain_trace.py
View file @
ffb7622f
from
flask
import
request
,
Response
from
flask
import
request
,
Response
def
receive
():
def
receive
():
# print(request.json)
return
Response
(
status
=
501
)
return
Response
(
status
=
201
)
transaction-hub-in/trace-retrieval-microservice/app/db/MongoRepository.py
0 → 100644
View file @
ffb7622f
import
pymongo
MONGO_DB_HOST
=
'trace-retrieval-db'
MONGO_DB_PORT
=
'27017'
class
MongoRepository
:
# TODO extract to docker env var
_username
=
'root'
_password
=
'root'
_collection
:
pymongo
.
collection
.
Collection
=
None
def
__init__
(
self
,
username
=
_username
,
password
=
_password
):
myclient
=
pymongo
.
MongoClient
(
f
"mongodb://{username}:{password}@{MONGO_DB_HOST}:{MONGO_DB_PORT}/"
)
database
=
myclient
[
'traceRetrievalDB'
]
# trace retrieval
self
.
_collection
=
database
[
'traces'
]
def
insert_trace
(
self
,
content
:
dict
):
self
.
_collection
.
insert_one
(
content
)
def
get_traces
(
self
,
selection
:
dict
=
{}):
return
self
.
_collection
.
find
(
selection
)
transaction-hub-in/trace-retrieval-microservice/app/main.py
View file @
ffb7622f
...
@@ -8,10 +8,11 @@ if os.path.exists(modules_path):
...
@@ -8,10 +8,11 @@ if os.path.exists(modules_path):
# init logging to file
# init logging to file
import
logging
import
logging
LOG_FORMAT
=
(
'
%(levelname) -5
s
%(asctime)
s
%(name)
s:
%(funcName) -35
s
%(lineno) -5
d:
%(message)
s'
)
LOG_FORMAT
=
(
'
%(levelname) -5
s
%(asctime)
s
%(name)
s:
%(funcName) -35
s
%(lineno) -5
d:
%(message)
s'
)
logging
.
basicConfig
(
filename
=
'
trace-retrieval
.log'
,
level
=
logging
.
WARNING
,
format
=
LOG_FORMAT
)
logging
.
basicConfig
(
filename
=
'
error
.log'
,
level
=
logging
.
WARNING
,
format
=
LOG_FORMAT
)
LOGGER
=
logging
.
getLogger
(
__name__
)
LOGGER
=
logging
.
getLogger
(
__name__
)
import
connexion
import
connexion
from
messaging.MessageHandler
import
MessageHandler
from
messaging.MessageReceiver
import
MessageReceiver
from
messaging.MessageReceiver
import
MessageReceiver
from
messaging.MessageSender
import
MessageSender
from
messaging.MessageSender
import
MessageSender
...
@@ -21,9 +22,9 @@ RABBIT_MQ_PORT = '5672'
...
@@ -21,9 +22,9 @@ RABBIT_MQ_PORT = '5672'
message_sender
=
None
message_sender
=
None
# init message handler
# init message handler
message_handler
=
MessageHandler
()
def
message_received_callback
(
channel
,
method
,
properties
,
body
):
def
message_received_callback
(
channel
,
method
,
properties
,
body
):
print
(
f
"### Received: {body}"
)
message_handler
.
handle_message
(
body
)
# channel.basic_ack(delivery_tag=method.delivery_tag)
message_sender
.
send
(
'rest-gateway'
,
str
(
body
)
+
' (sent from trace-retrieval-microservice)'
,
'rest-gateway'
)
message_sender
.
send
(
'rest-gateway'
,
str
(
body
)
+
' (sent from trace-retrieval-microservice)'
,
'rest-gateway'
)
# load swagger config
# load swagger config
...
...
transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
0 → 100644
View file @
ffb7622f
from
db.MongoRepository
import
MongoRepository
import
logging
LOGGER
=
logging
.
getLogger
(
__name__
)
class
MessageHandler
:
_mongo_repo
=
None
def
__init__
(
self
):
self
.
_mongo_repo
=
MongoRepository
()
def
handle_message
(
self
,
body
):
LOGGER
.
info
(
f
"Received message: {body}"
)
if
not
'type'
in
body
:
LOGGER
.
warning
(
f
"Message has no type field"
)
return
if
body
[
'type'
]
==
'blockchain-transaction'
:
self
.
handle_blockchain_transaction
(
body
[
'content'
])
def
handle_blockchain_transaction
(
self
,
transaction
):
self
.
_mongo_repo
.
insert_trace
(
transaction
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment