Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arc3n integration into Modernized Impact Analysis #4

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bundles/dev.abunai.impact.analysis/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ Bundle-Name: Uncertainty Impact Analysis
Bundle-SymbolicName: edu.kit.kastel.dsis.uncertainty.impactanalysis
Bundle-Version: 1.0.0.qualifier
Export-Package: dev.abunai.impact.analysis,
dev.abunai.impact.analysis.interactive,
dev.abunai.impact.analysis.model,
dev.abunai.impact.analysis.model.impact,
dev.abunai.impact.analysis.util
Require-Bundle: org.eclipse.core.runtime,
org.dataflowanalysis.analysis;bundle-version="1.0.0";visibility:=reexport,
org.dataflowanalysis.analysis.pcm;bundle-version="1.0.0";visibility:=reexport
org.dataflowanalysis.analysis.pcm;bundle-version="1.0.0";visibility:=reexport,
com.fasterxml.jackson.core.jackson-databind,
com.fasterxml.jackson.core.jackson-core,
org.dataflowanalysis.pcm.extension.nodecharacteristics,
com.fasterxml.jackson.core.jackson-annotations
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: edu.kit.kastel.dsis.uncertainty.impactanalysis
Bundle-ActivationPolicy: lazy
16 changes: 16 additions & 0 deletions bundles/dev.abunai.impact.analysis/dev.abunai.impact.analysis.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
<orderEntry type="module" module-name="org.dataflowanalysis.analysis" />
<orderEntry type="module" module-name="org.dataflowanalysis.analysis.pcm" />
<orderEntry type="module" module-name="dev.abunai.impact.analysis.testmodels" />
<orderEntry type="library" name="ECLIPSE" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.abunai.impact.analysis;

import dev.abunai.impact.analysis.interactive.InteractiveAnalysisHandler;
import dev.abunai.impact.analysis.testmodels.Activator;

import java.io.IOException;
import java.nio.file.Paths;

