Search in sources :

Example 61 with AssemblyContext

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;
}
Also used : AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) Connector(org.palladiosimulator.pcm.core.composition.Connector) AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) ArrayList(java.util.ArrayList) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) LinkedList(java.util.LinkedList)

Example 62 with AssemblyContext

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;
}
Also used : AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) RepositoryComponent(org.palladiosimulator.pcm.repository.RepositoryComponent)

Example 63 with AssemblyContext

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));
}
Also used : AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) System(org.palladiosimulator.pcm.system.System) Test(org.junit.Test)

Example 64 with AssemblyContext

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));
}
Also used : AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) System(org.palladiosimulator.pcm.system.System) Test(org.junit.Test)

Aggregations

AssemblyContext (org.palladiosimulator.pcm.core.composition.AssemblyContext)64 AllocationContext (org.palladiosimulator.pcm.allocation.AllocationContext)16 RepositoryComponent (org.palladiosimulator.pcm.repository.RepositoryComponent)11 ArrayList (java.util.ArrayList)9 ResourceContainer (org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)9 AssemblyConnector (org.palladiosimulator.pcm.core.composition.AssemblyConnector)8 System (org.palladiosimulator.pcm.system.System)8 Test (org.junit.Test)7 Connector (org.palladiosimulator.pcm.core.composition.Connector)7 OperationProvidedRole (org.palladiosimulator.pcm.repository.OperationProvidedRole)6 HashSet (java.util.HashSet)5 EObject (org.eclipse.emf.ecore.EObject)5 Allocation (org.palladiosimulator.pcm.allocation.Allocation)5 DataPrivacyLvl (org.palladiosimulator.pcm.compositionprivacy.DataPrivacyLvl)5 OperationRequiredRole (org.palladiosimulator.pcm.repository.OperationRequiredRole)5 ProvidedRole (org.palladiosimulator.pcm.repository.ProvidedRole)5 HashMap (java.util.HashMap)4 AssemblyEntry (org.iobserve.model.correspondence.AssemblyEntry)4 RequiredRole (org.palladiosimulator.pcm.repository.RequiredRole)4 URL (java.net.URL)3