示例#1
0
    def checkOsManagerRelated(self) -> str:
        osManager = self.userServiceInstance.osmanager()

        state = State.USABLE

        # and make this usable if os manager says that it is usable, else it pass to configuring state
        # This is an "early check" for os manager, so if we do not have os manager, or os manager
        # already notifies "ready" for this, we
        if osManager is not None and State.isPreparing(
                self.userService.os_state):
            logger.debug('Has valid osmanager for %s',
                         self.userService.friendly_name)

            stateOs = osManager.checkState(self.userService)
        else:
            stateOs = State.FINISHED

        logger.debug('State %s, StateOS %s for %s', State.toString(state),
                     State.toString(stateOs), self.userService.friendly_name)
        if stateOs == State.RUNNING:
            self.userService.setOsState(State.PREPARING)
        else:
            # If state is finish, we need to notify the userService again that os has finished
            # This will return a new task state, and that one will be the one taken into account
            self.userService.setOsState(State.USABLE)
            rs = self.userServiceInstance.notifyReadyFromOsManager('')
            if rs != State.FINISHED:
                self.checkLater()
                state = self.userService.state  # No not alter current state if after notifying os manager the user service keeps working
            else:
                self.logIp()

        return state
示例#2
0
 def __str__(self):
     return "User service {}, unique_id {}, cache_level {}, user {}, name {}, state {}:{}".format(
         self.name,
         self.unique_id,
         self.cache_level,
         self.user,
         self.friendly_name,
         State.toString(self.state),
         State.toString(self.os_state),
     )
示例#3
0
    def remove(self, userService: UserService) -> UserService:
        """
        Removes a uService element
        """
        with transaction.atomic():
            userService = UserService.objects.select_for_update().get(
                id=userService.id)
            logger.debug('Removing userService %a', userService)
            if userService.isUsable() is False and State.isRemovable(
                    userService.state) is False:
                raise OperationException(
                    _('Can\'t remove a non active element'))
            userService.setState(State.REMOVING)
            logger.debug("***** The state now is %s *****",
                         State.toString(userService.state))
            userService.setInUse(
                False
            )  # For accounting, ensure that it is not in use right now
            userService.save()

        userServiceInstance = userService.getInstance()
        state = userServiceInstance.destroy()

        # Data will be serialized on makeUnique process
        UserServiceOpChecker.makeUnique(userService, userServiceInstance,
                                        state)

        return userService
示例#4
0
    def checkAndUpdateState(userService: UserService,
                            userServiceInstance: UserDeployment, state: str):
        """
        Checks the value returned from invocation to publish or checkPublishingState, updating the servicePoolPub database object
        Return True if it has to continue checking, False if finished
        """
        try:
            # Fills up basic data
            userService.unique_id = userServiceInstance.getUniqueId(
            )  # Updates uniqueId
            userService.friendly_name = userServiceInstance.getName(
            )  # And name, both methods can modify serviceInstance, so we save it later
            userService.save(update_fields=['unique_id', 'friendly_name'])

            updater = {
                State.PREPARING: UpdateFromPreparing,
                State.REMOVING: UpdateFromRemoving,
                State.CANCELING: UpdateFromCanceling
            }.get(userService.state, UpdateFromOther)

            logger.debug('Updating %s from %s with updater %s and state %s',
                         userService.friendly_name,
                         State.toString(userService.state), updater, state)

            updater(userService, userServiceInstance).run(state)

        except Exception as e:
            logger.exception('Checking service state')
            log.doLog(userService, log.ERROR, 'Exception: {}'.format(e),
                      log.INTERNAL)
            userService.setState(State.ERROR)
            userService.save(update_fields=['data'])
示例#5
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)
示例#6
0
    def run(self, state):
        executor = {
            State.RUNNING: self.running,
            State.ERROR: self.error,
            State.FINISHED: self.finish
        }.get(state, self.error)

        logger.debug('Running Executor for %s with state %s and executor %s',
                     self.userService.friendly_name, State.toString(state),
                     executor)

        try:
            executor()
        except Exception as e:
            self.setError('Exception: {}'.format(e))

        logger.debug('Executor for %s done', self.userService.friendly_name)
 def __str__(self):
     return 'Publication {}, rev {}, state {}'.format(
         self.deployed_service.name, self.revision,
         State.toString(self.state))
示例#8
0
 def running(self):
     self.setError('Unknown running transition from {}'.format(
         State.toString(self.userService.state)))