1 # Copyright (C) 2021 Wind River Systems, Inc.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
17 from o2app import bootstrap
\r
18 from o2common.service.watcher.base import WatcherTree
\r
19 from o2common.service.watcher.worker import PollWorker
\r
21 from o2ims.service.watcher.ocloud_watcher import OcloudWatcher
\r
22 from o2ims.service.watcher.ocloud_watcher import DmsWatcher
\r
23 from o2ims.service.watcher.resourcepool_watcher import ResourcePoolWatcher
\r
24 from o2ims.adapter.clients.ocloud_sa_client import StxSaDmsClient
\r
25 from o2ims.adapter.clients.ocloud_sa_client import StxSaOcloudClient
\r
26 from o2ims.adapter.clients.ocloud_sa_client import StxSaResourcePoolClient
\r
28 from o2ims.service.watcher.pserver_watcher import PServerWatcher
\r
29 from o2ims.adapter.clients.ocloud_sa_client import StxPserverClient
\r
31 from o2ims.service.watcher.pserver_cpu_watcher import PServerCpuWatcher
\r
32 from o2ims.adapter.clients.ocloud_sa_client import StxCpuClient
\r
34 from o2ims.service.watcher.pserver_mem_watcher import PServerMemWatcher
\r
35 from o2ims.adapter.clients.ocloud_sa_client import StxMemClient
\r
37 from o2ims.service.watcher.pserver_if_watcher import PServerIfWatcher
\r
38 from o2ims.adapter.clients.ocloud_sa_client import StxIfClient
\r
40 from o2ims.service.watcher.pserver_port_watcher import PServerIfPortWatcher
\r
41 from o2ims.adapter.clients.ocloud_sa_client import StxIfPortClient
\r
43 from o2ims.service.watcher.pserver_eth_watcher import PServerEthWatcher
\r
44 from o2ims.adapter.clients.ocloud_sa_client import StxEthClient
\r
46 from o2common.helper import o2logging
\r
47 logger = o2logging.get_logger(__name__)
\r
49 # r = redis.Redis(**config.get_redis_host_and_port())
\r
52 class WatcherService(cotyledon.Service):
\r
53 def __init__(self, worker_id, args=None) -> None:
\r
54 super().__init__(worker_id)
\r
56 self.bus = bootstrap.bootstrap()
\r
57 self.worker = PollWorker()
\r
61 root = WatcherTree(OcloudWatcher(
\r
62 StxSaOcloudClient(), self.bus))
\r
64 DmsWatcher(StxSaDmsClient(), self.bus))
\r
66 child_respool = root.addchild(
\r
67 ResourcePoolWatcher(StxSaResourcePoolClient(),
\r
69 child_pserver = child_respool.addchild(
\r
70 PServerWatcher(StxPserverClient(), self.bus))
\r
71 child_pserver.addchild(
\r
72 PServerCpuWatcher(StxCpuClient(), self.bus))
\r
73 child_pserver.addchild(
\r
74 PServerMemWatcher(StxMemClient(), self.bus))
\r
75 child_pserver.addchild(
\r
76 PServerEthWatcher(StxEthClient(), self.bus))
\r
77 child_if = child_pserver.addchild(
\r
78 PServerIfWatcher(StxIfClient(), self.bus))
\r
79 # child_if.addchild(
\r
80 # PServerIfPortWatcher(StxIfPortClient(), self.bus))
\r
82 self.worker.add_watcher(root)
\r
85 except Exception as ex:
\r
86 logger.warning("WorkerService Exception:" + str(ex))
\r
91 def start_watchers(sm: cotyledon.ServiceManager = None):
\r
92 watchersm = sm if sm else cotyledon.ServiceManager()
\r
93 watchersm.add(WatcherService, workers=1, args=())
\r
98 logger.info("Resource watcher starting")
\r
102 if __name__ == "__main__":
\r