1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from o2app import bootstrap
18 from o2common.service.watcher.base import WatcherTree
19 from o2common.service.watcher.worker import PollWorker
21 from o2ims.service.watcher.ocloud_watcher import OcloudWatcher
22 from o2ims.service.watcher.ocloud_watcher import DmsWatcher
23 from o2ims.service.watcher.resourcepool_watcher import ResourcePoolWatcher
24 from o2ims.service.watcher.alarm_watcher import AlarmWatcher
26 from o2ims.adapter.clients.ocloud_client import StxDmsClient
27 from o2ims.adapter.clients.ocloud_client import StxOcloudClient
28 from o2ims.adapter.clients.ocloud_client import StxResourcePoolClient
29 from o2ims.adapter.clients.fault_client import StxAlarmClient
31 from o2ims.service.watcher.pserver_watcher import PServerWatcher
32 from o2ims.adapter.clients.ocloud_client import StxPserverClient
34 from o2ims.service.watcher.pserver_cpu_watcher import PServerCpuWatcher
35 from o2ims.adapter.clients.ocloud_client import StxCpuClient
37 from o2ims.service.watcher.pserver_mem_watcher import PServerMemWatcher
38 from o2ims.adapter.clients.ocloud_client import StxMemClient
40 from o2ims.service.watcher.pserver_if_watcher import PServerIfWatcher
41 from o2ims.adapter.clients.ocloud_client import StxIfClient
43 # from o2ims.service.watcher.pserver_port_watcher import PServerIfPortWatcher
44 # from o2ims.adapter.clients.ocloud_client import StxIfPortClient
46 from o2ims.service.watcher.pserver_eth_watcher import PServerEthWatcher
47 from o2ims.adapter.clients.ocloud_client import StxEthClient
49 # from o2ims.service.watcher.pserver_dev_watcher import PServerDevWatcher
50 # from o2ims.adapter.clients.ocloud_client import StxDevClient
51 from o2ims.service.watcher.pserver_acc_watcher import PServerAccWatcher
52 from o2ims.adapter.clients.ocloud_client import StxAccClient
54 from o2common.helper import o2logging
55 logger = o2logging.get_logger(__name__)
57 # r = redis.Redis(**config.get_redis_host_and_port())
60 class WatcherService(cotyledon.Service):
61 def __init__(self, worker_id, args=None) -> None:
62 super().__init__(worker_id)
64 self.bus = bootstrap.bootstrap()
65 self.worker = PollWorker(bus=self.bus)
69 root = WatcherTree(OcloudWatcher(
70 StxOcloudClient(), self.bus))
72 DmsWatcher(StxDmsClient(), self.bus))
74 # AlarmWatcher(StxFaultClient(), self.bus))
76 child_respool = root.addchild(
77 ResourcePoolWatcher(StxResourcePoolClient(),
79 child_pserver = child_respool.addchild(
80 PServerWatcher(StxPserverClient(), self.bus))
81 child_pserver.addchild(
82 PServerCpuWatcher(StxCpuClient(), self.bus))
83 child_pserver.addchild(
84 PServerMemWatcher(StxMemClient(), self.bus))
85 child_pserver.addchild(
86 PServerEthWatcher(StxEthClient(), self.bus))
87 child_pserver.addchild(
88 PServerIfWatcher(StxIfClient(), self.bus))
90 # PServerIfPortWatcher(StxIfPortClient(), self.bus))
91 # child_pserver.addchild(
92 # PServerDevWatcher(StxDevClient(), self.bus))
93 child_pserver.addchild(
94 PServerAccWatcher(StxAccClient(), self.bus))
96 self.worker.add_watcher(root)
100 AlarmWatcher(StxAlarmClient(self.bus.uow), self.bus))
101 self.worker.add_watcher(root)
104 except Exception as ex:
105 logger.warning("WorkerService Exception:" + str(ex))
110 def start_watchers(sm: cotyledon.ServiceManager = None):
111 watchersm = sm if sm else cotyledon.ServiceManager()
112 watchersm.add(WatcherService, workers=1, args=())
117 logger.info("Resource watcher starting")
121 if __name__ == "__main__":