Exemple #1
0
    def checkOsManagerRelated(self):
        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 {}'.format(
                self.userService.friendly_name))

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

        logger.debug('State {}, StateOS {} for {}'.format(
            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
Exemple #2
0
    def checkOsManagerRelated(self):
        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 {}'.format(self.userService.friendly_name))

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

        logger.debug('State {}, StateOS {} for {}'.format(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
Exemple #3
0
 def __str__(self):
     return "User service {0}, cache_level {1}, user {2}, name {3}, state {4}:{5}".format(
         self.id,
         self.cache_level,
         self.user,
         self.friendly_name,
         State.toString(self.state),
         State.toString(self.os_state),
     )
    def moveToLevel(self, cache, cacheLevel):
        """
        Moves a cache element from one level to another
        @return: cache element
        """
        cache = UserService.objects.get(id=cache.id)
        logger.debug('Moving cache {0} to level {1}'.format(cache, cacheLevel))
        ci = cache.getInstance()
        state = ci.moveToCache(cacheLevel)
        cache.cache_level = cacheLevel
        logger.debug('Service State: {0} {1} {2}'.format(State.toString(state), State.toString(cache.state), State.toString(cache.os_state)))
        if State.isRuning(state) and cache.isUsable():
            cache.setState(State.PREPARING)

        UserServiceOpChecker.makeUnique(cache, ci, state)
    def moveToLevel(self, cache, cacheLevel):
        '''
        Moves a cache element from one level to another
        @return: cache element
        '''
        cache = UserService.objects.get(id=cache.id)
        logger.debug('Moving cache {0} to level {1}'.format(cache, cacheLevel))
        ci = cache.getInstance()
        state = ci.moveToCache(cacheLevel)
        cache.cache_level = cacheLevel
        logger.debug('Service State: {0} {1} {2}'.format(State.toString(state), State.toString(cache.state), State.toString(cache.os_state)))
        if State.isRuning(state) and cache.isUsable():
            cache.setState(State.PREPARING)

        UserServiceOpChecker.makeUnique(cache, ci, state)
Exemple #6
0
    def remove(self, uService):
        """
        Removes a uService element
        @return: the uService removed (marked for removal)
        """
        with transaction.atomic():
            uService = UserService.objects.select_for_update().get(
                id=uService.id)
            logger.debug('Removing uService {0}'.format(uService))
            if uService.isUsable() is False and State.isRemovable(
                    uService.state) is False:
                raise OperationException(
                    _('Can\'t remove a non active element'))
            uService.setState(State.REMOVING)
            logger.debug("***** The state now is {}".format(
                State.toString(uService.state)))
            uService.setInUse(
                False
            )  # For accounting, ensure that it is not in use right now
            uService.save()

        ci = uService.getInstance()
        state = ci.destroy()

        UserServiceOpChecker.makeUnique(uService, ci, state)
Exemple #7
0
    def checkAndUpdateState(userService, userServiceInstance, state):
        '''
        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

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

            logger.debug(
                'Updating from {} with updater {} and state {}'.format(
                    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: {0}'.format(e),
                      log.INTERNAL)
            userService.setState(State.ERROR)
            userService.save()
Exemple #8
0
    def checkAndUpdateState(userService, userServiceInstance, state):
        """
        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 from {} with updater {} and state {}'.format(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: {0}'.format(e), log.INTERNAL)
            userService.setState(State.ERROR)
            userService.save(update_fields=['data'])
Exemple #9
0
    def setState(self, state):
        '''
        Updates the state of this object and, optionally, saves it

        Args:
            state: new State to store at record

            save: Defaults to true. If false, record will not be saved to db, just modified

        '''
        logger.debug(' *** Setting state to {} from {} for {}'.format(
            State.toString(state), State.toString(self.state), self))

        if state != self.state:
            self.state_date = getSqlDatetime()
            self.state = state
    def checkAndUpdateState(userService, userServiceInstance, state):
        '''
        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:
            prevState = userService.state
            userService.unique_id = userServiceInstance.getUniqueId()  # Updates uniqueId
            userService.friendly_name = userServiceInstance.getName()  # And name, both methods can modify serviceInstance, so we save it later
            if State.isFinished(state):
                checkLater = False
                userServiceInstance.finish()
                if State.isPreparing(prevState):
                    if userServiceInstance.service().publicationType is None or userService.publication == userService.deployed_service.activePublication():
                        userService.setState(State.USABLE)
                        # and make this usable if os manager says that it is usable, else it pass to configuring state
                        if userServiceInstance.osmanager() is not None and userService.os_state == State.PREPARING:  # If state is already "Usable", do not recheck it
                            stateOs = userServiceInstance.osmanager().checkState(userService)
                            # If state is finish, we need to notify the userService again that os has finished
                            if State.isFinished(stateOs):
                                state = userServiceInstance.notifyReadyFromOsManager('')
                                userService.updateData(userServiceInstance)
                        else:
                            stateOs = State.FINISHED

                        if State.isRuning(stateOs):
                            userService.setOsState(State.PREPARING)
                        else:
                            userService.setOsState(State.USABLE)
                    else:
                        # We ignore OsManager info and if userService don't belong to "current" publication, mark it as removable
                        userService.setState(State.REMOVABLE)
                elif State.isRemoving(prevState):
                    if userServiceInstance.osmanager() is not None:
                        userServiceInstance.osmanager().release(userService)
                    userService.setState(State.REMOVED)
                else:
                    # Canceled,
                    logger.debug("Canceled us {2}: {0}, {1}".format(prevState, State.toString(state), State.toString(userService)))
                    userService.setState(State.CANCELED)
                    userServiceInstance.osmanager().release(userService)
                userService.updateData(userServiceInstance)
            elif State.isErrored(state):
                checkLater = False
                userService.updateData(userServiceInstance)
                userService.setState(State.ERROR)
            else:
                checkLater = True  # The task is running
                userService.updateData(userServiceInstance)
            userService.save()
            if checkLater:
                UserServiceOpChecker.checkLater(userService, userServiceInstance)
        except Exception as e:
            logger.exception('Checking service state')
            log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
            userService.setState(State.ERROR)
            userService.save()
Exemple #11
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 updater with state {} and executor {}'.format(State.toString(state), executor))

        try:
            executor()
        except Exception as e:
            self.setError('Exception: {}'.format(e))
Exemple #12
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 updater with state {} and executor {}'.format(State.toString(state), executor))

        try:
            executor()
        except Exception as e:
            self.setError('Exception: {}'.format(e))
Exemple #13
0
    def setState(self, state):
        '''
        Updates the state of this object and, optionally, saves it

        Args:
            state: new State to store at record

            save: Defaults to true. If false, record will not be saved to db, just modified

        '''
        logger.debug(' *** Setting state to {} from {} for {}'.format(State.toString(state), State.toString(self.state), self))

        if state != self.state:
            self.state_date = getSqlDatetime()
            self.state = state
    def remove(self, uService):
        '''
        Removes a uService element
        @return: the uService removed (marked for removal)
        '''
        with transaction.atomic():
            uService = UserService.objects.select_for_update().get(id=uService.id)
            logger.debug('Removing uService {0}'.format(uService))
            if uService.isUsable() is False and State.isRemovable(uService.state) is False:
                raise OperationException(_('Can\'t remove a non active element'))
            uService.setState(State.REMOVING)
            logger.debug("***** The state now is {}".format(State.toString(uService.state)))
            uService.setInUse(False)  # For accounting, ensure that it is not in use right now
            uService.save()

        ci = uService.getInstance()
        state = ci.destroy()

        UserServiceOpChecker.makeUnique(uService, ci, state)
 def __str__(self):
     return 'Publication {0}, rev {1}, state {2}'.format(self.deployed_service.name, self.revision, State.toString(self.state))
Exemple #16
0
    def checkAndUpdateState(userService, userServiceInstance, state):
        '''
        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:
            prevState = userService.state
            userService.unique_id = userServiceInstance.getUniqueId(
            )  # Updates uniqueId
            userService.friendly_name = userServiceInstance.getName(
            )  # And name, both methods can modify serviceInstance, so we save it later
            if State.isFinished(state):
                checkLater = False
                userServiceInstance.finish()
                if State.isPreparing(prevState):
                    if userServiceInstance.service(
                    ).publicationType is None or userService.publication == userService.deployed_service.activePublication(
                    ):
                        userService.setState(State.USABLE)
                        # and make this usable if os manager says that it is usable, else it pass to configuring state
                        if userServiceInstance.osmanager(
                        ) is not None and userService.os_state == State.PREPARING:  # If state is already "Usable", do not recheck it
                            stateOs = userServiceInstance.osmanager(
                            ).checkState(userService)
                            # If state is finish, we need to notify the userService again that os has finished
                            if State.isFinished(stateOs):
                                state = userServiceInstance.notifyReadyFromOsManager(
                                    '')
                                userService.updateData(userServiceInstance)
                        else:
                            stateOs = State.FINISHED

                        if State.isRuning(stateOs):
                            userService.setOsState(State.PREPARING)
                        else:
                            userService.setOsState(State.USABLE)
                    else:
                        # We ignore OsManager info and if userService don't belong to "current" publication, mark it as removable
                        userService.setState(State.REMOVABLE)
                elif State.isRemoving(prevState):
                    if userServiceInstance.osmanager() is not None:
                        userServiceInstance.osmanager().release(userService)
                    userService.setState(State.REMOVED)
                else:
                    # Canceled,
                    logger.debug("Canceled us {2}: {0}, {1}".format(
                        prevState, State.toString(state),
                        State.toString(userService)))
                    userService.setState(State.CANCELED)
                    userServiceInstance.osmanager().release(userService)
                userService.updateData(userServiceInstance)
            elif State.isErrored(state):
                checkLater = False
                userService.updateData(userServiceInstance)
                userService.setState(State.ERROR)
            else:
                checkLater = True  # The task is running
                userService.updateData(userServiceInstance)
            userService.save()
            if checkLater:
                UserServiceOpChecker.checkLater(userService,
                                                userServiceInstance)
        except Exception as e:
            logger.exception('Checking service state')
            log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e),
                      log.INTERNAL)
            userService.setState(State.ERROR)
            userService.save()
Exemple #17
0
 def running(self):
     self.setError('Unknown running transition from {}'.format(State.toString(self.userService.state)))
Exemple #18
0
 def running(self):
     self.setError('Unknown running transition from {}'.format(
         State.toString(self.userService.state)))
Exemple #19
0
 def __str__(self):
     return "User service {0}, cache_level {1}, user {2}, name {3}, state {4}:{5}".format(
         self.id, self.cache_level, self.user, self.friendly_name,
         State.toString(self.state), State.toString(self.os_state))
 def __str__(self):
     return 'Publication {0}, rev {1}, state {2}'.format(
         self.deployed_service.name, self.revision,
         State.toString(self.state))