diff --git a/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ExecutionModelMerger.java b/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ExecutionModelMerger.java index 9aebaa8..ab6b83c 100644 --- a/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ExecutionModelMerger.java +++ b/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ExecutionModelMerger.java @@ -19,6 +19,7 @@ import org.eclipse.emf.common.util.EMap; +import kieker.model.analysismodel.deployment.DeployedComponent; import kieker.model.analysismodel.deployment.DeployedOperation; import kieker.model.analysismodel.deployment.DeployedStorage; import kieker.model.analysismodel.deployment.DeploymentModel; @@ -41,14 +42,20 @@ private ExecutionModelMerger() { } /* default */ static void mergeExecutionModel(final DeploymentModel deploymentModel, // NOPMD - final ExecutionModel lastModel, final ExecutionModel mergeModel) { - ExecutionModelMerger.mergeInvocations(deploymentModel, lastModel, mergeModel); + final ExecutionModel lastModel, final DeploymentModel mergeDeploymentModel, + final ExecutionModel mergeModel) { + ExecutionModelMerger.mergeInvocations(deploymentModel, lastModel, mergeDeploymentModel, mergeModel); ExecutionModelMerger.mergeStorageDataflows(deploymentModel, lastModel, mergeModel); ExecutionModelMerger.mergeOperationDataflows(deploymentModel, lastModel, mergeModel); } private static void mergeInvocations(final DeploymentModel deploymentModel, final ExecutionModel lastModel, - final ExecutionModel mergeModel) { + final DeploymentModel mergeDeploymentModel, final ExecutionModel mergeModel) { + // checkExecution(lastModel, "LAST"); + // checkExecution(mergeModel, "MERGE"); + // checkDeployment(deploymentModel, "LAST"); + // checkDeployment(mergeDeploymentModel, "MERGE"); + // checkWhereResourceAreFrom(mergeDeploymentModel, mergeModel, "MERGE"); for (final Entry, Invocation> entry : mergeModel.getInvocations()) { if (!ExecutionModelMerger.compareTupleOperationKeys(lastModel.getInvocations(), entry.getKey())) { final Invocation value = ExecutionModelCloneUtils.duplicate(deploymentModel, entry.getValue()); @@ -60,12 +67,87 @@ private static void mergeInvocations(final DeploymentModel deploymentModel, fina } } + private static void checkWhereResourceAreFrom(final DeploymentModel dm, final ExecutionModel em, + final String string) { + System.err.println("++++++ " + string); + em.getInvocations().forEach(entry -> { + checkPerOp(dm, entry.getKey().getFirst()); + checkPerOp(dm, entry.getKey().getSecond()); + checkPerOp(dm, entry.getValue().getCaller()); + checkPerOp(dm, entry.getValue().getCallee()); + }); + } + + private static void checkPerOp(final DeploymentModel dm, final DeployedOperation op) { + dm.getContexts().values().forEach(context -> { + context.getComponents().values().forEach(component -> { + final DeployedOperation dop = component.getOperations() + .get(op.getAssemblyOperation().getOperationType().getSignature()); + if (dop != null) { + if (dop != op) { + System.err.println("OP " + op.eResource()); + System.err.println("DOP " + dop.eResource()); + } else { + // System.err.println("context " + + // op.eContainer().eContainer().eContainer().eContainer()); + } + } + }); + }); + } + + private static void checkDeployment(final DeploymentModel deploymentModel, final String string) { + System.err.println("###### " + string); + deploymentModel.getContexts().forEach(entry -> { + System.err.println(" context " + entry.getKey()); + entry.getValue().getComponents().forEach(cEntry -> { + final DeployedComponent component = cEntry.getValue(); + if (component.getContext() == null) { + System.err.printf(" component %s has no context\n", component.getSignature()); + } + }); + }); + } + + private static void checkExecution(final ExecutionModel em, final String name) { + System.err.println("!!!!! " + name); + em.getInvocations().entrySet().forEach(m -> { + final Tuple key = m.getKey(); + final Invocation value = m.getValue(); + check(key.getFirst(), "first"); + check(key.getSecond(), "second"); + check(value.getCaller(), "caller"); + check(value.getCallee(), "callee"); + }); + } + + private static void check(final DeployedOperation op, final String string) { + final DeployedComponent dc = (DeployedComponent) op.eContainer().eContainer(); + if (dc == null) { + System.err.println( + ">> container " + op.getAssemblyOperation().getOperationType().getSignature() + " " + string); + return; + } + if (op.getComponent() == null) { + System.err.println( + ">> component " + op.getAssemblyOperation().getOperationType().getSignature() + " " + string); + return; + } + + if (dc.getAssemblyComponent().getComponentType() == null) { + System.err.println("shite " + string); + return; + } + + // System.err.println("op " + op.getAssemblyOperation().getOperationType().getSignature()); + } + private static boolean compareTupleOperationKeys( final EMap, Invocation> invocations, - final Tuple key) { + final Tuple searchKey) { for (final Tuple invocationKey : invocations.keySet()) { - if (ModelUtils.isEqual(invocationKey.getFirst(), key.getFirst()) - && ModelUtils.isEqual(invocationKey.getSecond(), key.getSecond())) { + if (ModelUtils.isEqual(invocationKey.getFirst(), searchKey.getFirst()) + && ModelUtils.isEqual(invocationKey.getSecond(), searchKey.getSecond())) { return true; } } diff --git a/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelRepositoryMergerUtils.java b/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelRepositoryMergerUtils.java index b3889b9..2c3a51c 100644 --- a/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelRepositoryMergerUtils.java +++ b/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelRepositoryMergerUtils.java @@ -48,6 +48,7 @@ public static void perform(final ModelRepository lastModelRepository, final Mode ExecutionModelMerger.mergeExecutionModel( lastModelRepository.getModel(DeploymentPackage.Literals.DEPLOYMENT_MODEL), lastModelRepository.getModel(ExecutionPackage.Literals.EXECUTION_MODEL), + mergeModelRepository.getModel(DeploymentPackage.Literals.DEPLOYMENT_MODEL), mergeModelRepository.getModel(ExecutionPackage.Literals.EXECUTION_MODEL)); StatisticsModelMerger.mergeStatisticsModel( lastModelRepository.getModel(ExecutionPackage.Literals.EXECUTION_MODEL), diff --git a/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelUtils.java b/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelUtils.java index af3dfca..419d37a 100644 --- a/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelUtils.java +++ b/tools/mop/src/main/java/org/oceandsl/tools/mop/merge/ModelUtils.java @@ -210,7 +210,7 @@ public static boolean isEqual(final String leftSignature, final String signature public static boolean isEqual(final DeploymentContext leftDeploymentContext, final DeploymentContext rightDeploymentContext) { ModelUtils.check(leftDeploymentContext, "left deployment context"); - ModelUtils.check(leftDeploymentContext, "right deployment context"); + ModelUtils.check(rightDeploymentContext, "right deployment context"); return leftDeploymentContext.getName().equals(rightDeploymentContext.getName()); } @@ -265,10 +265,13 @@ private static void isContained(final DeployedComponent component, final String check(component, signature); final EObject container = component.eContainer(); if (container == null) { - throw new InternalError("Container of " + signature + " is null"); + throw new InternalError("DC Container of " + signature + " is null" + component.eResource()); } if (container.eIsProxy()) { - throw new InternalError("Container of " + signature + " could not be resolved."); + throw new InternalError("DC Container of " + signature + " could not be resolved." + component.eResource()); + } + if (component.getContext() == null) { + throw new InternalError("DC Context " + signature + " is null " + component.eResource()); } } } diff --git a/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/MergeClosestFitComponentStage.java b/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/MergeClosestFitComponentStage.java index 3d176ae..9f1f9d0 100644 --- a/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/MergeClosestFitComponentStage.java +++ b/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/MergeClosestFitComponentStage.java @@ -26,8 +26,13 @@ import kieker.model.analysismodel.assembly.AssemblyModel; import kieker.model.analysismodel.assembly.AssemblyPackage; import kieker.model.analysismodel.deployment.DeployedComponent; +import kieker.model.analysismodel.deployment.DeployedOperation; import kieker.model.analysismodel.deployment.DeploymentModel; import kieker.model.analysismodel.deployment.DeploymentPackage; +import kieker.model.analysismodel.execution.ExecutionModel; +import kieker.model.analysismodel.execution.ExecutionPackage; +import kieker.model.analysismodel.execution.Invocation; +import kieker.model.analysismodel.execution.Tuple; import kieker.model.analysismodel.type.ComponentType; import kieker.model.analysismodel.type.TypeModel; import kieker.model.analysismodel.type.TypePackage; @@ -79,22 +84,64 @@ protected void execute(final ModelRepository repository) throws Exception { this.similarityOutputPort.send(this.makeTable(entries, repository.getName())); + // this.checkExecution(repository, "BEFORE"); + this.changeComponentNamesBasedOnBestFit(repository, entries); + + // this.checkExecution(repository, "AFTER"); } this.outputPort.send(repository); } + private void checkExecution(final ModelRepository repository, final String name) { + System.err.println("++ " + name); + final ExecutionModel em = repository.getModel(ExecutionPackage.Literals.EXECUTION_MODEL); + em.getInvocations().entrySet().forEach(m -> { + final Tuple key = m.getKey(); + final Invocation value = m.getValue(); + this.check(key.getFirst(), "first"); + this.check(key.getSecond(), "second"); + this.check(value.getCaller(), "caller"); + this.check(value.getCallee(), "callee"); + }); + } + + private void check(final DeployedOperation op, final String string) { + final DeployedComponent dc = (DeployedComponent) op.eContainer().eContainer(); + if (dc == null) { + System.err.println( + ">> container " + op.getAssemblyOperation().getOperationType().getSignature() + " " + string); + return; + } + if (op.getComponent() == null) { + System.err.println( + ">> component " + op.getAssemblyOperation().getOperationType().getSignature() + " " + string); + return; + } + + if (dc.getAssemblyComponent().getComponentType() == null) { + System.err.println("shite " + string); + return; + } + + if (dc.eContainer() == null) { + System.err.println(">> component NOT CONTAINED " + dc.getSignature()); + } + if (dc.getContext() == null) { + System.err.println(">> component NO CONTEXT " + dc.getSignature()); + } + } + private void ensureNoNameClashes(final List entries, final ModelRepository repository) { - final DeploymentModel model = repository.getModel(DeploymentPackage.Literals.DEPLOYMENT_MODEL); - model.getContexts().values().forEach(context -> { - context.getComponents().values().forEach(component -> { - entries.forEach(entry -> { - if (component.getSignature().equals(entry.getLeft().getSignature()) - && (component != entry.getRight())) { // NOPMD check really if identical - entry.increpementEqualNamesCount(); - } - }); - }); + final TypeModel model = repository.getModel(TypePackage.Literals.TYPE_MODEL); + // we need to ensure that the new name for a component is not already present in the + // model. + entries.forEach(entry -> { + final String signature = entry.getLeft().getSignature(); + final ComponentType component = model.getComponentTypes().get(signature); + if (component != null && entry.getRight() != component) { + entry.incrementEqualNamesCount(); + } }); } @@ -136,8 +183,8 @@ private void removeLesserFittingEntries(final List entries) { for (int j = i + 1; j < entries.size(); j++) { final SimilarityEntry next = entries.get(j); // really check if objects are identical - if ((current.getLeft() == next.getLeft()) || (current.getLeft() == next.getRight()) // NOPMD - || (current.getRight() == next.getLeft()) || (current.getRight() == next.getRight())) { // NOPMD + if (current.getLeft() == next.getLeft() || current.getLeft() == next.getRight() // NOPMD + || current.getRight() == next.getLeft() || current.getRight() == next.getRight()) { // NOPMD entries.remove(j); j--; // NOCS, NOPMD this is necessary due to list operations } @@ -182,7 +229,11 @@ private void changeComponentNamesBasedOnBestFit(final ModelRepository repository } private String makeName(final String signature, final int equalNamesCount) { - return String.format("%s_%d", signature, equalNamesCount); + if (equalNamesCount > 0) { + return String.format("%s_%d", signature, equalNamesCount); + } else { + return signature; + } } private Table makeTable(final List entries, final String name) { @@ -213,9 +264,9 @@ private void fixDeploymentSignature(final ModelRepository repository, final Stri final DeploymentModel model = repository.getModel(DeploymentPackage.Literals.DEPLOYMENT_MODEL); model.getContexts().values().forEach(context -> { final DeployedComponent component = context.getComponents().get(search); - context.getComponents().put(replacement, component); component.setSignature(replacement); context.getComponents().removeKey(search); + context.getComponents().put(replacement, component); }); } @@ -243,6 +294,6 @@ private double computeSimilarity(final ComponentType left, final ComponentType r final double leftMatch = leftSet.stream().filter(l -> rightSet.contains(l)).count(); final double rightMatch = rightSet.stream().filter(r -> leftSet.contains(r)).count(); - return ((leftMatch / leftSet.size()) + (rightMatch / rightSet.size())) / 2.0d; + return (leftMatch / leftSet.size() + rightMatch / rightSet.size()) / 2.0d; } } diff --git a/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/SimilarityEntry.java b/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/SimilarityEntry.java index 135f68f..43cc4e9 100644 --- a/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/SimilarityEntry.java +++ b/tools/mop/src/main/java/org/oceandsl/tools/mop/stages/SimilarityEntry.java @@ -79,7 +79,7 @@ public int getEqualNamesCount() { return this.equalNamesCount; } - public void increpementEqualNamesCount() { + public void incrementEqualNamesCount() { this.equalNamesCount++; } } \ No newline at end of file