Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
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()