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

Service component:

- Minor code cleanup before merging
parent 131d8008
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!89First implementation of location-aware services
......@@ -14,7 +14,7 @@
anytree==2.8.0
geopy==2.3.0
networkx==2.6.3
pydot==1.4.2
redis==4.1.2
geopy==2.3.0
\ No newline at end of file
redis==4.1.2
\ No newline at end of file
......@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import grpc, json, logging
import copy, grpc, json, logging
from typing import Optional
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.method_wrappers.ServiceExceptions import AlreadyExistsException, InvalidArgumentException
......@@ -26,7 +26,6 @@ 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__)
......@@ -121,18 +120,16 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
for config_rule in request.service_config.config_rules:
service.service_config.config_rules.add().CopyFrom(config_rule) # pylint: disable=no-member
for constraint in request.service_constraints:
if constraint.WhichOneof('constraint') == 'endpoint_location':
context_client = ContextClient()
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 endpoint.endpoint_location.HasField('gps_position'):
distance = gps_distance(service_location.gps_position, endpoint.endpoint_location.gps_position)
distances[distance] = endpoint.endpoint_id
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
closer_endpoint_uuid = distances[min(distances)]
service.service_endpoint_ids.append(closer_endpoint_uuid)
......
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