From c20250c4b9e66e1fc1f8c066e1f62b0f8a783eb2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Henning?= <stu114708@informatik.uni-kiel.de>
Date: Mon, 30 May 2016 14:12:23 +0200
Subject: [PATCH] worked on dependency graph creation

---
 .../analysis/dev/DependencyCreator.java       | 12 +--
 .../dev/DotDependencyFileWriterStage.java     |  5 ++
 ...OperationsDependencyGraphCreatorStage.java | 79 ++++++++++++-------
 .../export/dot/DotExportConfiguration.java    | 23 ++++++
 .../analysis/util/graph/impl/GraphImpl.java   |  2 +
 5 files changed, 87 insertions(+), 34 deletions(-)

diff --git a/src/main/java/kieker/analysis/dev/DependencyCreator.java b/src/main/java/kieker/analysis/dev/DependencyCreator.java
index f6b53f28..d896a1b4 100644
--- a/src/main/java/kieker/analysis/dev/DependencyCreator.java
+++ b/src/main/java/kieker/analysis/dev/DependencyCreator.java
@@ -26,15 +26,15 @@ public class DependencyCreator extends OperationCallVisitor<AggregatedOperationC
 
 		final AggregatedOperationCall parentCall = call.getParent();
 		if (parentCall != null) {
-			Container callerContainer = softwareSystem.addContainer(call.getContainer());
-			Component callerComponent = callerContainer.addComponent(call.getComponent());
-			Operation callerOperation = callerComponent.addOperation(call.getOperation());
+			Container callerContainer = softwareSystem.addContainer(parentCall.getContainer());
+			Component callerComponent = callerContainer.addComponent(parentCall.getComponent());
+			Operation callerOperation = callerComponent.addOperation(parentCall.getOperation());
 
 			final int numberOfCalls = call.getCalls();
 
-			softwareSystem.addOperationDependency(callerOperation, calleeOperation).setCalls(numberOfCalls);
-			softwareSystem.addComponentDependency(callerComponent, calleeComponent).setCalls(numberOfCalls);
-			softwareSystem.addContainerDependency(callerContainer, calleeContainer).setCalls(numberOfCalls);
+			softwareSystem.addOperationDependency(callerOperation, calleeOperation).addCalls(numberOfCalls);
+			softwareSystem.addComponentDependency(callerComponent, calleeComponent).addCalls(numberOfCalls);
+			softwareSystem.addContainerDependency(callerContainer, calleeContainer).addCalls(numberOfCalls);
 
 			// TODO set failure calls
 		}
diff --git a/src/main/java/kieker/analysis/dev/DotDependencyFileWriterStage.java b/src/main/java/kieker/analysis/dev/DotDependencyFileWriterStage.java
index 15d8a4e5..46a0e78a 100644
--- a/src/main/java/kieker/analysis/dev/DotDependencyFileWriterStage.java
+++ b/src/main/java/kieker/analysis/dev/DotDependencyFileWriterStage.java
@@ -1,6 +1,7 @@
 package kieker.analysis.dev;
 
 import kieker.analysis.util.graph.export.dot.DotFileWriterStage;
