Beispiel #1
0
    def __init__(self):
        self.style = {"description_width": "initial"}
        self.bars = {}
        self.labels = {}
        self.last_job = None

        self.progressbars = VBox([])

        cancel_button = Button(button_style="", tooltip="Cancel Spark Job", icon="window-close")
        cancel_button.add_class("db-button")

        toggle_button = Button(
            button_style="", tooltip="Toggle progress bar", icon="arrow-circle-right"
        )
        toggle_button.add_class("db-button")
        toggle_button.on_click(self._toggle(self.progressbars))

        self.indicator = HBox([toggle_button, self.progressbars])
        self.progressbar_showing = False
Beispiel #2
0
    def worker(self):
        def cancel(b):
            self.sc.cancelJobGroup(self.job_info.group_id)

        def toggle(widget):
            def f(b):
                for w in widget.children:
                    h = w.layout.height
                    if h is None or h == "16px":
                        w.layout.height = "0px"
                        b.icon = "arrow-circle-down"
                    else:
                        w.layout.height = "16px"
                        b.icon = "arrow-circle-right"

            return f

        style = {"description_width": "initial"}
        bars = {}
        labels = {}
        lastJob = None

        progressbars = VBox([])

        cancel_button = Button(button_style="",
                               tooltip="Cancel Spark Job",
                               icon="window-close")
        cancel_button.add_class("db-button")
        cancel_button.on_click(cancel)

        toggle_button = Button(button_style="",
                               tooltip="Toggle progress bar",
                               icon="arrow-circle-right")
        toggle_button.add_class("db-button")
        toggle_button.on_click(toggle(progressbars))

        indicator = HBox([toggle_button, progressbars])

        while self.running == 1:
            time.sleep(0.2)
            jobs = [(jobid, self.tracker.getJobInfo(jobid)) for jobid in
                    self.tracker.getJobIdsForGroup(self.job_info.group_id)
                    if self.tracker.getJobInfo(jobid).status == "RUNNING"]

            for j, job in jobs:
                if bars.get(j, None) is None:
                    if lastJob is not None:
                        bars[lastJob].value = 100.0
                    bars[j] = FloatProgress(
                        value=0.0,
                        min=0.0,
                        max=100.0,
                        description="Job: %04d Stage: %04d" % (j, 0),
                        bar_style="info",
                        orientation="horizontal",
                        style=style,
                    )
                    bars[j].add_class("db-bar")
                    labels[j] = Label(
                        value="",
                        description="Code:",
                        disabled=False,
                        layout=Layout(width="800px",
                                      height="100%",
                                      margin="0 0 0 5px"),
                    )
                    labels[j].add_class("db-label")

                    progressbar = HBox([bars[j], labels[j]])
                    progressbars.children = progressbars.children + (
                        progressbar, )
                    if not self.progressbar_showing:
                        self.progressbar_showing = True
                        display(indicator)

                lastJob = j
                stageIds = sorted(job.stageIds)
                for s in stageIds:
                    stageInfo = self.tracker.getStageInfo(s)
                    bars[j].description = "Job: %04d Stage: %04d" % (j, s)
                    labels[j].value = "code: '%s' / stages: %s" % (
                        stageInfo.name,
                        str(stageIds)[1:-1],
                    )
                    if stageInfo.numActiveTasks > 0:
                        progress = int(100 * stageInfo.numCompletedTasks /
                                       stageInfo.numTasks)
                        bars[j].value = progress

        if lastJob is not None and self.running == 0:
            bars[lastJob].value = 100.0