Skip to content

Commit

Permalink
Fixed merge issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reiner Jung committed Aug 18, 2023
1 parent 835e0b6 commit fdbd226
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Tuple<DeployedOperation, DeployedOperation>, Invocation> entry : mergeModel.getInvocations()) {
if (!ExecutionModelMerger.compareTupleOperationKeys(lastModel.getInvocations(), entry.getKey())) {
final Invocation value = ExecutionModelCloneUtils.duplicate(deploymentModel, entry.getValue());
Expand All @@ -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<DeployedOperation, DeployedOperation> 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<Tuple<DeployedOperation, DeployedOperation>, Invocation> invocations,
final Tuple<DeployedOperation, DeployedOperation> key) {
final Tuple<DeployedOperation, DeployedOperation> searchKey) {
for (final Tuple<DeployedOperation, DeployedOperation> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DeployedOperation, DeployedOperation> 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<SimilarityEntry> 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();
}
});
}

Expand Down Expand Up @@ -136,8 +183,8 @@ private void removeLesserFittingEntries(final List<SimilarityEntry> 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
}
Expand Down Expand Up @@ -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<String, SimilarityEntry> makeTable(final List<SimilarityEntry> entries, final String name) {
Expand Down Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public int getEqualNamesCount() {
return this.equalNamesCount;
}

public void increpementEqualNamesCount() {
public void incrementEqualNamesCount() {
this.equalNamesCount++;
}
}

0 comments on commit fdbd226

Please sign in to comment.