forked from shaba/openuds
More transaction fixed
This commit is contained in:
parent
50e04eda7d
commit
1140f1b4e6
@ -40,7 +40,7 @@ import logging
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Enclosed methods under /auth path
|
# Enclosed methods under /config path
|
||||||
|
|
||||||
|
|
||||||
class Config(Handler):
|
class Config(Handler):
|
||||||
|
@ -50,7 +50,6 @@ class PublicationOldMachinesCleaner(DelayedTask):
|
|||||||
super(PublicationOldMachinesCleaner, self).__init__()
|
super(PublicationOldMachinesCleaner, self).__init__()
|
||||||
self._id = publicationId
|
self._id = publicationId
|
||||||
|
|
||||||
@transaction.atomic
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
dsp = DeployedServicePublication.objects.get(pk=self._id)
|
dsp = DeployedServicePublication.objects.get(pk=self._id)
|
||||||
@ -75,12 +74,11 @@ class PublicationLauncher(DelayedTask):
|
|||||||
def run(self):
|
def run(self):
|
||||||
logger.debug('Publishing')
|
logger.debug('Publishing')
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
dsp = DeployedServicePublication.objects.select_for_update().get(pk=self._publishId)
|
||||||
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
|
||||||
if dsp.state != State.LAUNCHING: # If not preparing (may has been canceled by user) just return
|
return
|
||||||
return
|
dsp.state = State.PREPARING
|
||||||
dsp.state = State.PREPARING
|
dsp.save()
|
||||||
dsp.save()
|
|
||||||
pi = dsp.getInstance()
|
pi = dsp.getInstance()
|
||||||
state = pi.publish()
|
state = pi.publish()
|
||||||
deployedService = dsp.deployed_service
|
deployedService = dsp.deployed_service
|
||||||
@ -151,7 +149,6 @@ class PublicationFinishChecker(DelayedTask):
|
|||||||
'''
|
'''
|
||||||
DelayedTaskRunner.runner().insert(PublicationFinishChecker(dsp), pi.suggestedTime, PUBTAG + str(dsp.id))
|
DelayedTaskRunner.runner().insert(PublicationFinishChecker(dsp), pi.suggestedTime, PUBTAG + str(dsp.id))
|
||||||
|
|
||||||
@transaction.atomic
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logger.debug('Checking publication finished {0}'.format(self._publishId))
|
logger.debug('Checking publication finished {0}'.format(self._publishId))
|
||||||
try:
|
try:
|
||||||
@ -180,9 +177,8 @@ class PublicationManager(object):
|
|||||||
return PublicationManager._manager
|
return PublicationManager._manager
|
||||||
|
|
||||||
def publish(self, deployedService):
|
def publish(self, deployedService):
|
||||||
with transaction.atomic():
|
if deployedService.publications.select_for_update().filter(state__in=State.PUBLISH_STATES).count() > 0:
|
||||||
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'))
|
||||||
raise PublishException(_('Already publishing. Wait for previous publication to finish and try again'))
|
|
||||||
try:
|
try:
|
||||||
now = getSqlDatetime()
|
now = getSqlDatetime()
|
||||||
dsp = deployedService.publications.create(state=State.LAUNCHING, state_date=now, publish_date=now, revision=deployedService.current_pub_revision)
|
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))
|
logger.debug('Caught exception at publish: {0}'.format(e))
|
||||||
raise PublishException(str(e))
|
raise PublishException(str(e))
|
||||||
|
|
||||||
@transaction.atomic
|
|
||||||
def cancel(self, dsp):
|
def cancel(self, dsp):
|
||||||
dsp = DeployedServicePublication.objects.select_for_update().get(pk=dsp.id)
|
dsp = DeployedServicePublication.objects.select_for_update().get(pk=dsp.id)
|
||||||
if dsp.state not in State.PUBLISH_STATES:
|
if dsp.state not in State.PUBLISH_STATES:
|
||||||
@ -211,7 +206,6 @@ class PublicationManager(object):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise PublishException(str(e))
|
raise PublishException(str(e))
|
||||||
|
|
||||||
@transaction.atomic
|
|
||||||
def unpublish(self, dsp):
|
def unpublish(self, dsp):
|
||||||
if State.isUsable(dsp.state) == False and State.isRemovable(dsp.state) == False:
|
if State.isUsable(dsp.state) == False and State.isRemovable(dsp.state) == False:
|
||||||
raise PublishException(_('Can\'t unpublish non usable publication'))
|
raise PublishException(_('Can\'t unpublish non usable publication'))
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from uds.core.Serializable import Serializable
|
from uds.core.Serializable import Serializable
|
||||||
import cPickle
|
import cPickle
|
||||||
|
@ -58,11 +58,9 @@ class Storage(object):
|
|||||||
data = data.encode(Storage.CODEC)
|
data = data.encode(Storage.CODEC)
|
||||||
attr1 = '' if attr1 == None else attr1
|
attr1 = '' if attr1 == None else attr1
|
||||||
try:
|
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:
|
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')
|
logger.debug('Key saved')
|
||||||
|
|
||||||
def put(self, skey, data):
|
def put(self, skey, data):
|
||||||
|
@ -55,15 +55,14 @@ class AssignedAndUnused(Job):
|
|||||||
since_state = getSqlDatetime() - timedelta(seconds=GlobalConfig.CHECK_UNUSED_TIME.getInt())
|
since_state = getSqlDatetime() - timedelta(seconds=GlobalConfig.CHECK_UNUSED_TIME.getInt())
|
||||||
for ds in DeployedService.objects.all():
|
for ds in DeployedService.objects.all():
|
||||||
# If do not needs os manager, this is
|
# If do not needs os manager, this is
|
||||||
with transaction.atomic():
|
if ds.osmanager is not None:
|
||||||
if ds.osmanager is not None:
|
osm = ds.osmanager.getInstance()
|
||||||
osm = ds.osmanager.getInstance()
|
if osm.processUnusedMachines is True:
|
||||||
if osm.processUnusedMachines is True:
|
logger.debug('Processing unused services for {0}'.format(osm))
|
||||||
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
|
|
||||||
for us in ds.assignedUserServices().select_for_update().filter(in_use=False, state_date__lt=since_state, state=State.USABLE, os_state=State.USABLE):
|
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))
|
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
|
self._state = service.state
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@transaction.atomic
|
|
||||||
def checkAndUpdateState(userService, userServiceInstance, state):
|
def checkAndUpdateState(userService, userServiceInstance, state):
|
||||||
'''
|
'''
|
||||||
Checks the value returned from invocation to publish or checkPublishingState, updating the dsp database object
|
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
|
self._id = providerId
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@transaction.atomic
|
|
||||||
def migrate(serviceId, toNode):
|
def migrate(serviceId, toNode):
|
||||||
try:
|
try:
|
||||||
service = UserService.objects.select_for_update().get(pk=serviceId)
|
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)
|
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))
|
logger.info('Deployed service {0} is restrained, will check this later'.format(deployedService.name))
|
||||||
|
|
||||||
@transaction.atomic
|
|
||||||
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
|
||||||
@ -180,15 +179,14 @@ class ServiceCacheUpdater(Job):
|
|||||||
# First, we try to assign from L2 cache
|
# First, we try to assign from L2 cache
|
||||||
if cacheL2 > 0:
|
if cacheL2 > 0:
|
||||||
valid = None
|
valid = None
|
||||||
with transaction.atomic():
|
for n in ds.cachedUserServices().select_for_update().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date'):
|
||||||
for n in ds.cachedUserServices().select_for_update().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date'):
|
if n.needsOsManager():
|
||||||
if n.needsOsManager():
|
if State.isUsable(n.state) is False or State.isUsable(n.os_state):
|
||||||
if State.isUsable(n.state) is False or State.isUsable(n.os_state):
|
|
||||||
valid = n
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
valid = n
|
valid = n
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
valid = n
|
||||||
|
break
|
||||||
|
|
||||||
if valid is not None:
|
if valid is not None:
|
||||||
valid.moveToLevel(services.UserDeployment.L1_CACHE)
|
valid.moveToLevel(services.UserDeployment.L1_CACHE)
|
||||||
|
@ -1999,7 +1999,7 @@ class DelayedTask(models.Model):
|
|||||||
# objects = LockingManager()
|
# objects = LockingManager()
|
||||||
|
|
||||||
def __unicode__(self):
|
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):
|
class Network(models.Model):
|
||||||
|
@ -25,6 +25,21 @@ Handlebars.registerHelper "eachKey", (context, options) ->
|
|||||||
first = false
|
first = false
|
||||||
ret
|
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)
|
# Equal comparision (like if helper, but with comparation)
|
||||||
# Use as block as {{#ifequals [element] [element]}}....{{/ifequals}}
|
# Use as block as {{#ifequals [element] [element]}}....{{/ifequals}}
|
||||||
|
@ -92,6 +92,11 @@ gui.servicesPools.link = (event) ->
|
|||||||
if value.state is "P"
|
if value.state is "P"
|
||||||
value.state = gettext("Generating")
|
value.state = gettext("Generating")
|
||||||
return
|
return
|
||||||
|
if value.state is "K"
|
||||||
|
value.state = gettext("Cancelling")
|
||||||
|
return
|
||||||
|
if value.state is "C"
|
||||||
|
value.state = gettext("Cancelled")
|
||||||
value.state = gettext("Unknown")
|
value.state = gettext("Unknown")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<div class="tab-content col-md-12 col-md-offset-0 col-lg-8 col-lg-offset-2">
|
<div class="tab-content col-md-12 col-md-offset-0 col-lg-8 col-lg-offset-2">
|
||||||
{{# eachKey config }}
|
{{# eachKey config }}
|
||||||
<div class="tab-pane {{# if first }}active{{/ if }}" id="section_{{ key }}">
|
<div class="tab-pane {{# if first }}active{{/ if }}" id="section_{{ key }}">
|
||||||
{{# eachKey value }}
|
{{# eachKeySorted value }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="fld_{{ clean_whitespace ../key }}{{ key }}" class="col-sm-5 control-label">{{ key }}</label>
|
<label for="fld_{{ clean_whitespace ../key }}{{ key }}" class="col-sm-5 control-label">{{ key }}</label>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
@ -46,7 +46,7 @@
|
|||||||
{{/ if }}
|
{{/ if }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/ eachKey }}
|
{{/ eachKeySorted }}
|
||||||
</div>
|
</div>
|
||||||
{{/ eachKey }}
|
{{/ eachKey }}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user