public class ImpactAnalysisCLI {
private static final String MODEL_PATH = "models/BranchingOnlineShop/default";
public static final String TEST_MODEL_PROJECT_NAME = "dev.abunai.impact.analysis.testmodels";

public static void main(String[] args) throws IOException {
final var usageModelPath = Paths.get(MODEL_PATH + ".usagemodel")
.toString();
final var allocationPath = Paths.get(MODEL_PATH + ".allocation")
.toString();
final var nodeCharacteristicsPath = Paths
.get(MODEL_PATH + ".nodecharacteristics").toString();

var builder = new PCMUncertaintyImpactAnalysisBuilder().standalone().modelProjectName(TEST_MODEL_PROJECT_NAME)
.usePluginActivator(Activator.class).useUsageModel(usageModelPath).useAllocationModel(allocationPath)
.useNodeCharacteristicsModel(nodeCharacteristicsPath);

var analysis = ((PCMUncertaintyImpactAnalysisBuilder) builder).build();
analysis.initializeAnalysis();
new InteractiveAnalysisHandler(analysis).handle();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package dev.abunai.impact.analysis;

import java.util.List;
import java.util.Optional;

import org.dataflowanalysis.analysis.pcm.core.PCMFlowGraphCollection;
import org.eclipse.core.runtime.Plugin;
import org.dataflowanalysis.analysis.core.ActionSequence;
import org.dataflowanalysis.analysis.core.DataCharacteristicsCalculatorFactory;
import org.dataflowanalysis.analysis.core.NodeCharacteristicsCalculator;
import org.dataflowanalysis.analysis.pcm.PCMDataFlowConfidentialityAnalysis;
import org.dataflowanalysis.analysis.pcm.resource.PCMResourceProvider;

Expand All @@ -16,28 +13,20 @@

public class PCMUncertaintyImpactAnalysis extends PCMDataFlowConfidentialityAnalysis {

private List<ActionSequence> actionSequences = null;
private PropagationHelper propagationHelper = null;
private UncertaintySourceCollection uncertaintySourceCollection = null;
private UncertaintySourceCollection uncertaintySourceCollection = null;

public PCMUncertaintyImpactAnalysis(NodeCharacteristicsCalculator nodeCharacteristicsCalculator,
DataCharacteristicsCalculatorFactory dataCharacteristicsCalculatorFactory,
PCMResourceProvider resourceProvider, String modelProjectName,
Optional<Class<? extends Plugin>> modelProjectActivator) {
super(nodeCharacteristicsCalculator, dataCharacteristicsCalculatorFactory, resourceProvider, modelProjectName,
public PCMUncertaintyImpactAnalysis(PCMResourceProvider resourceProvider, String modelProjectName,
Optional<Class<? extends Plugin>> modelProjectActivator) {
super(resourceProvider, modelProjectName,
modelProjectActivator);
}

@Override
public boolean initializeAnalysis() {
if (super.initializeAnalysis()) {
this.actionSequences = super.findAllSequences();
this.propagationHelper = new PropagationHelper(this.actionSequences, this.resourceProvider);
this.uncertaintySourceCollection = new UncertaintySourceCollection(this.actionSequences, propagationHelper);
return true;
} else {
return false;
}
public void initializeAnalysis() {
super.initializeAnalysis();
PCMFlowGraphCollection flowGraphs = super.findFlowGraphs();
PropagationHelper propagationHelper = new PropagationHelper(flowGraphs, this.resourceProvider);
this.uncertaintySourceCollection = new UncertaintySourceCollection(flowGraphs, propagationHelper);
}

public UncertaintySourceCollection getUncertaintySources() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dev.abunai.impact.analysis;

import org.dataflowanalysis.analysis.pcm.PCMDataFlowConfidentialityAnalysisBuilder;
import org.dataflowanalysis.analysis.pcm.core.PCMDataCharacteristicsCalculatorFactory;
import org.dataflowanalysis.analysis.pcm.core.PCMNodeCharacteristicsCalculator;
import org.dataflowanalysis.analysis.pcm.resource.PCMResourceProvider;
import org.dataflowanalysis.analysis.pcm.resource.PCMURIResourceProvider;
import org.dataflowanalysis.analysis.utils.ResourceUtils;
Expand All @@ -16,8 +14,7 @@ public PCMUncertaintyImpactAnalysis build() {
ResourceUtils.createRelativePluginURI(relativeUsageModelPath, modelProjectName),
ResourceUtils.createRelativePluginURI(relativeAllocationModelPath, modelProjectName),
ResourceUtils.createRelativePluginURI(relativeNodeCharacteristicsPath, modelProjectName));
return new PCMUncertaintyImpactAnalysis(new PCMNodeCharacteristicsCalculator(resourceProvider),
new PCMDataCharacteristicsCalculatorFactory(resourceProvider), resourceProvider, modelProjectName,
return new PCMUncertaintyImpactAnalysis(resourceProvider, modelProjectName,
pluginActivator);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.abunai.impact.analysis.interactive;

import java.util.NoSuchElementException;

enum ArchitecturalElementType {

//From https://github.com/abunai-dev/UncertaintySourceArchive/blob/main/UncertaintySourceArchive/src/model/categories/options/ArchitecturalElementTypeOptions.ts
COMPONENT("Component"),
CONNECTOR("Connector"),
INTERFACE("Interface"),
EXTERNAL_RESOURCE("External"),
BEHAVIOR_DESCRIPTION("Behavior");

private final String jsonName;

private ArchitecturalElementType(String jsonName) {
this.jsonName = jsonName;
}

public static ArchitecturalElementType getFromName(String jsonName) {
for (ArchitecturalElementType element : ArchitecturalElementType.values()) {
if (element.jsonName.equals(jsonName)) {
return element;
}
}

throw new NoSuchElementException(String.format("No element with name %s found.", jsonName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package dev.abunai.impact.analysis.interactive;

import java.util.ArrayList;
import java.util.List;

import org.palladiosimulator.pcm.core.entity.Entity;
import org.palladiosimulator.pcm.seff.BranchAction;
import org.palladiosimulator.pcm.seff.ExternalCallAction;
import org.palladiosimulator.pcm.seff.SeffPackage;
import org.palladiosimulator.pcm.seff.SetVariableAction;
import org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall;
import org.palladiosimulator.pcm.usagemodel.UsagemodelPackage;

import dev.abunai.impact.analysis.PCMUncertaintyImpactAnalysis;

public class BehaviorEntityLookup extends EntityLookup {

private final List<ExternalCallAction> externalCalls;
private final List<EntryLevelSystemCall> entryLevelSystemCalls;
private final List<SetVariableAction> setVariableActions;
private final List<BranchAction> branchActions;

public BehaviorEntityLookup(PCMUncertaintyImpactAnalysis analysis) {
super(analysis);

externalCalls = findAllElementsOfType(SeffPackage.eINSTANCE.getExternalCallAction(), ExternalCallAction.class);
entryLevelSystemCalls = findAllElementsOfType(UsagemodelPackage.eINSTANCE.getEntryLevelSystemCall(), EntryLevelSystemCall.class);
setVariableActions = findAllElementsOfType(SeffPackage.eINSTANCE.getSetVariableAction(), SetVariableAction.class);
branchActions = findAllElementsOfType(SeffPackage.eINSTANCE.getBranchAction(), BranchAction.class);
}

@Override
public List<Entity> getEntities() {
List<Entity> result = new ArrayList<>();
result.addAll(externalCalls);
result.addAll(entryLevelSystemCalls);
result.addAll(setVariableActions);
result.addAll(branchActions);
return result;
}

@Override
public void addToAnalysis(int index) {
int currentIndex = index;
if (currentIndex < externalCalls.size()) {
analysis.getUncertaintySources().addBehaviorUncertaintyInExternalCallAction(externalCalls.get(currentIndex).getId());
return;
}
currentIndex -= externalCalls.size();

if (currentIndex < entryLevelSystemCalls.size()) {
analysis.getUncertaintySources().addBehaviorUncertaintyInEntryLevelSystemCall(entryLevelSystemCalls.get(currentIndex).getId());
return;
}
currentIndex -= entryLevelSystemCalls.size();

if (currentIndex < setVariableActions.size()) {
analysis.getUncertaintySources().addBehaviorUncertaintyInSetVariableAction(setVariableActions.get(currentIndex).getId());
return;
}
currentIndex -= setVariableActions.size();

analysis.getUncertaintySources().addBehaviorUncertaintyInBranch(branchActions.get(currentIndex).getId());

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.abunai.impact.analysis.interactive;

import java.util.List;

import org.palladiosimulator.pcm.core.composition.AssemblyContext;
import org.palladiosimulator.pcm.core.composition.CompositionPackage;
import org.palladiosimulator.pcm.core.entity.Entity;

import dev.abunai.impact.analysis.PCMUncertaintyImpactAnalysis;

class ComponentEntityLookup extends EntityLookup {

private final List<AssemblyContext> assemblyContexts;

public ComponentEntityLookup(PCMUncertaintyImpactAnalysis analysis) {
super(analysis);

assemblyContexts = findAllElementsOfType(CompositionPackage.eINSTANCE.getAssemblyContext(), AssemblyContext.class);
}

@Override
public List<Entity> getEntities() {
return assemblyContexts.stream().map(e -> (Entity)e).toList();
}

@Override
public void addToAnalysis(int index) {
analysis.getUncertaintySources().addComponentUncertaintyInAssemblyContext(assemblyContexts.get(index).getId());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.abunai.impact.analysis.interactive;

import java.util.List;
import java.util.ArrayList;

import org.palladiosimulator.pcm.core.composition.AssemblyConnector;
import org.palladiosimulator.pcm.core.composition.CompositionPackage;
import org.palladiosimulator.pcm.core.composition.ProvidedDelegationConnector;
import org.palladiosimulator.pcm.core.entity.Entity;

import dev.abunai.impact.analysis.PCMUncertaintyImpactAnalysis;

public class ConnectorEntityLookup extends EntityLookup {

private final List<AssemblyConnector> assemblyConnectors;
private final List<ProvidedDelegationConnector> providedDelegationConnector;

public ConnectorEntityLookup(PCMUncertaintyImpactAnalysis analysis) {
super(analysis);

assemblyConnectors = findAllElementsOfType(CompositionPackage.eINSTANCE.getAssemblyConnector(), AssemblyConnector.class);
providedDelegationConnector = findAllElementsOfType(CompositionPackage.eINSTANCE.getProvidedDelegationConnector(), ProvidedDelegationConnector.class);
}

@Override
public List<Entity> getEntities() {
List<Entity> result = new ArrayList<>();
result.addAll(assemblyConnectors);
result.addAll(providedDelegationConnector);
return result;
}

@Override
public void addToAnalysis(int index) {
if (index < assemblyConnectors.size()) {
analysis.getUncertaintySources().addConnectorUncertaintyInConnector(assemblyConnectors.get(index).getId());
} else {
analysis.getUncertaintySources().addConnectorUncertaintyInConnector(providedDelegationConnector.get(index - assemblyConnectors.size()).getId());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.abunai.impact.analysis.interactive;

import java.util.List;
import java.util.ArrayList;
import org.eclipse.emf.ecore.EObject;

import dev.abunai.impact.analysis.PCMUncertaintyImpactAnalysis;
import org.eclipse.emf.ecore.EClass;
import org.palladiosimulator.pcm.core.entity.Entity;

abstract class EntityLookup {

protected final PCMUncertaintyImpactAnalysis analysis;

public EntityLookup(PCMUncertaintyImpactAnalysis analysis) {
this.analysis = analysis;
}

public abstract List<Entity> getEntities();

public abstract void addToAnalysis(int index);

protected <T extends Entity> List<T> findAllElementsOfType(EClass targetType, Class<T> targetClass) {
ArrayList<EObject> result = new ArrayList<EObject>();

while (true) {
var element = analysis.getResourceProvider()
.lookupElementWithCondition(it -> it.eClass().equals(targetType) && !result.contains(it));

if (element.isPresent()) {
result.add(element.get());
} else {
break;
}
}

return result.stream().filter(targetClass::isInstance).map(targetClass::cast).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.abunai.impact.analysis.interactive;

import java.util.ArrayList;
import java.util.List;

import org.dataflowanalysis.pcm.extension.nodecharacteristics.nodecharacteristics.NodeCharacteristicsPackage;
import org.dataflowanalysis.pcm.extension.nodecharacteristics.nodecharacteristics.ResourceAssignee;
import org.dataflowanalysis.pcm.extension.nodecharacteristics.nodecharacteristics.UsageAssignee;
import org.palladiosimulator.pcm.core.entity.Entity;

import dev.abunai.impact.analysis.PCMUncertaintyImpactAnalysis;

class ExternalEntityLookup extends EntityLookup {

private final List<ResourceAssignee> resourceAssignees;
private final List<UsageAssignee> usageAssignees;

public ExternalEntityLookup(PCMUncertaintyImpactAnalysis analysis) {
super(analysis);

resourceAssignees = findAllElementsOfType(NodeCharacteristicsPackage.eINSTANCE.getResourceAssignee(), ResourceAssignee.class);
usageAssignees = findAllElementsOfType(NodeCharacteristicsPackage.eINSTANCE.getUsageAssignee(), UsageAssignee.class);

}

@Override
public List<Entity> getEntities() {
List<Entity> results = new ArrayList<>();
results.addAll(resourceAssignees);
results.addAll(usageAssignees);
return results;
}

@Override
public void addToAnalysis(int index) {
if (index < resourceAssignees.size()) {
analysis.getUncertaintySources().addActorUncertaintyInResourceContainer(resourceAssignees.get(index).getId());
} else {
analysis.getUncertaintySources().addActorUncertaintyInResourceContainer(usageAssignees.get(index - resourceAssignees.size()).getId());
}
}

}
Loading