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
447c76aa
Commit
447c76aa
authored
Aug 19, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rest Gateway: takes traces via REST, message to trace-retrieval
parent
5a50ca77
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
8 deletions
+83
-8
MessageSender.py
modules/messaging/MessageSender.py
+1
-1
swagger.yml
rest-gateway/app/configs/swagger.yml
+51
-1
main.py
rest-gateway/app/main.py
+5
-6
blockchain_trace.py
rest-gateway/app/rest/blockchain_trace.py
+26
-0
No files found.
modules/messaging/MessageSender.py
View file @
447c76aa
...
...
@@ -13,7 +13,7 @@ class MessageSender:
_connection
:
pika
.
BlockingConnection
=
None
_channel
:
pika
.
channel
.
Channel
=
None
def
__init__
(
self
,
rabbit_mq_ip
=
'
143.205.173.36'
,
rabbit_mq_port
=
3030
2
):
def
__init__
(
self
,
rabbit_mq_ip
=
'
rabbit-mq'
,
rabbit_mq_port
=
567
2
):
self
.
_rabbit_mq_ip
=
rabbit_mq_ip
self
.
_rabbit_mq_port
=
rabbit_mq_port
...
...
rest-gateway/app/configs/swagger.yml
View file @
447c76aa
...
...
@@ -39,4 +39,54 @@ paths:
description
:
"
Lists
all
messages
received
from
Rabbit
MQ."
responses
:
200
:
description
:
"
Message
list"
\ No newline at end of file
description
:
"
Message
list"
/trace
:
post
:
operationId
:
"
rest.blockchain_trace.receive"
tags
:
-
"
Blockchain
Trace"
summary
:
"
Add
a
new
blockchain
trace
to
SMART"
description
:
"
Receives
a
new
blockchain
trace
to
store
in
SMART."
parameters
:
-
in
:
body
name
:
"
BlockchainTrace"
description
:
"
The
trace
to
be
added"
required
:
true
schema
:
$ref
:
"
#/definitions/BlockchainTrace"
responses
:
201
:
description
:
"
Successfully
added"
400
:
description
:
"
Invalid
input"
definitions
:
BlockchainTrace
:
type
:
"
object"
properties
:
TransactionId
:
type
:
string
format
:
uuid
Timestamp
:
type
:
"
string"
format
:
"
date-time"
ApplicationType
:
type
:
"
string"
TransactionFrom
:
type
:
"
string"
format
:
"
uuid"
TransactionTo
:
type
:
"
string"
format
:
"
uuid"
TransferredAsset
:
type
:
"
string"
ResourceIds
:
type
:
"
string"
ResourceMd5
:
type
:
"
string"
ResourceState
:
type
:
"
string"
Metadata
:
type
:
"
string"
\ No newline at end of file
rest-gateway/app/main.py
View file @
447c76aa
...
...
@@ -19,11 +19,12 @@ from messaging.MessageReceiver import MessageReceiver
from
messaging.MessageSender
import
MessageSender
from
MessageList
import
MessageList
RABBIT_MQ_DNS_NAME
=
'rabbit-mq'
RABBIT_MQ_PORT
=
'5672'
messages
=
MessageList
.
getInstance
()
message_sender
=
MessageSender
()
message_sender
.
connect
()
message_sender
.
create_exchange
(
'inhub'
,
'direct'
)
# init message handler
def
message_received_callback
(
channel
,
method
,
properties
,
body
):
messages
.
appendMessage
(
body
)
...
...
@@ -44,9 +45,7 @@ def api_root():
# start app
if
__name__
==
'__main__'
:
message_rec
=
MessageReceiver
(
rabbit_mq_ip
=
RABBIT_MQ_DNS_NAME
,
rabbit_mq_port
=
RABBIT_MQ_PORT
,
exchange_name
=
'rest-gateway'
,
exchange_type
=
'direct'
,
queue_name
=
'rest-gateway'
,
auto_ack
=
True
)
message_rec
=
MessageReceiver
(
exchange_name
=
'rest-gateway'
,
exchange_type
=
'direct'
,
queue_name
=
'rest-gateway'
,
auto_ack
=
True
)
message_rec
.
start
(
message_received_callback
,
pika_error_callback
)
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
debug
=
True
,
use_reloader
=
False
)
# disable reloader so only subscribed once to rabbitmq
\ No newline at end of file
rest-gateway/app/rest/blockchain_trace.py
0 → 100644
View file @
447c76aa
from
flask
import
request
,
Response
import
main
def
receive
():
body
=
request
.
json
if
isBlockchainTraceValid
(
body
):
message
=
{
'type'
:
'blockchain-transaction'
,
'content'
:
body
}
main
.
message_sender
.
send
(
'inhub'
,
message
,
'trace-retrieval'
)
return
Response
(
status
=
201
)
def
isBlockchainTraceValid
(
trace
)
->
bool
:
return
'TransactionId'
in
trace
\
and
'Timestamp'
in
trace
\
and
'ApplicationType'
in
trace
\
and
'TransactionFrom'
in
trace
\
and
'TransactionFromLatLng'
in
trace
\
and
'TransactionTo'
in
trace
\
and
'TransactionToLatLng'
in
trace
\
and
'TransferredAsset'
in
trace
\
and
'ResourceIds'
in
trace
\
and
'ResourceMd5'
in
trace
\
and
'ResourceState'
in
trace
\
and
'Metadata'
in
trace
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