summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2017-07-11 16:08:49 +0200
committerGitHub <noreply@github.com>2017-07-11 16:08:49 +0200
commit730fd6edd9569cd328ccabf3655394bb9ad081f1 (patch)
tree0dc8b15d25af7aebfbfa49da99ffd79faad4ba27
parent2ceac3d88f57d218ced860eec76d60dd9d05fb99 (diff)
Revert "Bjorncs/scala stuff"
-rw-r--r--application/src/main/java/com/yahoo/application/container/handler/Headers.java2
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/bundle/AnalyzeBundle.scala8
-rw-r--r--bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala6
-rw-r--r--bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala7
-rw-r--r--bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala6
-rw-r--r--bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala8
-rw-r--r--bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala8
-rw-r--r--bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala9
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java16
-rw-r--r--container-core/src/main/scala/com/yahoo/container/handler/observability/Graphviz.scala33
-rw-r--r--container-core/src/main/scala/com/yahoo/container/handler/observability/HtmlUtil.scala42
-rw-r--r--container-core/src/main/scala/com/yahoo/container/handler/observability/OverviewHandler.scala118
-rw-r--r--pom.xml12
-rw-r--r--service-monitor/pom.xml2
14 files changed, 239 insertions, 38 deletions
diff --git a/application/src/main/java/com/yahoo/application/container/handler/Headers.java b/application/src/main/java/com/yahoo/application/container/handler/Headers.java
index 8c49d36c078..3b5a62471ac 100644
--- a/application/src/main/java/com/yahoo/application/container/handler/Headers.java
+++ b/application/src/main/java/com/yahoo/application/container/handler/Headers.java
@@ -79,7 +79,7 @@ public class Headers implements Map<String, List<String>> {
}
@Override
- public Set<Map.Entry<String, List<String>>> entrySet() {
+ public Set<Entry<String, List<String>>> entrySet() {
return h.entrySet();
}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/bundle/AnalyzeBundle.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/bundle/AnalyzeBundle.scala
index 1b3979476bd..f1bbf644ac6 100644
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/bundle/AnalyzeBundle.scala
+++ b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/bundle/AnalyzeBundle.scala
@@ -1,11 +1,11 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.bundle
-import java.io.File
import java.util.jar.{Manifest => JarManifest}
-
-import com.yahoo.container.plugin.osgi.ExportPackageParser
-import com.yahoo.container.plugin.osgi.ExportPackages.Export
+import java.io.File
+import com.yahoo.container.plugin.osgi.{ExportPackages, ExportPackageParser}
+import ExportPackages.Export
+import collection.immutable.LinearSeq
import com.yahoo.container.plugin.util.JarFiles
diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala
index 3ef1b1fea87..cf6ae3ccf9c 100644
--- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala
+++ b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala
@@ -1,18 +1,16 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.bundle
-import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite}
+import org.scalatest.junit.{JUnitSuite, ShouldMatchersForJUnit}
import org.junit.Test
import com.yahoo.container.plugin.bundle.AnalyzeBundle.PublicPackages
import com.yahoo.container.plugin.osgi.ExportPackages
import java.io.File
-import org.scalatest.Matchers
-
/**
* @author tonytv
*/
-class AnalyzeBundleTest extends JUnitSuite with AssertionsForJUnit with Matchers {
+class AnalyzeBundleTest extends JUnitSuite with ShouldMatchersForJUnit {
val jarDir = new File("src/test/resources/jar")
val PublicPackages(exports, globals) = AnalyzeBundle.publicPackagesAggregated(
diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala
index e2d0e3c6f10..3377315e3d8 100644
--- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala
+++ b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala
@@ -2,22 +2,19 @@
package com.yahoo.container.plugin.classanalysis
import org.junit.Test
-import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite}
+import org.scalatest.junit.{ShouldMatchersForJUnit, JUnitSuite}
import java.awt.Image
import java.awt.image.{ImagingOpException, Kernel}
-
import sampleclasses._
import TestUtilities._
import com.yahoo.osgi.annotation.{ExportPackage, Version}
import javax.security.auth.login.LoginException
-import org.scalatest.Matchers
-
/**
* Tests that analysis of class files works.
* @author tonytv
*/
-class AnalyzeClassTest extends JUnitSuite with AssertionsForJUnit with Matchers {
+class AnalyzeClassTest extends JUnitSuite with ShouldMatchersForJUnit {
@Test def require_that_full_class_name_is_returned() {
analyzeClass[Base].name should be(name[Base])
}
diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala
index 43f52884f39..231aba36325 100644
--- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala
+++ b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala
@@ -1,19 +1,17 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.classanalysis
-import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite}
+import org.scalatest.junit.{JUnitSuite, ShouldMatchersForJUnit}
import sampleclasses._
import TestUtilities._
import org.junit.Test
import java.io.PrintStream
-import org.scalatest.Matchers
-
/**
* Tests that classes used in method bodies are included in the imports list.
* @author tonytv
*/
-class AnalyzeMethodBodyTest extends JUnitSuite with AssertionsForJUnit with Matchers {
+class AnalyzeMethodBodyTest extends JUnitSuite with ShouldMatchersForJUnit {
@Test def require_that_class_of_locals_are_included() {
analyzeClass[Methods].referencedClasses should contain(name[Base])
}
diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala
index 5ddc7fef16d..37399ec8c00 100644
--- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala
+++ b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala
@@ -1,15 +1,15 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.osgi
-import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite}
+import org.scalatest.junit.{JUnitSuite, ShouldMatchersForJUnit}
import org.junit.Test
-import ExportPackages.{Export, Parameter}
-import org.scalatest.Matchers
+
+import ExportPackages.{Parameter, Export}
/**
* @author tonytv
*/
-class ExportPackageParserTest extends JUnitSuite with AssertionsForJUnit with Matchers {
+class ExportPackageParserTest extends JUnitSuite with ShouldMatchersForJUnit {
val versionParameter = Parameter("version", "1.2.3.sample")
@Test
diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala
index 4011f170da9..b39c8da7df6 100644
--- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala
+++ b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala
@@ -1,16 +1,16 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.osgi
-import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite}
+import org.scalatest.junit.{JUnitSuite, ShouldMatchersForJUnit}
import org.junit.Test
+
import ImportPackages.Import
-import ExportPackages.{Export, Parameter}
-import org.scalatest.Matchers
+import ExportPackages.{Parameter, Export}
/**
* @author tonytv
*/
-class ImportPackageTest extends JUnitSuite with AssertionsForJUnit with Matchers {
+class ImportPackageTest extends JUnitSuite with ShouldMatchersForJUnit {
val referencedPackages = Set("com.yahoo.exported")
val exports = exportByPackageName(Export(List("com.yahoo.exported"), List()))
val exportsWithVersion = exportByPackageName(exports.head._2.copy(parameters = List(Parameter("version", "1.3"))))
diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala
index 7efb0392f5e..d96273d81e1 100644
--- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala
+++ b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala
@@ -1,23 +1,22 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.util
-import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite}
+import org.scalatest.junit.{JUnitSuite, ShouldMatchersForJUnit}
import org.junit.Test
+
import IO.using
import java.io.Closeable
-import org.scalatest.Matchers
-
/**
* @author tonytv
*/
-class IOTest extends JUnitSuite with AssertionsForJUnit with Matchers {
+class IOTest extends JUnitSuite with ShouldMatchersForJUnit {
class ClosingException extends RuntimeException
class FunctionException extends RuntimeException
object throwWhenClosingResource extends Closeable {
def close() {
- throw new ClosingException()
+ throw new ClosingException();
}
}
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 66fb4c73560..01ff6918f7b 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,9 +13,12 @@ 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;
@@ -25,12 +28,14 @@ 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;
@@ -148,6 +153,7 @@ public class HandlersConfigurerDi {
RegistriesHack registriesHack = currentGraph.getInstance(RegistriesHack.class);
assert (registriesHack != null);
+ injectDotGraph();
}
@SuppressWarnings("deprecation")
@@ -170,6 +176,16 @@ 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
new file mode 100644
index 00000000000..845f0857323
--- /dev/null
+++ b/container-core/src/main/scala/com/yahoo/container/handler/observability/Graphviz.scala
@@ -0,0 +1,33 @@
+// 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
new file mode 100644
index 00000000000..6469d4604d2
--- /dev/null
+++ b/container-core/src/main/scala/com/yahoo/container/handler/observability/HtmlUtil.scala
@@ -0,0 +1,42 @@
+// 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 =
+ <a href={target}>{anchor}</a>
+
+ def link(targetAndAnchor: String): Elem = link(targetAndAnchor, targetAndAnchor)
+
+ def unorderedList(items: Elem*) =
+ <ul>
+ {items}
+ </ul>
+
+ def li[T](children: T*) =
+ <li>{children}</li>
+
+ def h1(name: String) =
+ <h1>{name}</h1>
+
+ def html(title: String, body: Elem*) =
+ <html>
+ <head>
+ <title>{title}</title>
+ </head>
+ <body>
+ {body}
+ </body>
+ </html>
+
+ def prettyPrintXhtml(elem: Elem): String = {
+ """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">""" +
+ "\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
new file mode 100644
index 00000000000..fcb00bb72ef
--- /dev/null
+++ b/container-core/src/main/scala/com/yahoo/container/handler/observability/OverviewHandler.scala
@@ -0,0 +1,118 @@
+// 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 :_*)))
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index e49f181a3bb..480c94d66b6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -953,22 +953,22 @@
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-parser-combinators_${scala.major-version}</artifactId>
- <version>1.0.6</version>
+ <version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_${scala.major-version}</artifactId>
- <version>1.0.6</version>
+ <version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.major-version}</artifactId>
- <version>3.0.3</version>
+ <version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-native_${scala.major-version}</artifactId>
- <version>3.5.2</version>
+ <version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -1082,8 +1082,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<test.hide>true</test.hide>
<doclint>all</doclint>
- <scala.major-version>2.12</scala.major-version>
- <scala.version>${scala.major-version}.2</scala.version>
+ <scala.major-version>2.11</scala.major-version>
+ <scala.version>${scala.major-version}.4</scala.version>
<surefire.version>2.19.1</surefire.version> <!-- NOTE bjorncs 15.06.2017: Version 2.20 has OoM issues -->
</properties>
diff --git a/service-monitor/pom.xml b/service-monitor/pom.xml
index f0678974ec2..a23760c435b 100644
--- a/service-monitor/pom.xml
+++ b/service-monitor/pom.xml
@@ -27,7 +27,7 @@
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxscala_${scala.major-version}</artifactId>
- <version>0.26.5</version>
+ <version>0.23.1</version>
</dependency>
<dependency>
<groupId>com.yahoo.vespa</groupId>