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

Device - EmulatedDriver:

- first try of decorating device driver
parent de520e7c
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!36Performance Evaluation Framework + Helper Tools
...@@ -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 []
......
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