Loading src/service/service/ServiceServiceServicerImpl.py +12 −33 Original line number Diff line number Diff line Loading @@ -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__) Loading Loading @@ -92,10 +94,11 @@ 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[:] Loading Loading @@ -131,10 +134,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): 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) Loading @@ -149,43 +150,21 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): 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() Loading Loading
src/service/service/ServiceServiceServicerImpl.py +12 −33 Original line number Diff line number Diff line Loading @@ -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__) Loading Loading @@ -92,10 +94,11 @@ 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[:] Loading Loading @@ -131,10 +134,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): 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) Loading @@ -149,43 +150,21 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): 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() Loading