Beispiel #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
Beispiel #2
0
    def checkAndUpdateState(publication: ServicePoolPublication,
                            publicationInstance: 'services.Publication',
                            state: str) -> None:
        """
        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: str = publication.state
            checkLater: bool = False
            if State.isFinished(state):
                # Now we mark, if it exists, the previous usable publication as "Removable"
                if State.isPreparing(prevState):
                    old: ServicePoolPublication
                    for old in publication.deployed_service.publications.filter(
                            state=State.USABLE):
                        old.setState(State.REMOVABLE)

                        osm = publication.deployed_service.osmanager
                        # If os manager says "machine is persistent", do not tray to delete "previous version" assigned machines
                        doPublicationCleanup = True if osm is None else not osm.getInstance(
                        ).isPersistent()

                        if doPublicationCleanup:
                            pc = PublicationOldMachinesCleaner(old.id)
                            pc.register(
                                GlobalConfig.SESSION_EXPIRE_TIME.getInt(True) *
                                3600, 'pclean-' + str(old.id), True)
                            publication.deployed_service.markOldUserServicesAsRemovables(
                                publication)
                        else:  # Remove only cache services, not assigned
                            publication.deployed_service.markOldUserServicesAsRemovables(
                                publication, True)

                    publication.setState(State.USABLE)
                elif State.isRemoving(prevState):
                    publication.setState(State.REMOVED)
                else:  # State is canceling
                    publication.setState(State.CANCELED)
                # Mark all previous publications deployed services as removables
                # and make this usable
                publicationInstance.finish()
                publication.updateData(publicationInstance)
            elif State.isErrored(state):
                publication.updateData(publicationInstance)
                publication.setState(State.ERROR)
            else:
                checkLater = True  # The task is running
                publication.updateData(publicationInstance)

            if checkLater:
                PublicationFinishChecker.checkLater(publication,
                                                    publicationInstance)
        except Exception:
            logger.exception('At checkAndUpdate for publication')
            PublicationFinishChecker.checkLater(publication,
                                                publicationInstance)
Beispiel #3
0
 def isPreparing(self) -> bool:
     """
     Returns if this service is in preparation (not ready to use, but in its way to be so...)
     """
     return State.isPreparing(self.state)