def growL1Cache(self, sp, cacheL1, cacheL2, assigned): ''' This method tries to enlarge L1 cache. If for some reason the number of deployed services (Counting all, ACTIVE and PREPARING, assigned, L1 and L2) is over max allowed service deployments, this method will not grow the L1 cache ''' logger.debug("Growing L1 cache creating a new service for {0}".format(sp)) # First, we try to assign from L2 cache if cacheL2 > 0: valid = None with transaction.atomic(): for n in sp.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) return try: UserServiceManager.manager().createCacheFor(sp.activePublication(), services.UserDeployment.L1_CACHE) except MaxServicesReachedException as e: log.doLog(sp, log.ERROR, 'Max number of services reached for this service', log.INTERNAL) logger.error(str(e)) except: logger.exception('Exception')
def reduceL1Cache(self, sp, cacheL1, cacheL2, assigned): logger.debug("Reducing L1 cache erasing a service in cache for {0}".format(sp)) # We will try to destroy the newest cacheL1 element that is USABLE if the deployer can't cancel a new service creation cacheItems = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L1_CACHE)).order_by('-creation_date') if len(cacheItems) == 0: logger.debug('There is more services than configured, but could not reduce cache cause its already empty') return if cacheL2 < sp.cache_l2_srvs: valid = None for n in cacheItems: 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.L2_CACHE) return cache = cacheItems[0] cache.removeOrCancel()
def reduceL1Cache(self, sp, cacheL1, cacheL2, assigned): logger.debug( "Reducing L1 cache erasing a service in cache for {0}".format(sp)) # We will try to destroy the newest cacheL1 element that is USABLE if the deployer can't cancel a new service creation cacheItems = sp.cachedUserServices().filter( UserServiceManager.getCacheStateFilter( services.UserDeployment.L1_CACHE)).order_by('-creation_date') if len(cacheItems) == 0: logger.debug( 'There is more services than configured, but could not reduce cache cause its already empty' ) return if cacheL2 < sp.cache_l2_srvs: valid = None for n in cacheItems: 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.L2_CACHE) return cache = cacheItems[0] cache.removeOrCancel()
def growL1Cache(self, sp, cacheL1, cacheL2, assigned): """ This method tries to enlarge L1 cache. If for some reason the number of deployed services (Counting all, ACTIVE and PREPARING, assigned, L1 and L2) is over max allowed service deployments, this method will not grow the L1 cache """ logger.debug( "Growing L1 cache creating a new service for {0}".format(sp)) # First, we try to assign from L2 cache if cacheL2 > 0: valid = None with transaction.atomic(): for n in sp.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) return try: UserServiceManager.manager().createCacheFor( sp.activePublication(), services.UserDeployment.L1_CACHE) except MaxServicesReachedError as e: log.doLog(sp, log.ERROR, 'Max number of services reached for this service', log.INTERNAL) logger.error(str(e)) except: logger.exception('Exception')
def unpublish(self, servicePoolPub): # pylint: disable=no-self-use ''' Unpublishes an active (usable) or removable publication :param servicePoolPub: Publication to unpublish ''' if State.isUsable(servicePoolPub.state) is False and State.isRemovable(servicePoolPub.state) is False: raise PublishException(_('Can\'t unpublish non usable publication') ) if servicePoolPub.userServices.exclude(state__in=State.INFO_STATES).count() > 0: raise PublishException(_('Can\'t unpublish publications with services in process')) try: pubInstance = servicePoolPub.getInstance() state = pubInstance.destroy() servicePoolPub.setState(State.REMOVING) PublicationFinishChecker.checkAndUpdateState(servicePoolPub, pubInstance, state) except Exception, e: raise PublishException(str(e))
def unpublish(self, servicePoolPub): # pylint: disable=no-self-use ''' Unpublishes an active (usable) or removable publication :param servicePoolPub: Publication to unpublish ''' if State.isUsable(servicePoolPub.state) is False and State.isRemovable(servicePoolPub.state) is False: raise PublishException(_('Can\'t unpublish non usable publication') ) if servicePoolPub.userServices.exclude(state__in=State.INFO_STATES).count() > 0: raise PublishException(_('Can\'t unpublish publications with services in process')) try: pubInstance = servicePoolPub.getInstance() state = pubInstance.destroy() servicePoolPub.setState(State.REMOVING) PublicationFinishChecker.checkAndUpdateState(servicePoolPub, pubInstance, state) except Exception as e: raise PublishException(str(e))
def isUsable(self): """ Returns if this service is usable """ return State.isUsable(self.state)
def isUsable(self): ''' Returns if this service is usable ''' return State.isUsable(self.state)