use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.
the class SystemModification method modifySystemDeallocations.
public List<AssemblyContext> modifySystemDeallocations(final int deallocations) {
final List<AssemblyContext> deallocatedAssemblyContexts = new LinkedList<>();
final EList<AssemblyContext> assemblyContexts = this.systemModel.getAssemblyContexts__ComposedStructure();
final List<AssemblyConnector> assemblyConnectors = new ArrayList<>();
for (final Connector connector : this.systemModel.getConnectors__ComposedStructure()) {
if (connector instanceof AssemblyConnector) {
assemblyConnectors.add((AssemblyConnector) connector);
}
}
for (int i = 0; i < deallocations && assemblyContexts.size() > 0; i++) {
final int randomIndex = ThreadLocalRandom.current().nextInt(assemblyContexts.size());
final AssemblyContext assemblyContext = assemblyContexts.remove(randomIndex);
SystemModification.LOGGER.info("REMOVING: \tAssemblyContext: \t{}", assemblyContext.getId());
for (final AssemblyConnector assemblyConnector : assemblyConnectors) {
boolean removeAC = false;
if (assemblyConnector.getProvidingAssemblyContext_AssemblyConnector() == assemblyContext) {
final String interfaceID = assemblyConnector.getRequiredRole_AssemblyConnector().getRequiredInterface__OperationRequiredRole().getId();
if (!this.openRequiredInterfaces.containsKey(interfaceID)) {
this.openRequiredInterfaces.put(interfaceID, new ArrayList<AssemblyContext>());
}
// Add open required AC
this.openRequiredInterfaces.get(interfaceID).add(assemblyConnector.getRequiringAssemblyContext_AssemblyConnector());
removeAC = true;
} else if (assemblyConnector.getRequiringAssemblyContext_AssemblyConnector() == assemblyContext) {
final String interfaceID = assemblyConnector.getProvidedRole_AssemblyConnector().getProvidedInterface__OperationProvidedRole().getId();
if (!this.openProvidedInterfaces.containsKey(interfaceID)) {
this.openProvidedInterfaces.put(interfaceID, new ArrayList<AssemblyContext>());
}
// Add open providing AC
this.openProvidedInterfaces.get(interfaceID).add(assemblyConnector.getProvidingAssemblyContext_AssemblyConnector());
removeAC = true;
}
if (removeAC) {
this.systemModel.getConnectors__ComposedStructure().remove(assemblyConnector);
}
}
deallocatedAssemblyContexts.add(assemblyContext);
}
for (final AssemblyContext ac : deallocatedAssemblyContexts) {
this.removeInterfaceMaps(ac);
}
return deallocatedAssemblyContexts;
}
use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.
the class SystemModification method modifySystemChangeComp.
public int modifySystemChangeComp(final int changes) {
int madeChanges = 0;
// Copy the assembly context list
final EList<AssemblyContext> assemblyContextsList = this.systemModel.getAssemblyContexts__ComposedStructure();
final List<AssemblyContext> assemblyContexts = assemblyContextsList.stream().collect(Collectors.toList());
// Randomize the list!
Collections.shuffle(assemblyContexts);
// Iterate over random list
for (final AssemblyContext assemblyContext : assemblyContexts) {
final String interfaceSignature = this.caluclateInterfaceSignature(assemblyContext.getEncapsulatedComponent__AssemblyContext());
if (this.duplicateRepositoryComponents.containsKey(interfaceSignature)) {
// Duplicate to containing comp is available!
final List<RepositoryComponent> equalComponents = this.duplicateRepositoryComponents.get(interfaceSignature);
// Find non-self replacement
RepositoryComponent newRepoComp = null;
for (int j = 0; newRepoComp != null && j < equalComponents.size() * 10; j++) {
final int randomIndex = ThreadLocalRandom.current().nextInt(equalComponents.size());
final RepositoryComponent candidate = equalComponents.get(randomIndex);
if (!assemblyContext.getEncapsulatedComponent__AssemblyContext().getId().equals(candidate.getId())) {
newRepoComp = candidate;
}
}
if (newRepoComp != null) {
// Exchange containing comp
assemblyContext.setEncapsulatedComponent__AssemblyContext(newRepoComp);
madeChanges++;
if (madeChanges == changes) {
break;
}
}
}
}
return madeChanges;
}
use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.
the class SystemModelProviderTest method createThenUpdateThenReadUpdated.
@Override
@Test
public void createThenUpdateThenReadUpdated() {
final ModelProvider<System> modelProvider = new ModelProvider<>(SystemModelProviderTest.GRAPH);
final TestModelBuilder testModelBuilder = new TestModelBuilder();
final System writtenModel = testModelBuilder.getSystem();
final System readModel;
modelProvider.createComponent(writtenModel);
// Update the model by renaming and removing the business context
writtenModel.setEntityName("MyVideoOnDemandService");
writtenModel.getAssemblyContexts__ComposedStructure().remove(testModelBuilder.getBusinessOrderAssemblyContext());
writtenModel.getConnectors__ComposedStructure().remove(testModelBuilder.getBusinessQueryInputConnector());
writtenModel.getConnectors__ComposedStructure().remove(testModelBuilder.getBusinessPayConnector());
// Replace the business context by a context for groups of people placing an order
final AssemblyContext sharedOrderContext = CompositionFactory.eINSTANCE.createAssemblyContext();
final AssemblyConnector sharedQueryInputConnector = CompositionFactory.eINSTANCE.createAssemblyConnector();
final AssemblyConnector sharedPayConnector = CompositionFactory.eINSTANCE.createAssemblyConnector();
sharedOrderContext.setEntityName("sharedOrderContext_org.myvideoondemandservice.orderComponent");
sharedQueryInputConnector.setEntityName("sharedQueryInput");
sharedQueryInputConnector.setProvidedRole_AssemblyConnector(testModelBuilder.getProvidedInputOperation());
sharedQueryInputConnector.setRequiredRole_AssemblyConnector(testModelBuilder.getRequiredInputOperation());
sharedQueryInputConnector.setProvidingAssemblyContext_AssemblyConnector(sharedOrderContext);
sharedQueryInputConnector.setRequiringAssemblyContext_AssemblyConnector(testModelBuilder.getQueryInputAssemblyContext());
sharedPayConnector.setEntityName("sharedPayment");
sharedPayConnector.setProvidedRole_AssemblyConnector(testModelBuilder.getProvidedPayOperation());
sharedPayConnector.setRequiredRole_AssemblyConnector(testModelBuilder.getRequiredPayOperation());
sharedPayConnector.setProvidingAssemblyContext_AssemblyConnector(testModelBuilder.getPaymentAssemblyContext());
sharedPayConnector.setRequiringAssemblyContext_AssemblyConnector(sharedOrderContext);
writtenModel.getAssemblyContexts__ComposedStructure().add(sharedOrderContext);
writtenModel.getConnectors__ComposedStructure().add(sharedQueryInputConnector);
writtenModel.getConnectors__ComposedStructure().add(sharedPayConnector);
modelProvider.updateComponent(System.class, writtenModel);
readModel = modelProvider.readOnlyRootComponent(System.class);
Assert.assertTrue(this.equalityHelper.equals(writtenModel, readModel));
}
use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.
the class SystemModelProviderTest method createThenReadContaining.
@Override
@Test
public void createThenReadContaining() {
final ModelProvider<System> modelProvider = new ModelProvider<>(SystemModelProviderTest.GRAPH);
final System writtenModel = new TestModelBuilder().getSystem();
final System readModel;
final AssemblyContext ac = writtenModel.getAssemblyContexts__ComposedStructure().get(0);
modelProvider.createComponent(writtenModel);
readModel = (System) modelProvider.readOnlyContainingComponentById(AssemblyContext.class, ac.getId());
Assert.assertTrue(this.equalityHelper.equals(writtenModel, readModel));
}
Aggregations