1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-03 01:17:56 +03:00

More transaction fixed

This commit is contained in:
Adolfo Gómez 2014-03-27 11:46:56 +00:00
parent 50e04eda7d
commit 1140f1b4e6
11 changed files with 48 additions and 42 deletions

View File

@ -40,7 +40,7 @@ import logging
logger = logging.getLogger(__name__)
# Enclosed methods under /auth path
# Enclosed methods under /config path
class Config(Handler):

View File

@ -50,7 +50,6 @@ class PublicationOldMachinesCleaner(DelayedTask):
super(PublicationOldMachinesCleaner, self).__init__()
self._id = publicationId
@transaction.atomic
def run(self):
try:
dsp = DeployedServicePublication.objects.get(pk=self._id)
@ -75,7 +74,6 @@ class PublicationLauncher(DelayedTask):
def run(self):
logger.debug('Publishing')
try:
with transaction.atomic():
dsp = DeployedServicePublication.objects.select_for_update().get(pk=self._publishId)
if dsp.state != State.LAUNCHING: # If not preparing (may has been canceled by user) just return
return
@ -151,7 +149,6 @@ class PublicationFinishChecker(DelayedTask):
'''
DelayedTaskRunner.runner().insert(PublicationFinishChecker(dsp), pi.suggestedTime, PUBTAG + str(dsp.id))
@transaction.atomic
def run(self):
logger.debug('Checking publication finished {0}'.format(self._publishId))
try:
@ -180,7 +177,6 @@ class PublicationManager(object):
return PublicationManager._manager
def publish(self, deployedService):
with transaction.atomic():
if deployedService.publications.select_for_update().filter(state__in=State.PUBLISH_STATES).count() > 0:
raise PublishException(_('Already publishing. Wait for previous publication to finish and try again'))
try:
@ -191,7 +187,6 @@ class PublicationManager(object):
logger.debug('Caught exception at publish: {0}'.format(e))
raise PublishException(str(e))
@transaction.atomic
def cancel(self, dsp):
dsp = DeployedServicePublication.objects.select_for_update().get(pk=dsp.id)
if dsp.state not in State.PUBLISH_STATES:
@ -211,7 +206,6 @@ class PublicationManager(object):
except Exception, e:
raise PublishException(str(e))
@transaction.atomic
def unpublish(self, dsp):
if State.isUsable(dsp.state) == False and State.isRemovable(dsp.state) == False:
raise PublishException(_('Can\'t unpublish non usable publication'))

View File

@ -30,7 +30,6 @@
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
from uds.core.Serializable import Serializable
import cPickle

View File

@ -58,10 +58,8 @@ class Storage(object):
data = data.encode(Storage.CODEC)
attr1 = '' if attr1 == None else attr1
try:
with transaction.atomic():
dbStorage.objects.create(owner=self._owner, key=key, data=data, attr1=attr1)
except Exception:
with transaction.atomic():
dbStorage.objects.filter(key=key).update(owner=self._owner, data=data, attr1=attr1)
logger.debug('Key saved')

View File

@ -55,7 +55,6 @@ class AssignedAndUnused(Job):
since_state = getSqlDatetime() - timedelta(seconds=GlobalConfig.CHECK_UNUSED_TIME.getInt())
for ds in DeployedService.objects.all():
# If do not needs os manager, this is
with transaction.atomic():
if ds.osmanager is not None:
osm = ds.osmanager.getInstance()
if osm.processUnusedMachines is True:

View File

@ -111,7 +111,6 @@ class ClusterMigrationTask(DelayedTask):
self._state = service.state
@staticmethod
@transaction.atomic
def checkAndUpdateState(userService, userServiceInstance, state):
'''
Checks the value returned from invocation to publish or checkPublishingState, updating the dsp database object
@ -186,7 +185,6 @@ class ClusterBalancingTask(DelayedTask):
self._id = providerId
@staticmethod
@transaction.atomic
def migrate(serviceId, toNode):
try:
service = UserService.objects.select_for_update().get(pk=serviceId)

View File

@ -70,7 +70,6 @@ class ServiceCacheUpdater(Job):
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))
@transaction.atomic
def bestDeployedServiceNeedingCacheUpdate(self):
# State filter for cached and inAssigned objects
# First we get all deployed services that could need cache generation
@ -180,7 +179,6 @@ class ServiceCacheUpdater(Job):
# First, we try to assign from L2 cache
if cacheL2 > 0:
valid = None
with transaction.atomic():
for n in ds.cachedUserServices().select_for_update().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date'):
if n.needsOsManager():
if State.isUsable(n.state) is False or State.isUsable(n.os_state):

View File

@ -1999,7 +1999,7 @@ class DelayedTask(models.Model):
# objects = LockingManager()
def __unicode__(self):
return u"Run Queue task {0} owned by {3},inserted at {1} and with {2} seconds delay".format(self.type, self.insert_date, self.execution_delay, self.owner_server)
return u"Run Queue task {0} owned by {3},inserted at {1} and with {2} seconds delay".format(self.type, self.insert_date, self.execution_delay, self.execution_time)
class Network(models.Model):

View File

@ -25,6 +25,21 @@ Handlebars.registerHelper "eachKey", (context, options) ->
first = false
ret
Handlebars.registerHelper "eachKeySorted", (context, options) ->
ret = ""
first = true
keys = (k for k of context)
sortedKeys = keys.sort (a,b) -> a.toLowerCase().localeCompare(b.toLowerCase())
for prop in sortedKeys
ret = ret + options.fn(
key: prop
value: context[prop]
first: first
)
first = false
ret
# Equal comparision (like if helper, but with comparation)
# Use as block as {{#ifequals [element] [element]}}....{{/ifequals}}

View File

@ -92,6 +92,11 @@ gui.servicesPools.link = (event) ->
if value.state is "P"
value.state = gettext("Generating")
return
if value.state is "K"
value.state = gettext("Cancelling")
return
if value.state is "C"
value.state = gettext("Cancelled")
value.state = gettext("Unknown")
return

View File

@ -21,7 +21,7 @@
<div class="tab-content col-md-12 col-md-offset-0 col-lg-8 col-lg-offset-2">
{{# eachKey config }}
<div class="tab-pane {{# if first }}active{{/ if }}" id="section_{{ key }}">
{{# eachKey value }}
{{# eachKeySorted value }}
<div class="form-group">
<label for="fld_{{ clean_whitespace ../key }}{{ key }}" class="col-sm-5 control-label">{{ key }}</label>
<div class="col-sm-6">
@ -46,7 +46,7 @@
{{/ if }}
</div>
</div>
{{/ eachKey }}
{{/ eachKeySorted }}
</div>
{{/ eachKey }}
</div>