Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

Commit 7e5ff90e authored by Jiahang Chen's avatar Jiahang Chen

add some try except in on_service_req

parent 31f8d8db
Pipeline #366577 passed with stages
in 35 seconds
......@@ -299,6 +299,7 @@ class Thing:
value = self._uriToData(attribute_path)
except KeyError:
value = "invalid attribute path"
APP_LOGGER.critical(value)
get_value_reply.fillGetValueReply(
senderUUID=self.thing_id,
......@@ -416,6 +417,7 @@ class Thing:
)
service_type = body_json.get("serviceType")
parameters = body_json.get("parameters")
service_reply = ServiceReply()
service_functionality = service_type.split('/')[0]
service_functionality_obj = self.features.get(service_functionality)
if service_functionality_obj is None:
......@@ -423,46 +425,79 @@ class Thing:
"Functionality %s is not one of the built-in functionalities in %s!" % (
service_functionality, self.name)
)
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)
if isinstance(result, bool):
result = {"ok": result}
service_reply = ServiceReply()
service_reply.fillServiceReply(
senderUUID=self.thing_id,
receiverUUID=body_json.get("sender", None),
serviceType=body_json.get("serviceType", None),
results=result,
results={"error": "invalid functionalities (serviceType) {}".format(service_functionality)},
replyingToUUID=body_json.get("identifier", None),
msgUUID="s3i:{}".format(uuid.uuid4())
)
res = self.broker.send(receiver_endpoints=[body_json.get("replyToEndpoint", None)],
msg=json.dumps(service_reply.msg))
if self.__is_broker_rest:
if res.status_code == 201:
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": Send a S³I-B ServiceReply back to the requester "
else:
# TODO: Call right functionality.
try:
method = getattr(service_functionality_obj, service_type.split('/')[1])
except AttributeError:
APP_LOGGER.critical(
"Functionality %s is not one of the built-in functionalities in %s!" % (
service_type.split('/')[1], self.name)
)
service_reply.fillServiceReply(
senderUUID=self.thing_id,
receiverUUID=body_json.get("sender", None),
serviceType=body_json.get("serviceType", None),
results={"error": "invalid functionalities (serviceType) {}".format(service_type.split('/')[1])},
replyingToUUID=body_json.get("identifier", None),
msgUUID="s3i:{}".format(uuid.uuid4())
)
else:
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])
)
try:
result = method(**parameters)
except TypeError:
APP_LOGGER.critical("Invalid function arguments")
service_reply.fillServiceReply(
senderUUID=self.thing_id,
receiverUUID=body_json.get("sender", None),
serviceType=body_json.get("serviceType", None),
results={"error": "invalid function arguments (parameters)"},
replyingToUUID=body_json.get("identifier", None),
msgUUID="s3i:{}".format(uuid.uuid4())
)
else:
print( BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ res.text)
if isinstance(result, bool):
result = {"ok": result}
service_reply.fillServiceReply(
senderUUID=self.thing_id,
receiverUUID=body_json.get("sender", None),
serviceType=body_json.get("serviceType", None),
results=result,
replyingToUUID=body_json.get("identifier", None),
msgUUID="s3i:{}".format(uuid.uuid4())
)
res = self.broker.send(receiver_endpoints=[body_json.get("replyToEndpoint", None)],
msg=json.dumps(service_reply.msg))
if self.__is_broker_rest:
if res.status_code == 201:
print(
BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ ": Send a S³I-B ServiceReply back to the requester "
)
else:
print( BColors.OKBLUE
+ "[S³I][Broker]"
+ BColors.ENDC
+ res.text)
def on_get_value_reply(self, msg):
print(
......
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