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
21a3d49c
Commit
21a3d49c
authored
9 months ago
by
Javier Diaz
Browse files
Options
Downloads
Patches
Plain Diff
Debugging
parent
22ffe9d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!294
Release TeraFlowSDN 4.0
,
!259
Resolve "(CTTC) Replace DLT Gateway functionality with an opensource and Hyper Ledger v2.4+ compliant version"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/dlt/connector/service/tools/Checkers.py
+1
-1
1 addition, 1 deletion
src/dlt/connector/service/tools/Checkers.py
src/interdomain/service/topology_abstractor/DltRecorderOld.py
+0
-133
0 additions, 133 deletions
...interdomain/service/topology_abstractor/DltRecorderOld.py
with
1 addition
and
134 deletions
src/dlt/connector/service/tools/Checkers.py
+
1
−
1
View file @
21a3d49c
...
...
@@ -20,5 +20,5 @@ def record_exists(record : DltRecord) -> bool:
exists
=
exists
and
(
record
.
record_id
.
type
!=
DLTRECORDTYPE_UNDEFINED
)
exists
=
exists
and
(
len
(
record
.
record_id
.
record_uuid
.
uuid
)
>
0
)
#exists = exists and (record.operation != DLTRECORDOPERATION_UNDEFINED)
exists
=
exists
and
(
len
(
record
.
data_json
)
>
0
)
#
exists = exists and (len(record.data_json) > 0)
return
exists
This diff is collapsed.
Click to expand it.
src/interdomain/service/topology_abstractor/DltRecorderOld.py
deleted
100644 → 0
+
0
−
133
View file @
22ffe9d0
import
logging
import
threading
from
typing
import
Dict
,
Optional
from
common.Constants
import
DEFAULT_CONTEXT_NAME
,
DEFAULT_TOPOLOGY_NAME
,
INTERDOMAIN_TOPOLOGY_NAME
,
ServiceNameEnum
from
common.Settings
import
ENVVAR_SUFIX_SERVICE_HOST
,
ENVVAR_SUFIX_SERVICE_PORT_GRPC
,
find_environment_variables
,
get_env_var_name
from
common.proto.context_pb2
import
ContextEvent
,
ContextId
,
Device
,
DeviceEvent
,
DeviceId
,
EndPointId
,
Link
,
LinkEvent
,
TopologyId
,
TopologyEvent
from
common.tools.context_queries.Context
import
create_context
from
common.tools.context_queries.Device
import
get_uuids_of_devices_in_topology
from
common.tools.context_queries.Topology
import
create_missing_topologies
from
common.tools.grpc.Tools
import
grpc_message_to_json_string
from
common.tools.object_factory.Context
import
json_context_id
from
common.tools.object_factory.Device
import
json_device_id
from
common.tools.object_factory.Topology
import
json_topology_id
from
context.client.ContextClient
import
ContextClient
from
context.client.EventsCollector
import
EventsCollector
from
dlt.connector.client.DltConnectorClient
import
DltConnectorClient
from
.DltRecordSender
import
DltRecordSender
from
.Types
import
EventTypes
LOGGER
=
logging
.
getLogger
(
__name__
)
ADMIN_CONTEXT_ID
=
ContextId
(
**
json_context_id
(
DEFAULT_CONTEXT_NAME
))
INTERDOMAIN_TOPOLOGY_ID
=
TopologyId
(
**
json_topology_id
(
INTERDOMAIN_TOPOLOGY_NAME
,
context_id
=
ADMIN_CONTEXT_ID
))
class
DLTRecorder
(
threading
.
Thread
):
def
__init__
(
self
)
->
None
:
super
().
__init__
(
daemon
=
True
)
self
.
terminate
=
threading
.
Event
()
self
.
context_client
=
ContextClient
()
self
.
context_event_collector
=
EventsCollector
(
self
.
context_client
)
def
stop
(
self
):
self
.
terminate
.
set
()
def
run
(
self
)
->
None
:
self
.
context_client
.
connect
()
create_context
(
self
.
context_client
,
DEFAULT_CONTEXT_NAME
)
self
.
create_topologies
()
self
.
context_event_collector
.
start
()
while
not
self
.
terminate
.
is_set
():
event
=
self
.
context_event_collector
.
get_event
(
timeout
=
0.1
)
if
event
is
None
:
continue
LOGGER
.
info
(
'
Processing Event({:s})...
'
.
format
(
grpc_message_to_json_string
(
event
)))
self
.
update_record
(
event
)
self
.
context_event_collector
.
stop
()
self
.
context_client
.
close
()
def
create_topologies
(
self
):
topology_uuids
=
[
DEFAULT_TOPOLOGY_NAME
,
INTERDOMAIN_TOPOLOGY_NAME
]
create_missing_topologies
(
self
.
context_client
,
ADMIN_CONTEXT_ID
,
topology_uuids
)
def
get_dlt_connector_client
(
self
)
->
Optional
[
DltConnectorClient
]:
env_vars
=
find_environment_variables
([
get_env_var_name
(
ServiceNameEnum
.
DLT
,
ENVVAR_SUFIX_SERVICE_HOST
),
get_env_var_name
(
ServiceNameEnum
.
DLT
,
ENVVAR_SUFIX_SERVICE_PORT_GRPC
),
])
if
len
(
env_vars
)
==
2
:
dlt_connector_client
=
DltConnectorClient
()
dlt_connector_client
.
connect
()
return
dlt_connector_client
return
None
def
update_record
(
self
,
event
:
EventTypes
)
->
None
:
dlt_connector_client
=
self
.
get_dlt_connector_client
()
dlt_record_sender
=
DltRecordSender
(
self
.
context_client
,
dlt_connector_client
)
if
isinstance
(
event
,
ContextEvent
):
LOGGER
.
debug
(
'
Processing ContextEvent({:s})
'
.
format
(
grpc_message_to_json_string
(
event
)))
LOGGER
.
warning
(
'
Ignoring ContextEvent({:s})
'
.
format
(
grpc_message_to_json_string
(
event
)))
elif
isinstance
(
event
,
TopologyEvent
):
LOGGER
.
debug
(
'
Processing TopologyEvent({:s})
'
.
format
(
grpc_message_to_json_string
(
event
)))
self
.
process_topology_event
(
event
,
dlt_record_sender
)
elif
isinstance
(
event
,
DeviceEvent
):
LOGGER
.
debug
(
'
Processing DeviceEvent({:s})
'
.
format
(
grpc_message_to_json_string
(
event
)))
self
.
process_device_event
(
event
,
dlt_record_sender
)
elif
isinstance
(
event
,
LinkEvent
):
LOGGER
.
debug
(
'
Processing LinkEvent({:s})
'
.
format
(
grpc_message_to_json_string
(
event
)))
self
.
process_link_event
(
event
,
dlt_record_sender
)
else
:
LOGGER
.
warning
(
'
Unsupported Event({:s})
'
.
format
(
grpc_message_to_json_string
(
event
)))
dlt_record_sender
.
commit
()
if
dlt_connector_client
is
not
None
:
dlt_connector_client
.
close
()
def
process_topology_event
(
self
,
event
:
TopologyEvent
,
dlt_record_sender
:
DltRecordSender
)
->
None
:
topology_id
=
event
.
topology_id
topology_uuid
=
topology_id
.
topology_uuid
.
uuid
context_id
=
topology_id
.
context_id
context_uuid
=
context_id
.
context_uuid
.
uuid
topology_uuids
=
{
DEFAULT_TOPOLOGY_NAME
,
INTERDOMAIN_TOPOLOGY_NAME
}
context
=
self
.
context_client
.
GetContext
(
context_id
)
context_name
=
context
.
name
topology_details
=
self
.
context_client
.
GetTopologyDetails
(
topology_id
)
topology_name
=
topology_details
.
name
if
((
context_uuid
==
DEFAULT_CONTEXT_NAME
)
or
(
context_name
==
DEFAULT_CONTEXT_NAME
))
and
\
(
topology_uuid
not
in
topology_uuids
)
and
(
topology_name
not
in
topology_uuids
):
for
device
in
topology_details
.
devices
:
dlt_record_sender
.
add_device
(
topology_id
,
device
)
for
link
in
topology_details
.
links
:
dlt_record_sender
.
add_link
(
topology_id
,
link
)
else
:
MSG
=
'
Ignoring ({:s}/{:s})({:s}/{:s}) TopologyEvent({:s})
'
args
=
context_uuid
,
context_name
,
topology_uuid
,
topology_name
,
grpc_message_to_json_string
(
event
)
LOGGER
.
warning
(
MSG
.
format
(
*
args
))
#Check which ID to use.
def
process_device_event
(
self
,
event
:
DeviceEvent
,
dlt_record_sender
:
DltRecordSender
)
->
None
:
device_id
=
event
.
device_id
device_uuid
=
device_id
.
device_uuid
.
uuid
device
=
self
.
context_client
.
GetDevice
(
device_id
)
dlt_record_sender
.
add_device
(
device_id
.
context_id
,
device
)
def
process_link_event
(
self
,
event
:
LinkEvent
,
dlt_record_sender
:
DltRecordSender
)
->
None
:
link_id
=
event
.
link_id
link
=
self
.
context_client
.
GetLink
(
link_id
)
dlt_record_sender
.
add_link
(
link_id
.
context_id
,
link
)
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