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:
parent
50e04eda7d
commit
1140f1b4e6
@ -40,7 +40,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Enclosed methods under /auth path
|
||||
# Enclosed methods under /config path
|
||||
|
||||
|
||||
class Config(Handler):
|
||||
|
@ -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,12 +74,11 @@ 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
|
||||
dsp.state = State.PREPARING
|
||||
dsp.save()
|
||||
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
|
||||
dsp.state = State.PREPARING
|
||||
dsp.save()
|
||||
pi = dsp.getInstance()
|
||||
state = pi.publish()
|
||||
deployedService = dsp.deployed_service
|
||||
@ -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,9 +177,8 @@ 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'))
|
||||
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:
|
||||
now = getSqlDatetime()
|
||||
dsp = deployedService.publications.create(state=State.LAUNCHING, state_date=now, publish_date=now, revision=deployedService.current_pub_revision)
|
||||
@ -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'))
|
||||
|
@ -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
|
||||
|
@ -58,11 +58,9 @@ 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)
|
||||
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)
|
||||
dbStorage.objects.filter(key=key).update(owner=self._owner, data=data, attr1=attr1)
|
||||
logger.debug('Key saved')
|
||||
|
||||
def put(self, skey, data):
|
||||
|
@ -55,15 +55,14 @@ 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:
|
||||
logger.debug('Processing unused services for {0}'.format(osm))
|
||||
for us in ds.assignedUserServices().select_for_update().filter(in_use=False, state_date__lt=since_state, state=State.USABLE, os_state=State.USABLE):
|
||||
logger.debug('Found unused assigned service {0}'.format(us))
|
||||
osm.processUnused(us)
|
||||
else: # No os manager, simply remove unused services in specified time
|
||||
if ds.osmanager is not None:
|
||||
osm = ds.osmanager.getInstance()
|
||||
if osm.processUnusedMachines is True:
|
||||
logger.debug('Processing unused services for {0}'.format(osm))
|
||||
for us in ds.assignedUserServices().select_for_update().filter(in_use=False, state_date__lt=since_state, state=State.USABLE, os_state=State.USABLE):
|
||||
logger.debug('Found unused assigned service {0}'.format(us))
|
||||
us.remove()
|
||||
osm.processUnused(us)
|
||||
else: # No os manager, simply remove unused services in specified time
|
||||
for us in ds.assignedUserServices().select_for_update().filter(in_use=False, state_date__lt=since_state, state=State.USABLE, os_state=State.USABLE):
|
||||
logger.debug('Found unused assigned service {0}'.format(us))
|
||||
us.remove()
|
||||
|
@ -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)
|
||||
|
@ -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,15 +179,14 @@ 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):
|
||||
valid = n
|
||||
break
|
||||
else:
|
||||
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):
|
||||
valid = n
|
||||
break
|
||||
else:
|
||||
valid = n
|
||||
break
|
||||
|
||||
if valid is not None:
|
||||
valid.moveToLevel(services.UserDeployment.L1_CACHE)
|
||||
|
@ -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):
|
||||
|
@ -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}}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user