def Prime(self, keys, fuxorcheck=1): if fuxorcheck: i = 0 for each in keys: if each not in self.data: i += 1 if i >= 50: flag = [log.LGINFO, log.LGWARN][i >= 100] log.general.Log( '%s - Prime() called for %s items from %s' % (self.GetFetcherString(), i, log.WhoCalledMe()), flag) if boot.role != 'server' and i == 1: NUM_SEC = 2 s = int(blue.os.GetWallclockTime() / (NUM_SEC * const.SEC)) if s > self.singlePrimeTimestamp + NUM_SEC: self.singlePrimeCount = 0 self.singlePrimeTimestamp = s self.singlePrimeCount += 1 if self.singlePrimeCount < 100: tick = 10 flag = log.LGWARN else: tick = 50 flag = log.LGERR if self.singlePrimeCount >= tick and self.singlePrimeCount % tick == 0: log.general.Log( '%s - Prime() called for %s single items. Last caller was %s. Caller might want to consider using Prime()' % (self.GetFetcherString(), self.singlePrimeCount, log.WhoCalledMe()), flag) if keys: self.waitingKeys.update(keys) uthread.Lock(self, 0) try: self._Prime() finally: uthread.UnLock(self, 0)
def AddToLogEventCounter(self, eventName, numArgs): if len(self.logEventCounter) > self.maxNumEventCounters: self.LogError( 'The maximum number of event counters has been exceeded!', repr(self.logEventCounter.keys())[:1024]) return False if eventName not in self.logEventCounter: self.logEventCounter[eventName] = [numArgs, 0] c = self.logEventCounter[eventName] if numArgs != c[0]: if (eventName, numArgs) not in self.parameterErrors: self.LogWarn( 'Event is being called with different number of arguments. This will lead to inconsistent data!', eventName, 'got', numArgs, 'arguments but expected', c[0], 'arguments. Called from', log.WhoCalledMe(4)) self.parameterErrors.add((eventName, numArgs)) self.logEventCounter[eventName][1] += 1 return True
def StartService(self, serviceName, ms=None, reason='StartService'): telemetry.APPEND_TO_ZONE(serviceName) srv = self.services.get(serviceName, None) if srv and srv.state == service.SERVICE_RUNNING: return srv if serviceName in self.services: srv = self.services[serviceName] else: if serviceName in self.blockedServices: raise RuntimeError( '%s has been blocked from running on this system' % serviceName) srv = self.CreateServiceInstance(serviceName) self.services[serviceName] = srv if srv.state in (service.SERVICE_START_PENDING, ): return srv if srv.state == service.SERVICE_STARTING_DEPENDENCIES: desiredStates = (service.SERVICE_START_PENDING, service.SERVICE_RUNNING) errorStates = (service.SERVICE_FAILED, service.SERVICE_STOPPED) self.WaitForServiceObjectState(srv, desiredStates, errorStates) return srv if self.state in (service.SERVICE_STOP_PENDING, service.SERVICE_STOPPED): raise RuntimeError, "Can't start service " + serviceName + ' when service manager is shutting down' if srv.state == service.SERVICE_FAILED: return srv try: r = reason if reason in ('GetService', 'StartService'): up = 4 if reason == 'StartService': up = 2 r = '%s - called from %s' % (reason, log.WhoCalledMe(up)) self.LogInfo('Starting', serviceName, '. Reason:', r) except: pass srv.state = service.SERVICE_STARTING_DEPENDENCIES srv.__error__ = None try: self.dependants[serviceName] = [] if srv.__startupdependencies__: self.LogInfo( 'starting startup dependencies for %s, which are: %s' % (serviceName, str(srv.__startupdependencies__))) for each in srv.__startupdependencies__: if each == srv.__guid__.split('.')[1]: self.LogError( 'Found a service with a dependancy on it self:', each, '. The service reference will not be assigned, things will probaly blow up' ) continue if type(each) is str: each = (each, each) depname, asname = each if not self.IsServiceRunning(depname): self.LogInfo(serviceName, 'is waiting while', depname, 'is started') depService = self.StartServiceAndWaitForRunningState( depname, reason='startup dependency for %s' % serviceName) self.dependants[depname].append(serviceName) if getattr(boot, 'replaceDependencyServiceWrappers', 'false').lower( ) != 'true' or not depService.IsRunning(): setattr(srv, asname, srv.session.ConnectToService(depname)) else: setattr(srv, asname, depService) srv.state = service.SERVICE_START_PENDING if srv.__dependencies__: uthread.new( self._LoadServiceDependenciesAsych, srv, serviceName ).context = serviceName + ' _LoadServiceDependenciesAsych' for notify in srv.__notifyevents__: if not hasattr(srv, notify): raise RuntimeError('MissingSvcExportAttribute', serviceName, 'notify', notify) if not self.notify.has_key(notify): self.notify[notify] = [] self.notify[notify].append(srv) except Exception as e: srv.state = service.SERVICE_FAILED srv.__error__ = sys.exc_info() raise if ms: ms.Seek(0) args = (ms, ) if serviceName in self.startInline: self.StartServiceRun(srv, args, serviceName) else: uthread.pool(serviceName + ' StartServiceRun', self.StartServiceRun, srv, args, serviceName) return srv
def Prime(self, keys, fuxorcheck = 1): """ accumulate all queuing requests while we are dealing with current priming this should result in reduction of round trips if I get a flood of requests... """ if fuxorcheck: i = 0 for each in keys: if each not in self.data: i += 1 if i >= 50: flag = [log.LGINFO, log.LGWARN][i >= 100] log.general.Log('%s - Prime() called for %s items from %s' % (self.GetFetcherString(), i, log.WhoCalledMe()), flag) if boot.role == 'client' and i == 1: NUM_SEC = 2 s = int(blue.os.GetWallclockTime() / (NUM_SEC * const.SEC)) if s > self.singlePrimeTimestamp + NUM_SEC: self.singlePrimeCount = 0 self.singlePrimeTimestamp = s self.singlePrimeCount += 1 if self.singlePrimeCount < 100: tick = 10 flag = log.LGWARN else: tick = 50 flag = log.LGERR if self.singlePrimeCount >= tick and self.singlePrimeCount % tick == 0: log.general.Log('%s - Prime() called for %s single items. Last caller was %s. Caller might want to consider using Prime()' % (self.GetFetcherString(), self.singlePrimeCount, log.WhoCalledMe()), flag) if keys: self.waitingKeys.update(keys) uthread.Lock(self, 0) try: self._Prime() finally: uthread.UnLock(self, 0)