Fixes for 1.1u1

This commit is contained in:
Adolfo Gómez 2013-03-15 08:22:19 +00:00
commit 4e6a03a34f
6 changed files with 48 additions and 10 deletions

View File

@ -77,7 +77,7 @@ class LogManager(object):
LogManager._manager = LogManager()
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
'''
@ -87,7 +87,17 @@ class LogManager(object):
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
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
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.
@ -123,7 +133,7 @@ class LogManager(object):
owner_type = transDict.get(type(wichObject), 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:
logger.debug('Requested doLog for a type of object not covered: {0}'.format(wichObject))

View File

@ -70,9 +70,9 @@ def useLog(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
logManager().doLog(wichObject, level, message, source)
logManager().doLog(wichObject, level, message, source, avoidDuplicates)
def getLogs(wichObject, limit = None):

View File

@ -51,7 +51,10 @@ def loadModulesUrls():
for _, name, _ in pkgutil.iter_modules([pkgpath]):
fullModName = '%s.%s.urls' % (modName, name)
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:
logger.debug(e)
pass

View File

@ -64,6 +64,12 @@ class ServiceCacheUpdater(Job):
def calcProportion(max, actual):
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):
# State filter for cached and inAssigned objects
# First we get all deployed services that could need cache generation
@ -88,8 +94,7 @@ class ServiceCacheUpdater(Job):
continue
if ds.isRestrained():
log.doLog(ds, log.WARN, 'Deployed service is restrained due to errors', log.INTERNAL)
logger.info('Deployed service {0} is restrained, will check this later'.format(ds.name))
ServiceCacheUpdater.__notifyRestrain(ds)
continue
# Get data related to actual state of cache

View File

@ -935,6 +935,27 @@ class DeployedService(models.Model):
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):
'''

View File

@ -167,4 +167,3 @@ class TSRDPTransport(Transport):
def getHtmlComponent(self, id, os, componentId):
# We use helper to keep this clean
return getHtmlComponent(self.__module__, componentId)