Exemple #1
0
    def start_button_callback(self, check_state, comp, failed_name):
        """Handles the signal for a finished component start displaying user information on a fail.

        :param check_state: Status of the component check run after the start
        :type check_state: int
        :param comp: Component that was started
        :type comp: dict
        :param failed_name: Name of a dependency that failed during the start process (dummy if none failed)
        :type failed_name: str
        :return: None
        """

        try:
            start_state = config.StartState(check_state)
        except ValueError:
            start_state = None

        try:
            check_state = config.CheckState(check_state)
        except ValueError:
            check_state = None

        msg = QtGui.QMessageBox()
        if check_state is config.CheckState.DEP_FAILED:
            msg.setIcon(QtGui.QMessageBox.Warning)
            msg.setText("Start process of '%s' was interrupted" % comp['id'])
            msg.setInformativeText("Dependency '%s' failed!" % failed_name)
            msg.setWindowTitle("Warning")
            msg.setStandardButtons(QtGui.QMessageBox.Retry
                                   | QtGui.QMessageBox.Cancel)
            self.logger.debug(
                "Warning, start process of '%s' was interrupted. Dependency '%s' failed!"
                % (comp['id'], failed_name))
            retval = msg.exec_()

            if retval == QtGui.QMessageBox.Retry:
                self.handle_start_button(comp)

        elif check_state is config.CheckState.STOPPED:
            msg.setIcon(QtGui.QMessageBox.Warning)
            msg.setText("Failed starting '%s'" % comp['id'])
            msg.setWindowTitle("Warning")
            msg.setStandardButtons(QtGui.QMessageBox.Retry
                                   | QtGui.QMessageBox.Cancel)
            retval = msg.exec_()

            if retval == QtGui.QMessageBox.Retry:
                self.handle_start_button(comp)
        elif start_state is config.StartState.ALREADY_RUNNING:
            self.logger.debug("Component '%s' already running!" % comp['id'])
            msg.setIcon(QtGui.QMessageBox.Warning)
            msg.setText("Component '%s' already running!" % comp['id'])
            msg.setWindowTitle("Warning")
            msg.setStandardButtons(QtGui.QMessageBox.Ok)
            msg.exec_()
        else:
            self.logger.debug("Starting '%s' succeeded without interference" %
                              comp['id'])
            return
Exemple #2
0
    def check_button_callback(self, check_state, comp_name, popup):
        """Handles the signal for a finished component check execution displaying user information on a fail.

        :param check_state: Status returned by the component check
        :type check_state: int
        :param comp_name: Name of the checked component
        :type comp_name: str
        :return: None
        """

        check_state = config.CheckState(check_state)
        check_button = self.centralwidget.findChild(
            QtGui.QPushButton, "check_button_%s" % comp_name)

        check_button.setStyleSheet(
            "background-color: %s" %
            config.STATE_CHECK_BUTTON_STYLE.get(check_state))

        check_button.setEnabled(True)

        if self.animations.has_key("start_%s" % comp_name):
            self.animations.pop("start_%s" % comp_name).stop()
            start_button = self.centralwidget.findChild(
                QtGui.QPushButton, "start_button_%s" % comp_name)
            start_button.setColor(QtGui.QColor(255, 255, 255))
            start_button.setEnabled(True)

        if self.animations.has_key("check_%s" % comp_name):
            self.animations.pop("check_%s" % comp_name).stop()
            check_button.setColor(QtGui.QColor(255, 255, 255))

        if self.animations.has_key("stop_%s" % comp_name):
            self.animations.pop("stop_%s" % comp_name).stop()
            stop_button = self.centralwidget.findChild(
                QtGui.QPushButton, "stop_button_%s" % comp_name)
            stop_button.setColor(QtGui.QColor(255, 255, 255))
            stop_button.setEnabled(True)

        if popup:
            if check_state is config.CheckState.NOT_INSTALLED or check_state is config.CheckState.UNREACHABLE:
                msg = QtGui.QMessageBox()
                msg.setIcon(QtGui.QMessageBox.Critical)
                msg.setText(
                    "'%s' failed with status: %s" %
                    (comp_name, config.STATE_DESCRIPTION.get(check_state)))
                msg.setWindowTitle("Error")
                msg.setStandardButtons(QtGui.QMessageBox.Close)
                msg.exec_()
Exemple #3
0
    def handle_crash_signal(self, check_status, comp_name, unused):
        """Handler for a crash signal event that informs the user of a component crash.

        :param check_status: Status generated by the check of the crashed component
        :type check_status: int
        :param comp_name: Name of the crashed component
        :type comp_name: str
        :return: None
        """
        check_status = config.CheckState(check_status)
        if check_status is config.CheckState.STOPPED:
            msg = QtGui.QMessageBox()
            msg.setIcon(QtGui.QMessageBox.Critical)
            msg.setText("Component '%s' crashed!" % comp_name)
            msg.setWindowTitle("Error")
            msg.setStandardButtons(QtGui.QMessageBox.Close)

            msg.exec_()

            self.logger.debug("Component %s stopped!" % comp_name)
Exemple #4
0
def refresh(_loop, state_controller, _data=None):
    """Update Hyperion logger and set an automatic trigger for .5 seconds.

    :param _loop: Urwid main loop
    :param _data:
    :param state_controller: Reference to UI manager
    :type state_controller: StateController
    :return: None
    """

    logger = logging.getLogger(__name__)
    if state_controller.tail_log:
        state_controller.log_viewer.read_file()
        state_controller.log_viewer.set_focus(len(state_controller.log_viewer.lines)-1)

    # Get selected log, if one is selected
    selection, index = state_controller.content_walker.get_focus()
    selected = None
    if isinstance(selection, urwid.GridFlow):
        index = state_controller.additional_content_grid.focus_position
        if index > 0: # Not 'All Components/Host Stats' Pile in Grid flow
            # Grants LogTextWalker
            selected = state_controller.additional_content_grid[index].body

    for log_name in state_controller.comp_log_map:
        widget = state_controller.comp_log_map.get(log_name)
        if widget:
            # AttrMap -> LineBox -> BoxAdapter -> ListBox -> LogTextWalker
            log = widget.original_widget.original_widget.original_widget.body
            log.read_file()
            if log is not selected:
                log.set_focus(len(log.lines)-1)

    event_queue = state_controller.event_queue
    while not event_queue.empty():
        event = event_queue.get_nowait()

        # logger.debug("Got event: %s" % event)

        if isinstance(event, events.CheckEvent):
            logger.debug("Check event - comp %s; state %s" % (event.comp_id, event.check_state))
            state_controller.states[event.comp_id].set_text([
                "state: ",
                (
                    '%s' % config.URWID_ATTRIBUTE_FOR_STATE.get(config.CheckState(event.check_state)),
                    "%s" % config.SHORT_STATE_DESCRIPTION.get(config.CheckState(event.check_state))
                )
            ])
        elif isinstance(event, events.StartingEvent):
            state_controller.states[event.comp_id].set_text([
                "state: STARTING..."
            ])
        elif isinstance(event, events.StoppingEvent):
            state_controller.states[event.comp_id].set_text([
                "state: STOPPING..."
            ])
        elif isinstance(event, events.CrashEvent):
            logger.warning("Component %s crashed!" % event.comp_id)
            state_controller.cc.check_component(state_controller.cc.get_component_by_id(event.comp_id))
            state_controller.states[event.comp_id].set_text([
                "state: ",
                ('darkred', "CRASHED")
            ])
        elif isinstance(event, events.SlaveReconnectEvent):
            logger.warn("Reconnected to slave on '%s'" % event.host_name)
            state_controller.fetch_host_items()
        elif isinstance(event, events.SlaveDisconnectEvent):
            logger.warn("Connection to slave on '%s' lost" % event.host_name)
            state_controller.fetch_host_items()
        elif isinstance(event, events.DisconnectEvent):
            logger.warning("Lost connection to host '%s'" % event.host_name)
            state_controller.fetch_host_items()
        elif isinstance(event, events.ReconnectEvent):
            logger.info("Reconnected to host '%s'" % event.host_name)
            state_controller.fetch_host_items()
        elif isinstance(event, events.StartReportEvent):
            state_controller.start_report_popup(event)
        elif isinstance(event, events.ServerDisconnectEvent):
            logger.critical("Server disconnected!")
            state_controller.handle_shutdown(None, False)
            # TODO: Show custom popup with option to quit or cancel
        elif isinstance(event, events.ConfigReloadEvent):
            state_controller.load_groups_from_config()
            state_controller.selected_group = state_controller.groups.keys()[0]
            state_controller.fetch_host_items()
            state_controller.fetch_components()
        elif isinstance(event, events.StatResponseEvent):
            state_controller.cc.host_stats[event.hostname] = ['%s' % event.load, '%s' % event.cpu, '%s' % event.mem]
            state_controller.fetch_host_items()
        else:
            logger.debug("Got unrecognized event of type: %s" % type(event))

    main_loop.set_alarm_in(.2, refresh, state_controller)
 def __str__(self):
     return str("CheckEvent - %s: %s" % (self.comp_id, config.STATE_DESCRIPTION.get(config.CheckState(
         self.check_state
     ))))