diff --git a/server/src/uds/core/managers/user_service.py b/server/src/uds/core/managers/user_service.py index e2a4420d..6f10c323 100644 --- a/server/src/uds/core/managers/user_service.py +++ b/server/src/uds/core/managers/user_service.py @@ -304,7 +304,6 @@ class UserServiceManager: return None def getAssignationForUser(self, servicePool: ServicePool, user: User) -> typing.Optional[UserService]: # pylint: disable=too-many-branches - if servicePool.service.getInstance().spawnsNew is False: assignedUserService = self.getExistingAssignationForUser(servicePool, user) else: diff --git a/server/src/uds/core/util/states/__init__.py b/server/src/uds/core/util/states/__init__.py index bf1d2d5c..c27382d9 100644 --- a/server/src/uds/core/util/states/__init__.py +++ b/server/src/uds/core/util/states/__init__.py @@ -30,13 +30,11 @@ """ @author: Adolfo Gómez, dkmaster at dkmon dot com """ -from __future__ import unicode_literals - from . import action from . import common from . import group from . import process from . import publication -from . import userService -from . import servicePool +from . import user_service as userService +from . import service_pool as servicePool from . import task diff --git a/server/src/uds/core/util/states/servicePool.py b/server/src/uds/core/util/states/service_pool.py similarity index 94% rename from server/src/uds/core/util/states/servicePool.py rename to server/src/uds/core/util/states/service_pool.py index c685f4aa..d9bb1925 100644 --- a/server/src/uds/core/util/states/servicePool.py +++ b/server/src/uds/core/util/states/service_pool.py @@ -32,5 +32,5 @@ """ # pylint: disable=unused-import -from .common import ACTIVE, REMOVABLE, REMOVING, REMOVED, INFO_STATES, VALID_STATES # @UnusedImport +from .common import ACTIVE, REMOVABLE, REMOVING, REMOVED # @UnusedImport diff --git a/server/src/uds/core/util/states/userService.py b/server/src/uds/core/util/states/user_service.py similarity index 96% rename from server/src/uds/core/util/states/userService.py rename to server/src/uds/core/util/states/user_service.py index 1e9bcd80..a2176c58 100644 --- a/server/src/uds/core/util/states/userService.py +++ b/server/src/uds/core/util/states/user_service.py @@ -32,4 +32,4 @@ """ # pylint: disable=unused-import -from .common import ERROR, USABLE, PREPARING, REMOVABLE, REMOVING, REMOVED # @UnusedImport +from .common import ERROR, USABLE, PREPARING, REMOVABLE, REMOVING, REMOVED, INFO_STATES, VALID_STATES # @UnusedImport diff --git a/server/src/uds/models/meta_pool.py b/server/src/uds/models/meta_pool.py index 11b812cf..9f52e044 100644 --- a/server/src/uds/models/meta_pool.py +++ b/server/src/uds/models/meta_pool.py @@ -169,11 +169,12 @@ class MetaPool(UUIDModel, TaggingMixin): # type: ignore ) if user: meta = meta.annotate( - number_assignations=models.Count( + number_in_use=models.Count( 'pools__userServices', filter=models.Q( pools__userServices__user=user, - pools__userServices__in_use=True + pools__userServices__in_use=True, + pools__userServices__state__in=states.userService.USABLE ) ) ) diff --git a/server/src/uds/models/service_pool.py b/server/src/uds/models/service_pool.py index 4f1268ad..c9dd8109 100644 --- a/server/src/uds/models/service_pool.py +++ b/server/src/uds/models/service_pool.py @@ -490,16 +490,20 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore ) if user: # Optimize loading if there is some assgned service.. list1 = list1.annotate( - number_assignations=models.Count( + number_in_use=models.Count( 'userServices', filter=models.Q( - userServices__user=user, userServices__in_use=True + userServices__user=user, + userServices__in_use=True, + userServices__state__in=states.userService.USABLE ) ) ) list2 = list2.annotate( - number_assignations=models.Count( + number_in_use=models.Count( 'userServices', filter=models.Q( - userServices__user=user, userServices__in_use=True + userServices__user=user, + userServices__in_use=True, + userServices__state__in=states.userService.USABLE ) ) ) diff --git a/server/src/uds/web/util/services.py b/server/src/uds/web/util/services.py index d558aca3..edee2b05 100644 --- a/server/src/uds/web/util/services.py +++ b/server/src/uds/web/util/services.py @@ -97,7 +97,7 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: # for meta in availMetaPools: # Check that we have access to at least one transport on some of its children hasUsablePools = False - in_use = False + in_use = meta.number_in_use > 0 # False for pool in meta.pools.all(): # if pool.isInMaintenance(): # continue @@ -107,10 +107,10 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: # hasUsablePools = True break - if not in_use and meta.number_assignations: # Only look for assignation on possible used - assignedUserService = userServiceManager().getExistingAssignationForUser(pool, request.user) - if assignedUserService: - in_use = assignedUserService.in_use + # if not in_use and meta.number_in_use: # Only look for assignation on possible used + # assignedUserService = userServiceManager().getExistingAssignationForUser(pool, request.user) + # if assignedUserService: + # in_use = assignedUserService.in_use # Stop when 1 usable pool is found if hasUsablePools: @@ -180,20 +180,21 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: # imageId = 'x' # Locate if user service has any already assigned user service for this. Use "pre cached" number of assignations in this pool to optimize - in_use = False - if svr.number_assignations: # Anotated value got from getDeployedServicesForGroups(...). If 0, no assignation for this user - ads = userServiceManager().getExistingAssignationForUser(svr, request.user) - if ads: - in_use = ads.in_use + in_use = svr.number_in_use > 0 + # if svr.number_in_use: # Anotated value got from getDeployedServicesForGroups(...). If 0, no assignation for this user + # ads = userServiceManager().getExistingAssignationForUser(svr, request.user) + # if ads: + # in_use = ads.in_use group = svr.servicesPoolGroup.as_dict if svr.servicesPoolGroup else ServicePoolGroup.default().as_dict - tbr = svr.toBeReplaced(request.user) - if tbr: - tbr = formats.date_format(tbr, "SHORT_DATETIME_FORMAT") - tbrt = ugettext('This service is about to be replaced by a new version. Please, close the session before {} and save all your work to avoid loosing it.').format(tbr) + toBeReplaced = svr.toBeReplaced(request.user) + # tbr = False + if toBeReplaced: + toBeReplaced = formats.date_format(toBeReplaced, "SHORT_DATETIME_FORMAT") + toBeReplacedTxt = ugettext('This service is about to be replaced by a new version. Please, close the session before {} and save all your work to avoid loosing it.').format(toBeReplaced) else: - tbrt = '' + toBeReplacedTxt = '' services.append({ 'id': 'F' + svr.uuid, @@ -209,8 +210,8 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: # 'maintenance': svr.isInMaintenance(), 'not_accesible': not svr.isAccessAllowed(now), 'in_use': in_use, - 'to_be_replaced': tbr, - 'to_be_replaced_text': tbrt, + 'to_be_replaced': toBeReplaced, + 'to_be_replaced_text': toBeReplacedTxt, 'custom_calendar_text': svr.calendar_message, })