+import kieker.analysis.util.graph.util.dot.attributes.DotEdgeAttribute;
 import kieker.analysis.util.graph.util.dot.attributes.DotNodeAttribute;
 
 public class DotDependencyFileWriterStage extends DotFileWriterStage {
@@ -8,6 +9,10 @@ public class DotDependencyFileWriterStage extends DotFileWriterStage {
 	public DotDependencyFileWriterStage(final String outputDirectory) {
 		super(outputDirectory);
 		this.exportConfiguration.getDefaultNodeAttributes().put(DotNodeAttribute.SHAPE, (g -> "none"));
+		// Something like this would be good:
+		// this.exportConfiguration.addNodeAttribute(DotNodeAttribute.LABEL, new PropertyMapper("calls"));
+		this.exportConfiguration.addNodeAttribute(DotNodeAttribute.LABEL, (v -> v.toString()));
+		this.exportConfiguration.addEdgeAttribute(DotEdgeAttribute.LABEL, (e -> e.getProperty("calls").toString()));
 		// Styling
 	}
 
diff --git a/src/main/java/kieker/analysis/dev/dependencygraphs/OperationsDependencyGraphCreatorStage.java b/src/main/java/kieker/analysis/dev/dependencygraphs/OperationsDependencyGraphCreatorStage.java
index 864c4f7b..62037555 100644
--- a/src/main/java/kieker/analysis/dev/dependencygraphs/OperationsDependencyGraphCreatorStage.java
+++ b/src/main/java/kieker/analysis/dev/dependencygraphs/OperationsDependencyGraphCreatorStage.java
@@ -28,10 +28,11 @@ public class OperationsDependencyGraphCreatorStage extends AbstractTransformatio
 			containerVertex.setProperty("MeanDuration", container.getMeanDuration());
 			containerVertex.setProperty("MedianDuration", container.getMedianDuration());
 			containerVertex.setProperty("TotalDuration", container.getTotalDuration());
+			Graph componentGraph = containerVertex.addChildGraph();
 
 			for (Component component : container.getComponents()) {
 
-				Vertex componentVertex = graph.addVertex(component.getIdentifier());
+				Vertex componentVertex = componentGraph.addVertex(component.getIdentifier());
 				componentVertex.setProperty("ComponentName", component.getName());
 				componentVertex.setProperty("ContainerName", component.getContainer().getName());
 				componentVertex.setProperty("MaxDuration", component.getMaxDuration());
@@ -39,10 +40,11 @@ public class OperationsDependencyGraphCreatorStage extends AbstractTransformatio
 				componentVertex.setProperty("MeanDuration", component.getMeanDuration());
 				componentVertex.setProperty("MedianDuration", component.getMedianDuration());
 				componentVertex.setProperty("TotalDuration", component.getTotalDuration());
+				Graph operationsGraph = componentVertex.addChildGraph();
 
 				for (Operation operation : component.getOperations()) {
 
-					Vertex operationVertex = graph.addVertex(operation.getIdentifier());
+					Vertex operationVertex = operationsGraph.addVertex(operation.getIdentifier());
 					operationVertex.setProperty("OperationName", operation.getName());
 					operationVertex.setProperty("ComponentName", operation.getComponent().getName());
 					operationVertex.setProperty("ContainerName", operation.getComponent().getContainer().getName());
@@ -56,34 +58,55 @@ public class OperationsDependencyGraphCreatorStage extends AbstractTransformatio
 			}
 		}
 
-		for (Dependency<Container> containerDependency : softwareSystem.getContainerDependencies()) {
-
-			Vertex callerVertex = graph.getVertex(containerDependency.getCaller().getIdentifier());
-			Vertex calleeVertex = graph.getVertex(containerDependency.getCaller().getIdentifier());
-
-			Edge dependencyEdge = graph.addEdge(null, callerVertex, calleeVertex);
-			dependencyEdge.setProperty("calls", containerDependency.getCalls());
-			dependencyEdge.setProperty("failuredCalls", containerDependency.getFailuredCalls());
-		}
-
-		for (Dependency<Component> componentDependency : softwareSystem.getComponentDependencies()) {
-
-			Vertex callerVertex = graph.getVertex(componentDependency.getCaller().getIdentifier());
-			Vertex calleeVertex = graph.getVertex(componentDependency.getCaller().getIdentifier());
-
-			Edge dependencyEdge = graph.addEdge(null, callerVertex, calleeVertex);
-			dependencyEdge.setProperty("calls", componentDependency.getCalls());
-			dependencyEdge.setProperty("failuredCalls", componentDependency.getFailuredCalls());
-		}
-
-		for (Dependency<Operation> operationDependency : softwareSystem.getOperationDependencies()) {
-
-			Vertex callerVertex = graph.getVertex(operationDependency.getCaller().getIdentifier());
-			Vertex calleeVertex = graph.getVertex(operationDependency.getCaller().getIdentifier());
+		/*
+		 * for (Dependency<Container> dependency : softwareSystem.getContainerDependencies()) {
+		 * 
+		 * String callerContainerIdentifier = dependency.getCaller().getIdentifier();
+		 * String calleeContainerIdentifier = dependency.getCallee().getIdentifier();
+		 * 
+		 * Vertex callerVertex = graph.getVertex(callerContainerIdentifier);
+		 * Vertex calleeVertex = graph.getVertex(calleeContainerIdentifier);
+		 * 
+		 * Edge dependencyEdge = graph.addEdge(null, callerVertex, calleeVertex);
+		 * dependencyEdge.setProperty("calls", dependency.getCalls());
+		 * dependencyEdge.setProperty("failuredCalls", dependency.getFailuredCalls());
+		 * }
+		 * 
+		 * for (Dependency<Component> dependency : softwareSystem.getComponentDependencies()) {
+		 * 
+		 * String callerContainerIdentifier = dependency.getCaller().getContainer().getIdentifier();
+		 * String callerComponentIdentifier = dependency.getCaller().getIdentifier();
+		 * 
+		 * String calleeContainerIdentifier = dependency.getCallee().getContainer().getIdentifier();
+		 * String calleeComponentIdentifier = dependency.getCallee().getIdentifier();
+		 * 
+		 * Vertex callerVertex = graph.getVertex(callerContainerIdentifier).getChildGraph().getVertex(callerComponentIdentifier);
+		 * Vertex calleeVertex = graph.getVertex(calleeContainerIdentifier).getChildGraph().getVertex(calleeComponentIdentifier);
+		 * 
+		 * Edge dependencyEdge = graph.addEdge(null, callerVertex, calleeVertex);
+		 * dependencyEdge.setProperty("calls", dependency.getCalls());
+		 * dependencyEdge.setProperty("failuredCalls", dependency.getFailuredCalls());
+		 * }
+		 */
+
+		for (Dependency<Operation> dependency : softwareSystem.getOperationDependencies()) {
+
+			String callerContainerIdentifier = dependency.getCaller().getComponent().getContainer().getIdentifier();
+			String callerComponentIdentifier = dependency.getCaller().getComponent().getIdentifier();
+			String callerOperationIdentifier = dependency.getCaller().getIdentifier();
+
+			String calleeContainerIdentifier = dependency.getCallee().getComponent().getContainer().getIdentifier();
+			String calleeComponentIdentifier = dependency.getCallee().getComponent().getIdentifier();
+			String calleeOperationIdentifier = dependency.getCallee().getIdentifier();
+
+			Vertex callerVertex = graph.getVertex(callerContainerIdentifier).getChildGraph().getVertex(callerComponentIdentifier).getChildGraph()
+					.getVertex(callerOperationIdentifier);
+			Vertex calleeVertex = graph.getVertex(calleeContainerIdentifier).getChildGraph().getVertex(calleeComponentIdentifier).getChildGraph()
+					.getVertex(calleeOperationIdentifier);
 
 			Edge dependencyEdge = graph.addEdge(null, callerVertex, calleeVertex);
-			dependencyEdge.setProperty("calls", operationDependency.getCalls());
-			dependencyEdge.setProperty("failuredCalls", operationDependency.getFailuredCalls());
+			dependencyEdge.setProperty("calls", dependency.getCalls());
+			dependencyEdge.setProperty("failuredCalls", dependency.getFailuredCalls());
 		}
 
 		this.outputPort.send(graph);
diff --git a/src/main/java/kieker/analysis/util/graph/export/dot/DotExportConfiguration.java b/src/main/java/kieker/analysis/util/graph/export/dot/DotExportConfiguration.java
index a1ef1e84..cee79f66 100644
--- a/src/main/java/kieker/analysis/util/graph/export/dot/DotExportConfiguration.java
+++ b/src/main/java/kieker/analysis/util/graph/export/dot/DotExportConfiguration.java
@@ -45,4 +45,27 @@ public class DotExportConfiguration {
 		return clusterAttributes;
 	}
 
+	public void addGraphAttribute(final DotGraphAttribute attribute, final Function<Graph, String> function) {
+		this.graphAttributes.put(attribute, function);
+	}
+
+	public void addDefaultNodeAttribute(final DotNodeAttribute attribute, final Function<Graph, String> function) {
+		this.defaultNodeAttributes.put(attribute, function);
+	}
+
+	public void addDefaultEdgeAttribute(final DotEdgeAttribute attribute, final Function<Graph, String> function) {
+		this.defaultEdgeAttributes.put(attribute, function);
+	}
+
+	public void addNodeAttribute(final DotNodeAttribute attribute, final Function<Vertex, String> function) {
+		this.nodeAttributes.put(attribute, function);
+	}
+
+	public void addEdgeAttribute(final DotEdgeAttribute attribute, final Function<Edge, String> function) {
+		this.edgeAttributes.put(attribute, function);
+	}
+
+	public void addClusterAttribute(final DotClusterAttribute attribute, final Function<Vertex, String> function) {
+		this.clusterAttributes.put(attribute, function);
+	}
 }
diff --git a/src/main/java/kieker/analysis/util/graph/impl/GraphImpl.java b/src/main/java/kieker/analysis/util/graph/impl/GraphImpl.java
index d6df8acd..495fcfbd 100644
--- a/src/main/java/kieker/analysis/util/graph/impl/GraphImpl.java
+++ b/src/main/java/kieker/analysis/util/graph/impl/GraphImpl.java
@@ -79,6 +79,8 @@ public class GraphImpl extends ElementImpl implements Graph {
 	@Override
 	public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex) {
 
+		// BETTER Throw Exception if Vertices are null
+
 		Stack<VertexImpl> outVertexParents = new Stack<>();
 		for (VertexImpl parent = (VertexImpl) outVertex; parent != null; parent = parent.graph.parentVertex) {
 			outVertexParents.push(parent);
-- 
GitLab