Commit 3200e789 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Pre-release CI/CD pipeline fixes

parent b20960b0
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -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)

@@ -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:
@@ -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

@@ -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)))