From 0b68b813af7447c6d24a9d55751456c8d013fa20 Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Sun, 3 Sep 2017 14:25:36 -0500 Subject: [PATCH] CO - Bug fix attempt with filter --- src/utils/agents/manager.py | 82 +++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/src/utils/agents/manager.py b/src/utils/agents/manager.py index 02fafeb..10fcae9 100644 --- a/src/utils/agents/manager.py +++ b/src/utils/agents/manager.py @@ -32,9 +32,9 @@ class Manager() : self.config = args['config'] self.key = args['key'] self.actors = args['actors'] - self.status() #-- Initializing status information + self.update() #-- Initializing status information - def status(self) : + def update(self) : """ This method inspect the plans for the current account and makes sure it can/should proceed The user must be subscribed and to the service otherwise this is not going to work @@ -54,41 +54,32 @@ class Manager() : self.DELAY = -1 self.LIMIT = -1 - self.filter(meta) - self._filter('scope','apps',meta,self.agents) - self._filter('','folders',meta,self.agents) - #if len(self.actors) > 0 : - # self.setup(meta) - def _filter(self,id,key,meta,values): + #self.filter(meta) + self.filter('agents',meta,self.agents) + self.filter('actors',meta,self.actors) + self.setup(meta) + + def filter_collectors(self,meta) : """ - This function is designed to perform a filter on a list of values given a full set - @param id - @param lvalues - @param values + remove collectors that are not specified by the plan + Note that the agents (collectors) have already been initialized ? """ - read_class = self.config['store']['class']['read'] - read_args = self.config['store']['args'] - couchdb = self.factory.instance(type=read_class,args=read_args) - info = couchdb.view('config/'+key,key=self.key) - - if info is None or (type(info) == list and len(info) == 0) : - return [] - else: - # - # At this point we have a configuration we can keep apps/folders actors - # - r = [] - plan = meta[id] - - for item in values : - if item.getName() in plan : - item.init(info) - r.append(item) - - + values = meta['agents'].replace(' ','').split(',') + self.agents = [agent for agent in self.agents if agent.getName() in values] + + def filter_actors(self,meta): + """ + removes actors that are NOT specified by the subscription plan + Note that the actor have already been instatiated and need initialization + """ + values = meta['actors'].replace(' ','').split('.' + self.actors = [actor for actor in self.actors if actor.getName() in values] - def filter(self,meta) : + def filter(self,id,meta,objects): + values = meta[id].replace(' ','').split(',') + return [item for item in objects if object.getName() in values] + def __filter(self,meta) : scope = [] lactors= [] for item in meta : @@ -136,7 +127,28 @@ class Manager() : mailer.init(self.config['mailer']) return meta - def setup(self,meta): + def setup(self,meta) : + conf = {"folders":None,"apps":None} + read_class = self.config['store']['class']['read'] + read_args = self.config['store']['args'] + + + couchdb = self.factory.instance(type=read_class,args=read_args) + args = couchdb.view('config/apps',key=self.key) + if len(args.keys()) > 0 : + self.apply_setup('apps',args) + args = couchdb.view('config/folders',key=self.key) + if 'folder_threshold' not in meta : + args['threshold'] = meta['folder_threshold'] + self.apply_setup('folders',args) + + def apply_setup(self,name,args) : + for actor in self.actors : + if args is not None and actor.getName() == name and len(args.keys()) > 0: + actor.init(args) + + + def __setup(self,meta): # # We should configure the actors accordingly and make sure they are operational # @@ -170,7 +182,7 @@ class Manager() : mailer.init(self.config['mailer']) def isvalid(self): - self.status() + self.update() return self.DELAY > -1 and self.LIMIT > -1 def post(self,row) : """