Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
c4e942d5
Commit
c4e942d5
authored
2 years ago
by
Carlos Manso
Browse files
Options
Downloads
Patches
Plain Diff
Bugfix Location
parent
28bba9bd
No related branches found
No related tags found
2 merge requests
!142
Release TeraFlowSDN 2.1
,
!89
First implementation of location-aware services
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/service/service/ServiceServiceServicerImpl.py
+12
-33
12 additions, 33 deletions
src/service/service/ServiceServiceServicerImpl.py
with
12 additions
and
33 deletions
src/service/service/ServiceServiceServicerImpl.py
+
12
−
33
View file @
c4e942d5
...
...
@@ -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,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
[:]
...
...
@@ -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
)
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment