Example #1
0
    def cancel(self, userService: UserService) -> UserService:
        """
        Cancels an user service creation
        @return: the Uservice canceling
        """
        userService.refresh_from_db()
        logger.debug('Canceling userService %s creation', userService)

        if userService.isPreparing() is False:
            logger.info(
                'Cancel requested for a non running operation, performing removal instead'
            )
            return self.remove(userService)

        userServiceInstance = userService.getInstance()

        if not userServiceInstance.supportsCancel(
        ):  # Does not supports cancel, but destroy, so mark it for "later" destroy
            # State is kept, just mark it for destroy after finished preparing
            userService.setProperty('destroy_after', 'y')
        else:
            userService.setState(State.CANCELING)
            # We simply notify service that it should cancel operation
            state = userServiceInstance.cancel()

            # Data will be serialized on makeUnique process
            # If cancel is not supported, base cancel always returns "FINISHED", and
            # opchecker will set state to "removable"
            UserServiceOpChecker.makeUnique(userService, userServiceInstance,
                                            state)

        return userService
Example #2
0
    def isReady(self, userService: UserService) -> bool:
        userService.refresh_from_db()
        logger.debug('Checking ready of %s', userService)

        if userService.state != State.USABLE or userService.os_state != State.USABLE:
            logger.debug('State is not usable for %s', userService.name)
            return False

        logger.debug('Service %s is usable, checking it via setReady',
                     userService)
        userServiceInstance = userService.getInstance()
        try:
            state = userServiceInstance.setReady()
        except Exception as e:
            logger.warn('Could not check readyness of %s: %s', userService, e)
            return False

        logger.debug('State: %s', state)

        if state == State.FINISHED:
            userService.updateData(userServiceInstance)
            return True

        userService.setState(State.PREPARING)
        UserServiceOpChecker.makeUnique(userService, userServiceInstance,
                                        state)

        return False
Example #3
0
    def reset(self, userService: UserService) -> None:
        userService.refresh_from_db()

        if not userService.deployed_service.service.getType().canReset:
            return

        logger.debug('Reseting %s', userService)

        userServiceInstance = userService.getInstance()
        try:
            userServiceInstance.reset()
        except Exception:
            logger.exception('Reseting service')
Example #4
0
    def moveToLevel(self, cache: UserService, cacheLevel: int) -> None:
        """
        Moves a cache element from one level to another
        @return: cache element
        """
        cache.refresh_from_db()
        logger.debug('Moving cache %s to level %s', cache, cacheLevel)
        cacheInstance = cache.getInstance()
        state = cacheInstance.moveToCache(cacheLevel)
        cache.cache_level = cacheLevel
        cache.save(update_fields=['cache_level'])
        logger.debug('Service State: %a %s %s', State.toString(state), State.toString(cache.state), State.toString(cache.os_state))
        if State.isRuning(state) and cache.isUsable():
            cache.setState(State.PREPARING)

        # Data will be serialized on makeUnique process
        UserServiceOpChecker.makeUnique(cache, cacheInstance, state)