From 5836b33299252aab6becd1fc953bded0b55acc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 17 Mar 2022 14:53:32 +0100 Subject: [PATCH] Added new way of counting "active" machines (taking into account the removable and removing services also) --- server/src/uds/core/managers/user_service.py | 9 ++++++--- server/src/uds/core/util/config.py | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/uds/core/managers/user_service.py b/server/src/uds/core/managers/user_service.py index a1118a21..489173e9 100644 --- a/server/src/uds/core/managers/user_service.py +++ b/server/src/uds/core/managers/user_service.py @@ -38,6 +38,7 @@ from django.utils.translation import ugettext as _ from django.db.models import Q from django.db import transaction from uds.core.services.exceptions import OperationException +from uds.core.util.config import GlobalConfig from uds.core.util.state import State from uds.core.util import log from uds.core.services.exceptions import ( @@ -82,7 +83,11 @@ class UserServiceManager(metaclass=singleton.Singleton): @staticmethod def getStateFilter() -> Q: - return Q(state__in=[State.PREPARING, State.USABLE]) + if GlobalConfig.MAX_SERVICES_COUNT_NEW.getBool() == False: + states = [State.PREPARING, State.USABLE] + else: + states = [State.PREPARING, State.USABLE, State.REMOVING, State.REMOVABLE] + return Q(state__in=states) def __checkMaxDeployedReached(self, servicePool: ServicePool) -> None: """ @@ -515,13 +520,11 @@ class UserServiceManager(metaclass=singleton.Singleton): # Can't assign directly from L2 cache... so we check if we can create e new service in the limits requested serviceType = servicePool.service.getType() if serviceType.usesCache: - # inCacheL1 = ds.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L1_CACHE)).count() inAssigned = ( servicePool.assignedUserServices() .filter(UserServiceManager.getStateFilter()) .count() ) - # totalL1Assigned = inCacheL1 + inAssigned if ( inAssigned >= servicePool.max_srvs ): # cacheUpdater will drop unnecesary L1 machines, so it's not neccesary to check against inCacheL1 diff --git a/server/src/uds/core/util/config.py b/server/src/uds/core/util/config.py index 75dd5d72..1b1ab0f2 100644 --- a/server/src/uds/core/util/config.py +++ b/server/src/uds/core/util/config.py @@ -414,6 +414,11 @@ class GlobalConfig: 'Notify on new publication', '0', type=Config.BOOLEAN_FIELD ) + # How "max services" is computed + MAX_SERVICES_COUNT_NEW: Config.Value = Config.section(GLOBAL_SECTION).value( + 'New Max restriction', '0', type=Config.BOOLEAN_FIELD + ) + # Allowed "trusted sources" for request TRUSTED_SOURCES: Config.Value = Config.section(SECURITY_SECTION).value( 'Trusted Hosts', '*', type=Config.TEXT_FIELD