|
| 1 | +from uuid import uuid4 |
| 2 | + |
| 3 | +from oshconnect.datasource import Mode |
| 4 | + |
| 5 | + |
| 6 | +class DataSource: |
| 7 | + |
| 8 | + def __init__(self, name: str, mode: Mode, properties: dict): |
| 9 | + self._id = f'datasource-{uuid4()}' |
| 10 | + self.name = name |
| 11 | + self.mode = mode |
| 12 | + self.properties = properties |
| 13 | + |
| 14 | + def get_id(self) -> str: |
| 15 | + return self._id |
| 16 | + |
| 17 | + def get_name(self): |
| 18 | + pass |
| 19 | + |
| 20 | + def create_process(self): |
| 21 | + pass |
| 22 | + |
| 23 | + def terminate_process(self): |
| 24 | + pass |
| 25 | + |
| 26 | + # Might not be necessary |
| 27 | + def subscribe(self): |
| 28 | + pass |
| 29 | + |
| 30 | + def update_properties(self, properties: dict): |
| 31 | + # TODO: need to stop in progress sub-processes and restart |
| 32 | + self.properties = properties |
| 33 | + |
| 34 | + def initialize(self): |
| 35 | + pass |
| 36 | + |
| 37 | + def connect(self): |
| 38 | + pass |
| 39 | + |
| 40 | + def disconnect(self): |
| 41 | + pass |
| 42 | + |
| 43 | + def reset(self): |
| 44 | + pass |
| 45 | + |
| 46 | + def get_status(self): |
| 47 | + pass |
| 48 | + |
| 49 | + |
| 50 | +class DatasourceHandler: |
| 51 | + datasource_map: dict[str, DataSource] |
| 52 | + |
| 53 | + def __init__(self): |
| 54 | + self.datasource_map = {} |
| 55 | + |
| 56 | + def add_datasource(self, datasource: DataSource): |
| 57 | + self.datasource_map[datasource.get_id()] = datasource |
| 58 | + |
| 59 | + def initialize_ds(self, datasource_id: str, properties: dict): |
| 60 | + ds = self.datasource_map.get(datasource_id) |
| 61 | + ds.initialize() |
| 62 | + |
| 63 | + def initialize_all(self): |
| 64 | + # list comp is faster than for loop |
| 65 | + [ds.initialize() for ds in self.datasource_map.values()] |
| 66 | + |
| 67 | + def connect_ds(self, datasource_id: str): |
| 68 | + ds = self.datasource_map.get(datasource_id) |
| 69 | + ds.connect() |
| 70 | + |
| 71 | + def connect_all(self): |
| 72 | + [ds.connect() for ds in self.datasource_map.values()] |
| 73 | + |
| 74 | + def disconnect_ds(self, datasource_id: str): |
| 75 | + ds = self.datasource_map.get(datasource_id) |
| 76 | + ds.disconnect() |
| 77 | + |
| 78 | + def disconnect_all(self): |
| 79 | + [ds.disconnect() for ds in self.datasource_map.values()] |
0 commit comments