diff --git a/src/main/java/kieker/analysis/dev/SoftwareSystemAggregator.java b/src/main/java/kieker/analysis/dev/SoftwareSystemAggregator.java new file mode 100644 index 0000000000000000000000000000000000000000..2f1538cb48cfcde80b757546cf7e938746b38e37 --- /dev/null +++ b/src/main/java/kieker/analysis/dev/SoftwareSystemAggregator.java @@ -0,0 +1,63 @@ +package kieker.analysis.dev; + +import java.util.HashMap; +import java.util.Map; + +import kieker.analysis.domain.systemdependency.Component; +import kieker.analysis.domain.systemdependency.Container; +import kieker.analysis.domain.systemdependency.Dependency; +import kieker.analysis.domain.systemdependency.Operation; +import kieker.analysis.domain.systemdependency.SoftwareSystem; + +import teetime.stage.basic.AbstractTransformation; + +// Transformation: +// SoftwareSystem (Deployment) --> SoftwareSystem (Assembly) +// aggregate Containers +public class SoftwareSystemAggregator extends AbstractTransformation<SoftwareSystem, SoftwareSystem> { + + @Override + protected void execute(final SoftwareSystem deploymentSoftwareSystem) { + + Map<Component, Component> components = new HashMap<>(); // Old -> New + Map<Operation, Operation> operations = new HashMap<>(); // Old -> New + + SoftwareSystem assemblySoftwareSystem = new SoftwareSystem(); + Container newContainer = assemblySoftwareSystem.addContainer("DEFAULT"); + + for (Container container : deploymentSoftwareSystem.getContainers()) { + for (Component component : container.getComponents()) { + Component newComponent = newContainer.addComponent(component.getName()); + components.put(component, newComponent); + for (Operation operation : component.getOperations()) { + Operation newOperation = newComponent.addOperation(operation.getName()); + newOperation.getOperationCalls().addAll(operation.getOperationCalls()); + operations.put(operation, newOperation); + } + } + } + + for (Dependency<Component> componentDependency : deploymentSoftwareSystem.getComponentDependencies()) { + Component newCaller = components.get(componentDependency.getCaller()); + Component newCallee = components.get(componentDependency.getCallee()); + + // Adds only if absent + Dependency<Component> dependency = assemblySoftwareSystem.addComponentDependency(newCaller, newCallee); + dependency.addCalls(componentDependency.getCalls()); + dependency.addFailuredCalls(componentDependency.getFailuredCalls()); + } + + for (Dependency<Operation> operationDependency : deploymentSoftwareSystem.getOperationDependencies()) { + Operation newCaller = operations.get(operationDependency.getCaller()); + Operation newCallee = operations.get(operationDependency.getCallee()); + + // Adds only if absent + Dependency<Operation> dependency = assemblySoftwareSystem.addOperationDependency(newCaller, newCallee); + dependency.addCalls(operationDependency.getCalls()); + dependency.addFailuredCalls(operationDependency.getFailuredCalls()); + } + + this.outputPort.send(assemblySoftwareSystem); + } + +}