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:
         if State.isFinished(state):
             checkLater = False
             userServiceInstance.finish()
             userService.updateData(userServiceInstance)
             userService.setState(State.USABLE)  # Wi will only migrate fully functional services
         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:
             ClusterMigrationTask.checkLater(userService, userServiceInstance)
     except Exception as e:
         logger.exception('Migrating service')
         log.doLog(userService, log.ERROR, 'Exception: {0}'.format(e), log.INTERNAL)
         userService.setState(State.ERROR)
         userService.save()
Ejemplo n.º 2
0
 def getItems(self, parent, item):
     return [{
         'id': i.uuid,
         'revision': i.revision,
         'publish_date': i.publish_date,
         'state': i.state,
         'reason': State.isErrored(i.state) and i.getInstance().reasonOfError() or '',
         'state_date': i.state_date,
     } for i in parent.publications.all()]
Ejemplo n.º 3
0
 def getItems(self, parent, item):
     return [{
         'id': i.uuid,
         'revision': i.revision,
         'publish_date': i.publish_date,
         'state': i.state,
         'reason': State.isErrored(i.state) and i.getInstance().reasonOfError() or '',
         'state_date': i.state_date,
     } for i in parent.publications.all()]
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()
Ejemplo n.º 5
0
 def getItems(self, parent, item):
     return [
         {
             "id": i.uuid,
             "revision": i.revision,
             "publish_date": i.publish_date,
             "state": i.state,
             "reason": State.isErrored(i.state) and i.getInstance().reasonOfError() or "",
             "state_date": i.state_date,
         }
         for i in parent.publications.all()
     ]
Ejemplo n.º 6
0
    def checkAndUpdateState(servicePoolPub, pi, 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 = servicePoolPub.state
            checkLater = False
            if State.isFinished(state):
                # Now we mark, if it exists, the previous usable publication as "Removable"
                if State.isPreparing(prevState):
                    for old in servicePoolPub.deployed_service.publications.filter(
                            state=State.USABLE):
                        old.setstate(State.REMOVABLE)

                        osm = servicePoolPub.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)

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

            if checkLater:
                PublicationFinishChecker.checkLater(servicePoolPub, pi)
        except Exception:
            logger.exception('At checkAndUpdate for publication')
            PublicationFinishChecker.checkLater(servicePoolPub, pi)
Ejemplo n.º 7
0
    def checkAndUpdateState(servicePoolPub, pi, 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 = servicePoolPub.state
            checkLater = False
            if State.isFinished(state):
                # Now we mark, if it exists, the previous usable publication as "Removable"
                if State.isPreparing(prevState):
                    for old in servicePoolPub.deployed_service.publications.filter(state=State.USABLE):
                        old.state = State.REMOVABLE
                        old.save()

                        osm = servicePoolPub.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)

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

            servicePoolPub.save()
            if checkLater:
                PublicationFinishChecker.checkLater(servicePoolPub, pi)
        except Exception:
            logger.exception('At checkAndUpdate for publication')
            PublicationFinishChecker.checkLater(servicePoolPub, pi)
Ejemplo n.º 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:
            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()