def run(self): sm = SyncManager.getDBInstance() logger = self.getLogger() # go over all the agents for agtName, agent in sm.getAllAgents().iteritems(): # skip agents if they're not active if not agent.isActive(): logger.warning("Agent '%s' is not active - skipping" % agtName) continue logger.info("Starting agent '%s'" % agtName) try: dbi = DBMgr.getInstance() # pass the current time and a logger result = agent.run(int_timestamp(nowutc()), logger=logger, dbi=dbi, task=self) except: logger.exception("Problem running agent '%s'" % agtName) return if result: logger.info("Acknowledged successful operation") agent.acknowledge() dbi.commit() else: logger.info("'Acknowledge' not done - no records?") logger.info("Agent '%s' finished" % agtName)
def run(self): sm = SyncManager.getDBInstance() logger = self.getLogger() # go over all the agents for agtName, agent in sm.getAllAgents().iteritems(): # skip agents if they're not active if not agent.isActive(): logger.warning("Agent '%s' is not active - skipping" % agtName) continue logger.info("Starting agent '%s'" % agtName) try: dbi = DBMgr.getInstance() # pass the current time and a logger result = agent.run(int_timestamp(nowutc()), logger=logger, dbi=dbi) except: logger.exception("Problem running agent '%s'" % agtName) return if result: logger.info("Acknowledged successful operation") agent.acknowledge() dbi.commit() else: logger.info("'Acknowledge' not done - no records?") logger.info("Agent '%s' finished" % agtName)
def start(self, obj): super(LiveSync_Feature, self).start(obj) with obj._context('database') as conn: obj._ph.getPluginType('livesync').toggleActive() db.updateDBStructures(conn.root._root, granularity=1) obj._sm = SyncManager.getDBInstance()
def getVars(self): tplVars = WTemplated.getVars(self) smanager = SyncManager.getDBInstance() tplVars["trackData"], tplVars["lastAgentTS"] = self._calculateTrackData(smanager) tplVars["agents"] = smanager.getAllAgents() tplVars["currentTS"] = int_timestamp(nowutc()) tplVars["granularity"] = smanager.getGranularity() return tplVars
def getVars(self): tplVars = WTemplated.getVars(self) smanager = SyncManager.getDBInstance() tplVars['trackData'], tplVars['lastAgentTS'] = \ self._calculateTrackData(smanager) tplVars['agents'] = smanager.getAllAgents() tplVars['currentTS'] = int_timestamp(nowutc()) tplVars['granularity'] = smanager.getGranularity() return tplVars
def _getAnswer(self): sm = SyncManager.getDBInstance() avtypes = AgentTypeInspector.getAvailableTypes() if self._type not in avtypes: raise ServiceError("", "Agent type %s is unknown" % self._type) typeClass = avtypes[self._type] access = AdminList().getInstance().getList()[0] sm.registerNewAgent(typeClass(self._id, self._name, self._description, 60, access, **self._specificParams))
def _initialize(self): self._srvc1 = RemoteServiceStub() self._srvc2 = RemoteServiceStub() self._mgr = SyncManager(granularity=1) # let's create some books self._objs = [ ObjectStub(1, 'Python Cookbook'), ObjectStub(2, 'Angels and Demons'), ObjectStub(3, 'Der Process') ]
def run(self, args): self._dbi = DBMgr.getInstance() self._dbi.startRequest() self._sm = SyncManager.getDBInstance() self._track = self._sm.getTrack() result = self._run(args) self._dbi.endRequest(False) return result
def _getAnswer(self): sm = SyncManager.getDBInstance() avtypes = AgentTypeInspector.getAvailableTypes() if self._type not in avtypes: raise ServiceError('', 'Agent type %s is unknown' % self._type) typeClass = avtypes[self._type] access = AdminList().getInstance().getList()[0] sm.registerNewAgent( typeClass(self._id, self._name, self._description, 60, access, **self._specificParams))
def getVars(self): tplVars = WTemplated.getVars(self) smanager = SyncManager.getDBInstance() avtypes = AgentTypeInspector.getAvailableTypes() tplVars['syncManager'] = smanager tplVars['agents'] = smanager.getAllAgents() tplVars['availableTypes'] = avtypes.keys() tplVars['extraAgentOptions'] = dict((typeName, typeClass._extraOptions) for (typeName, typeClass) in avtypes.iteritems()) tplVars['agentTableData'] = dict((agentId, agent.fossilize()) for \ (agentId, agent) in \ smanager.getAllAgents().iteritems()) return tplVars
def getVars(self): tplVars = WTemplated.getVars(self) smanager = SyncManager.getDBInstance() avtypes = AgentTypeInspector.getAvailableTypes() tplVars['syncManager'] = smanager tplVars['agents'] = smanager.getAllAgents() tplVars['availableTypes'] = avtypes.keys() tplVars['extraAgentOptions'] = dict( (typeName, typeClass._extraOptions) for (typeName, typeClass) in avtypes.iteritems()) tplVars['agentTableData'] = dict((agentId, agent.fossilize()) for \ (agentId, agent) in \ smanager.getAllAgents().iteritems()) return tplVars
def runTests(host='localhost', port=FAKE_SERVICE_PORT, scenarios=[(2, 10)]): execTimes = [] agent = InvenioBatchUploaderAgent('test1', 'test1', 'test', 0, 'http://%s:%s' \ % (host, port)) ph = PluginsHolder() ph.reloadAllPlugins() ph.getPluginType('livesync').toggleActive() do = DummyObservable() do._notify('updateDBStructures', 'indico.ext.livesync', None, None, None) sm = SyncManager.getDBInstance() sm.registerNewAgent(agent) cm = CategoryManager() avatar = user.Avatar() avatar.setName( "fake" ) avatar.setSurName( "fake" ) avatar.setOrganisation( "fake" ) avatar.setLang( "en_GB" ) avatar.setEmail( "*****@*****.**" ) #registering user ah = user.AvatarHolder() ah.add(avatar) #setting up the login info li = user.LoginInfo( "dummyuser", "dummyuser" ) ih = AuthenticatorMgr() userid = ih.createIdentity( li, avatar, "Local" ) ih.add( userid ) #activate the account avatar.activateAccount() #since the DB is empty, we have to add dummy user as admin minfo = HelperMaKaCInfo.getMaKaCInfoInstance() al = minfo.getAdminList() al.grant( avatar ) dummy = avatar ContextManager.destroy() HelperMaKaCInfo.getMaKaCInfoInstance().setDefaultConference(DefaultConference()) cm.getRoot() do._notify('requestStarted') home = cm.getById('0') # execute code for nconf in range(0, 1000): conf = home.newConference(dummy) conf.setTitle('Test Conference %s' % nconf) do._notify('requestFinished') time.sleep(1) # params won't be used task = LiveSyncUpdateTask(dateutil.rrule.MINUTELY) for scen in scenarios: print "Scenario %s workers, size = %s " % scen, # configure scenario InvenioBatchUploaderAgent.NUM_WORKERS = scen[0] InvenioBatchUploaderAgent.BATCH_SIZE = scen[1] ts = time.time() # just run it task.run() te = time.time() execTimes.append(te - ts) print "%s" % (te - ts) sm._track._pointers['test1'] = None for i in range(0, len(execTimes)): results[scenarios[i]] = execTimes[i]
def runTests(host='localhost', port=FAKE_SERVICE_PORT, scenarios=[(2, 10)]): execTimes = [] agent = InvenioBatchUploaderAgent('test1', 'test1', 'test', 0, 'http://%s:%s' \ % (host, port)) ph = PluginsHolder() ph.reloadAllPlugins() ph.getPluginType('livesync').toggleActive() do = DummyObservable() do._notify('updateDBStructures', 'indico.ext.livesync', None, None, None) sm = SyncManager.getDBInstance() sm.registerNewAgent(agent) cm = CategoryManager() avatar = user.Avatar() avatar.setName( "fake" ) avatar.setSurName( "fake" ) avatar.setOrganisation( "fake" ) avatar.setLang( "en_GB" ) avatar.setEmail( "*****@*****.**" ) #registering user ah = user.AvatarHolder() ah.add(avatar) #setting up the login info li = user.LoginInfo("dummyuser", None) am = AuthenticatorMgr() userid = am.createIdentity( li, avatar, "Local" ) am.add( userid ) #activate the account avatar.activateAccount() #since the DB is empty, we have to add dummy user as admin minfo = HelperMaKaCInfo.getMaKaCInfoInstance() al = minfo.getAdminList() al.grant( avatar ) dummy = avatar ContextManager.destroy() HelperMaKaCInfo.getMaKaCInfoInstance().setDefaultConference(DefaultConference()) cm.getRoot() do._notify('requestStarted') home = cm.getById('0') # execute code for nconf in range(0, 1000): conf = home.newConference(dummy) conf.setTitle('Test Conference %s' % nconf) do._notify('requestFinished') time.sleep(1) # params won't be used task = LiveSyncUpdateTask(dateutil.rrule.MINUTELY) for scen in scenarios: print "Scenario %s workers, size = %s " % scen, # configure scenario InvenioBatchUploaderAgent.NUM_WORKERS = scen[0] InvenioBatchUploaderAgent.BATCH_SIZE = scen[1] ts = time.time() # just run it task.run() te = time.time() execTimes.append(te - ts) print "%s" % (te - ts) sm._track._pointers['test1'] = None for i in range(0, len(execTimes)): results[scenarios[i]] = execTimes[i]
def _checkParams(self): self._pm = ParameterManager(self._params) AdminService._checkParams(self) self._id = self._pm.extract('id', pType=str) self._sm = SyncManager.getDBInstance() self._agent = self._sm.getAllAgents()[self._id]