diff --git a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt index 222dad1..0d61e4e 100644 --- a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt +++ b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/api/model/Graph.kt @@ -114,7 +114,9 @@ class Graph { * Model to represent a node in a graph */ class Node( - val label: String + val label: String, + + val representedByResourceName: String ) /** diff --git a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt index bc492ef..55cd5b9 100644 --- a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt +++ b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt @@ -60,7 +60,10 @@ internal class ReportRunner : IReportRunner { } DiagramRenderer(diagramWidth, diagramHeight).use { renderer -> - + positions.forEach { node, position -> + val imageResource = imageSource.get(node.representedByResourceName) + renderer.addImage(position.x.toInt(), position.y.toInt(), imageResource) + } } } diff --git a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/render/DiagramRenderer.kt b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/render/DiagramRenderer.kt index 2f1b2d5..be23111 100644 --- a/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/render/DiagramRenderer.kt +++ b/acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/render/DiagramRenderer.kt @@ -8,6 +8,7 @@ import java.awt.Polygon import java.awt.image.BufferedImage import java.awt.image.BufferedImage.TYPE_INT_RGB import java.io.File +import java.io.InputStream import java.lang.IllegalStateException import javax.imageio.ImageIO @@ -36,9 +37,9 @@ class DiagramRenderer( * * @param positionX The offset of the left side of the image from the left side of the diagram * @param positionY The offset of the top side of the image from the top side of the diagram - * @param source The source to fetch the image from + * @param source The input stream to read the image from */ - fun addImage(positionX: Int, positionY: Int, source: File) { + fun addImage(positionX: Int, positionY: Int, source: InputStream) { val img = ImageIO.read(source) target.drawImage(img, positionX, positionY, img.width, img.height, null) } diff --git a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt index c8cb226..f46b253 100644 --- a/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt +++ b/acropolis-service/src/main/kotlin/org/ephyra/acropolis/service/impl/ReportService.kt @@ -1,8 +1,14 @@ package org.ephyra.acropolis.service.impl +import org.ephyra.acropolis.external.SystemSoftwareSpecialization +import org.ephyra.acropolis.external.packSystemSpecialization import org.ephyra.acropolis.persistence.api.ConnectionType import org.ephyra.acropolis.persistence.api.IConnectable import org.ephyra.acropolis.persistence.api.entity.ApplicationSoftwareEntity +import org.ephyra.acropolis.persistence.api.entity.DatastoreEntity +import org.ephyra.acropolis.persistence.api.entity.LoadBalancerEntity +import org.ephyra.acropolis.persistence.api.entity.QueueEntity +import org.ephyra.acropolis.persistence.api.entity.ReverseProxyEntity import org.ephyra.acropolis.persistence.api.entity.SystemSoftwareEntity import org.ephyra.acropolis.report.api.IReportRunner import org.ephyra.acropolis.report.api.model.Graph @@ -50,14 +56,14 @@ class ReportService : IReportService { val graph = Graph() applications.forEach { app -> - val node = Node(app.name) + val node = Node(app.name, "application") graph.addNode(node) nodeMap[app] = node } systems.forEach { system -> - val node = Node(system.name) + val node = Node(system.name, getRepresentedByResourceNameFromSystem(system)) graph.addNode(node) nodeMap[system] = node @@ -79,4 +85,24 @@ class ReportService : IReportService { val graphContainer = GraphContainer(graph) reportRunner.run(graphContainer, graphicalAssetImageSource) } + + /** + * Gets the default image resource name for a given system. Falls back to the + * default resource names. + */ + private fun getRepresentedByResourceNameFromSystem(system: SystemSoftwareEntity): String { + // TODO this is bootstrap data and should be extracted. + return if (system.specialization == null) { + "system" + } + else { + when (system.specialization) { + is LoadBalancerEntity -> "load-balancer" + is DatastoreEntity -> "datastore" + is QueueEntity -> "queue" + is ReverseProxyEntity -> "reverse-proxy" + else -> "system" + } + } + } }