Commit e8b426c1 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component:

- Minor code cleanup before merging
parent 131d8008
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@


anytree==2.8.0
geopy==2.3.0
networkx==2.6.3
pydot==1.4.2
redis==4.1.2
 No newline at end of file
geopy==2.3.0
 No newline at end of file
+4 −7
Original line number Diff line number Diff line
@@ -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,16 +120,14 @@ 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'):
                        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