Loading src/service/service/ServiceServiceServicerImpl.py +17 −3 Original line number Diff line number Diff line Loading @@ -95,7 +95,20 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): context_client = ContextClient() _service : Optional[Service] = get_service_by_id( context_client, request.service_id, rw_copy=False, include_config_rules=False, include_constraints=False, include_endpoint_ids=False) include_config_rules=True, include_constraints=True, include_endpoint_ids=True) location_aware = False for constraint in request.service_constraints: if constraint.WhichOneof('constraint') != 'endpoint_location': continue location_aware = True LOGGER.warning('location_aware={:s}'.format(str(location_aware))) if _service is not None and location_aware: LOGGER.warning('removing previous service') tasks_scheduler = TasksScheduler(self.service_handler_factory) tasks_scheduler.compose_from_service(_service, is_delete=True) tasks_scheduler.execute_all() service = Service() service.CopyFrom(request if _service is None else _service) Loading @@ -107,6 +120,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): for endpoint_id in request.service_endpoint_ids: service.service_endpoint_ids.add().CopyFrom(endpoint_id) # pylint: disable=no-member device_list = context_client.ListDevices(Empty()) LOGGER.warning('[before] request={:s}'.format(grpc_message_to_json_string(request))) for constraint in request.service_constraints: if constraint.action == ConstraintActionEnum.CONSTRAINTACTION_UNDEFINED: Loading @@ -117,13 +132,11 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): if constraint.WhichOneof('constraint') != 'endpoint_location': continue if constraint.endpoint_location.HasField('endpoint_id'): continue device_list = context_client.ListDevices(Empty()) service_location = constraint.endpoint_location.location distances = {} for device in device_list.devices: for endpoint in device.device_endpoints: if not endpoint.endpoint_location.HasField('gps_position'): continue distance = gps_distance(service_location.gps_position, endpoint.endpoint_location.gps_position) distances[distance] = endpoint.endpoint_id Loading @@ -136,6 +149,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): ] if closer_endpoint_id not in service_endpoint_ids: service.service_endpoint_ids.append(closer_endpoint_id) LOGGER.warning('[after] request={:s}'.format(grpc_message_to_json_string(request))) LOGGER.warning('[after] service={:s}'.format(grpc_message_to_json_string(service))) Loading Loading
src/service/service/ServiceServiceServicerImpl.py +17 −3 Original line number Diff line number Diff line Loading @@ -95,7 +95,20 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): context_client = ContextClient() _service : Optional[Service] = get_service_by_id( context_client, request.service_id, rw_copy=False, include_config_rules=False, include_constraints=False, include_endpoint_ids=False) include_config_rules=True, include_constraints=True, include_endpoint_ids=True) location_aware = False for constraint in request.service_constraints: if constraint.WhichOneof('constraint') != 'endpoint_location': continue location_aware = True LOGGER.warning('location_aware={:s}'.format(str(location_aware))) if _service is not None and location_aware: LOGGER.warning('removing previous service') tasks_scheduler = TasksScheduler(self.service_handler_factory) tasks_scheduler.compose_from_service(_service, is_delete=True) tasks_scheduler.execute_all() service = Service() service.CopyFrom(request if _service is None else _service) Loading @@ -107,6 +120,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): for endpoint_id in request.service_endpoint_ids: service.service_endpoint_ids.add().CopyFrom(endpoint_id) # pylint: disable=no-member device_list = context_client.ListDevices(Empty()) LOGGER.warning('[before] request={:s}'.format(grpc_message_to_json_string(request))) for constraint in request.service_constraints: if constraint.action == ConstraintActionEnum.CONSTRAINTACTION_UNDEFINED: Loading @@ -117,13 +132,11 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): if constraint.WhichOneof('constraint') != 'endpoint_location': continue if constraint.endpoint_location.HasField('endpoint_id'): continue device_list = context_client.ListDevices(Empty()) service_location = constraint.endpoint_location.location distances = {} for device in device_list.devices: for endpoint in device.device_endpoints: if not endpoint.endpoint_location.HasField('gps_position'): continue distance = gps_distance(service_location.gps_position, endpoint.endpoint_location.gps_position) distances[distance] = endpoint.endpoint_id Loading @@ -136,6 +149,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): ] if closer_endpoint_id not in service_endpoint_ids: service.service_endpoint_ids.append(closer_endpoint_id) LOGGER.warning('[after] request={:s}'.format(grpc_message_to_json_string(request))) LOGGER.warning('[after] service={:s}'.format(grpc_message_to_json_string(service))) Loading