diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index b81fa79b6c4a062ea1f7e8996ed03f2cf684245f..ad44ff183a2b3da846f205d0927eb5dbf894cf8b 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -25,6 +25,8 @@ from context.client.ContextClient import ContextClient from pathcomp.frontend.client.PathCompClient import PathCompClient from .service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory from .task_scheduler.TaskScheduler import TasksScheduler +from .tools.GeodesicDistance import gps_distance +import copy LOGGER = logging.getLogger(__name__) @@ -92,15 +94,16 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): context_client, request.service_id, rw_copy=False, include_config_rules=False, include_constraints=False, include_endpoint_ids=False) service = Service() - service.CopyFrom(request if _service is None else _service) + service.CopyFrom(request) - if service.service_status.service_status == ServiceStatusEnum.SERVICESTATUS_ACTIVE: - self.DeleteService(service.service_id, context) + if _service.service_status.service_status == ServiceStatusEnum.SERVICESTATUS_ACTIVE: + context_client.UnsetService(_service) + self.DeleteService(_service.service_id, context) new_service = copy.deepcopy(service) del new_service.service_endpoint_ids[:] del new_service.service_constraints[:] del new_service.service_config.config_rules[:] - self.CreateService(new_service , context) + self.CreateService(new_service, context) if service.service_type == ServiceTypeEnum.SERVICETYPE_UNKNOWN: # pylint: disable=no-member service.service_type = request.service_type # pylint: disable=no-member @@ -128,13 +131,11 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): for device in device_list.devices: for endpoint in device.device_endpoints: if endpoint.endpoint_location.HasField('gps_position'): - distance = gps_distance(service_location.gps_position, endpoint.endpoint_location.gps_position) + distance = gps_distance(service_location.gps_position, endpoint.endpoint_location.gps_position) distances[distance] = endpoint.endpoint_id - min_distance = min(distances) - closer_endpoint_id = distances[min_distance] - service.service_endpoint_ids.append(closer_endpoint_id) - # pathcomp_request.services[0].service_endpoint_ids.extend(closer_endpoint_ids) + closer_endpoint_uuid = distances[min(distances)] + service.service_endpoint_ids.append(closer_endpoint_uuid) service_id_with_uuids = context_client.SetService(service) @@ -148,44 +149,22 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): if constraint.WhichOneof('constraint') == 'sla_availability': num_disjoint_paths = constraint.sla_availability.num_disjoint_paths break - - service_locations = None - for constraint in request.service_constraints: - if constraint.WhichOneof('constraint') == 'endpoint_location': - service_location = constraint.endpoint_location.location num_disjoint_paths = 1 if num_disjoint_paths is None or num_disjoint_paths == 0 else num_disjoint_paths num_expected_endpoints = num_disjoint_paths * 2 tasks_scheduler = TasksScheduler(self.service_handler_factory) - if len(service_with_uuids.service_endpoint_ids) >= num_expected_endpoints or\ - len(service_locations) >= num_expected_endpoints: + if len(service_with_uuids.service_endpoint_ids) >= num_expected_endpoints: pathcomp_request = PathCompRequest() pathcomp_request.services.append(service_with_uuids) # pylint: disable=no-member - LOGGER.warning('__PR1: {}'.format(grpc_message_to_json(pathcomp_request))) - - if service_locations: - context_client = ContextClient() - device_list = context_client.ListDevices(Empty()) - - closer_endpoint_id = None - if service_location: - distances = {} - for device in device_list.devices: - for endpoint in device.device_endpoints: - distances[gps_distance(service_location.gps_position, endpoint.endpoint_location.gps_position)] = endpoint.endpoint_id - min_distance = min(distances) - closer_endpoint_id = distances[min_distance] - - pathcomp_request.services[0].service_endpoint_ids.extend(closer_endpoint_id) if num_disjoint_paths is None or num_disjoint_paths in {0, 1}: pathcomp_request.shortest_path.Clear() # pylint: disable=no-member else: pathcomp_request.k_disjoint_path.num_disjoint = num_disjoint_paths # pylint: disable=no-member - LOGGER.info('pathcomp_request={:s}'.format(grpc_message_to_json_string(pathcomp_request))) + LOGGER.debug('pathcomp_request={:s}'.format(grpc_message_to_json_string(pathcomp_request))) pathcomp = PathCompClient() pathcomp_reply = pathcomp.Compute(pathcomp_request) pathcomp.close()