def updateJob(self, job): item = self.__jobs[job.id] item.setData(0, JOB_ROLE, job) item.setText(2, "%02d" % job.totals.running) item.setText(3, "%02d" % job.totals.waiting) item.setText(4, "%02d" % job.minCores) item.setText(5, formatMaxValue(job.maxCores)) item.setText(6, formatMaxValue(job.stats.highRam)) item.setText(7, formatDuration(job.startTime, job.stopTime)) item.setToolTip(7, "Started: %s\nStopped:%s" % (formatDateTime(job.startTime), formatDateTime(job.stopTime))) self.__tree.itemWidget(item, len(self.HEADER)-1).setTotals(job.totals) self.__setJobStateAndColor(item)
def addJob(self, job): if self.__jobs.has_key(job.id): return False item = QtGui.QTreeWidgetItem([ job.name, "", "%02d" % job.totals.running, "%02d" % job.totals.waiting, "%02d" % job.minCores, formatMaxValue(job.maxCores), formatDuration(job.startTime, job.stopTime) ]) self.__jobs[job.id] = item item.setToolTip( 6, "Started: %s\nStopped:%s" % (formatDateTime(job.startTime), formatDateTime(job.stopTime))) item.setData(0, JOBID_ROLE, job.id) item.setData(0, JOB_ROLE, job) self.__tree.addTopLevelItem(item) progress = JobProgressBar(job.totals, self.__tree) self.__tree.setItemWidget(item, len(self.Header) - 1, progress) self.__setJobStateAndColor(item) return True
def addJob(self, job): if self.__jobs.has_key(job.id): return False item = QtGui.QTreeWidgetItem([ job.name, "", "%02d" % job.totals.running, "%02d" % job.totals.waiting, "%02d" % job.minCores, formatMaxValue(job.maxCores), formatDuration(job.startTime, job.stopTime) ]) self.__jobs[job.id] = item item.setToolTip(6, "Started: %s\nStopped:%s" % (formatDateTime(job.startTime), formatDateTime(job.stopTime))) item.setData(0, JOBID_ROLE, job.id) item.setData(0, JOB_ROLE, job) self.__tree.addTopLevelItem(item) progress = JobProgressBar(job.totals, self.__tree) self.__tree.setItemWidget(item, len(self.Header)-1, progress); self.__setJobStateAndColor(item) return True
def updateJob(self, job): item = self.__jobs[job.id] item.setData(0, JOB_ROLE, job) item.setText(2, "%02d" % job.totals.running) item.setText(3, "%02d" % job.totals.waiting) item.setText(4, "%02d" % job.minCores) item.setText(5, formatMaxValue(job.maxCores)) item.setText(6, formatMaxValue(job.stats.highRam)) item.setText(7, formatDuration(job.startTime, job.stopTime)) item.setToolTip( 7, "Started: %s\nStopped:%s" % (formatDateTime(job.startTime), formatDateTime(job.stopTime))) self.__tree.itemWidget(item, len(self.HEADER) - 1).setTotals(job.totals) self.__setJobStateAndColor(item)
def addJob(self, job): if self.__jobs.has_key(job.id): return False item = QtGui.QTreeWidgetItem([ job.name, "", "%02d" % job.totals.running, "%02d" % (job.totals.waiting + job.totals.depend), "%02d" % job.minCores, formatMaxValue(job.maxCores), formatMaxValue(job.stats.highRam), formatDuration(job.startTime, job.stopTime) ]) center = QtCore.Qt.AlignCenter for i in xrange(2, item.columnCount()): item.setTextAlignment(i, center) self.__jobs[job.id] = item item.setToolTip(0, job.name) item.setToolTip( 6, "Started: %s\nStopped:%s" % (formatDateTime(job.startTime), formatDateTime(job.stopTime))) item.setData(0, JOBID_ROLE, job.id) item.setData(0, JOB_ROLE, job) self.__tree.addTopLevelItem(item) progress = JobProgressBar(job.totals, self.__tree) self.__tree.setItemWidget(item, len(self.HEADER) - 1, progress) self.__setJobStateAndColor(item) return True
def addJob(self, job): if self.__jobs.has_key(job.id): return False item = QtGui.QTreeWidgetItem([ job.name, "", "%02d" % job.totals.running, "%02d" % (job.totals.waiting + job.totals.depend), "%02d" % job.minCores, formatMaxValue(job.maxCores), formatMaxValue(job.stats.highRam), formatDuration(job.startTime, job.stopTime) ]) center = QtCore.Qt.AlignCenter for i in xrange(2, item.columnCount()): item.setTextAlignment(i, center) self.__jobs[job.id] = item item.setToolTip(0, job.name) item.setToolTip(6, "Started: %s\nStopped:%s" % (formatDateTime(job.startTime), formatDateTime(job.stopTime))) item.setData(0, JOBID_ROLE, job.id) item.setData(0, JOB_ROLE, job) self.__tree.addTopLevelItem(item) progress = JobProgressBar(job.totals, self.__tree) self.__tree.setItemWidget(item, len(self.HEADER)-1, progress); self.__setJobStateAndColor(item) return True
class TaskModel(models.PlowTableModel): HEADERS = [ "Name", "State", "Node", "Resources", "Max Resources", "Duration", "Retries", "Log" ] DISPLAY_CALLBACKS = { 0: lambda t: t.name, 1: lambda t: constants.TASK_STATES[t.state], 2: lambda t: t.stats.lastNode, 3: lambda t: "%s/%02dMB" % (t.stats.cores, t.stats.ram), 4: lambda t: "%0.2f/%02dMB" % (t.stats.highCores, t.stats.highRam), 5: lambda t: formatDuration(t.stats.startTime, t.stats.stopTime), 6: lambda t: formatMaxValue(t.stats.retryNum), 7: lambda t: t.stats.lastLogLine, } SORT_CALLBACKS = DISPLAY_CALLBACKS.copy() SORT_CALLBACKS[3] = lambda t: (t.stats.cores, t.stats.ram) SORT_CALLBACKS[4] = lambda t: (t.stats.highCores, t.stats.highRam) SORT_CALLBACKS[5] = lambda t: t.stats.stopTime - t.stats.startTime SORT_CALLBACKS[6] = lambda t: t.stats.retryNum SortRole = models.PlowTableModel.DataRole def __init__(self, parent=None): super(TaskModel, self).__init__(parent) self.__jobId = None self.__lastUpdateTime = 0 # Tasks are updated incrementally, so don't # remove missing ones self.refreshShouldRemove = False # A timer for refreshing duration column. self.__timer = QtCore.QTimer(self) self.__timer.setInterval(1000) self.__timer.timeout.connect(self.__durationRefreshTimer) def fetchObjects(self): if not self.__jobId: return [] opts = {"jobId": self.__jobId} if self.__lastUpdateTime: opts["lastUpdateTime"] = self.__lastUpdateTime t = plow.client.get_plow_time() tasks = plow.client.get_tasks(**opts) self.__lastUpdateTime = t return tasks def getJobId(self): return self.__jobId def setJob(self, jobid): ## Clear out existing tasks. ## TODO make sure to emit right signals self.__timer.stop() self.__jobId = jobid self.__lastUpdateTime = 0 try: tasks = self.fetchObjects() self.setItemList(tasks) finally: self.__timer.start() def refresh(self): if not self.__jobId: return super(TaskModel, self).refresh() def data(self, index, role): row = index.row() col = index.column() if role == QtCore.Qt.TextAlignmentRole: if 0 < col < 6: return QtCore.Qt.AlignCenter task = self._items[row] stats = task.stats BG = QtCore.Qt.BackgroundRole FG = QtCore.Qt.ForegroundRole if col == 1: if role == BG: return constants.COLOR_TASK_STATE[task.state] elif role == FG: if task.state == TaskState.RUNNING: return constants.BLACK else: return constants.WHITE elif role == TaskModel.SortRole: cbk = self.SORT_CALLBACKS.get(col) if cbk is not None: return cbk(task) elif role == QtCore.Qt.ToolTipRole and col == 3: tip = "Allocated Cores: %d\nCurrent CPU Perc:%d\n" \ "Max CPU Perc:%d\nAllocated RAM:%dMB\nCurrent RSS:%dMB\nMaxRSS:%dMB" return tip % (stats.cores, stats.usedCores, stats.highCores, stats.ram, stats.usedRam, stats.highRam) return super(TaskModel, self).data(index, role) def headerData(self, section, orientation, role): if role == QtCore.Qt.ToolTipRole: if section == 3: return "The Cores/Ram that were allocated to the task" elif section == 4: return "The maximum Cores/Ram that this task has used" return super(TaskModel, self).headerData(section, orientation, role) def __durationRefreshTimer(self): RUNNING = plow.client.TaskState.RUNNING for idx, t in enumerate(self._items): if t.state == RUNNING: self.dataChanged.emit(self.index(idx, 4), self.index(idx, 4))