Skip to content
Snippets Groups Projects
Commit a72e275d authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component:

- extended AddDevice to create a device placeholder and get the correct device UUID
parent 11731ae4
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!34Context Scalability extensions using CockroachDB + Removal of Stateful database inside Device + other
......@@ -43,8 +43,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def AddDevice(self, request : Device, context : grpc.ServicerContext) -> DeviceId:
device_id = request.device_id
device_uuid = device_id.device_uuid.uuid
device_uuid = request.device_id.device_uuid.uuid
connection_config_rules = check_connect_rules(request.device_config)
check_no_endpoints(request.device_endpoints)
......@@ -52,9 +51,18 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
context_client = ContextClient()
device = get_device(context_client, device_uuid, rw_copy=True)
if device is None:
# not in context, create from request
# not in context, create blank one to get UUID, and populate it below
device = Device()
device.CopyFrom(request)
device.device_id.CopyFrom(request.device_id) # pylint: disable=no-member
device.name = request.name
device.device_type = request.device_type
device.device_operational_status = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_UNDEFINED
device.device_drivers.extend(request.device_drivers) # pylint: disable=no-member
device_id = context_client.SetDevice(device)
device = get_device(context_client, device_id.device_uuid.uuid, rw_copy=True)
# update device_uuid to honor UUID provided by Context
device_uuid = device.device_id.device_uuid.uuid
self.mutex_queues.wait_my_turn(device_uuid)
try:
......@@ -70,6 +78,8 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
# created from request, populate config rules using driver
errors.extend(populate_config_rules(device, driver))
# TODO: populate components
if len(errors) > 0:
for error in errors: LOGGER.error(error)
raise OperationFailedException('AddDevice', extra_details=errors)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment