From 977b3ceb0e8f86ae72f71e130419974e0ef04193 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Tue, 11 Jul 2017 14:49:14 +0200 Subject: Remove dead Scala code that triggers a Scala compiler crash --- .../core/config/HandlersConfigurerDi.java | 16 --- .../container/handler/observability/Graphviz.scala | 33 ------ .../container/handler/observability/HtmlUtil.scala | 42 -------- .../handler/observability/OverviewHandler.scala | 118 --------------------- 4 files changed, 209 deletions(-) delete mode 100644 container-core/src/main/scala/com/yahoo/container/handler/observability/Graphviz.scala delete mode 100644 container-core/src/main/scala/com/yahoo/container/handler/observability/HtmlUtil.scala delete mode 100644 container-core/src/main/scala/com/yahoo/container/handler/observability/OverviewHandler.scala diff --git a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java index 01ff6918f7b..66fb4c73560 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java @@ -13,12 +13,9 @@ import com.yahoo.container.core.DiagnosticsConfig; import com.yahoo.container.di.ComponentDeconstructor; import com.yahoo.container.di.Container; import com.yahoo.container.di.componentgraph.core.ComponentGraph; -import com.yahoo.container.di.componentgraph.core.DotGraph; import com.yahoo.container.di.config.SubscriberFactory; import com.yahoo.container.di.osgi.OsgiUtil; -import com.yahoo.container.handler.observability.OverviewHandler; import com.yahoo.container.logging.AccessLog; -import com.yahoo.container.logging.AccessLogInterface; import com.yahoo.jdisc.application.OsgiFramework; import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.service.ClientProvider; @@ -28,14 +25,12 @@ import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.log.LogLevel; import com.yahoo.osgi.OsgiImpl; import com.yahoo.statistics.Statistics; - import org.osgi.framework.Bundle; import org.osgi.framework.wiring.BundleWiring; import scala.collection.immutable.Set; import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.logging.Logger; @@ -153,7 +148,6 @@ public class HandlersConfigurerDi { RegistriesHack registriesHack = currentGraph.getInstance(RegistriesHack.class); assert (registriesHack != null); - injectDotGraph(); } @SuppressWarnings("deprecation") @@ -176,16 +170,6 @@ public class HandlersConfigurerDi { }); } - private void injectDotGraph() { - try { - OverviewHandler overviewHandler = currentGraph.getInstance(OverviewHandler.class); - overviewHandler.setDotGraph(DotGraph.generate(currentGraph)); - } catch (Exception e) { - log.fine("No overview handler"); - } - - } - public void reloadConfig(long generation) { container.reloadConfig(generation); } diff --git a/container-core/src/main/scala/com/yahoo/container/handler/observability/Graphviz.scala b/container-core/src/main/scala/com/yahoo/container/handler/observability/Graphviz.scala deleted file mode 100644 index 845f0857323..00000000000 --- a/container-core/src/main/scala/com/yahoo/container/handler/observability/Graphviz.scala +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.handler.observability - -import com.yahoo.text.Utf8 -import com.yahoo.io.IOUtils -import java.io.{IOException, InputStreamReader, InputStream} -import com.google.common.io.ByteStreams - -/** - * @author tonytv - */ - -object Graphviz { - - @throws(classOf[IOException]) - def runDot(outputType: String, graph: String) = { - val process = Runtime.getRuntime.exec(Array("/bin/sh", "-c", "unflatten -l7 | dot -T" + outputType)) - process.getOutputStream.write(Utf8.toBytes(graph)) - process.getOutputStream.close() - - val result = ByteStreams.toByteArray(process.getInputStream) - process.waitFor() match { - case 0 => result - case 127 => throw new RuntimeException("Couldn't find dot, please ensure that Graphviz is installed.") - case _ => throw new RuntimeException("Failed running dot: " + readString(process.getErrorStream)) - } - } - - private def readString(inputStream: InputStream): String = { - IOUtils.readAll(new InputStreamReader(inputStream, "UTF-8")) - } - -} diff --git a/container-core/src/main/scala/com/yahoo/container/handler/observability/HtmlUtil.scala b/container-core/src/main/scala/com/yahoo/container/handler/observability/HtmlUtil.scala deleted file mode 100644 index 6469d4604d2..00000000000 --- a/container-core/src/main/scala/com/yahoo/container/handler/observability/HtmlUtil.scala +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.handler.observability - -import xml.{PrettyPrinter, Elem} - - -/** - * @author gjoranv - * @author tonytv - */ -object HtmlUtil { - def link(target: String, anchor: String): Elem = - {anchor} - - def link(targetAndAnchor: String): Elem = link(targetAndAnchor, targetAndAnchor) - - def unorderedList(items: Elem*) = - - - def li[T](children: T*) = -
  • {children}
  • - - def h1(name: String) = -

    {name}

    - - def html(title: String, body: Elem*) = - - - {title} - - - {body} - - - - def prettyPrintXhtml(elem: Elem): String = { - """""" + - "\n" + new PrettyPrinter(120, 2).format(elem) - } -} diff --git a/container-core/src/main/scala/com/yahoo/container/handler/observability/OverviewHandler.scala b/container-core/src/main/scala/com/yahoo/container/handler/observability/OverviewHandler.scala deleted file mode 100644 index fcb00bb72ef..00000000000 --- a/container-core/src/main/scala/com/yahoo/container/handler/observability/OverviewHandler.scala +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.handler.observability - -import java.util.concurrent.Executor - -import HtmlUtil._ -import OverviewHandler._ -import com.yahoo.container.jdisc.{HttpResponse, HttpRequest, ThreadedHttpRequestHandler} -import com.yahoo.text.Utf8 -import java.io.{PrintWriter, OutputStream} - - -/** - * @author gjoranv - * @author tonytv - */ -class OverviewHandler(executor: Executor) extends ThreadedHttpRequestHandler(executor) { - - @volatile - private var dotGraph: String = _ - - def handle(request: HttpRequest): HttpResponse = { - val path = request.getUri.getPath - - try { - if (path.endsWith("/ComponentGraph")) - handleComponentGraph(request) - else if (path.endsWith("/Overview")) - handleOverview(request) - else - null - } catch { - case e: Exception => errorResponse(e.getMessage) - } - - } - - def handleOverview(request: HttpRequest): HttpResponse = { - new HttpResponse(com.yahoo.jdisc.Response.Status.OK) { - def render(stream: OutputStream) { - stream.write(Utf8.toBytes(overviewPageText)) - } - - override def getContentType: String = { - "text/html" - } - } - } - - def errorResponse(message: String): HttpResponse = { - new HttpResponse(com.yahoo.jdisc.Response.Status.BAD_REQUEST) { - def render(stream: OutputStream) { - new PrintWriter(stream).println(message) - } - } - } - - def handleComponentGraph(request: HttpRequest): HttpResponse = { - var graphType = request.getProperty("type"); - if (graphType == null) - graphType = "text" - - graphType match { - case "text" => textualComponentGraph(dotGraph) - case t if componentGraphTypes.contains(t) => graphicalComponentGraph(t, Graphviz.runDot(graphType,dotGraph)) - case t => errorResponse(t) - } - } - - def textualComponentGraph(dotGraph: String) = - new HttpResponse(com.yahoo.jdisc.Response.Status.OK) { - def render(stream: OutputStream) { - stream.write(Utf8.toBytes(dotGraph)) - } - - override def getContentType: String = { - "text/plain" - } - } - - def graphicalComponentGraph(graphType: String, image: Array[Byte] ): HttpResponse = - new HttpResponse(com.yahoo.jdisc.Response.Status.OK) { - def render(output: OutputStream) { - output.write(image) - } - - override def getContentType: String = { - componentGraphTypes(graphType) - } - } - - def setDotGraph(dotGraph: String) { - this.dotGraph = dotGraph - } -} - -object OverviewHandler { - val componentGraphTypes = Map( - "svg" -> "image/svg+xml", - "png" -> "image/png", - "text" -> "text/plain") - - val overviewPageText = prettyPrintXhtml(overviewPage) - - private def overviewPage = { - def componentGraphLink(graphType: String) = link("Overview/ComponentGraph?type=" + graphType, graphType) - - - html( - title = "Container Overview", - body = - h1("Container Overview"), - unorderedList( - li(link("ApplicationStatus")), - li("ComponentGraph" +: (componentGraphTypes.keys map {componentGraphLink}).toSeq :_*))) - } - -} -- cgit v1.2.3