X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2common%2Fservice%2Fwatcher%2Fbase.py;h=0e5bc3ab744ee7f4161fd0fe05d714aa6c6fcfa5;hb=1f8a5aade209f5998a405f9a24ee54dd2eb52c57;hp=0807eecbf966f7ac5249ddf2c714653c0edaf486;hpb=defe8209b3628593c186487857fe02586d7e1503;p=pti%2Fo2.git diff --git a/o2common/service/watcher/base.py b/o2common/service/watcher/base.py index 0807eec..0e5bc3a 100644 --- a/o2common/service/watcher/base.py +++ b/o2common/service/watcher/base.py @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import traceback # from logging import exception # from cgtsclient import exc + from o2common.service.client.base_client import BaseClient from o2common.domain import commands from o2common.service.messagebus import MessageBus @@ -27,24 +29,29 @@ class BaseWatcher(object): super().__init__() self._client = client self._bus = bus + self._tags = None # self._uow = bus.uow def targetname(self) -> str: return self._targetname() - def probe(self, parent: commands.Command = None): + def probe(self, parent: commands.Command = None, tags: object = None): try: - cmds = self._probe(parent.data if parent else None) + cmds = self._probe( + parent.data if parent else None, tags) for cmd in cmds: self._bus.handle(cmd) # return self._probe(parent) return cmds except Exception as ex: - logger.warning("Failed to probe resource due to: " + str(ex)) + logger.warning("Failed to probe %s watcher due to: %s - %s" % + (self._targetname(), type(ex), str(ex))) + logger.debug(traceback.format_exc()) return [] - def _probe(self, parent: object = None) -> commands.Command: + def _probe(self, parent: object = None, tags: object = None) \ + -> commands.Command: raise NotImplementedError def _targetname(self): @@ -70,6 +77,7 @@ class WatcherTree(object): super().__init__() self.watcher = watcher self.children = {} + self.tags = None def addchild(self, watcher: BaseWatcher) -> object: child = WatcherTree(watcher) @@ -80,12 +88,14 @@ class WatcherTree(object): return self.children.pop(targetname) # probe all resources by parent, depth = 0 for indefinite recursive - def probe(self, parentresource=None, depth: int = 0): + def probe(self, parentresource=None, depth: int = 0, tags: object = None): logger.debug("probe resources with watcher: " + self.watcher.targetname()) childdepth = depth - 1 if depth > 0 else 0 - resources = self.watcher.probe(parentresource) + resources = self.watcher.probe(parentresource, tags) logger.debug("probe returns " + str(len(resources)) + " resources") + if self.watcher._tags is not None: + tags = self.watcher._tags if depth == 1: # stop recursive @@ -93,4 +103,4 @@ class WatcherTree(object): for res in resources: for targetname in self.children.keys(): - self.children[targetname].probe(res, childdepth) + self.children[targetname].probe(res, childdepth, tags)