forked from shaba/openuds
Fixes for 1.1u1
This commit is contained in:
commit
4e6a03a34f
@ -77,7 +77,7 @@ class LogManager(object):
|
|||||||
LogManager._manager = LogManager()
|
LogManager._manager = LogManager()
|
||||||
return LogManager._manager
|
return LogManager._manager
|
||||||
|
|
||||||
def __log(self, owner_type, owner_id, level, message, source):
|
def __log(self, owner_type, owner_id, level, message, source, avoidDuplicates):
|
||||||
'''
|
'''
|
||||||
Logs a message associated to owner
|
Logs a message associated to owner
|
||||||
'''
|
'''
|
||||||
@ -87,7 +87,17 @@ class LogManager(object):
|
|||||||
qs = Log.objects.filter(owner_id = owner_id, owner_type = owner_type)
|
qs = Log.objects.filter(owner_id = owner_id, owner_type = owner_type)
|
||||||
# First, ensure we do not have more than requested logs, and we can put one more log item
|
# First, ensure we do not have more than requested logs, and we can put one more log item
|
||||||
if qs.count() >= GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt():
|
if qs.count() >= GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt():
|
||||||
for i in qs.order_by('-created',)[GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt()-1:]: i.delete()
|
for i in qs.order_by('-created',)[GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt()-1:]:
|
||||||
|
i.delete()
|
||||||
|
|
||||||
|
if avoidDuplicates is True:
|
||||||
|
try:
|
||||||
|
lg = Log.objects.filter(owner_id = owner_id, owner_type = owner_type, level = level, source = source).order_by('-created', '-id')[0]
|
||||||
|
if lg.message == message:
|
||||||
|
# Do not log again, already logged
|
||||||
|
return
|
||||||
|
except: # Do not exists log
|
||||||
|
pass
|
||||||
|
|
||||||
# now, we add new log
|
# now, we add new log
|
||||||
Log.objects.create(owner_type = owner_type, owner_id = owner_id, created = getSqlDatetime(), source = source, level = level, data = message)
|
Log.objects.create(owner_type = owner_type, owner_id = owner_id, created = getSqlDatetime(), source = source, level = level, data = message)
|
||||||
@ -112,7 +122,7 @@ class LogManager(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def doLog(self, wichObject, level, message, source):
|
def doLog(self, wichObject, level, message, source, avoidDuplicates = True):
|
||||||
'''
|
'''
|
||||||
Do the logging for the requested object.
|
Do the logging for the requested object.
|
||||||
|
|
||||||
@ -123,7 +133,7 @@ class LogManager(object):
|
|||||||
|
|
||||||
owner_type = transDict.get(type(wichObject), None)
|
owner_type = transDict.get(type(wichObject), None)
|
||||||
if owner_type is not None:
|
if owner_type is not None:
|
||||||
self.__log(owner_type, wichObject.id, level, message, source)
|
self.__log(owner_type, wichObject.id, level, message, source, avoidDuplicates)
|
||||||
else:
|
else:
|
||||||
logger.debug('Requested doLog for a type of object not covered: {0}'.format(wichObject))
|
logger.debug('Requested doLog for a type of object not covered: {0}'.format(wichObject))
|
||||||
|
|
||||||
|
@ -70,9 +70,9 @@ def useLog(type_, serviceUniqueId, serviceIp, username):
|
|||||||
useLogger.info('|'.join([type_, serviceUniqueId, serviceIp, username]))
|
useLogger.info('|'.join([type_, serviceUniqueId, serviceIp, username]))
|
||||||
|
|
||||||
|
|
||||||
def doLog(wichObject, level, message, source = UNKNOWN):
|
def doLog(wichObject, level, message, source = UNKNOWN, avoidDuplicates = True):
|
||||||
from uds.core.managers import logManager
|
from uds.core.managers import logManager
|
||||||
logManager().doLog(wichObject, level, message, source)
|
logManager().doLog(wichObject, level, message, source, avoidDuplicates)
|
||||||
|
|
||||||
|
|
||||||
def getLogs(wichObject, limit = None):
|
def getLogs(wichObject, limit = None):
|
||||||
|
@ -51,7 +51,10 @@ def loadModulesUrls():
|
|||||||
for _, name, _ in pkgutil.iter_modules([pkgpath]):
|
for _, name, _ in pkgutil.iter_modules([pkgpath]):
|
||||||
fullModName = '%s.%s.urls' % (modName, name)
|
fullModName = '%s.%s.urls' % (modName, name)
|
||||||
mod = __import__(fullModName, globals(), locals(), ['urlpatterns'], -1)
|
mod = __import__(fullModName, globals(), locals(), ['urlpatterns'], -1)
|
||||||
patterns += mod.urlpatterns
|
try:
|
||||||
|
patterns += mod.urlpatterns
|
||||||
|
except:
|
||||||
|
logger.info( 'Module {0} has no url patterns'.format(mod))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.debug(e)
|
logger.debug(e)
|
||||||
pass
|
pass
|
||||||
|
@ -64,6 +64,12 @@ class ServiceCacheUpdater(Job):
|
|||||||
def calcProportion(max, actual):
|
def calcProportion(max, actual):
|
||||||
return actual * 10000 / max
|
return actual * 10000 / max
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __notifyRestrain(deployedService):
|
||||||
|
log.doLog(deployedService, log.WARN, 'Deployed service is restrained due to errors', log.INTERNAL)
|
||||||
|
logger.info('Deployed service {0} is restrained, will check this later'.format(deployedService.name))
|
||||||
|
|
||||||
|
|
||||||
def bestDeployedServiceNeedingCacheUpdate(self):
|
def bestDeployedServiceNeedingCacheUpdate(self):
|
||||||
# State filter for cached and inAssigned objects
|
# State filter for cached and inAssigned objects
|
||||||
# First we get all deployed services that could need cache generation
|
# First we get all deployed services that could need cache generation
|
||||||
@ -88,8 +94,7 @@ class ServiceCacheUpdater(Job):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if ds.isRestrained():
|
if ds.isRestrained():
|
||||||
log.doLog(ds, log.WARN, 'Deployed service is restrained due to errors', log.INTERNAL)
|
ServiceCacheUpdater.__notifyRestrain(ds)
|
||||||
logger.info('Deployed service {0} is restrained, will check this later'.format(ds.name))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get data related to actual state of cache
|
# Get data related to actual state of cache
|
||||||
|
@ -935,6 +935,27 @@ class DeployedService(models.Model):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def storeValue(self, name, value):
|
||||||
|
'''
|
||||||
|
Stores a value inside custom storage
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: Name of the value to store
|
||||||
|
value: Value of the value to store
|
||||||
|
'''
|
||||||
|
self.getEnvironment().storage().put(name, value)
|
||||||
|
|
||||||
|
def recoverValue(self, name):
|
||||||
|
'''
|
||||||
|
Recovers a value from custom storage
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: Name of values to recover
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Stored value, None if no value was stored
|
||||||
|
'''
|
||||||
|
return self.getEnvironment().storage().get(name)
|
||||||
|
|
||||||
def setState(self, state, save = True):
|
def setState(self, state, save = True):
|
||||||
'''
|
'''
|
||||||
|
@ -167,4 +167,3 @@ class TSRDPTransport(Transport):
|
|||||||
def getHtmlComponent(self, id, os, componentId):
|
def getHtmlComponent(self, id, os, componentId):
|
||||||
# We use helper to keep this clean
|
# We use helper to keep this clean
|
||||||
return getHtmlComponent(self.__module__, componentId)
|
return getHtmlComponent(self.__module__, componentId)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user