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
6b246594
Commit
6b246594
authored
2 years ago
by
Lluis Gifre Renom
Browse files
Options
Downloads
Patches
Plain Diff
Device - EmulatedDriver:
- first try of decorating device driver
parent
de520e7c
No related branches found
No related tags found
2 merge requests
!54
Release 2.0.0
,
!36
Performance Evaluation Framework + Helper Tools
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/device/service/drivers/emulated/EmulatedDriver.py
+9
-0
9 additions, 0 deletions
src/device/service/drivers/emulated/EmulatedDriver.py
with
9 additions
and
0 deletions
src/device/service/drivers/emulated/EmulatedDriver.py
+
9
−
0
View file @
6b246594
...
@@ -19,6 +19,7 @@ from apscheduler.executors.pool import ThreadPoolExecutor
...
@@ -19,6 +19,7 @@ from apscheduler.executors.pool import ThreadPoolExecutor
from
apscheduler.job
import
Job
from
apscheduler.job
import
Job
from
apscheduler.jobstores.memory
import
MemoryJobStore
from
apscheduler.jobstores.memory
import
MemoryJobStore
from
apscheduler.schedulers.background
import
BackgroundScheduler
from
apscheduler.schedulers.background
import
BackgroundScheduler
from
common.perf_eval_method_wrapper.Decorator
import
MetricsPool
,
meter_method
from
common.type_checkers.Checkers
import
chk_float
,
chk_length
,
chk_string
,
chk_type
from
common.type_checkers.Checkers
import
chk_float
,
chk_length
,
chk_string
,
chk_type
from
device.service.database.KpiSampleType
import
ORM_KpiSampleTypeEnum
,
grpc_to_enum__kpi_sample_type
from
device.service.database.KpiSampleType
import
ORM_KpiSampleTypeEnum
,
grpc_to_enum__kpi_sample_type
from
device.service.driver_api._Driver
import
(
from
device.service.driver_api._Driver
import
(
...
@@ -122,6 +123,8 @@ def do_sampling(
...
@@ -122,6 +123,8 @@ def do_sampling(
value
=
abs
(
0.95
*
waveform
+
0.05
*
noise
)
value
=
abs
(
0.95
*
waveform
+
0.05
*
noise
)
out_samples
.
put_nowait
((
timestamp
,
resource_key
,
value
))
out_samples
.
put_nowait
((
timestamp
,
resource_key
,
value
))
METRICS_POOL
=
MetricsPool
(
labels
=
{
'
driver
'
:
'
emulated
'
})
class
EmulatedDriver
(
_Driver
):
class
EmulatedDriver
(
_Driver
):
def
__init__
(
self
,
address
:
str
,
port
:
int
,
**
settings
)
->
None
:
# pylint: disable=super-init-not-called
def
__init__
(
self
,
address
:
str
,
port
:
int
,
**
settings
)
->
None
:
# pylint: disable=super-init-not-called
self
.
__lock
=
threading
.
Lock
()
self
.
__lock
=
threading
.
Lock
()
...
@@ -170,10 +173,12 @@ class EmulatedDriver(_Driver):
...
@@ -170,10 +173,12 @@ class EmulatedDriver(_Driver):
self
.
__scheduler
.
shutdown
()
self
.
__scheduler
.
shutdown
()
return
True
return
True
@meter_method
(
METRICS_POOL
)
def
GetInitialConfig
(
self
)
->
List
[
Tuple
[
str
,
Any
]]:
def
GetInitialConfig
(
self
)
->
List
[
Tuple
[
str
,
Any
]]:
with
self
.
__lock
:
with
self
.
__lock
:
return
dump_subtree
(
self
.
__initial
)
return
dump_subtree
(
self
.
__initial
)
@meter_method
(
METRICS_POOL
)
def
GetConfig
(
self
,
resource_keys
:
List
[
str
]
=
[])
->
List
[
Tuple
[
str
,
Union
[
Any
,
None
,
Exception
]]]:
def
GetConfig
(
self
,
resource_keys
:
List
[
str
]
=
[])
->
List
[
Tuple
[
str
,
Union
[
Any
,
None
,
Exception
]]]:
chk_type
(
'
resources
'
,
resource_keys
,
list
)
chk_type
(
'
resources
'
,
resource_keys
,
list
)
with
self
.
__lock
:
with
self
.
__lock
:
...
@@ -197,6 +202,7 @@ class EmulatedDriver(_Driver):
...
@@ -197,6 +202,7 @@ class EmulatedDriver(_Driver):
results
.
extend
(
dump_subtree
(
resource_node
))
results
.
extend
(
dump_subtree
(
resource_node
))
return
results
return
results
@meter_method
(
METRICS_POOL
)
def
SetConfig
(
self
,
resources
:
List
[
Tuple
[
str
,
Any
]])
->
List
[
Union
[
bool
,
Exception
]]:
def
SetConfig
(
self
,
resources
:
List
[
Tuple
[
str
,
Any
]])
->
List
[
Union
[
bool
,
Exception
]]:
chk_type
(
'
resources
'
,
resources
,
list
)
chk_type
(
'
resources
'
,
resources
,
list
)
if
len
(
resources
)
==
0
:
return
[]
if
len
(
resources
)
==
0
:
return
[]
...
@@ -231,6 +237,7 @@ class EmulatedDriver(_Driver):
...
@@ -231,6 +237,7 @@ class EmulatedDriver(_Driver):
results
.
append
(
True
)
results
.
append
(
True
)
return
results
return
results
@meter_method
(
METRICS_POOL
)
def
DeleteConfig
(
self
,
resources
:
List
[
Tuple
[
str
,
Any
]])
->
List
[
Union
[
bool
,
Exception
]]:
def
DeleteConfig
(
self
,
resources
:
List
[
Tuple
[
str
,
Any
]])
->
List
[
Union
[
bool
,
Exception
]]:
chk_type
(
'
resources
'
,
resources
,
list
)
chk_type
(
'
resources
'
,
resources
,
list
)
if
len
(
resources
)
==
0
:
return
[]
if
len
(
resources
)
==
0
:
return
[]
...
@@ -268,6 +275,7 @@ class EmulatedDriver(_Driver):
...
@@ -268,6 +275,7 @@ class EmulatedDriver(_Driver):
results
.
append
(
True
)
results
.
append
(
True
)
return
results
return
results
@meter_method
(
METRICS_POOL
)
def
SubscribeState
(
self
,
subscriptions
:
List
[
Tuple
[
str
,
float
,
float
]])
->
List
[
Union
[
bool
,
Exception
]]:
def
SubscribeState
(
self
,
subscriptions
:
List
[
Tuple
[
str
,
float
,
float
]])
->
List
[
Union
[
bool
,
Exception
]]:
chk_type
(
'
subscriptions
'
,
subscriptions
,
list
)
chk_type
(
'
subscriptions
'
,
subscriptions
,
list
)
if
len
(
subscriptions
)
==
0
:
return
[]
if
len
(
subscriptions
)
==
0
:
return
[]
...
@@ -305,6 +313,7 @@ class EmulatedDriver(_Driver):
...
@@ -305,6 +313,7 @@ class EmulatedDriver(_Driver):
results
.
append
(
True
)
results
.
append
(
True
)
return
results
return
results
@meter_method
(
METRICS_POOL
)
def
UnsubscribeState
(
self
,
subscriptions
:
List
[
Tuple
[
str
,
float
,
float
]])
->
List
[
Union
[
bool
,
Exception
]]:
def
UnsubscribeState
(
self
,
subscriptions
:
List
[
Tuple
[
str
,
float
,
float
]])
->
List
[
Union
[
bool
,
Exception
]]:
chk_type
(
'
subscriptions
'
,
subscriptions
,
list
)
chk_type
(
'
subscriptions
'
,
subscriptions
,
list
)
if
len
(
subscriptions
)
==
0
:
return
[]
if
len
(
subscriptions
)
==
0
:
return
[]
...
...
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