diff --git a/server/.pydevproject b/server/.pydevproject index 1ce3ca467..2b045655f 100644 --- a/server/.pydevproject +++ b/server/.pydevproject @@ -1,40 +1,5 @@ -<<<<<<< HEAD - - uds 3.0 - - python 3.7 - - - - DJANGO_MANAGE_LOCATION - - src/manage.py - - DJANGO_SETTINGS_MODULE - - server.settings - - - - - - /uds/src - - - -======= -uds 2.2 -python 2.7 - -DJANGO_MANAGE_LOCATION -src/manage.py -DJANGO_SETTINGS_MODULE -server.settings - - -/uds/src - ->>>>>>> origin/v2.2 + Default + python interpreter diff --git a/server/src/uds/core/managers/UserServiceManager.py b/server/src/uds/core/managers/UserServiceManager.py index ac3f21cb7..12186c6d3 100644 --- a/server/src/uds/core/managers/UserServiceManager.py +++ b/server/src/uds/core/managers/UserServiceManager.py @@ -58,11 +58,7 @@ import json import logging import random -<<<<<<< HEAD -__updated__ = '2019-02-11' -======= __updated__ = '2019-02-22' ->>>>>>> origin/v2.2 logger = logging.getLogger(__name__) traceLogger = logging.getLogger('traceLog') @@ -302,17 +298,12 @@ class UserServiceManager(object): cache = None if cache: - cache.assignToUser(user) - cache.save() # Store assigned ASAP, we do not know how long assignToUser method of instance will take + cache.assignToUser(user, save=True) # Out of atomic transaction if cache is not None: logger.debug('Found a cached-ready service from {0} for user {1}, item {2}'.format(ds, user, cache)) events.addEvent(ds, events.ET_CACHE_HIT, fld1=ds.cachedUserServices().filter(cache_level=services.UserDeployment.L1_CACHE, state=State.USABLE).count()) - ci = cache.getInstance() # User Deployment instance - ci.assignToUser(user) - cache.updateData(ci) - cache.save() return cache # Cache missed @@ -325,8 +316,7 @@ class UserServiceManager(object): if ds.cachedUserServices().select_for_update().filter(user=None, uuid=cache.uuid).update(user=user, cache_level=0) != 1: cache = None else: - cache.assignToUser(user) - cache.save() + cache.assignToUser(user, save=True) else: cache = None @@ -334,10 +324,6 @@ class UserServiceManager(object): if cache is not None: logger.debug('Found a cached-preparing service from {0} for user {1}, item {2}'.format(ds, user, cache)) events.addEvent(ds, events.ET_CACHE_MISS, fld1=ds.cachedUserServices().filter(cache_level=services.UserDeployment.L1_CACHE, state=State.PREPARING).count()) - ci = cache.getInstance() # User Deployment instance - ci.assignToUser(user) - cache.updateData(ci) - cache.save() return cache # Can't assign directly from L2 cache... so we check if we can create e new service in the limits requested diff --git a/server/src/uds/core/services/BaseDeployed.py b/server/src/uds/core/services/BaseDeployed.py index d642361b6..cd03e12ce 100644 --- a/server/src/uds/core/services/BaseDeployed.py +++ b/server/src/uds/core/services/BaseDeployed.py @@ -449,25 +449,6 @@ class UserDeployment(Environmentable, Serializable): """ pass - def assignToUser(self, user): - """ - This method is invoked whenever a cache item gets assigned to an user. - This is not a task method right now, simply a notification. This means - that L1 cache items must be directly usable (except for the readyness part) - by users in a single step operation. - - Note that there will be an setReady call before letting the user consume - this user deployment, so this is more informational (so, if you keep at - what cache level is this instance, you can update it) than anything else. - - This is not a task method. All level 1 cache items can be dircetly - assigned to an user with no more work needed, but, if something is needed, - here you can do whatever you need. - - user is a Database user object. - """ - pass - def moveToCache(self, newLevel): """ This method is invoked whenever the core needs to move from the current diff --git a/server/src/uds/models/UserService.py b/server/src/uds/models/UserService.py index 17a232875..10936ffa4 100644 --- a/server/src/uds/models/UserService.py +++ b/server/src/uds/models/UserService.py @@ -116,7 +116,7 @@ class UserService(UUIDModel): """ return "{}\\{}".format(self.deployed_service.name, self.friendly_name) - def getEnvironment(self) -> Environment: + def getEnvironment(self): """ Returns an environment valid for the record this object represents. @@ -138,7 +138,7 @@ class UserService(UUIDModel): } ) - def getInstance(self) -> UserDeployment: + def getInstance(self): """ Instantiates the object this record contains. In this case, the instantiated object needs also the os manager and the publication, so we also instantiate those here. @@ -336,7 +336,7 @@ class UserService(UUIDModel): self.state_date = getSqlDatetime() self.os_state = state - def assignToUser(self, user): + def assignToUser(self, user, save=False): """ Assigns this user deployed service to an user. @@ -346,6 +346,8 @@ class UserService(UUIDModel): self.cache_level = 0 self.state_date = getSqlDatetime() self.user = user + if save: + self.save(update_fields=['cache_level', 'state_date', 'user']) def setInUse(self, state): """ diff --git a/server/src/uds/services/OVirt/OVirtLinkedDeployment.py b/server/src/uds/services/OVirt/OVirtLinkedDeployment.py index 03319fb0a..89d5e9407 100644 --- a/server/src/uds/services/OVirt/OVirtLinkedDeployment.py +++ b/server/src/uds/services/OVirt/OVirtLinkedDeployment.py @@ -523,14 +523,6 @@ class OVirtLinkedDeployment(UserDeployment): self.__debug('finish') pass - def assignToUser(self, user): - """ - This method is invoked whenever a cache item gets assigned to an user. - This gives the User Deployment an oportunity to do whatever actions - are required so the service puts at a correct state for using by a service. - """ - pass - def moveToCache(self, newLevel): """ Moves machines between cache levels diff --git a/server/src/uds/services/OpenNebula/LiveDeployment.py b/server/src/uds/services/OpenNebula/LiveDeployment.py index 31872c5c1..2fc113b66 100644 --- a/server/src/uds/services/OpenNebula/LiveDeployment.py +++ b/server/src/uds/services/OpenNebula/LiveDeployment.py @@ -459,14 +459,6 @@ class LiveDeployment(UserDeployment): self.__debug('finish') pass - def assignToUser(self, user): - """ - This method is invoked whenever a cache item gets assigned to an user. - This gives the User Deployment an oportunity to do whatever actions - are required so the service puts at a correct state for using by a service. - """ - pass - def moveToCache(self, newLevel): """ Moves machines between cache levels diff --git a/server/src/uds/services/OpenStack/LiveDeployment.py b/server/src/uds/services/OpenStack/LiveDeployment.py index 159546e68..951834dd1 100644 --- a/server/src/uds/services/OpenStack/LiveDeployment.py +++ b/server/src/uds/services/OpenStack/LiveDeployment.py @@ -463,14 +463,6 @@ class LiveDeployment(UserDeployment): self.__debug('finish') pass - def assignToUser(self, user): - """ - This method is invoked whenever a cache item gets assigned to an user. - This gives the User Deployment an oportunity to do whatever actions - are required so the service puts at a correct state for using by a service. - """ - pass - def moveToCache(self, newLevel): """ Moves machines between cache levels diff --git a/server/src/uds/services/Sample/SampleUserDeploymentOne.py b/server/src/uds/services/Sample/SampleUserDeploymentOne.py index bd6af456d..8d5714d8c 100644 --- a/server/src/uds/services/Sample/SampleUserDeploymentOne.py +++ b/server/src/uds/services/Sample/SampleUserDeploymentOne.py @@ -289,20 +289,6 @@ class SampleUserDeploymentOne(UserDeployment): # Note that this is not really needed, is just a sample of storage use self.storage.remove('count') - def assignToUser(self, user): - """ - This method is invoked whenever a cache item gets assigned to an user. - This gives the User Deployment an oportunity to do whatever actions - are required so the service puts at a correct state for using by a service. - - In our sample, the service is always ready, so this does nothing. - - This is not a task method. All level 1 cache items can be diretly - assigned to an user with no more work needed, but, if something is needed, - here you can do whatever you need - """ - pass - def userLoggedIn(self, user): """ This method must be available so os managers can invoke it whenever diff --git a/server/src/uds/services/Sample/SampleUserDeploymentTwo.py b/server/src/uds/services/Sample/SampleUserDeploymentTwo.py index b362e70eb..de5c75748 100644 --- a/server/src/uds/services/Sample/SampleUserDeploymentTwo.py +++ b/server/src/uds/services/Sample/SampleUserDeploymentTwo.py @@ -379,25 +379,6 @@ class SampleUserDeploymentTwo(UserDeployment): # We set count to 0, not needed but for sample purposes self._count = 0 - def assignToUser(self, user): - """ - This method is invoked whenever a cache item gets assigned to an user. - This is not a task method right now, simply a notification. This means - that L1 cache items must be directly usable (except for the readyness part) - by users in a single step operation. - - Note that there will be an setReady call before letting the user consume - this user deployment, so this is more informational (so, if you keep at - what cache level is this instance, you can update it) than anything else. - - This is not a task method. All level 1 cache items can be dircetly - assigned to an user with no more work needed, but, if something is needed, - here you can do whatever you need. - - user is a Database user object. - """ - logger.debug('Assigned to user {0}'.format(user)) - def userLoggedIn(self, user): """ This method must be available so os managers can invoke it whenever diff --git a/server/src/uds/services/Xen/XenLinkedDeployment.py b/server/src/uds/services/Xen/XenLinkedDeployment.py index 6bd7e735f..450897865 100644 --- a/server/src/uds/services/Xen/XenLinkedDeployment.py +++ b/server/src/uds/services/Xen/XenLinkedDeployment.py @@ -515,14 +515,6 @@ class XenLinkedDeployment(UserDeployment): self.__debug('finish') pass - def assignToUser(self, user): - """ - This method is invoked whenever a cache item gets assigned to an user. - This gives the User Deployment an oportunity to do whatever actions - are required so the service puts at a correct state for using by a service. - """ - pass - def moveToCache(self, newLevel): """ Moves machines between cache levels