Skip to content

Conversation

@mgaido91
Copy link
Contributor

What changes were proposed in this pull request?

As suggested in #20651, the code is very redundant in AllStagesPage and modifying it is a copy-and-paste work. We should avoid such a pattern, which is error prone, and have a cleaner solution which avoids code redundancy.

How was this patch tested?

existing UTs

@mgaido91
Copy link
Contributor Author

cc @vanzin

@SparkQA
Copy link

SparkQA commented Feb 23, 2018

Test build #87631 has finished for PR 20663 at commit d246df2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor

vanzin commented Feb 23, 2018

Could you file a separate bug for this cleanup? Thx

@mgaido91
Copy link
Contributor Author

@vanzin sure, thanks. I am creating a new JIRA. Thank you.

@mgaido91 mgaido91 changed the title [SPARK-23475][UI][FOLLOWUP] Refactor AllStagesPage in order to avoid redundant code [SPARK-23501][UI] Refactor AllStagesPage in order to avoid redundant code Feb 23, 2018
/** Page showing list of all ongoing and recently finished stages and pools */
private[ui] class AllStagesPage(parent: StagesTab) extends WebUIPage("") {
private val sc = parent.sc
private lazy val allStages = parent.store.stageList(null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the class (AllStagesPage) is only instantiated once, and the render method is called for each request. So this won't really work.

</div>
}

private def tableHeaderID(status: StageStatus): String = status match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these look very similar. Having a single one that does the mapping and have the others call that method would be nice.

e.g.

def stageTag(status: StageStatus) = s"${statusName(status)}Stage"

Then you could also get rid of classSuffix, for example, since it's only really called in one place, and the new implementation would be much simpler.


private def summaryContent(status: StageStatus, size: Int): String = {
if (status == StageStatus.COMPLETE
&& appSummary.numCompletedStages != size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fits in previous line.

</li>

if (status == StageStatus.COMPLETE) {
summary % Attribute(None, "id", Text("completed-summary"), Null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous code this was also the case for SKIPPED, are you changing that intentionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I realized it while doing the refactor. It was a copy-and-paste mistake, sorry.

{pendingStagesTable.toNodeSeq}
</div>

tables.flatten.foreach(content ++= _)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content ++= tables.flatten?

But I think this would be better as:

val summary = blah
val pools = if (sc.isDefined && isFairScheduler) ... else ...
val stages = tables.flatten

val content = summary ++ pools ++ stages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that won't really works, since tables.flatten is a Seq[NodeSeq]. But I'll try and do something similar.

@jiangxb1987
Copy link
Contributor

@gengliangwang Mind take a look?

@SparkQA
Copy link

SparkQA commented Feb 26, 2018

Test build #87670 has finished for PR 20663 at commit 9a8e032.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@mgaido91
Copy link
Contributor Author

Jenkins, retest this please

Copy link
Contributor

@vanzin vanzin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one minor nit.

private def table(
appSummary: AppSummary,
status: StageStatus,
stagesTable: StageTableBase, size: Int): NodeSeq = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: size goes in next line

@SparkQA
Copy link

SparkQA commented Feb 26, 2018

Test build #87676 has finished for PR 20663 at commit 9a8e032.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

s"${appSummary.numCompletedStages}, only showing ${completedStages.size}"
}

val (summaries, tables) = allStatuses.map(
Copy link
Member

@gengliangwang gengliangwang Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have two separate functions for getting summaries and tables? So that the code is more straight forward.

Overall LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is some (few) logic which is common to the two (ie. when they are empty), I chose this approach in order to avoid redundancy and enforce coherence. But I am fine also having two separate functions. What do you think @vanzin ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current version is fine. It avoids filtering a potentially long list of stages twice.

@SparkQA
Copy link

SparkQA commented Feb 27, 2018

Test build #87717 has finished for PR 20663 at commit a5c2f2f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@mgaido91
Copy link
Contributor Author

Jenkins, retest this please

@SparkQA
Copy link

SparkQA commented Feb 27, 2018

Test build #87728 has finished for PR 20663 at commit a5c2f2f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor

vanzin commented Feb 27, 2018

Merging to master.

@asfgit asfgit closed this in 598446b Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants