Commit 359deef2 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

update the print out

parent 4dc617cf
Pipeline #349268 passed with stage
in 19 seconds
......@@ -252,11 +252,18 @@ def on_user_message(self, msg):
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": You have received a user message"
+ ": You have received a S³I-B UserMessage"
+ json.dumps(msg, indent=2)
)
def on_get_value_request(self, msg):
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": You have received a S³I-B GetValueRequest"
+ json.dumps(msg, indent=2)
)
get_value_reply = GetValueReply()
request_sender = msg.get("sender")
request_msg_id = msg.get("identifier")
......@@ -264,6 +271,13 @@ def on_get_value_request(self, msg):
attribute_path = msg.get("attributePath")
reply_msg_uuid = "s3i:" + str(uuid.uuid4())
try:
print(
BColors.OKBLUE
+ "[S³I]"
+ BColors.ENDC
+ ": Search the attribute with path: "
+ attribute_path
)
value = self._uriToData(attribute_path)
except KeyError:
value = "invalid attribute path"
......@@ -275,10 +289,18 @@ def on_get_value_request(self, msg):
msgUUID=reply_msg_uuid,
replyingToUUID=request_msg_id,
)
self.broker.send(
res = self.broker.send(
receiver_endpoints=[request_sender_endpoint],
msg=json.dumps(get_value_reply.msg),
)
if res.status_code == 201:
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": Send a S³I-B GetValueReply back to the requester."
)
def _uriToData(self, uri):
if uri == "":
......@@ -361,6 +383,13 @@ def _findValue(self, json, value):
return False
def on_service_request(self, body_json):
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": You have received a S³I-B ServiceRequest "
+ json.dumps(body_json, indent=2)
)
service_type = body_json.get("serviceType")
parameters = body_json.get("parameters")
service_functionality = service_type.split('/')[0]
......@@ -372,6 +401,13 @@ def on_service_request(self, body_json):
)
else:
# TODO: Call right functionality.
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": Execute the function {0} of the class {1}.".format(service_type.split('/')[1],
service_type.split('/')[0])
)
method = getattr(service_functionality_obj, service_type.split('/')[1])
result = method(**parameters)
......@@ -387,26 +423,58 @@ def on_service_request(self, body_json):
replyingToUUID=body_json.get("identifier", None),
msgUUID="s3i:{}".format(uuid.uuid4())
)
self.broker.send(receiver_endpoints=[body_json.get("replyToEndpoint", None)],
res = self.broker.send(receiver_endpoints=[body_json.get("replyToEndpoint", None)],
msg=json.dumps(service_reply.msg))
if res.status_code == 201:
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": Send a S³I-B ServiceReply back to the requester "
+ json.dumps(body_json, indent=2)
)
def on_get_value_reply(self, msg):
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": You have received a get value reply"
+ ": You have received a S³I-B GetValueReply"
+ json.dumps(msg, indent=2)
)
value = msg.get("value", None)
if isinstance(value, dict):
value = json.dumps(value, indent=2)
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": The queried value is: {0}{1}{2}".format(BColors.OKGREEN, value,
BColors.ENDC)
)
def on_service_reply(self, msg):
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": You have received a service reply"
+ ": You have received a S³I-B ServiceReply"
+ json.dumps(msg, indent=2)
)
results = msg.get("results", None)
if isinstance(results, dict):
results = json.dumps(results, indent=2)
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": The result is: {0}{1}{2}".format(BColors.OKGREEN, results,
BColors.ENDC)
)
def to_dir_json(self):
self.dir_json = self.dir.queryThingIDBased(self.thing_id)
......
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