scala.xml.Text Scala Examples
The following examples show how to use scala.xml.Text.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: ExecutorThreadDumpPage.scala From drizzle-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import javax.servlet.http.HttpServletRequest import scala.xml.{Node, Text} import org.apache.spark.ui.{UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage(parent: ExecutorsTab) extends WebUIPage("threadDump") { private val sc = parent.sc def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(request.getParameter("executorId")).map { executorId => UIUtils.decodeURLParameter(executorId) }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.sortWith { case (threadTrace1, threadTrace2) => val v1 = if (threadTrace1.threadName.contains("Executor task launch")) 1 else 0 val v2 = if (threadTrace2.threadName.contains("Executor task launch")) 1 else 0 if (v1 == v2) { threadTrace1.threadName.toLowerCase < threadTrace2.threadName.toLowerCase } else { v1 > v2 } }.map { thread => val threadId = thread.threadId <tr id={s"thread_${threadId}_tr"} class="accordion-heading" onclick={s"toggleThreadStackTrace($threadId, false)"} onmouseover={s"onMouseOverAndOut($threadId)"} onmouseout={s"onMouseOverAndOut($threadId)"}> <td id={s"${threadId}_td_id"}>{threadId}</td> <td id={s"${threadId}_td_name"}>{thread.threadName}</td> <td id={s"${threadId}_td_state"}>{thread.threadState}</td> <td id={s"${threadId}_td_stacktrace"} class="hidden">{thread.stackTrace}</td> </tr> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="expandAllThreadStackTrace(true)"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="collapseAllThreadStackTrace(true)"> Collapse All </a></p> <div class="form-inline"> <div class="bs-example" data-example-id="simple-form-inline"> <div class="form-group"> <div class="input-group"> Search: <input type="text" class="form-control" id="search" oninput="onSearchStringChange()"></input> </div> </div> </div> </div> <p></p> // scalastyle:on } <table class={UIUtils.TABLE_CLASS_STRIPED + " accordion-group" + " sortable"}> <thead> <th onClick="collapseAllThreadStackTrace(false)">Thread ID</th> <th onClick="collapseAllThreadStackTrace(false)">Thread Name</th> <th onClick="collapseAllThreadStackTrace(false)">Thread State</th> </thead> <tbody>{dumpRows}</tbody> </table> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 2
Source File: RegexSentenceAnnotator.scala From jigg with Apache License 2.0 | 5 votes |
package jigg.pipeline import java.util.Properties import scala.io.Source import scala.xml.{Node, Elem, Text, Atom} import jigg.util.XMLUtil.RichNode class RegexSentenceAnnotator(override val name: String, override val props: Properties) extends Annotator { @Prop(gloss = "Regular expression to segment lines (if omitted, specified method is used)") var pattern = "" @Prop(gloss = "Use predefined segment pattern newLine|point|pointAndNewLine") var method = "pointAndNewLine" readProps() val splitRegex = pattern match { case "" => method match { case "newLine" => RegexSentenceAnnotator.newLine case "point" => RegexSentenceAnnotator.point case "pointAndNewLine" => RegexSentenceAnnotator.pointAndNewLine case other => argumentError("method") } case pattern => pattern.r } private[this] val sentenceIDGen = jigg.util.IDGenerator("s") override def annotate(annotation: Node): Node = { annotation.replaceAll("document") { e => val line = e.text val sentenceBoundaries = 0 +: splitRegex.findAllMatchIn(line).map(_.end).toVector :+ line.length val sentences: Vector[Node] = sentenceBoundaries.sliding(2).toVector flatMap { case Seq(begin_, end_) => def isSpace(c: Char) = c == ' ' || c == '\t' || c == '\n' val snippet = line.substring(begin_, end_) val begin = snippet.indexWhere(!isSpace(_)) match { case -1 => begin_ // space only case offset => begin_ + offset } val end = snippet.lastIndexWhere(!isSpace(_)) match { case -1 => begin_ case offset => begin_ + offset + 1 } // val sentence: String = line.substring(begin, end).trim() val sentence: String = line.substring(begin, end) if (sentence.isEmpty) None else { Option(<sentence id={ sentenceIDGen.next } characterOffsetBegin={ begin+"" } characterOffsetEnd={ end+"" }>{ sentence }</sentence>) } } // val textRemoved = XMLUtil.removeText(e) // XMLUtil.addChild(textRemoved, <sentences>{ sentences }</sentences>) e addChild <sentences>{ sentences }</sentences> } } override def requires = Set() override def requirementsSatisfied = Set(Requirement.Ssplit) } object RegexSentenceAnnotator extends AnnotatorCompanion[RegexSentenceAnnotator] { val newLine = """\n+""".r val point = """。+""".r val pointAndNewLine = """\n+|。\n*""".r }
Example 3
Source File: SpaceTokenizerAnnotator.scala From jigg with Apache License 2.0 | 5 votes |
package jigg.pipeline class SpaceTokenizerAnnotator(override val name: String, override val props: Properties) extends SentencesAnnotator { override def newSentenceAnnotation(sentence: Node): Node = { val sindex = sentence \@ "id" val text = sentence.text val range = (0 until text.size) def isSpace(c: Char) = c == ' ' || c == '\t' val begins = 0 +: (1 until text.size).filter { i => isSpace(text(i-1)) && !isSpace(text(i)) } val ends = begins map { range indexWhere (i=>isSpace(text(i)), _) match { case -1 => text.size case e => e } } val tokenSeq = begins.zip(ends).zipWithIndex map { case ((b, e), i) => <token id={ sindex + "_tok" + i } form={ text.substring(b, e) } characterOffsetBegin={ b+"" } characterOffsetEnd={ e+"" }/> } val tokens = <tokens annotators={ name }>{ tokenSeq }</tokens> sentence addChild tokens } override def requires = Set(Requirement.Ssplit) override def requirementsSatisfied = Set(Requirement.Tokenize) }
Example 4
Source File: ExecutorThreadDumpPage.scala From sparkoscope with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import javax.servlet.http.HttpServletRequest import scala.xml.{Node, Text} import org.apache.spark.ui.{UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage(parent: ExecutorsTab) extends WebUIPage("threadDump") { private val sc = parent.sc def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(request.getParameter("executorId")).map { executorId => UIUtils.decodeURLParameter(executorId) }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.sortWith { case (threadTrace1, threadTrace2) => val v1 = if (threadTrace1.threadName.contains("Executor task launch")) 1 else 0 val v2 = if (threadTrace2.threadName.contains("Executor task launch")) 1 else 0 if (v1 == v2) { threadTrace1.threadName.toLowerCase < threadTrace2.threadName.toLowerCase } else { v1 > v2 } }.map { thread => val threadId = thread.threadId val blockedBy = thread.blockedByThreadId match { case Some(blockedByThreadId) => <div> Blocked by <a href={s"#${thread.blockedByThreadId}_td_id"}> Thread {thread.blockedByThreadId} {thread.blockedByLock}</a> </div> case None => Text("") } val heldLocks = thread.holdingLocks.mkString(", ") <tr id={s"thread_${threadId}_tr"} class="accordion-heading" onclick={s"toggleThreadStackTrace($threadId, false)"} onmouseover={s"onMouseOverAndOut($threadId)"} onmouseout={s"onMouseOverAndOut($threadId)"}> <td id={s"${threadId}_td_id"}>{threadId}</td> <td id={s"${threadId}_td_name"}>{thread.threadName}</td> <td id={s"${threadId}_td_state"}>{thread.threadState}</td> <td id={s"${threadId}_td_locking"}>{blockedBy}{heldLocks}</td> <td id={s"${threadId}_td_stacktrace"} class="hidden">{thread.stackTrace}</td> </tr> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="expandAllThreadStackTrace(true)"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="collapseAllThreadStackTrace(true)"> Collapse All </a></p> <div class="form-inline"> <div class="bs-example" data-example-id="simple-form-inline"> <div class="form-group"> <div class="input-group"> Search: <input type="text" class="form-control" id="search" oninput="onSearchStringChange()"></input> </div> </div> </div> </div> <p></p> // scalastyle:on } <table class={UIUtils.TABLE_CLASS_STRIPED + " accordion-group" + " sortable"}> <thead> <th onClick="collapseAllThreadStackTrace(false)">Thread ID</th> <th onClick="collapseAllThreadStackTrace(false)">Thread Name</th> <th onClick="collapseAllThreadStackTrace(false)">Thread State</th> <th onClick="collapseAllThreadStackTrace(false)">Thread Locks</th> </thead> <tbody>{dumpRows}</tbody> </table> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 5
Source File: ExecutorThreadDumpPage.scala From SparkCore with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import java.net.URLDecoder import javax.servlet.http.HttpServletRequest import scala.util.Try import scala.xml.{Text, Node} import org.apache.spark.ui.{UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage(parent: ExecutorsTab) extends WebUIPage("threadDump") { private val sc = parent.sc def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(request.getParameter("executorId")).map { executorId => // Due to YARN-2844, "<driver>" in the url will be encoded to "%25253Cdriver%25253E" when // running in yarn-cluster mode. `request.getParameter("executorId")` will return // "%253Cdriver%253E". Therefore we need to decode it until we get the real id. var id = executorId var decodedId = URLDecoder.decode(id, "UTF-8") while (id != decodedId) { id = decodedId decodedId = URLDecoder.decode(id, "UTF-8") } id }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.map { thread => <div class="accordion-group"> <div class="accordion-heading" onclick="$(this).next().toggleClass('hidden')"> <a class="accordion-toggle"> Thread {thread.threadId}: {thread.threadName} ({thread.threadState}) </a> </div> <div class="accordion-body hidden"> <div class="accordion-inner"> <pre>{thread.stackTrace}</pre> </div> </div> </div> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="$('.accordion-body').removeClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="$('.accordion-body').addClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Collapse All </a></p> // scalastyle:on } <div class="accordion">{dumpRows}</div> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 6
Source File: XmlSerialization.scala From ike with Apache License 2.0 | 5 votes |
package org.allenai.ike.index import scala.xml.{ Elem, Node, Text } object XmlSerialization { def xml(text: IndexableText): Elem = { val children = addSpaces(text.sentences map xml) <document>{ children }</document> } def xml(tokens: Seq[IndexableToken]): Elem = { val children = addSpaces(tokens map xml) <sentence>{ children }</sentence> } def xml(token: IndexableToken): Elem = <word pos={ token.pos } lemma={ token.lemma } chunk={ token.chunk }>{ token.word }</word> def addSpaces(elems: Seq[Elem]): Seq[Node] = { val n = elems.size val spaces = List.fill(n)(Text(" ")) for { (elem, space) <- elems.zip(spaces) node <- List(elem, space) } yield node } }
Example 7
Source File: ComplexTypes.scala From incubator-daffodil with Apache License 2.0 | 5 votes |
package org.apache.daffodil.dsom import scala.xml.Node import org.apache.daffodil.dpath.NodeInfo import org.apache.daffodil.api.WarnID import scala.xml.Text import scala.xml.Comment sealed abstract class ComplexTypeBase(xmlArg: Node, parentArg: SchemaComponent) extends SchemaComponentImpl(xmlArg, parentArg) with TypeBase with NonPrimTypeMixin { final override def optRestriction = None final override def optUnion = None final override def typeNode = NodeInfo.Complex requiredEvaluationsIfActivated(modelGroup) final def group = modelGroup final def sequence = group.asInstanceOf[Sequence] final def choice = group.asInstanceOf[Choice] private lazy val <complexType>{ xmlChildren @ _* }</complexType> = xml final lazy val Seq(modelGroup) = { val s = smg schemaDefinitionUnless(s.length == 1, "A complex type must have exactly one model-group element child which is a sequence, choice, or group reference.") s } private lazy val smg = { childrenForTerms.map { xmlChild => ModelGroupFactory(xmlChild, this, 1, false) } } private lazy val childrenForTerms = { xmlChildren.flatMap { xmlChild => { xmlChild match { case <annotation>{ annotationChildren @ _* }</annotation> => { val dais = annotationChildren.find { ai => ai.attribute("source") match { case Some(n) => n.text.contains("ogf") && n.text.contains("dfdl") case _ => false } } if (dais != None) { this.SDW(WarnID.InvalidAnnotationPoint, "complexType is not a valid annotation point. Annotation ignored.") } None } case textNode: Text => None case _: Comment => None case _ => Some(xmlChild) } } } } } final class GlobalComplexTypeDef( xmlArg: Node, schemaDocumentArg: SchemaDocument) extends ComplexTypeBase(xmlArg, schemaDocumentArg) with GlobalNonElementComponentMixin with NestingLexicalMixin { // Nothing needed here. The base class and mixins are providing all the functionality needed. } final class LocalComplexTypeDef(xmlArg: Node, val elementDecl: ElementDeclMixin) extends ComplexTypeBase(xmlArg, elementDecl) with LocalNonElementComponentMixin with NestingLexicalMixin { // Nothing needed here. The base class and mixins are providing all the functionality needed. }
Example 8
Source File: SimpleTransformationStd.scala From xml-lens with MIT License | 5 votes |
package pl.msitko.xml.bench import java.io.StringWriter import scala.xml.{Elem, Text, XML} object SimpleTransformationStd extends SimpleTransformation { def transform(el: Elem): Elem = { if(el.child.size == 1) { val replaceWith = el.child.head match { case t: Text => Text(t.text.toUpperCase) case a => a } el.copy(child = List(replaceWith)) } else { el } } override def transform(input: String): String = { val xml = XML.loadString(input) val transformed = xml.map { case el: Elem if el.label == "a" => el.copy(child = el.child.flatMap { case el: Elem if el.label == "interesting" => el.copy(child = el.child.flatMap { case el: Elem if el.label == "special" => transform(el) case a => a }) case a => a }) case a => a } val writer = new StringWriter XML.write(writer, transformed.head, "UTF-8", true, null) writer.toString } }
Example 9
Source File: ExecutorThreadDumpPage.scala From multi-tenancy-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import javax.servlet.http.HttpServletRequest import scala.xml.{Node, Text} import org.apache.spark.ui.{UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage(parent: ExecutorsTab) extends WebUIPage("threadDump") { private val sc = parent.sc def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(request.getParameter("executorId")).map { executorId => UIUtils.decodeURLParameter(executorId) }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.sortWith { case (threadTrace1, threadTrace2) => val v1 = if (threadTrace1.threadName.contains("Executor task launch")) 1 else 0 val v2 = if (threadTrace2.threadName.contains("Executor task launch")) 1 else 0 if (v1 == v2) { threadTrace1.threadName.toLowerCase < threadTrace2.threadName.toLowerCase } else { v1 > v2 } }.map { thread => val threadId = thread.threadId val blockedBy = thread.blockedByThreadId match { case Some(blockedByThreadId) => <div> Blocked by <a href={s"#${thread.blockedByThreadId}_td_id"}> Thread {thread.blockedByThreadId} {thread.blockedByLock}</a> </div> case None => Text("") } val heldLocks = thread.holdingLocks.mkString(", ") <tr id={s"thread_${threadId}_tr"} class="accordion-heading" onclick={s"toggleThreadStackTrace($threadId, false)"} onmouseover={s"onMouseOverAndOut($threadId)"} onmouseout={s"onMouseOverAndOut($threadId)"}> <td id={s"${threadId}_td_id"}>{threadId}</td> <td id={s"${threadId}_td_name"}>{thread.threadName}</td> <td id={s"${threadId}_td_state"}>{thread.threadState}</td> <td id={s"${threadId}_td_locking"}>{blockedBy}{heldLocks}</td> <td id={s"${threadId}_td_stacktrace"} class="hidden">{thread.stackTrace}</td> </tr> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="expandAllThreadStackTrace(true)"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="collapseAllThreadStackTrace(true)"> Collapse All </a></p> <div class="form-inline"> <div class="bs-example" data-example-id="simple-form-inline"> <div class="form-group"> <div class="input-group"> Search: <input type="text" class="form-control" id="search" oninput="onSearchStringChange()"></input> </div> </div> </div> </div> <p></p> // scalastyle:on } <table class={UIUtils.TABLE_CLASS_STRIPED + " accordion-group" + " sortable"}> <thead> <th onClick="collapseAllThreadStackTrace(false)">Thread ID</th> <th onClick="collapseAllThreadStackTrace(false)">Thread Name</th> <th onClick="collapseAllThreadStackTrace(false)">Thread State</th> <th onClick="collapseAllThreadStackTrace(false)">Thread Locks</th> </thead> <tbody>{dumpRows}</tbody> </table> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 10
Source File: ExecutorThreadDumpPage.scala From iolap with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import java.net.URLDecoder import javax.servlet.http.HttpServletRequest import scala.util.Try import scala.xml.{Text, Node} import org.apache.spark.ui.{UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage(parent: ExecutorsTab) extends WebUIPage("threadDump") { private val sc = parent.sc def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(request.getParameter("executorId")).map { executorId => // Due to YARN-2844, "<driver>" in the url will be encoded to "%25253Cdriver%25253E" when // running in yarn-cluster mode. `request.getParameter("executorId")` will return // "%253Cdriver%253E". Therefore we need to decode it until we get the real id. var id = executorId var decodedId = URLDecoder.decode(id, "UTF-8") while (id != decodedId) { id = decodedId decodedId = URLDecoder.decode(id, "UTF-8") } id }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.map { thread => <div class="accordion-group"> <div class="accordion-heading" onclick="$(this).next().toggleClass('hidden')"> <a class="accordion-toggle"> Thread {thread.threadId}: {thread.threadName} ({thread.threadState}) </a> </div> <div class="accordion-body hidden"> <div class="accordion-inner"> <pre>{thread.stackTrace}</pre> </div> </div> </div> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="$('.accordion-body').removeClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="$('.accordion-body').addClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Collapse All </a></p> // scalastyle:on } <div class="accordion">{dumpRows}</div> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 11
Source File: ExecutorThreadDumpPage.scala From spark1.52 with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import java.net.URLDecoder import javax.servlet.http.HttpServletRequest import scala.util.Try import scala.xml.{Text, Node} import org.apache.spark.ui.{UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage(parent: ExecutorsTab) extends WebUIPage("threadDump") { private val sc = parent.sc def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(request.getParameter("executorId")).map { executorId => // Due to YARN-2844, "<driver>" in the url will be encoded to "%25253Cdriver%25253E" when // running in yarn-cluster mode. `request.getParameter("executorId")` will return // "%253Cdriver%253E". Therefore we need to decode it until we get the real id. var id = executorId var decodedId = URLDecoder.decode(id, "UTF-8") while (id != decodedId) { id = decodedId decodedId = URLDecoder.decode(id, "UTF-8") } id }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.sortWith { case (threadTrace1, threadTrace2) => { val v1 = if (threadTrace1.threadName.contains("Executor task launch")) 1 else 0 val v2 = if (threadTrace2.threadName.contains("Executor task launch")) 1 else 0 if (v1 == v2) { threadTrace1.threadName.toLowerCase < threadTrace2.threadName.toLowerCase } else { v1 > v2 } } }.map { thread => val threadName = thread.threadName val className = "accordion-heading " + { if (threadName.contains("Executor task launch")) { "executor-thread" } else { "non-executor-thread" } } <div class="accordion-group"> <div class={className} onclick="$(this).next().toggleClass('hidden')"> <a class="accordion-toggle"> Thread {thread.threadId}: {threadName} ({thread.threadState}) </a> </div> <div class="accordion-body hidden"> <div class="accordion-inner"> <pre>{thread.stackTrace}</pre> </div> </div> </div> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="$('.accordion-body').removeClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="$('.accordion-body').addClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Collapse All </a></p> // scalastyle:on } <div class="accordion">{dumpRows}</div> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 12
Source File: ExecutorThreadDumpPage.scala From Spark-2.3.1 with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import java.util.Locale import javax.servlet.http.HttpServletRequest import scala.xml.{Node, Text} import org.apache.spark.SparkContext import org.apache.spark.ui.{SparkUITab, UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage( parent: SparkUITab, sc: Option[SparkContext]) extends WebUIPage("threadDump") { // stripXSS is called first to remove suspicious characters used in XSS attacks def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(UIUtils.stripXSS(request.getParameter("executorId"))).map { executorId => UIUtils.decodeURLParameter(executorId) }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.sortWith { case (threadTrace1, threadTrace2) => val v1 = if (threadTrace1.threadName.contains("Executor task launch")) 1 else 0 val v2 = if (threadTrace2.threadName.contains("Executor task launch")) 1 else 0 if (v1 == v2) { threadTrace1.threadName.toLowerCase(Locale.ROOT) < threadTrace2.threadName.toLowerCase(Locale.ROOT) } else { v1 > v2 } }.map { thread => val threadId = thread.threadId val blockedBy = thread.blockedByThreadId match { case Some(_) => <div> Blocked by <a href={s"#${thread.blockedByThreadId}_td_id"}> Thread {thread.blockedByThreadId} {thread.blockedByLock}</a> </div> case None => Text("") } val heldLocks = thread.holdingLocks.mkString(", ") <tr id={s"thread_${threadId}_tr"} class="accordion-heading" onclick={s"toggleThreadStackTrace($threadId, false)"} onmouseover={s"onMouseOverAndOut($threadId)"} onmouseout={s"onMouseOverAndOut($threadId)"}> <td id={s"${threadId}_td_id"}>{threadId}</td> <td id={s"${threadId}_td_name"}>{thread.threadName}</td> <td id={s"${threadId}_td_state"}>{thread.threadState}</td> <td id={s"${threadId}_td_locking"}>{blockedBy}{heldLocks}</td> <td id={s"${threadId}_td_stacktrace"} class="hidden">{thread.stackTrace}</td> </tr> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="expandAllThreadStackTrace(true)"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="collapseAllThreadStackTrace(true)"> Collapse All </a></p> <div class="form-inline"> <div class="bs-example" data-example-id="simple-form-inline"> <div class="form-group"> <div class="input-group"> Search: <input type="text" class="form-control" id="search" oninput="onSearchStringChange()"></input> </div> </div> </div> </div> <p></p> // scalastyle:on } <table class={UIUtils.TABLE_CLASS_STRIPED + " accordion-group" + " sortable"}> <thead> <th onClick="collapseAllThreadStackTrace(false)">Thread ID</th> <th onClick="collapseAllThreadStackTrace(false)">Thread Name</th> <th onClick="collapseAllThreadStackTrace(false)">Thread State</th> <th onClick="collapseAllThreadStackTrace(false)">Thread Locks</th> </thead> <tbody>{dumpRows}</tbody> </table> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 13
Source File: ExecutorThreadDumpPage.scala From BigDatalog with Apache License 2.0 | 5 votes |
package org.apache.spark.ui.exec import javax.servlet.http.HttpServletRequest import scala.util.Try import scala.xml.{Text, Node} import org.apache.spark.ui.{UIUtils, WebUIPage} private[ui] class ExecutorThreadDumpPage(parent: ExecutorsTab) extends WebUIPage("threadDump") { private val sc = parent.sc def render(request: HttpServletRequest): Seq[Node] = { val executorId = Option(request.getParameter("executorId")).map { executorId => UIUtils.decodeURLParameter(executorId) }.getOrElse { throw new IllegalArgumentException(s"Missing executorId parameter") } val time = System.currentTimeMillis() val maybeThreadDump = sc.get.getExecutorThreadDump(executorId) val content = maybeThreadDump.map { threadDump => val dumpRows = threadDump.sortWith { case (threadTrace1, threadTrace2) => { val v1 = if (threadTrace1.threadName.contains("Executor task launch")) 1 else 0 val v2 = if (threadTrace2.threadName.contains("Executor task launch")) 1 else 0 if (v1 == v2) { threadTrace1.threadName.toLowerCase < threadTrace2.threadName.toLowerCase } else { v1 > v2 } } }.map { thread => val threadName = thread.threadName val className = "accordion-heading " + { if (threadName.contains("Executor task launch")) { "executor-thread" } else { "non-executor-thread" } } <div class="accordion-group"> <div class={className} onclick="$(this).next().toggleClass('hidden')"> <a class="accordion-toggle"> Thread {thread.threadId}: {threadName} ({thread.threadState}) </a> </div> <div class="accordion-body hidden"> <div class="accordion-inner"> <pre>{thread.stackTrace}</pre> </div> </div> </div> } <div class="row-fluid"> <p>Updated at {UIUtils.formatDate(time)}</p> { // scalastyle:off <p><a class="expandbutton" onClick="$('.accordion-body').removeClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Expand All </a></p> <p><a class="expandbutton hidden" onClick="$('.accordion-body').addClass('hidden'); $('.expandbutton').toggleClass('hidden')"> Collapse All </a></p> // scalastyle:on } <div class="accordion">{dumpRows}</div> </div> }.getOrElse(Text("Error fetching thread dump")) UIUtils.headerSparkPage(s"Thread dump for executor $executorId", content, parent) } }
Example 14
Source File: BasicElemFormats.scala From xmlconfect with Apache License 2.0 | 5 votes |
package com.mthaler.xmlconfect import scala.reflect._ import scala.xml.{ Node, Null, Text } object BasicElemFormats { implicit object BooleanXmlElemFormat extends SimpleXmlElemFormat[Boolean] { protected def readElem(node: Node, name: String = ""): Boolean = node.text.toBoolean } implicit object ByteXmlElemFormat extends SimpleXmlElemFormat[Byte] { protected def readElem(node: Node, name: String = ""): Byte = node.text.toByte } implicit object ShortXmlElemFormat extends SimpleXmlElemFormat[Short] { protected def readElem(node: Node, name: String = ""): Short = node.text.toShort } implicit object IntXmlElemFormat extends SimpleXmlElemFormat[Int] { protected def readElem(node: Node, name: String = ""): Int = node.text.toInt } implicit object LongXmlElemFormat extends SimpleXmlElemFormat[Long] { protected def readElem(node: Node, name: String = ""): Long = node.text.toLong } implicit object FloatXmlElemFormat extends SimpleXmlElemFormat[Float] { protected def readElem(node: Node, name: String = ""): Float = node.text.toFloat } implicit object DoubleXmlElemFormat extends SimpleXmlElemFormat[Double] { protected def readElem(node: Node, name: String = ""): Double = node.text.toDouble } implicit object StringXmlElemFormat extends SimpleXmlElemFormat[String] { protected def readElem(node: Node, name: String = ""): String = node.text } implicit object CharXmlElemFormat extends SimpleXmlElemFormat[Char] { protected def readElem(node: Node, name: String = ""): Char = { val txt = node.text if (txt.length == 1) txt.charAt(0) else deserializationError("Expected Char as single-character string, but got " + txt) } } implicit object SymbolXmlElemFormat extends SimpleXmlElemFormat[Symbol] { protected def readElem(node: Node, name: String = ""): Symbol = Symbol(node.text) protected override def writeElem(obj: Symbol, name: String = ""): Node = elem(name, Null, Seq(Text(obj.name))) } implicit object BigIntXmlElemFormat extends SimpleXmlElemFormat[BigInt] { protected def readElem(node: Node, name: String = ""): BigInt = BigInt(node.text) } implicit object BigDecimalXmlElemFormat extends SimpleXmlElemFormat[BigDecimal] { protected def readElem(node: Node, name: String = ""): BigDecimal = BigDecimal(node.text) } implicit def enumFormat[T <: Enum[T]: ClassTag] = new SimpleXmlElemFormat[T] { protected def readElem(node: Node, name: String = ""): T = { val c = classTag[T].runtimeClass.asInstanceOf[Class[T]] Enum.valueOf(c, node.text) } } }
Example 15
Source File: BasicTextFormats.scala From xmlconfect with Apache License 2.0 | 5 votes |
package com.mthaler.xmlconfect import scala.reflect._ import scala.xml.{ Null, Node, Text } object BasicTextFormats { implicit object BooleanXmlTextFormat extends SimpleXmlTextFormat[Boolean] { protected def readText(text: Text, name: String = ""): Boolean = text.text.toBoolean } implicit object ByteXmlTextFormat extends SimpleXmlTextFormat[Byte] { protected def readText(text: Text, name: String = ""): Byte = text.text.toByte } implicit object ShortXmlTextFormat extends SimpleXmlTextFormat[Short] { protected def readText(text: Text, name: String = ""): Short = text.text.toShort } implicit object IntXmlTextFormat extends SimpleXmlTextFormat[Int] { protected def readText(text: Text, name: String = ""): Int = text.text.toInt } implicit object LongXmlTextFormat extends SimpleXmlTextFormat[Long] { protected def readText(text: Text, name: String = ""): Long = text.text.toLong } implicit object FloatXmlTextFormat extends SimpleXmlTextFormat[Float] { protected def readText(text: Text, name: String = ""): Float = text.text.toFloat } implicit object DoubleXmlTextFormat extends SimpleXmlTextFormat[Double] { protected def readText(text: Text, name: String = ""): Double = text.text.toDouble } implicit object StringXmlTextFormat extends SimpleXmlTextFormat[String] { protected def readText(text: Text, name: String = ""): String = text.text } implicit object CharXmlTextFormat extends SimpleXmlTextFormat[Char] { protected def readText(text: Text, name: String = ""): Char = { val txt = text.text if (txt.length == 1) txt.charAt(0) else deserializationError("Expected Char as single-character string, but got " + txt) } } implicit object SymbolXmlTextFormat extends SimpleXmlTextFormat[Symbol] { protected def readText(text: Text, name: String = ""): Symbol = Symbol(text.text) protected override def writeElem(obj: Symbol, name: String = ""): Node = Text(obj.name) } implicit object BigIntXmlTextFormat extends SimpleXmlTextFormat[BigInt] { protected def readText(text: Text, name: String = ""): BigInt = BigInt(text.text) } implicit object BigDecimalXmlTextFormat extends SimpleXmlTextFormat[BigDecimal] { protected def readText(text: Text, name: String = ""): BigDecimal = BigDecimal(text.text) } implicit def enumFormat[T <: Enum[T]: ClassTag] = new SimpleXmlTextFormat[T] { protected def readText(text: Text, name: String = ""): T = { val c = classTag[T].runtimeClass.asInstanceOf[Class[T]] Enum.valueOf(c, text.text) } } }