Beispiel #1
0
 def __init__(self):
     QMainWindow.__init__(self)
     self.setupGUI()
     self.job_monitor = HadoopJobMonitor()
Beispiel #2
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupGUI()
        self.job_monitor = HadoopJobMonitor()

    def setupGUI(self):
        layout = QGridLayout()
        self.widget = QWidget()
        self.widget.setLayout(layout)
        self.setCentralWidget(self.widget)
        self.setWindowTitle("Nutch Job Service")

        # create active job list
        active_label = QLabel("Active Hadoop Jobs")
        layout.addWidget(active_label, 0, 0)
        self.lv = QListView()
        layout.addWidget(self.lv, 1, 0, 3, 1)

        # Create buttons
        self.stop_button = QPushButton("Stop")
        self.refresh_button = QPushButton("Refresh")
        button_layout = QVBoxLayout()
        button_layout.addWidget(self.stop_button)
        button_layout.addWidget(self.refresh_button)

        layout.addLayout(button_layout, 1, 1)

        # Start Button
        self.new_job_layout = QHBoxLayout()
        self.new_job_combo = QComboBox()
        self.new_job_combo.addItems(["Inject", "Generate", "Fetch", "Parse", "Solr"])
        self.new_job_button = QPushButton("Start New Job")
        self.new_job_layout.addWidget(self.new_job_combo)
        self.new_job_layout.addWidget(self.new_job_button)
        layout.addLayout(self.new_job_layout, 5, 0)

        # self.statusBar()
        self.connectSlots()

    def load_data(self):
        """
        Loads data from the hadoop job list.
        """

        self.showStatusMessage("Fetching Hadoop job list...")
        print "Loading data..."
        self.job_monitor.fetch_hadoop_job_info()
        self.job_list_model = JobListModel(self.job_monitor, self)
        self.lv.setModel(self.job_list_model)
        self.updateStatusBar()

    def start_new_nob(self):
        """
        Starts a new job according to the selected item in combo box.
        """
        current_text = self.new_job_combo.currentText()
        print "Starting %s" % current_text

    def stop_job(self):
        current_item = self.lv.currentIndex().data(0).toString()
        job_object = self.job_list_model.get_job_object(current_item)
        job_object.stop()

    def connectSlots(self):
        """
        Connects signals to slots.
        """
        self.connect(self.refresh_button, SIGNAL("clicked()"), self.load_data)
        self.connect(self.stop_button, SIGNAL("clicked()"), self.stop_job)
        self.connect(self.new_job_button, SIGNAL("clicked()"), self.start_new_nob)

    def showStatusMessage(self, message):
        self.statusBar().showMessage(message)

    def updateStatusBar(self):
        """
        Updates status bar according to the number of active hadoop jobs.
        """
        self.statusBar().showMessage("%s jobs are active." % self.job_monitor.num_jobs)